SQLite—Where is the .db file stored?


#1

This question came up on a blog post comment (see https://developer.telerik.com/products/nativescript/going-off-the-grid-with-nativescript/#comment-3430959241), and I was curious about this as well.

When you’re using SQLite where does your actual .db file get stored, and does it persist after you delete the app?

Thanks!


#2

[Android]
According to this SO post https://stackoverflow.com/questions/9227110/android-where-is-sqlite-database-stored the database chunks are stored in the application-specific data directory. What this means is that the database will be completely wiped if and when the application is removed. In the case where AutoBackUp - https://developer.android.com/guide/topics/data/backup.html is enabled, a DB file of up to 25MB of size will be restored on subsequent installation of the same application.


#3

I can confirm the database will not persist after uninstalling the app and on android is stored in /data/data/org.nativescript.myAppName/databases/

You can ship a database in your app directory and copy it to the databases folder. You can also download an sqlite database and move it into the databases folder using code found here if you prefer not to embed it.


#4

Hi Tj,
the db file is saved inside Documents folder for iOS. I use to open it when I’m working on it just to be sure everything is created as expected. You can use this awesome little tool to edit it http://sqlitebrowser.org/

The database (asume you are using ios simulator) is saved in simulator device so:

  1. Open Finder and click Go->go to folder ~/Library/Developer/CoreSimulator/Devices/
  2. That will open many devices if you are using simulator a lot. From there the “best” (read fastest) way to find your database is to search exact name example “test.db”, and it will popup somewhere deep in App Documents like this:

As database is saved as a part of your app, when you delete the app, database is also deleted, I use this method frequently when I need to “fake” new install and setup.
Hope it helps
davor


#5

Thanks all! This has been super helpful and exactly what I needed :smile: