0.9.6 • Published 4 years ago

nativescript-couchbase-plugin v0.9.6

Weekly downloads
55
License
Apache-2.0
Repository
-
Last release
4 years ago

npm npm Build Status

NativeScript-Couchbase

Installation

tns plugin add nativescript-couchbase-plugin

Usage

Note Android min-sdk is 19

import { Couchbase, ConcurrencyMode } from 'nativescript-couchbase-plugin';
const database = new Couchbase('my-database');

const documentId = database.createDocument({
    "firstname": "O",
    "lastname": "Fortune",
    "address": {
        "country": "Trinidad and Tobago"
    },
    "twitter": "https://www.twitter.com/triniwiz"
});

const person = 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 it
const isDeleted = database.deleteDocument(documentId, ConcurrencyMode.FailOnConflict);

Synchronization with Couchbase Sync Gateway and Couchbase Server

import { Couchbase } from 'nativescript-couchbase-plugin';
const database = new Couchbase('my-database');

const push = database.createPushReplication(
  'ws://sync-gateway-host:4984/my-database'
);
push.setUserNameAndPassword("user","password");
const pull = 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 (var i = 0; i < changes.length; i++) {
    const documentId = changes[i];
    console.log(documentId);
  }
});

Query

const results = database.query({
  select: [], // Leave empty to query for all
  from: 'otherDatabaseName', // Omit or set null to use current db
  where: [{ 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';
const database = new Couchbase('my-database');

database.inBatch(() => {
    const documentId = database.createDocument({
        "firstname": "O",
        "lastname": "Fortune",
        "address": {
            "country": "Trinidad and Tobago"
        }
        "twitter": "https://www.twitter.com/triniwiz"
    });
    
    const person = database.getDocument(documentId);
    
    
    database.updateDocument(documentId, {
        "firstname": "Osei",
        "lastname": "Fortune",
        "twitter": "https://www.twitter.com/triniwiz"
    });
    
    const isDeleted = database.deleteDocument(documentId);
});

API

License

Apache License Version 2.0, January 2004

0.9.6

4 years ago

0.9.5

4 years ago

0.9.4

4 years ago

0.9.2

5 years ago

0.9.1

5 years ago

0.9.0

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago