Skip to content

Repository files navigation

npmnpmBuild Status

NativeScript-Couchbase

The source is now managed athttps://github.com/triniwiz/nativescript-plugins

Installation

tns plugin add nativescript-couchbase-plugin

Usage

Note Android min-sdk is 19

import{Couchbase,ConcurrencyMode}from'nativescript-couchbase-plugin';constdatabase=newCouchbase('my-database');constdocumentId=database.createDocument({"firstname": "O","lastname": "Fortune","address": {"country": "Trinidad and Tobago"},"twitter": "https://www.twitter.com/triniwiz"});constperson=database.getDocument(documentId);database.updateDocument(documentId,{"firstname": "Osei","lastname": "Fortune","twitter": "https://www.twitter.com/triniwiz"});// Default concurrency mode is FailOnConflict if you don't pass itconstisDeleted=database.deleteDocument(documentId,ConcurrencyMode.FailOnConflict);

Synchronization with Couchbase Sync Gateway and Couchbase Server

import{Couchbase}from'nativescript-couchbase-plugin';constdatabase=newCouchbase('my-database');constpush=database.createPushReplication('ws://sync-gateway-host:4984/my-database');push.setUserNameAndPassword("user","password");constpull=database.createPullReplication('ws://sync-gateway-host:4984/my-database');pull.setSessionId("SomeId");pull.setSessionIdAndCookieName("SomeId","SomeCookieName");push.setContinuous(true);pull.setContinuous(true);push.start();pull.start();

Listening for Changes

database.addDatabaseChangeListener(function(changes){for(vari=0;i<changes.length;i++){constdocumentId=changes[i];console.log(documentId);}});

Query

constresults=database.query({select: [],// Leave empty to query for allfrom: 'otherDatabaseName',// Omit or set null to use current dbwhere: [{property: 'firstName',comparison: 'equalTo',value: 'Osei'}],order: [{property: 'firstName',direction: 'desc'}],limit: 2});

Transactions

Using the method inBatch to run group of database operations in a batch/transaction. Use this when performing bulk write operations like multiple inserts/updates; it saves the overhead of multiple database commits, greatly improving performance.

import{Couchbase}from'nativescript-couchbase-plugin';constdatabase=newCouchbase('my-database');database.inBatch(()=>{constdocumentId=database.createDocument({"firstname": "O","lastname": "Fortune","address": {"country": "Trinidad and Tobago"}
"twitter": "https://www.twitter.com/triniwiz"
});constperson=database.getDocument(documentId);database.updateDocument(documentId,{"firstname": "Osei","lastname": "Fortune","twitter": "https://www.twitter.com/triniwiz"});constisDeleted=database.deleteDocument(documentId);});

API

License

Apache License Version 2.0, January 2004

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages