在Sencha Touch + Cordova项目中预填充SQLite DB [英] PrePopulate SQLite DB in Sencha Touch + Cordova project

查看:161
本文介绍了在Sencha Touch + Cordova项目中预填充SQLite DB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Sencha Touch项目,我需要使用预填充的数据包打包应用程序。我正在使用Cordova-SQLitePlugin( https://github.com/brodysoft/Cordova-SQLitePlugin ) )作为cordova插件使用SQLite作为本地数据库,我一直在寻找的方式实现我的目标预先准备数据库,但没有成功。我发现是博客建议复制DB在一个cordova文件夹,它应该是神奇的工作,但我没有运气,我猜,这与我的项目是一个Sencha Touch + Cordova项目有关。



到目前为止,我所做的是运行应用程序的第一次启动的所有查询,并填充应用程序,但事情是我有50k插入所以它真的使代码可怕,我可以通过打包的应用程序与数据库准备使用,可以节省用户的时间它需要做的那些插入。



有人知道一个解决方案?

解决方案

是的!



我从Sencha论坛的一个家伙得到了一些帮助,他指着我在一个repo他发布在github上的一个Antair的例子Cordite插件Cordova。 / p>

这里是指向任何人需要的回购链接: https ://github.com/Yoinbol/SqlitePopulated



DB放置在cordova / www / db / folder(必须创建db文件夹)。
在cordova / www / resources / scripts /下有一个名为importdb.js的文件,它侦听deviceready并在触发时加载db。 (我不得不改变importIfExists从false到true在这里使其工作)
在Main.js控制器中有一个如何打开数据库的例子,如果任何人需要的话。



无论如何,希望这可以帮助任何人在有需要的时候,感谢Diego加西亚在Sencha论坛的帮助。


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?

解决方案

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.

这篇关于在Sencha Touch + Cordova项目中预填充SQLite DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆