cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

How to include a sqlite database in a snap

How to include a sqlite database in a snap

mvial
Member

Hey guys, I am writing an app that looks up information in a sqlite database and forwards it via datalayer to the PLC application running on the core. However I am unsure on how to include the database in the snap. I've tried using the layout feature in the snap.yaml to create a symlink to the database but I am not sure if this is the correctr approach 

mvial_0-1703000909746.png

I am also currently dynamically setting the path in the main program but when I print the path to the log I don't see the snap_data directory being used any thoughts are appreciated.

mvial_1-1703001033318.pngmvial_2-1703001063159.png

 

4 REPLIES 4

Sgilk
Contributor

Hello @mvial ,

When you say include the database, do you mean copy an existing database into the application, or connect to an external database?

There are many ways to do this, but I would think you could simply copy the database using the dump plugin. See this example from the SDK.

  configs:
    plugin: dump
    source: ./configs
    organize:
      'package-assets/*': package-assets/${SNAPCRAFT_PROJECT_NAME}/

This plugin copies the files from the build /configs directory and places the package-assets file within the app folder package-assets/${SNAPCRAFT_PROJECT_NAME}/

Thank you @Sgilk I can see that the .db has been included in the snap now the issue I'm having is trying to find the database in relation to where my main.py is executing. I don't really understand how the file structure is arranged within the snap

The snapcraft stage directory, created on build, is useful for this. It shows the file structure within the application. In this case, I have placed source files in directories of the same name within the snap, using the dump plugin.

Sgilk_0-1703012577438.png

@Sgilk thanks a bunch, after some guess and check I was able to find where it is in relation to the main.py. I can now stop banging my head against the wall.

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist