PrePopulate SQLite DB in Sencha Touch + Cordova project

折月煮酒 提交于 2019-12-08 11:58:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!