The code you are looking for is in the todo-lite phonegap application in the setupConfig function. you will need the modules.js, zepto.min.js and zepto.touch.js files from the todolite-phonegap application.
//check if couchbase lite plugin is installed if (!window.cblite) { return alert( 'Couchbase Lite not installed' ) } //get your local url from the plugin cblite.getURL( function(err, url) { console.log( "getURL: " + JSON.stringify( [ err, url ] ) ) if (err) { return alert( JSON.stringfiy( err ) ) } var xmlHttp = new XMLHttpRequest() xmlHttp.open( 'GET', url, false ) xmlHttp.send( null ) window.server = coax( url ); var db = coax( [ url, appDbName ] ); setupDb( db, function(err, info) { if (err) { return alert( JSON.stringify( err ) ) } // now your db connection is setup you do CRUD operations by //GET db.get( "myDocumentID", function (error, doc) { if( error ) { if( error.status == 404 ) { //INSERT var myDocument = { "key" : "value" }; db.put( "myDocumentID", myDocument, function( error, ok ) { if (error) { return alert( JSON.stringify( error ) } //success } ); } else { return alert(JSON.stringify( error) ) } } else { //UPDATE doc.my_key = "value"; //DELETE doc._deleted = true; db.put("myDocumentID", doc, function(error, ok) { if (error) { return alert( JSON.stringify( error ) } //success } ); } } ); } ); } ); function setupDb(db, cb) { db.get( function(err, res, body) { db.put( function(err, res, body) { db.get( cb ) } ) } ) }
source share