
Android remote sqlite database download#
Inside the downloadDatabase we download the JSON file from the beginning, make sure the JSON is valid for the import and then import the whole data into our SQLite database (or better, the database will actually be created with that name). Now go ahead and change the app/services/ to:Īwait CapacitorSQLite. So within the setupDatabase we either start the download and import, or if we already did it before we can directly open the database (based on the name we stored).Īdditionally I added a BehaviorSubject so we can subscribe to the database stead and not perform any queries before it’s ready. This is just a very rough idea in here, it really depends on your case: Do you want to get the latest data on every app start? Do you just need the remote data once to seed the app? Think about what you need inside your app and then build out the logic for your needs.



I’ve also added a bit of logic to store the name of the database (retrieved from the previous JSON file) inside Capacitor Storage, and also keep track whether we have already synced the initial data. Now our app can pull in that data and seed the initial SQLite database! Building a Database Serviceīefore we dive into the pages, let’s create the logic for the app upfront.īefore you can actually use the database, you should check whether you are running on Android, since you need to request permissions in that case!
