npm i --save nativescript-couchbase-plugin
- 版本: 0.9.6
- GitHub:
- NPM: https://npmjs.net.cn/package/nativescript-couchbase-plugin
- 下载次数
- 昨天: 1
- 上周: 41
- 上个月: 121
NativeScript-Couchbase
安装
tns plugin add nativescript-couchbase-plugin
使用方法
注意:Android 的最小 SDK 为 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);
与 Couchbase Sync Gateway 和 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();
监听变化
database.addDatabaseChangeListener(function(changes) {
for (var i = 0; i < changes.length; i++) {
const documentId = changes[i];
console.log(documentId);
}
});
查询
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
});
事务
使用方法 inBatch
在批量/事务中运行一组数据库操作。在执行批量写入操作(如多个插入/更新)时使用此方法;它减少了多次数据库提交的开销,大大提高了性能。
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
许可证
Apache 许可证第 2 版,2004 年 1 月