CouchDB as Cordova/Phonegap database

Nafeez Abrar picture Nafeez Abrar · Jul 22, 2014 · Viewed 8.2k times · Source

Target

I want to build a cross-platform mobile app with cordova/phonegap which require a database (client-side only). My target platform is mainly Android and iOS. I have chosen couchbase-lite as my storage.

Problem

But I could not find any good documentation for couchbase-lite in phonegap. Only I found some rest api and an application todo-lite in github and Play Store.

I could not understand if I don't have any server side implementation how could I get a url at which I can sent POST/GET/PUT/DELETE request.

Can anyone suggest me a way by which I can install, connect and run CRUD operation in couchbase-lite database locally in Android and iOS using cordova/phonegap.

Why Couchbase-lite (Not Important for all)

For those who will suggest me to choose another db, I am just sharing my findings...
From cordova 5.0 storage documentation there are several choices

  • LocalSorage: 5 MB limit is not sufficient for the application.
  • WebSQL: I'm afraid about the future of it since w3c dropped its planning.
  • IndexDB: Currently underdevelopment and not available for Android and iOS.
  • Plugin-Based Options: By motivating the evaluation of NoSQL. I have tried couchbase-lite. Which has plugin support for both Android and iOS platform.

Answer

Moonwalker picture Moonwalker · Dec 12, 2014

I have been looking for this as well and I think I finally found something. It turns out you need to use coax library to communicate with Couchbase Lite db. The Couchbase Lite plugin exposes only one methode getURL which returns a LOCAL internal URL for Couchbase Lite. Then you have to use coax to create a db object and run queries against it.

Basically it looks like access to Couchbaselite is all via REST queries using internally formed URL. But it is a pain to do therefore you need to use coax. With coax it seems the REST ops get exposed as functions on the objects..put, del, etc. the full reference to the API is listed here is good detail:

Here is the full spec of the REST operations for Couchbase Lite on mobile - your CRUD ops

Here is the Coax with simple instructions on how the rest queries work in the context of CouchDB

I found a very nice article on this here - it talks about the set up and all CRUD ops.

Couchase Lite in Cordova via Coax

Hope this help you...