How to implement an SQLite database in Phonegap? How to implement an SQLite database in Phonegap? sqlite sqlite

How to implement an SQLite database in Phonegap?


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 connectionvar lawnchair = new Lawnchair({table:'mytable', adaptor:'webkit'}, function(){    // Lawnchair setup! });// Getting some data out of the lawnchair databaselawnchair.get('my_data_key', function(obj) {    if (obj !== undefined) {        lastSyncDate = obj.lastSync;        dataList = obj.dataList;    }});// Saving to the databaselawnchair.save({key:'my_data_key', lastSync: currentTime, dataList: someData});


The PhoneGap documentation on storage is pretty explicit here, and includes some example code. The storage API is modelled on the Javascript API developed under HTML5 used in Opera and Webkit. Here's the relevant page:

Original 2011 link: http://docs.phonegap.com/phonegap_storage_storage.md.html

2017 update: now all out of date, but see this:http://docs.phonegap.com/en/1.2.0/phonegap_storage_storage.md.html