0
votes

I'm working on a Sencha Touch project and I'm in need to pack the app with a prepopulated DB. I'm using Cordova-SQLitePlugin (https://github.com/brodysoft/Cordova-SQLitePlugin) as a cordova plugin to use SQLite as a local DB and I've been looking around for ways of achieving my goal of prepopulating the DB but with no success. What I've found are blogs suggesting to copy the DB in a cordova folder and it's supposed to magically work but I haven't had any luck and I'm guessing it has something to do with my project being a Sencha Touch + Cordova project.

What I've done so far is run all the queries on the app's first launch and populate the app there, but the things is I have like 50k inserts to do so it really makes the code awful and I could spare the user the time it takes to do those inserts by packing the app with the DB ready to use.

Does anyone know a way around this?

1
I have found some links that I hope should get you moving in the right direction. This link is old but talks about the process of setting and using a pre-populated database. Also the blogs on his website are good if u need help on Phonegap/cordova. This link discusses adding the feature in the plugin. This link has the prepopulation feature added to it. Hope it helps.frank
I will check that Antair plugin you suggested in the last link. I've been through the first link though and it's pretty much "male cow maneuer" (if you know what I mean). I'll let you know if I had any success with that last plugin, it might take a while though. Thanks for your comment!martskins
Nope, I'm either an idiot or this is not workingmartskins
This link as per the documentation copies the sqlite db to the respective location. I hav'nt tried it myself.frank
Maybe this would help you? It is geared towards Ionic Framework, but for the most part will work with anything. blog.nraboy.com/2015/01/…Nic Raboy

1 Answers

0
votes

Ok! Did it!

I got some help from a guy at Sencha forums and he pointed me to a repo he posted on github with an example of Antair's SQLite plugin for Cordova.

Here's the link to the repo in case anyone needs it: https://github.com/Yoinbol/SqlitePopulated

The DB is placed at cordova/www/db/ folder (db folder must be created). There's a file named importdb.js at cordova/www/resources/scripts/ that listens to deviceready and loads the db when it fires. (I had to change importIfExists from false to true in here to make it work) In the Main.js controller there's an example of how to open the DB in case anyone needs that too.

Anyway, hope this helps anyone in need sometime and thanks to Diego Garcia at Sencha forums for the help.