PouchDB on PhoneGap

PouchDB is a portable database that uses IndexedDB for storage on the client. This post demonstrates how PouchDB can be used in a Phonegap (Cordova 2.2.0) based application for storing data, and syncing it to a remote couch server - https://bitbucket.org/axemclion/pouchdb-phonegap-ios/src

I had written about using Jquery-IndexedDB as a local database solution on Cordova(Phonegap) for iOS and Android, and how it was done using the IndexedDBShim. This post extends the idea and shows how pouchdb can be used on an iOS based Phonegap application.
The enables the ability to replicate data on a remote server using a simple function call. This would effectively mean that the phonegap application can work when a device is offline, collect and work with data, and finally sync back to the server when it comes offline. Syncing to the server is one of the most common problems for mobile applications, and this example can solve it in a very simple way. In addition, the same code can also be used for desktop browsers too.
With the IndexedDBShim, most of the PouchDB functionality is supported by simply adding IndexedDBShim.js file to the main HTML file. To understand the example, you can look at www/index.html. The file include pouch.alpha.js and the IndexedDBShim.min.js. It then uses the pouchdb functions like create and delete documents.

Note that pouchDB does not allow IndexedDB databases to be created on localhost, and this had to be disabled in the generated pouch.alpha.js file. Also, to enable replication, the "External Hosts" in Cordova.plist was set to "*". Like mentioned in the previous post, the first call to IndexedDB should be made only after a timeout (in this case, a user click) to allow time for the shim to do the housekeeping. 

Here are some screenshots from the example (sorry for the bad UI)

                     

Looking at the Safari Remote Debugger, here are some screenshots
 
and here is the WebSQL database that the IndexedDBShim populates

Note that deleteDatabase method is not yet supported in the IndexedDBShim. Hence, if you hit that button in this example, you may have to delete and restart the application to get it working again.

To run this example, simply clone the project at and open the xcode file.To start this in your project, you would just have to include the IndexedDBShim file in addition to the pouch file. Let me know any questions you may have, or issues when integrating in your project, in the comments below.