Which directory should I put an sqlite3 database? #1776
-
I would like to use an Sqlite3 database which already contains tables and data from another project. My goal is to create an Android app which uses the database, and I'm following the Beeware tutorials as a guide. Which directory should I copy the database into? Related question: In the app.py, should I use the full directory path to the database, or a relative path? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Any folder inside your app package will be accessible at runtime, so that's as good a place as any to put content like SQLite databases. You definitley need to use an absolute path for any reference to that database file - A toga app can't guarantee what the current working directory will be at runtime, as it will vary between platforms (and in the case of mobile deployments, will depend on the specific installation), so relative paths will be ambiguous at best. To assist with this, the Toga app instance has a |
Beta Was this translation helpful? Give feedback.
Any folder inside your app package will be accessible at runtime, so that's as good a place as any to put content like SQLite databases.
You definitley need to use an absolute path for any reference to that database file - A toga app can't guarantee what the current working directory will be at runtime, as it will vary between platforms (and in the case of mobile deployments, will depend on the specific installation), so relative paths will be ambiguous at best.
To assist with this, the Toga app instance has a
paths
attribute that contains a useful path roots that you can work off. For example, in yourstartup()
method, you can referenceself.paths.app
- that will be a Pathlib object prov…