An AngularJS wrapper for the Couchbase Lite Cordova plugin.
This is intended for use with Couchbase-Lite-PhoneGap-Plugin (com.couchbase.lite.phonegap) 1.1.x. If you are using an older version you probably want to use the version of this repo tagged v1.0.4
This is very much a work in progress. Obvious features are missing. The features that are there might fail in surprising ways. Take a peek by all means but please don't try using it in production ;) PRs are very welcome.
Install this module with bower or npm.
In your index.html include the necessary <script> tags.
<script src="lib/angular-couchbase-lite/angular-couchbase-lite.js"></script>
<script src="lib/angular-resource/angular-resource.min.js"></script>
<script src="lib/angular-utf8-base64/angular-utf8-base64.min.js"></script>
Refer to the Couchbase Lite API References for more details.
cblite.database("testdb").createIfMissing().then(function(db) {});
To reclaim disk space.
cblite.database("testdb").compact();
Will automatically generate a revision ID. Will return a conflict 409 error if document revision already exists.
cblite.database("testdb").document("testdoc").save({key:"value"});
cblite.database("testdb").all({include_docs:true}).then(function(documents) {});
cblite.database("testdb").document("testdoc").load().then(function(document) {});
When updating, you need to specify the document revision you wish to save.
cblite.database("testdb").document("testdoc").load(function(document) {
cblite.database("testdb").document("testdoc").save({key:"newvalue"}, document._rev);
});
Mark document as deleted.
cblite.database("testdb").document("testdoc").delete();
Permanently remove from database. Can optionally specify array of revisions to delete.
cblite.database("testdb").document("testdoc").purge();
var spec = {"language": "javascript",
"views": {
"all": {
"map": "function(doc) {emit(doc.id)}",
"reduce: "function(key, values, rereduce) {return;}"
cblite.database("testdb").design("designName").view(spec);
Using reduce
var opts = {reduce: true, group: true, group_level: 1};
cblite.database("testdb").design("v1").view("most_recent", opts)
Advanced parameters
cblite.database("testdb").design("help14").view("by_thread", {descending:true,start_key:"['thisid']",end_key: "[{},'thisid']"}).then(function(d){console.log(d)});
Unit tests are implemented using Jasmine 1.3 and can be run using Karma.
Integration testing is tougher as it needs to be done on a real device running a real Couchbase Lite. I haven't got around to automating this yet.