jfspencer / cordova-plugin-couchbase-lite

Couchbase Lite Cordova plugin that provides a standard cordova API
MIT License
1 stars 2 forks source link

Cannot create new CBL database #1

Open jashachik opened 8 years ago

jashachik commented 8 years ago

Good morning,

I am not able to create a new db with this code:

window.cbl.getServerURL(function (url, err) {
                if (err)
                {
                    return done("error launching Couchbase Lite: " + err + " URL: " + url);
                }
                else
                {
                    console.log("Couchbase Lite running at " + url);
                    var db = coax([url, appDbName]);
                    try
                    {
                        config = {
                            site : {
                                syncUrl : REMOTE_SYNC_URL
                            },
                            db : db,
                            s : coax(url),
                            server : url
                        };
                        console.log("config: " + JSON.stringify(config))
                    }
                    catch( ex )
                    {
                        console.log(" config create ex: " + ex)
                    }

                }
            });

In the console the log is not showing the db object getting created. Please help i recently moved from couchbase lite phonegap plugin to this cordova plugin

james

jfspencer commented 8 years ago

Hi @jashachik

(notes: add lodash, Promise library like bluebird.js and URI.js if you haven't already, the cbl wrapper depends on them. I just committed a dist directory containing a baked javascript file in case your are not using typescript.)

The native code is identical to the main couchbase lite phone gap repo. so if you are having issues with cbl itself, those issues will be here as well. I update the native code as it is made available from couchbase.

This repo aims to provide a clean async javascript api overtop of cbl's REST API.

Use either the javascript file dist/cbl.js or the typescript file and use the api like so:

Using dist/cbl.js var db = new cblDB('nameOfDB', 'optionalRemoteSyncUrl'); db.initDB('optionalRemoteSyncUrl');

or for Typescript

import cblDB = require('path/to/typescript/cbl/file'); const db = new cblDB('nameOfDB', 'optionalRemoteSyncUrl'); db.initDB('optionalRemoteSyncUrl');

This will handle the cordova plugin bridge code for you. Then you can interact with cbl very cleanly. like so:

db.get('docId',{param:'value'}).then(function(doc){.... do stuff with doc ..... })

More Info

I made some breaking changes from the vanilla couchbase lite plugin to encourage the use of the javascript wrapper. instead of clobbering window.cbl just cbl is clobbered. This implementation detail is intended to be hidden from the public API, but if you needed to get the cbl server url use cbl.getServerURL()

I don't like coax so I am not using it. The API functions construct the appropriate url, params, body etc and pass that to a vanilla XHR. I am using lodash, URI.js and a promise library to keep the actual api code clean from low level implementation details.

This fork is intended to be used with the provided wrapper. some assembly is required. in the case of javascript adding the dist/cbl.js into your project, or in the case of typescript adding the typescript file and the definition file into your project.

Hope that helps.