问题
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:
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.
来源:https://stackoverflow.com/questions/28154173/prepopulate-sqlite-db-in-sencha-touch-cordova-project