nativescript-cblite
Couchbase Lite NativeScript 插件。
npm i --save nativescript-cblite

NativeScript CB-Lite

支持 LiteServ 内部 REST 操作的 NativeScript Couchbase Lite 插件。

状态

Android 版本正在运行但仍在 CBL 1.4.4 中。iOS 还需要一些代码。要查看完整和更新的插件,请访问:https://github.com/triniwiz/nativescript-couchbase-plugin

安装

tns plugin add nativescript-cblite

使用

首先需要导入主类

import { CBLite } from 'nativescript-cblite';

如果您将使用 REST API,以下命令将初始化它并提供基本 URL

const url = Utils.startCBLListener();

然后需要实例化 CBLite

const cblite = new CBLite('databaseName');

创建本地文档

cblite.createDocument({name: 'John Doe', age: 99}, 'myDocumentId');

读取本地文档

// It will return a JSON object or false if the document does not exist
cblite.getDocument('myDocumentId');

更新本地文档

cblite.updateDocument('myDocumentId', {newData: 'My new data string'});

使用 SyncGateway 服务器复制您的文档

首先需要导入适当的类

import { CBLite, Replicator } from 'nativescript-cblite';

然后需要实例化这些类

const cblite = new CBLite('databaseName');
const pushReplicator: Replicator = cblite.createPushReplication('myRemoteUrl');
const pullReplicator: Replicator = cblite.createPullReplication('myRemoteUrl');

设置复制

pushReplicator.setContinuous(true);
pushReplicator.setAuthenticator('username', 'password');
pushReplicator.start();

pullReplicator.setContinuous(true);
pullReplicator.setAuthenticator('username', 'password');
pullReplicator.start();

API 参考

类 CBLite

方法名 参数 返回类型
getDocument documentId 对象
listAllDocuments - 字符串数组
listAllReplications - 字符串数组
addDatabaseChangeListener 回调
createDocument data, documentId 字符串
updateDocument documentId, data
deleteDocument documentId 布尔值
createPullReplication remoteUrl Replicator
createPushReplication remoteUrl Replicator

类 Replicator

方法名 参数 返回类型
start -
stop -
isRunning - 布尔值
addReplicationChangeListener changeListenerCallback
setAuthenticator username, password
setContinuous continuous
setDocumentIds docIds
setCookie name, value, path, expirationDate, secure, httpOnly
deleteCookie name

更多文档即将到来

许可

Apache 许可协议第 2 版,2004 年 1 月