如何实现在PhoneGap的SQLite数据库? [英] How to implement an SQLite database in Phonegap?
问题描述
我实现了跨平台的应用程序为Android,IOS和黑莓。我使用PhoneGap的产生本地语言版本为每个平台。我想知道如何创建,访问和搜索SQLite数据库。
I'm implementing a cross-platform app for Android, iOS, and BlackBerry. I'm using PhoneGap to produce native language versions for each platform. I want to know how to create, access, and search a SQLite database.
我读过,它可以通过一个JavaScript文件中创建的文档中,但我想知道在哪里放置文件,以及如何引用它在code。
I've read in the documentation that it can be created via a Javascript file but I want to know where to place that file and how to reference it in the code.
推荐答案
看看Lawnchair(的http://布赖恩.IO / lawnchair / ),它的pretty的易于使用,即开即用的盒可能确实大部分你所需要(包括搜索),它是跨浏览器,作战测试,并很好地降低通过使用适配器。有黑莓一个适配器,以及支持查询一个插件。下面是使用WebKit的适配器,这是很好的Android和iPhone简单的例子,以显示它是多么的简单。
Take a look at Lawnchair (http://brian.io/lawnchair/), its pretty easy to use and out-of-the box probably does most of what you need (including searching), it's cross-browser, battle tested and degrades nicely through the use of adapters. There is an adapter for Blackberry, and a plugin that supports queries. Here is quick example using the webkit adapter, which is good for Android and iPhone, to show how simple it is.
<script type="text/javascript" src="Lawnchair.js" charset="utf-8"></script>
<script type="text/javascript" src="webkit-sqlite.js" charset="utf-8"></script>
// Open local DB connection
var lawnchair = new Lawnchair({table:'mytable', adaptor:'webkit'}, function(){
// Lawnchair setup!
});
// Getting some data out of the lawnchair database
lawnchair.get('my_data_key', function(obj) {
if (obj !== undefined) {
lastSyncDate = obj.lastSync;
dataList = obj.dataList;
}
});
// Saving to the database
lawnchair.save({key:'my_data_key', lastSync: currentTime, dataList: someData});
这篇关于如何实现在PhoneGap的SQLite数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!