# nativescript-couchbase-plugin

> NativeScript couchbase

Latest version **0.9.6** (published 2020-01-06) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install nativescript-couchbase-plugin
pnpm add nativescript-couchbase-plugin
yarn add nativescript-couchbase-plugin
bun add nativescript-couchbase-plugin
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.6 |
| Published | 2020-01-06 |
| First published | 2018-10-17 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 344.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Osei Fortune |
| Maintainers | triniwiz |
| Keywords | NativeScript, JavaScript, Android, iOS |

## Links

- npm: https://www.npmjs.com/package/nativescript-couchbase-plugin
- Homepage: https://github.com/triniwiz/nativescript-couchbase-plugin
- Issues: https://github.com/triniwiz/nativescript-couchbase-plugin/issues
- npm.io page: https://npm.io/package/nativescript-couchbase-plugin

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.9.6 (latest) — 2020-01-06
- 0.9.5 — 2019-12-02
- 0.9.4 — 2019-12-02
- 0.9.2 — 2019-08-08
- 0.9.1 — 2019-04-04
- 0.9.0 — 2019-01-22
- 0.8.1 — 2019-01-22
- 0.8.0 — 2019-01-22
- 0.7.0 — 2019-01-22
- 0.6.0 — 2019-01-10
- 0.5.0 — 2018-11-30
- 0.4.1 — 2018-11-29
- 0.4.0 — 2018-11-29
- 0.3.2 — 2018-10-23
- 0.3.1 — 2018-10-22
- … 18 more at https://npm.io/package/nativescript-couchbase-plugin/versions

## README

[![npm](https://img.shields.io/npm/v/nativescript-couchbase-plugin.svg)](https://www.npmjs.com/package/nativescript-couchbase-plugin)
[![npm](https://img.shields.io/npm/dt/nativescript-couchbase-plugin.svg?label=npm%20downloads)](https://www.npmjs.com/package/nativescript-couchbase-plugin)
[![Build Status](https://travis-ci.org/triniwiz/nativescript-couchbase-plugin.svg?branch=master)](https://travis-ci.org/triniwiz/nativescript-couchbase-plugin)

# NativeScript-Couchbase

## Installation

`tns plugin add nativescript-couchbase-plugin`

## Usage
**Note Android min-sdk is 19**


```ts
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

```ts
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

```ts
database.addDatabaseChangeListener(function(changes) {
  for (var i = 0; i < changes.length; i++) {
    const documentId = changes[i];
    console.log(documentId);
  }
});
```

### Query

```ts
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.

```ts
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

---
_Source: https://npm.io/package/nativescript-couchbase-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
