未验证 提交 892beb40 编写于 作者: O openharmony_ci 提交者: Gitee

!2805 js-apis-distributed-data.md代码块样式修改:需同步翻译

Merge pull request !2805 from 葛亚芳/master
......@@ -27,27 +27,28 @@ createKVManager(config: KVManagerConfig, callback: AsyncCallback<KVManager&gt
| callback | AsyncCallback<[KVManager](#kvmanager)> | 是 | KVManager实例创建时调用的回调,返回KVManager对象实例。 |
**示例**
let kvManager;
try {
const kvManagerConfig = {
bundleName : 'com.example.datamanagertest',
userInfo : {
userId : '0',
userType : distributedData.UserType.SAME_USER_ID
}
```
let kvManager;
try {
const kvManagerConfig = {
bundleName : 'com.example.datamanagertest',
userInfo : {
userId : '0',
userType : distributedData.UserType.SAME_USER_ID
}
distributedData.createKVManager(kvManagerConfig, function (err, manager) {
if (err) {
console.log("createKVManager err: " + JSON.stringify(err));
return;
}
console.log("createKVManager success");
kvManager = manager;
});
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
distributedData.createKVManager(kvManagerConfig, function (err, manager) {
if (err) {
console.log("createKVManager err: " + JSON.stringify(err));
return;
}
console.log("createKVManager success");
kvManager = manager;
});
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
## distributedData.createKVManager
......@@ -71,25 +72,26 @@ createKVManager(config: KVManagerConfig): Promise<KVManager>
**示例**
let kvManager;
try {
const kvManagerConfig = {
bundleName : 'com.example.datamanagertest',
userInfo : {
userId : '0',
userType : distributedData.UserType.SAME_USER_ID
}
```
let kvManager;
try {
const kvManagerConfig = {
bundleName : 'com.example.datamanagertest',
userInfo : {
userId : '0',
userType : distributedData.UserType.SAME_USER_ID
}
distributedData.createKVManager(kvManagerConfig).then((manager) => {
console.log("createKVManager success");
kvManager = manager;
}).catch((err) => {
console.log("createKVManager err: " + JSON.stringify(err));
});
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
distributedData.createKVManager(kvManagerConfig).then((manager) => {
console.log("createKVManager success");
kvManager = manager;
}).catch((err) => {
console.log("createKVManager err: " + JSON.stringify(err));
});
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
## KVManagerConfig
......@@ -102,8 +104,6 @@ createKVManager(config: KVManagerConfig): Promise<KVManager>
| userInfo | [UserInfo](#userinfo) | 是 | 调用方的用户信息。 |
| bundleName | string | 是 | 调用方的包名。 |
## UserInfo
用户信息。
......@@ -131,8 +131,6 @@ createKVManager(config: KVManagerConfig): Promise<KVManager>
数据管理实例,用于获取KVStore的相关信息。在调用KVManager的方法前,需要先通过createKVManager构建一个KVManager实例。
### getKVStore
getKVStore<T extends KVStore>(storeId: string, options: Options, callback: AsyncCallback<T>): void
......@@ -151,30 +149,30 @@ getKVStore<T extends KVStore>(storeId: string, options: Options, callback:
**示例**
```
let kvStore;
let kvManager;
try {
const options = {
createIfMissing : true,
encrypt : false,
backup : false,
autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
securityLevel : distributedData.SecurityLevel.S2,
};
kvManager.getKVStore('storeId', options, function (err, store) {
if (err) {
console.log("getKVStore err: " + JSON.stringify(err));
return;
}
console.log("getKVStore success");
kvStore = store;
});
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
```
let kvStore;
let kvManager;
try {
const options = {
createIfMissing : true,
encrypt : false,
backup : false,
autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
securityLevel : distributedData.SecurityLevel.S2,
};
kvManager.getKVStore('storeId', options, function (err, store) {
if (err) {
console.log("getKVStore err: " + JSON.stringify(err));
return;
}
console.log("getKVStore success");
kvStore = store;
});
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
### getKVStore
......@@ -199,31 +197,30 @@ getKVStore<T extends KVStore>(storeId: string, options: Options): Promise&
| -------------------------------------- | ------------------------ |
| Promise<T> <T extends KVStore> | 指定的Promise回调方法,返回创建的KVStore数据库实例。 |
**示例**
```
let kvStore;
let kvManager;
try {
const options = {
createIfMissing : true,
encrypt : false,
backup : false,
autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
securityLevel : distributedData.SecurityLevel.S2,
};
kvManager.getKVStore('storeId', options).then((store) => {
console.log("getKVStore success");
kvStore = store;
}).catch((err) => {
console.log("getKVStore err: " + JSON.stringify(err));
});
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
```
let kvStore;
let kvManager;
try {
const options = {
createIfMissing : true,
encrypt : false,
backup : false,
autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
securityLevel : distributedData.SecurityLevel.S2,
};
kvManager.getKVStore('storeId', options).then((store) => {
console.log("getKVStore success");
kvStore = store;
}).catch((err) => {
console.log("getKVStore err: " + JSON.stringify(err));
});
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
### closeKVStore<sup>8+</sup> ###
......@@ -243,33 +240,33 @@ closeKVStore(appId: string, storeId: string, kvStore: KVStore, callback: AsyncCa
| kvStore | [KVStore](#kvstore) | 是 | 要关闭的KvStore数据库。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,如果数据库关闭成功则返回true,否则返回false。 |
**示例**
```
let kvStore;
let kvManager;
const options = {
createIfMissing : true,
encrypt : false,
backup : false,
autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
schema : '',
securityLevel : distributedData.SecurityLevel.S2,
}
try {
kvManager.getKVStore('storeId', options, async function (err, store) {
console.log('getKVStore success');
kvStore = store;
await kvManager.closeKVStore('appId', 'storeId', kvStore, function (err, data) {
console.log('closeKVStore success');
});
});
} catch (e) {
console.log('closeKVStore e ' + e);
}
```
```
let kvStore;
let kvManager;
const options = {
createIfMissing : true,
encrypt : false,
backup : false,
autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
schema : '',
securityLevel : distributedData.SecurityLevel.S2,
}
try {
kvManager.getKVStore('storeId', options, async function (err, store) {
console.log('getKVStore success');
kvStore = store;
await kvManager.closeKVStore('appId', 'storeId', kvStore, function (err, data) {
console.log('closeKVStore success');
});
});
} catch (e) {
console.log('closeKVStore e ' + e);
}
```
### closeKVStore<sup>8+</sup> ###
......@@ -295,34 +292,34 @@ closeKVStore(appId: string, storeId: string, kvStore: KVStore): Promise&lt;void&
**示例**
```
let kvManager;
let kvStore;
const options = {
createIfMissing : true,
encrypt : false,
backup : false,
autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
schema : '',
securityLevel : distributedData.SecurityLevel.S2,
}
try {
kvManager.getKVStore('storeId', options).then(async (store) => {
console.log('getKVStore success');
kvStore = store;
await kvManager.closeKVStore('appId', 'storeId', kvStore).then(() => {
console.log('closeKVStore success');
}).catch((err) => {
console.log('closeKVStore err ' + JSON.stringify(err));
});
}).catch((err) => {
console.log('CloseKVStore getKVStore err ' + JSON.stringify(err));
});
} catch (e) {
console.log('closeKVStore e ' + e);
}
```
```
let kvManager;
let kvStore;
const options = {
createIfMissing : true,
encrypt : false,
backup : false,
autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
schema : '',
securityLevel : distributedData.SecurityLevel.S2,
}
try {
kvManager.getKVStore('storeId', options).then(async (store) => {
console.log('getKVStore success');
kvStore = store;
await kvManager.closeKVStore('appId', 'storeId', kvStore).then(() => {
console.log('closeKVStore success');
}).catch((err) => {
console.log('closeKVStore err ' + JSON.stringify(err));
});
}).catch((err) => {
console.log('CloseKVStore getKVStore err ' + JSON.stringify(err));
});
} catch (e) {
console.log('closeKVStore e ' + e);
}
```
### deleteKVStore<sup>8+</sup> ###
......@@ -341,33 +338,32 @@ deleteKVStore(appId: string, storeId: string, callback: AsyncCallback&lt;void&gt
| storeId | string | 是 | 要删除的数据库唯一标识符,长度不大于[MAX_STORE_ID_LENGTH](#constants)。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,如果成功返回true,否则返回false。 |
**示例**
```
let kvManager;
let kvStore;
const options = {
createIfMissing : true,
encrypt : false,
backup : false,
autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
schema : '',
securityLevel : distributedData.SecurityLevel.S2,
}
try {
kvManager.getKVStore('store', options, async function (err, store) {
console.log('getKVStore success');
kvStore = store;
await kvManager.deleteKVStore('appId', 'storeId', function (err, data) {
console.log('deleteKVStore success');
});
```
let kvManager;
let kvStore;
const options = {
createIfMissing : true,
encrypt : false,
backup : false,
autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
schema : '',
securityLevel : distributedData.SecurityLevel.S2,
}
try {
kvManager.getKVStore('store', options, async function (err, store) {
console.log('getKVStore success');
kvStore = store;
await kvManager.deleteKVStore('appId', 'storeId', function (err, data) {
console.log('deleteKVStore success');
});
} catch (e) {
console.log('DeleteKVStore e ' + e);
}
```
});
} catch (e) {
console.log('DeleteKVStore e ' + e);
}
```
### deleteKVStore<sup>8+</sup> ###
......@@ -393,34 +389,34 @@ deleteKVStore(appId: string, storeId: string): Promise&lt;void&gt;
**示例**
```
let kvManager;
let kvStore;
const options = {
createIfMissing : true,
encrypt : false,
backup : false,
autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
schema : '',
securityLevel : distributedData.SecurityLevel.S2,
}
try {
kvManager.getKVStore('storId', options).then(async (store) => {
console.log('getKVStore success');
kvStore = store;
await kvManager.deleteKVStore('appId', 'storeId').then(() => {
console.log('deleteKVStore success');
}).catch((err) => {
console.log('deleteKVStore err ' + JSON.stringify(err));
});
```
let kvManager;
let kvStore;
const options = {
createIfMissing : true,
encrypt : false,
backup : false,
autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
schema : '',
securityLevel : distributedData.SecurityLevel.S2,
}
try {
kvManager.getKVStore('storId', options).then(async (store) => {
console.log('getKVStore success');
kvStore = store;
await kvManager.deleteKVStore('appId', 'storeId').then(() => {
console.log('deleteKVStore success');
}).catch((err) => {
console.log('getKVStore err ' + JSON.stringify(err));
console.log('deleteKVStore err ' + JSON.stringify(err));
});
} catch (e) {
console.log('deleteKVStore e ' + e);
}
```
}).catch((err) => {
console.log('getKVStore err ' + JSON.stringify(err));
});
} catch (e) {
console.log('deleteKVStore e ' + e);
}
```
### getAllKVStoreId<sup>8+</sup> ###
......@@ -440,17 +436,17 @@ getAllKVStoreId(appId: string, callback: AsyncCallback&lt;string[]&gt;): void
**示例**
```
let kvManager;
try {
kvManager.getAllKVStoreId('appId', function (err, data) {
console.log('GetAllKVStoreId success');
console.log('GetAllKVStoreId size = ' + data.length);
});
} catch (e) {
console.log('GetAllKVStoreId e ' + e);
}
```
```
let kvManager;
try {
kvManager.getAllKVStoreId('appId', function (err, data) {
console.log('GetAllKVStoreId success');
console.log('GetAllKVStoreId size = ' + data.length);
});
} catch (e) {
console.log('GetAllKVStoreId e ' + e);
}
```
### getAllKVStoreId<sup>8+</sup> ###
......@@ -476,20 +472,20 @@ getAllKVStoreId(appId: string): Promise&lt;string[]&gt;
**示例**
```
let kvManager;
try {
console.log('GetAllKVStoreId');
kvManager.getAllKVStoreId('apppId').then((data) => {
console.log('getAllKVStoreId success');
console.log('size = ' + data.length);
}).catch((err) => {
console.log('getAllKVStoreId err ' + JSON.stringify(err));
});
} catch(e) {
console.log('getAllKVStoreId e ' + e);
}
```
```
let kvManager;
try {
console.log('GetAllKVStoreId');
kvManager.getAllKVStoreId('apppId').then((data) => {
console.log('getAllKVStoreId success');
console.log('size = ' + data.length);
}).catch((err) => {
console.log('getAllKVStoreId err ' + JSON.stringify(err));
});
} catch(e) {
console.log('getAllKVStoreId e ' + e);
}
```
### on<sup>8+</sup> ###
......@@ -507,23 +503,21 @@ on(event: 'distributedDataServiceDie', deathCallback: Callback&lt;void&gt;): voi
| event | 'distributedDataServiceDie' | 是 | 服务状态改变时触发的事件名。 |
| deathCallback | Callback&lt;void&gt; | 是 | 回调函数,在设备状态改变时获取通知。 |
**示例**
```
let kvManager;
try {
console.log('KVManagerOn');
const deathCallback = function () {
console.log('death callback call');
}
kvManager.on('distributedDataServiceDie', deathCallback);
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
```
let kvManager;
try {
console.log('KVManagerOn');
const deathCallback = function () {
console.log('death callback call');
}
```
kvManager.on('distributedDataServiceDie', deathCallback);
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
### off<sup>8+</sup> ###
......@@ -544,19 +538,19 @@ off(event: 'distributedDataServiceDie', deathCallback?: Callback&lt;void&gt;): v
**示例**
```
let kvManager;
try {
console.log('KVManagerOff');
const deathCallback = function () {
console.log('death callback call');
}
kvManager.off('distributedDataServiceDie', deathCallback);
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
```
let kvManager;
try {
console.log('KVManagerOff');
const deathCallback = function () {
console.log('death callback call');
}
kvManager.off('distributedDataServiceDie', deathCallback);
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
```
## Options
......@@ -588,7 +582,6 @@ off(event: 'distributedDataServiceDie', deathCallback?: Callback&lt;void&gt;): v
| MULTI_VERSION | 2 | 表示多版本数据库。此类型当前不允许使用。 |
## SecurityLevel
用于指定创建的数据库的安全级别。
......@@ -629,7 +622,7 @@ KVStore常量。
| 名称 | 类型 | 说明 |
| --- | ---- | ----------------------- |
| root<sup>8+</sup> | [FieldNode](#fieldnode8) | 表示json根对象 |
| indexes<sup>8+</sup> | Array<string> | 表示json类型的字符串数组。 |
| indexes<sup>8+</sup> | Array\<string> | 表示json类型的字符串数组。 |
| mode<sup>8+</sup> | number | 表示Schema的模式。 |
| skip<sup>8+</sup> | number | Schema的跳跃大小。 |
......@@ -690,27 +683,25 @@ appendChild(child: FieldNode): boolean
**示例**
```
import ddm from '@ohos.data.distributedData';
try {
let node = new ddm.FieldNode("root");
let child1 = new ddm.FieldNode("child1");
let child2 = new ddm.FieldNode("child2");
let child3 = new ddm.FieldNode("child3");
node.appendChild(child1);
node.appendChild(child2);
node.appendChild(child3);
console.log("appendNode " + node.toJson());
child1 = null;
child2 = null;
child3 = null;
node = null;
} catch (e) {
console.log("AppendChild " + e);
}
```
```
import ddm from '@ohos.data.distributedData';
try {
let node = new ddm.FieldNode("root");
let child1 = new ddm.FieldNode("child1");
let child2 = new ddm.FieldNode("child2");
let child3 = new ddm.FieldNode("child3");
node.appendChild(child1);
node.appendChild(child2);
node.appendChild(child3);
console.log("appendNode " + node.toJson());
child1 = null;
child2 = null;
child3 = null;
node = null;
} catch (e) {
console.log("AppendChild " + e);
}
```
## KvStoreResultSet<sup>8+</sup> ##
......@@ -734,23 +725,22 @@ getCount(): number
**示例**
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const count = resultSet.getCount();
console.log("GetCount " + count);
} catch (e) {
console.log("GetCount fail " + e);
}
```
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const count = resultSet.getCount();
console.log("GetCount " + count);
} catch (e) {
console.log("GetCount fail " + e);
}
```
### getPosition<sup>8+</sup> ###
......@@ -768,22 +758,22 @@ getPosition(): number
**示例**
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const position = resultSet.getPosition();
console.log("getPosition " + position);
} catch (e) {
console.log("GetPosition fail " + e);
}
```
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const position = resultSet.getPosition();
console.log("getPosition " + position);
} catch (e) {
console.log("GetPosition fail " + e);
}
```
### moveToFirst<sup>8+</sup> ###
......@@ -802,22 +792,22 @@ moveToFirst(): boolean
**示例**
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.moveToFirst();
console.log("moveToFirst " + moved);
} catch (e) {
console.log("MoveToFirst fail " + e);
}
```
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.moveToFirst();
console.log("moveToFirst " + moved);
} catch (e) {
console.log("MoveToFirst fail " + e);
}
```
### moveToLast<sup>8+</sup> ###
......@@ -836,22 +826,22 @@ moveToLast(): boolean
**示例**
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.moveToLast();
console.log("moveToLast " + moved);
} catch (e) {
console.log("moveToLast fail " + e);
}
```
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.moveToLast();
console.log("moveToLast " + moved);
} catch (e) {
console.log("moveToLast fail " + e);
}
```
### moveToNext<sup>8+</sup> ###
......@@ -870,22 +860,22 @@ moveToNext(): boolean
**示例**
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.moveToNext();
console.log("moveToNext " + moved);
} catch (e) {
console.log("moveToNext fail " + e);
}
```
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.moveToNext();
console.log("moveToNext " + moved);
} catch (e) {
console.log("moveToNext fail " + e);
}
```
### moveToPrevious<sup>8+</sup> ###
......@@ -904,22 +894,22 @@ moveToPrevious(): boolean
**示例**
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.moveToPrevious();
console.log("moveToPrevious " + moved);
} catch (e) {
console.log("moveToPrevious fail " + e);
}
```
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.moveToPrevious();
console.log("moveToPrevious " + moved);
} catch (e) {
console.log("moveToPrevious fail " + e);
}
```
### move<sup>8+</sup> ###
......@@ -944,22 +934,22 @@ move(offset: number): boolean
**示例**
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.move();
console.log("move " + moved);
} catch (e) {
console.log("move fail " + e);
}
```
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.move();
console.log("move " + moved);
} catch (e) {
console.log("move fail " + e);
}
```
### moveToPosition<sup>8+</sup> ###
......@@ -984,22 +974,22 @@ moveToPosition(position: number): boolean
**示例**
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.moveToPosition();
console.log("moveToPosition " + moved);
} catch (e) {
console.log("moveToPosition fail " + e);
}
```
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.moveToPosition();
console.log("moveToPosition " + moved);
} catch (e) {
console.log("moveToPosition fail " + e);
}
```
### isFirst<sup>8+</sup> ###
......@@ -1018,22 +1008,22 @@ isFirst(): boolean
**示例**
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.isFirst();
console.log("isFirst " + moved);
} catch (e) {
console.log("isFirst fail " + e);
}
```
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.isFirst();
console.log("isFirst " + moved);
} catch (e) {
console.log("isFirst fail " + e);
}
```
### isLast<sup>8+</sup> ###
......@@ -1052,23 +1042,22 @@ isLast(): boolean
**示例**
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.isLast();
console.log("isLast " + moved);
} catch (e) {
console.log("isLast fail " + e);
}
```
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.isLast();
console.log("isLast " + moved);
} catch (e) {
console.log("isLast fail " + e);
}
```
### isBeforeFirst<sup>8+</sup> ###
......@@ -1086,22 +1075,22 @@ isBeforeFirst(): boolean
**示例**
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.isBeforeFirst();
console.log("isBeforeFirst " + moved);
} catch (e) {
console.log("isBeforeFirst fail " + e);
}
```
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.isBeforeFirst();
console.log("isBeforeFirst " + moved);
} catch (e) {
console.log("isBeforeFirst fail " + e);
}
```
### isAfterLast<sup>8+</sup> ###
......@@ -1120,22 +1109,22 @@ isAfterLast(): boolean
**示例**
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.isAfterLast();
console.log("isAfterLast " + moved);
} catch (e) {
console.log("isAfterLast fail " + e);
}
```
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.isAfterLast();
console.log("isAfterLast " + moved);
} catch (e) {
console.log("isAfterLast fail " + e);
}
```
### getEntry<sup>8+</sup> ###
......@@ -1154,23 +1143,23 @@ getEntry(): Entry
**示例**
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.moveToNext();
const entry = resultSet.getEntry();
console.log("getEntry " + JSON.stringify(entry));
} catch (e) {
console.log("getEntry fail " + e);
}
```
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
});
const moved = resultSet.moveToNext();
const entry = resultSet.getEntry();
console.log("getEntry " + JSON.stringify(entry));
} catch (e) {
console.log("getEntry fail " + e);
}
```
## Query<sup>8+</sup> ##
......@@ -1205,18 +1194,18 @@ reset(): Query
**示例**
```
try {
let query = new distributedData.Query();
query.equalTo("key", "value");
console.log("query is " + query.getSqlLike());
query.reset();
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("simply calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.equalTo("key", "value");
console.log("query is " + query.getSqlLike());
query.reset();
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("simply calls should be ok :" + e);
}
```
### equalTo<sup>8+</sup> ###
......@@ -1242,16 +1231,16 @@ equalTo(field: string, value: number|string|boolean): Query;
**示例**
```
try {
let query = new distributedData.Query();
query.equalTo("field", "value");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.equalTo("field", "value");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### notEqualTo<sup>8+</sup> ###
......@@ -1277,16 +1266,16 @@ notEqualTo(field: string, value: number|string|boolean): Query
**示例**
```
try {
let query = new distributedData.Query();
query.notEqualTo("field", "value");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.notEqualTo("field", "value");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### greaterThan<sup>8+</sup> ###
......@@ -1302,7 +1291,7 @@ greaterThan(field: string, value: number|string|boolean): Query
| 参数名 | 参数类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------- |
| fieId | string | 是 |表示指定字段,必须以$开头, 并且不能包含' ^ '。 |
| value | number/string/boolean | 是 | 表示指定的值。|
| value | number\|string\|boolean | 是 | 表示指定的值。|
**返回值**
......@@ -1312,16 +1301,16 @@ greaterThan(field: string, value: number|string|boolean): Query
**示例**
```
try {
let query = new distributedData.Query();
query.greaterThan("field", "value");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.greaterThan("field", "value");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### lessThan<sup>8+</sup> ###
......@@ -1337,7 +1326,7 @@ lessThan(field: string, value: number|string): Query
| 参数名 | 参数类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------- |
| fieId | string | 是 |表示指定字段,必须以$开头, 并且不能包含' ^ '。 |
| value | number/string/boolean | 是 | 表示指定的值。|
| value | number\|string\|boolean | 是 | 表示指定的值。|
**返回值**
......@@ -1347,16 +1336,16 @@ lessThan(field: string, value: number|string): Query
**示例**
```
try {
let query = new distributedData.Query();
query.lessThan("field", "value");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.lessThan("field", "value");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### greaterThanOrEqualTo<sup>8+</sup> ###
......@@ -1372,7 +1361,7 @@ greaterThanOrEqualTo(field: string, value: number|string): Query
| 参数名 | 参数类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------- |
| fieId | string | 是 |表示指定字段,必须以$开头, 并且不能包含' ^ '。 |
| value | number/string/boolean | 是 | 表示指定的值。|
| value | number\|string\|boolean | 是 | 表示指定的值。|
**返回值**
......@@ -1382,17 +1371,17 @@ greaterThanOrEqualTo(field: string, value: number|string): Query
**示例**
```
try {
let query = new distributedData.Query();
query.greaterThanOrEqualTo("field", "value");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.greaterThanOrEqualTo("field", "value");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### lessThanOrEqualTo<sup>8+</sup> ###
......@@ -1407,7 +1396,7 @@ lessThanOrEqualTo(field: string, value: number|string): Query
| 参数名 | 参数类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------- |
| fieId | string | 是 |表示指定字段,必须以$开头, 并且不能包含' ^ '。 |
| value | number/string/boolean | 是 | 表示指定的值。|
| value | number\|string\|boolean | 是 | 表示指定的值。|
**返回值**
......@@ -1417,16 +1406,16 @@ lessThanOrEqualTo(field: string, value: number|string): Query
**示例**
```
try {
let query = new distributedData.Query();
query.lessThanOrEqualTo("field", "value");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.lessThanOrEqualTo("field", "value");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### isNull<sup>8+</sup> ###
......@@ -1452,16 +1441,16 @@ isNull(field: string): Query
**示例**
```
try {
let query = new distributedData.Query();
query.isNull("field");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.isNull("field");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### inNumber<sup>8+</sup> ###
......@@ -1486,19 +1475,18 @@ inNumber(field: string, valueList: number[]): Query
| ------ | ------- |
| [Query](#query8) |返回查询对象。|
**示例**
```
try {
let query = new distributedData.Query();
query.inNumber("field", [0, 1]);
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.inNumber("field", [0, 1]);
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### inString<sup>8+</sup> ###
......@@ -1524,16 +1512,16 @@ inString(field: string, valueList: string[]): Query
**示例**
```
try {
let query = new distributedData.Query();
query.inString("field", ['test1', 'test2']);
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.inString("field", ['test1', 'test2']);
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### notInNumber<sup>8+</sup> ###
......@@ -1559,16 +1547,16 @@ notInNumber(field: string, valueList: number[]): Query
**示例**
```
try {
let query = new distributedData.Query();
query.notInNumber("field", [0, 1]);
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.notInNumber("field", [0, 1]);
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### notInString<sup>8+</sup> ###
......@@ -1594,16 +1582,16 @@ notInString(field: string, valueList: string[]): Query
**示例**
```
try {
let query = new distributedData.Query();
query.notInString("field", ['test1', 'test2']);
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.notInString("field", ['test1', 'test2']);
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### like<sup>8+</sup> ###
......@@ -1629,16 +1617,16 @@ like(field: string, value: string): Query
**示例**
```
try {
let query = new distributedData.Query();
query.like("field", "value");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.like("field", "value");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### unlike<sup>8+</sup> ###
......@@ -1664,16 +1652,16 @@ unlike(field: string, value: string): Query
**示例**
```
try {
let query = new distributedData.Query();
query.unlike("field", "value");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.unlike("field", "value");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### and<sup>8+</sup> ###
......@@ -1692,18 +1680,18 @@ and(): Query
**示例**
```
try {
let query = new distributedData.Query();
query.notEqualTo("field", "value1");
query.and();
query.notEqualTo("field", "value2");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.notEqualTo("field", "value1");
query.and();
query.notEqualTo("field", "value2");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### or<sup>8+</sup> ###
......@@ -1722,18 +1710,18 @@ or(): Query
**示例**
```
try {
let query = new distributedData.Query();
query.notEqualTo("field", "value1");
query.or();
query.notEqualTo("field", "value2");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.notEqualTo("field", "value1");
query.or();
query.notEqualTo("field", "value2");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### orderByAsc<sup>8+</sup> ###
......@@ -1758,17 +1746,17 @@ orderByAsc(field: string): Query
**示例**
```
try {
let query = new distributedData.Query();
query.notEqualTo("field", "value");
query.orderByAsc("field");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.notEqualTo("field", "value");
query.orderByAsc("field");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### orderByDesc<sup>8+</sup> ###
......@@ -1791,20 +1779,19 @@ orderByDesc(field: string): Query
| ------ | ------- |
| [Query](#query8) |返回查询对象。|
**示例**
```
try {
let query = new distributedData.Query();
query.notEqualTo("field", "value");
query.orderByDesc("field");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.notEqualTo("field", "value");
query.orderByDesc("field");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### limit<sup>8+</sup> ###
......@@ -1830,17 +1817,17 @@ limit(total: number, offset: number): Query
**示例**
```
try {
let query = new distributedData.Query();
query.notEqualTo("field", "value");
query.limit("total", "offset");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.notEqualTo("field", "value");
query.limit("total", "offset");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### isNotNull<sup>8+</sup> ###
......@@ -1865,16 +1852,16 @@ isNotNull(field: string): Query
**示例**
```
try {
let query = new distributedData.Query();
query.isNotNull("field");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.isNotNull("field");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### beginGroup<sup>8+</sup> ###
......@@ -1893,18 +1880,18 @@ beginGroup(): Query
**示例**
```
try {
let query = new distributedData.Query();
query.beginGroup();
query.isNotNull("field");
query.endGroup();
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.beginGroup();
query.isNotNull("field");
query.endGroup();
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### endGroup<sup>8+</sup> ###
......@@ -1923,18 +1910,18 @@ endGroup(): Query
**示例**
```
try {
let query = new distributedData.Query();
query.beginGroup();
query.isNotNull("field");
query.endGroup();
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.beginGroup();
query.isNotNull("field");
query.endGroup();
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### prefixKey<sup>8+</sup> ###
......@@ -1959,17 +1946,17 @@ prefixKey(prefix: string): Query
**示例**
```
try {
let query = new distributedData.Query();
query.prefixKey("$.name");
query.prefixKey("0");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.prefixKey("$.name");
query.prefixKey("0");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### setSuggestIndex<sup>8+</sup> ###
......@@ -1994,17 +1981,17 @@ setSuggestIndex(index: string): Query
**示例**
```
try {
let query = new distributedData.Query();
query.setSuggestIndex("$.name");
query.setSuggestIndex("0");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
```
try {
let query = new distributedData.Query();
query.setSuggestIndex("$.name");
query.setSuggestIndex("0");
console.log("query is " + query.getSqlLike());
query = null;
} catch (e) {
console.log("dumplicated calls should be ok :" + e);
}
```
### deviceId<sup>8+</sup> ###
......@@ -2030,15 +2017,15 @@ deviceId(deviceId:string):Query
**示例**
```
try {
let query = new distributedData.Query();
query.deviceId("deviceId");
console.log("query is " + query.getSqlLike());
} catch (e) {
console.log("should be ok on Method Chaining : " + e);
}
```
```
try {
let query = new distributedData.Query();
query.deviceId("deviceId");
console.log("query is " + query.getSqlLike());
} catch (e) {
console.log("should be ok on Method Chaining : " + e);
}
```
### getSqlLike<sup>8+</sup> ###
......@@ -2057,15 +2044,15 @@ getSqlLike():string
**示例**
```
try {
let query = new distributedData.Query();
let sql1 = query.getSqlLike();
console.log("GetSqlLike sql=" + sql1);
} catch (e) {
console.log("dumplicated calls should be ok : " + e);
}
```
```
try {
let query = new distributedData.Query();
let sql1 = query.getSqlLike();
console.log("GetSqlLike sql=" + sql1);
} catch (e) {
console.log("dumplicated calls should be ok : " + e);
}
```
## KVStore
......@@ -2092,22 +2079,22 @@ put(key: string, value: Uint8Array | string | number | boolean, callback: AsyncC
**示例**
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) {
if (err != undefined) {
console.log("put err: " + JSON.stringify(err));
return;
}
console.log("put success");
});
}catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) {
if (err != undefined) {
console.log("put err: " + JSON.stringify(err));
return;
}
console.log("put success");
});
}catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
### put
......@@ -2131,23 +2118,22 @@ put(key: string, value: Uint8Array | string | number | boolean): Promise&lt;void
| ------ | ------- |
| Promise&lt;void&gt; |Promise实例,用于异步处理。|
**示例**
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => {
console.log("put success: " + JSON.stringify(data));
}).catch((err) => {
console.log("put err: " + JSON.stringify(err));
});
}catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => {
console.log("put success: " + JSON.stringify(data));
}).catch((err) => {
console.log("put err: " + JSON.stringify(err));
});
}catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
### delete
......@@ -2167,29 +2153,29 @@ delete(key: string, callback: AsyncCallback&lt;void&gt;): void
**示例**
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) {
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) {
if (err != undefined) {
console.log("put err: " + JSON.stringify(err));
return;
}
console.log("put success");
kvStore.delete(KEY_TEST_STRING_ELEMENT, function (err,data) {
if (err != undefined) {
console.log("put err: " + JSON.stringify(err));
console.log("delete err: " + JSON.stringify(err));
return;
}
console.log("put success");
kvStore.delete(KEY_TEST_STRING_ELEMENT, function (err,data) {
if (err != undefined) {
console.log("delete err: " + JSON.stringify(err));
return;
}
console.log("delete success");
});
console.log("delete success");
});
}catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
});
}catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
### delete
......@@ -2214,25 +2200,25 @@ delete(key: string): Promise&lt;void&gt;
**示例**
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => {
console.log("put success: " + JSON.stringify(data));
kvStore.delete(KEY_TEST_STRING_ELEMENT).then((data) => {
console.log("delete success");
}).catch((err) => {
console.log("delete err: " + JSON.stringify(err));
});
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => {
console.log("put success: " + JSON.stringify(data));
kvStore.delete(KEY_TEST_STRING_ELEMENT).then((data) => {
console.log("delete success");
}).catch((err) => {
console.log("put err: " + JSON.stringify(err));
console.log("delete err: " + JSON.stringify(err));
});
}catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
}).catch((err) => {
console.log("put err: " + JSON.stringify(err));
});
}catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
### on
......@@ -2251,15 +2237,14 @@ on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;ChangeNotific
| type |[SubscribeType](#subscribetype) | 是 |表示订阅的类型。 |
| observer |Callback&lt;[ChangeNotification](#changenotification)&gt; | 是 |回调函数。 |
**示例**
```
let kvStore;
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, function (data) {
console.log("dataChange callback call data: " + JSON.stringify(data));
});
```
```
let kvStore;
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, function (data) {
console.log("dataChange callback call data: " + JSON.stringify(data));
});
```
### on
......@@ -2277,15 +2262,14 @@ on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt
| event |'syncComplete' | 是 |回调函数名称。 |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | 是 |回调函数。 |
**示例**
```
let kvStore;
kvStore.on('syncComplete', function (data) {
console.log("syncComplete callback call data: " + data);
});
```
```
let kvStore;
kvStore.on('syncComplete', function (data) {
console.log("syncComplete callback call data: " + data);
});
```
### off<sup>8+</sup>
......@@ -2304,15 +2288,15 @@ off(event:'dataChange', observer?: Callback&lt;ChangeNotification&gt;): void
**示例**
```
let kvStore;
kvStore.on('dataChange', function (data) {
console.log("syncComplete callback call data: " + data);
});
kvStore.off('dataChange', function (data) {
console.log("syncComplete callback call data: " + data);
});
```
```
let kvStore;
kvStore.on('dataChange', function (data) {
console.log("syncComplete callback call data: " + data);
});
kvStore.off('dataChange', function (data) {
console.log("syncComplete callback call data: " + data);
});
```
### putBatch<sup>8+</sup>
......@@ -2332,35 +2316,34 @@ putBatch(entries: Entry[], callback: AsyncCallback&lt;void&gt;): void
**示例**
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
await kvStore.getEntries('batch_test_string_key', function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
}catch(e) {
console.log('PutBatch e ' + e);
entries.push(entry);
}
```
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
await kvStore.getEntries('batch_test_string_key', function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
}catch(e) {
console.log('PutBatch e ' + e);
}
```
### putBatch<sup>8+</sup>
......@@ -2385,37 +2368,37 @@ putBatch(entries: Entry[]): Promise&lt;void&gt;
**示例**
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
await kvStore.getEntries('batch_test_string_key').then((entrys) => {
console.log('getEntries success');
console.log('PutBatch ' + JSON.stringify(entries));
}).catch((err) => {
console.log('getEntries fail ' + JSON.stringify(err));
});
entries.push(entry);
}
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
await kvStore.getEntries('batch_test_string_key').then((entrys) => {
console.log('getEntries success');
console.log('PutBatch ' + JSON.stringify(entries));
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
console.log('getEntries fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('PutBatch e ' + e);
}
```
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('PutBatch e ' + e);
}
```
### deleteBatch<sup>8+</sup>
......@@ -2435,34 +2418,34 @@ deleteBatch(keys: string[], callback: AsyncCallback&lt;void&gt;): void
**示例**
```
let kvStore;
try {
let entries = [];
let keys = [];
for (var i = 0; i < 5; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let entries = [];
let keys = [];
for (var i = 0; i < 5; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
keys.push(key + i);
}
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
await kvStore.deleteBatch(keys, async function (err,data) {
console.log('deleteBatch success');
});
});
}catch(e) {
console.log('DeleteBatch e ' + e);
entries.push(entry);
keys.push(key + i);
}
```
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
await kvStore.deleteBatch(keys, async function (err,data) {
console.log('deleteBatch success');
});
});
}catch(e) {
console.log('DeleteBatch e ' + e);
}
```
### deleteBatch<sup>8+</sup> ###
......@@ -2487,38 +2470,38 @@ deleteBatch(keys: string[]): Promise&lt;void&gt;
**示例**
```
let kvStore;
try {
let entries = [];
let keys = [];
for (var i = 0; i < 5; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let entries = [];
let keys = [];
for (var i = 0; i < 5; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
keys.push(key + i);
}
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
await kvStore.deleteBatch(keys).then((err) => {
console.log('deleteBatch success');
}).catch((err) => {
console.log('deleteBatch fail ' + JSON.stringify(err));
});
entries.push(entry);
keys.push(key + i);
}
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
await kvStore.deleteBatch(keys).then((err) => {
console.log('deleteBatch success');
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
console.log('deleteBatch fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('DeleteBatch e ' + e);
}
```
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('DeleteBatch e ' + e);
}
```
### startTransaction<sup>8+</sup> ###
......@@ -2537,40 +2520,40 @@ startTransaction(callback: AsyncCallback&lt;void&gt;): void
**示例**
```
let kvStore;
function putBatchString(len, prefix) {
let entries = [];
for (var i = 0; i < len; i++) {
var entry = {
key : prefix + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
function putBatchString(len, prefix) {
let entries = [];
for (var i = 0; i < len; i++) {
var entry = {
key : prefix + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
return entries;
entries.push(entry);
}
try {
var count = 0;
kvStore.on('dataChange', 0, function (data) {
console.log('startTransaction 0' + data)
count++;
});
kvStore.startTransaction(async function (err,data) {
console.log('startTransaction success');
let entries = putBatchString(10, 'batch_test_string_key');
console.log('entries: ' + JSON.stringify(entries));
await kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
});
return entries;
}
try {
var count = 0;
kvStore.on('dataChange', 0, function (data) {
console.log('startTransaction 0' + data)
count++;
});
kvStore.startTransaction(async function (err,data) {
console.log('startTransaction success');
let entries = putBatchString(10, 'batch_test_string_key');
console.log('entries: ' + JSON.stringify(entries));
await kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
});
}catch(e) {
console.log('startTransaction e ' + e);
}
```
});
}catch(e) {
console.log('startTransaction e ' + e);
}
```
### startTransaction<sup>8+</sup> ###
......@@ -2589,23 +2572,23 @@ startTransaction(): Promise&lt;void&gt;
**示例**
```
let kvStore;
try {
var count = 0;
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_ALL, function (data) {
console.log('startTransaction ' + JSON.stringify(data));
count++;
});
kvStore.startTransaction().then(async (err) => {
console.log('startTransaction success');
}).catch((err) => {
console.log('startTransaction fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('startTransaction e ' + e);
}
```
```
let kvStore;
try {
var count = 0;
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_ALL, function (data) {
console.log('startTransaction ' + JSON.stringify(data));
count++;
});
kvStore.startTransaction().then(async (err) => {
console.log('startTransaction success');
}).catch((err) => {
console.log('startTransaction fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('startTransaction e ' + e);
}
```
### commit<sup>8+</sup> ###
......@@ -2624,20 +2607,20 @@ commit(callback: AsyncCallback&lt;void&gt;): void
**示例**
```
let kvStore;
try {
kvStore.commit(function (err,data) {
if (err == undefined) {
console.log('commit success');
} else {
console.log('commit fail');
}
});
}catch(e) {
console.log('Commit e ' + e);
}
```
```
let kvStore;
try {
kvStore.commit(function (err,data) {
if (err == undefined) {
console.log('commit success');
} else {
console.log('commit fail');
}
});
}catch(e) {
console.log('Commit e ' + e);
}
```
### commit<sup>8+</sup> ###
......@@ -2656,18 +2639,18 @@ commit(): Promise&lt;void&gt;
**示例**
```
let kvStore;
try {
kvStore.commit().then(async (err) => {
console.log('commit success');
}).catch((err) => {
console.log('commit fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('Commit e ' + e);
}
```
```
let kvStore;
try {
kvStore.commit().then(async (err) => {
console.log('commit success');
}).catch((err) => {
console.log('commit fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('Commit e ' + e);
}
```
### rollback<sup>8+</sup> ###
......@@ -2686,20 +2669,20 @@ rollback(callback: AsyncCallback&lt;void&gt;): void
**示例**
```
let kvStore;
try {
kvStore.rollback(function (err,data) {
if (err == undefined) {
console.log('commit success');
} else {
console.log('commit fail');
}
});
}catch(e) {
console.log('Rollback e ' + e);
}
```
```
let kvStore;
try {
kvStore.rollback(function (err,data) {
if (err == undefined) {
console.log('commit success');
} else {
console.log('commit fail');
}
});
}catch(e) {
console.log('Rollback e ' + e);
}
```
### rollback<sup>8+</sup> ###
......@@ -2718,18 +2701,18 @@ rollback(): Promise&lt;void&gt;
**示例**
```
let kvStore;
try {
kvStore.rollback().then(async (err) => {
console.log('rollback success');
}).catch((err) => {
console.log('rollback fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('Rollback e ' + e);
}
```
```
let kvStore;
try {
kvStore.rollback().then(async (err) => {
console.log('rollback success');
}).catch((err) => {
console.log('rollback fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('Rollback e ' + e);
}
```
### enableSync<sup>8+</sup> ###
......@@ -2749,20 +2732,20 @@ enableSync(enabled: boolean, callback: AsyncCallback&lt;void&gt;): void
**示例**
```
let kvStore;
try {
kvStore.enableSync(true, function (err,data) {
if (err == undefined) {
console.log('enableSync success');
} else {
console.log('enableSync fail');
}
});
}catch(e) {
console.log('EnableSync e ' + e);
}
```
```
let kvStore;
try {
kvStore.enableSync(true, function (err,data) {
if (err == undefined) {
console.log('enableSync success');
} else {
console.log('enableSync fail');
}
});
}catch(e) {
console.log('EnableSync e ' + e);
}
```
### enableSync<sup>8+</sup> ###
......@@ -2787,18 +2770,18 @@ enableSync(enabled: boolean): Promise&lt;void&gt;
**示例**
```
let kvStore;
try {
kvStore.enableSync(true).then((err) => {
console.log('enableSync success');
}).catch((err) => {
console.log('enableSync fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('EnableSync e ' + e);
}
```
```
let kvStore;
try {
kvStore.enableSync(true).then((err) => {
console.log('enableSync success');
}).catch((err) => {
console.log('enableSync fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('EnableSync e ' + e);
}
```
### setSyncRange<sup>8+</sup> ###
......@@ -2819,18 +2802,18 @@ setSyncRange(localLabels: string[], remoteSupportLabels: string[], callback: Asy
**示例**
```
let kvStore;
try {
const localLabels = ['A', 'B'];
const remoteSupportLabels = ['C', 'D'];
kvStore.setSyncRange(localLabels, remoteSupportLabels, function (err,data) {
console.log('SetSyncRange put success');
});
}catch(e) {
console.log('SetSyncRange e ' + e);
}
```
```
let kvStore;
try {
const localLabels = ['A', 'B'];
const remoteSupportLabels = ['C', 'D'];
kvStore.setSyncRange(localLabels, remoteSupportLabels, function (err,data) {
console.log('SetSyncRange put success');
});
}catch(e) {
console.log('SetSyncRange e ' + e);
}
```
### setSyncRange<sup>8+</sup> ###
......@@ -2857,20 +2840,20 @@ setSyncRange(localLabels: string[], remoteSupportLabels: string[]): Promise&lt;v
**示例**
```
let kvStore;
try {
const localLabels = ['A', 'B'];
const remoteSupportLabels = ['C', 'D'];
kvStore.setSyncRange(localLabels, remoteSupportLabels).then((err) => {
console.log('setSyncRange success');
}).catch((err) => {
console.log('delete fail ' + err);
});
}catch(e) {
console.log('SetSyncRange e ' + e);
}
```
```
let kvStore;
try {
const localLabels = ['A', 'B'];
const remoteSupportLabels = ['C', 'D'];
kvStore.setSyncRange(localLabels, remoteSupportLabels).then((err) => {
console.log('setSyncRange success');
}).catch((err) => {
console.log('delete fail ' + err);
});
}catch(e) {
console.log('SetSyncRange e ' + e);
}
```
## SubscribeType
......@@ -2957,29 +2940,29 @@ get(key: string, callback: AsyncCallback&lt;Uint8Array | string | boolean | numb
| 参数名 | 参数类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------- |
| key |string | 是 |要查询数据的key,不能为空且长度不大于[MAX_KEY_LENGTH](#constants)。 |
| callback |AsyncCallback&lt;Uint8Array / string / boolean / number&gt;) | 是 |回调函数,获取查询的值。 |
| callback |AsyncCallback&lt;Uint8Array \| string \| boolean \| number&gt;) | 是 |回调函数,获取查询的值。 |
**示例**
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) {
if (err != undefined) {
console.log("put err: " + JSON.stringify(err));
return;
}
console.log("put success");
kvStore.get(KEY_TEST_STRING_ELEMENT, function (err,data) {
console.log("get success data: " + data);
});
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) {
if (err != undefined) {
console.log("put err: " + JSON.stringify(err));
return;
}
console.log("put success");
kvStore.get(KEY_TEST_STRING_ELEMENT, function (err,data) {
console.log("get success data: " + data);
});
}catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
});
}catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
### get
......@@ -3001,30 +2984,29 @@ get(key: string): Promise&lt;Uint8Array | string | boolean | number>
| 类型 | 说明 |
| ------ | ------- |
|Promise&lt;Uint8Array / string / boolean / number&gt; |Promise实例,用于获取异步返回结果。|
|Promise&lt;Uint8Array \| string \| boolean \| number&gt; |Promise实例,用于获取异步返回结果。|
**示例**
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => {
console.log("put success: " + JSON.stringify(data));
kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => {
console.log("get success data: " + data);
}).catch((err) => {
console.log("get err: " + JSON.stringify(err));
});
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => {
console.log("put success: " + JSON.stringify(data));
kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => {
console.log("get success data: " + data);
}).catch((err) => {
console.log("put err: " + JSON.stringify(err));
console.log("get err: " + JSON.stringify(err));
});
}catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
}).catch((err) => {
console.log("put err: " + JSON.stringify(err));
});
}catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
### getEntries<sup>8+</sup> ###
......@@ -3039,37 +3021,37 @@ getEntries(keyPrefix: string, callback: AsyncCallback&lt;Entry[]&gt;): void
| 参数名 | 参数类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------- |
| keyPrefix |string | 是 |表示要匹配的键前缀。 |
| callback |AsyncCallback&lt;Entry[]&gt; | 是 |回调函数,获取指定前缀的键值对列表。 |
| callback |AsyncCallback&lt;[Entry](#entry)[]&gt; | 是 |回调函数,获取指定前缀的键值对列表。 |
**示例**
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_number_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.INTEGER,
value : 222
}
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_number_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.INTEGER,
value : 222
}
entries.push(entry);
}
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
await kvStore.getEntries('batch_test_number_key', function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
}catch(e) {
console.log('PutBatch e ' + e);
entries.push(entry);
}
```
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
await kvStore.getEntries('batch_test_number_key', function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
}catch(e) {
console.log('PutBatch e ' + e);
}
```
### getEntries<sup>8+</sup> ###
......@@ -3094,40 +3076,40 @@ getEntries(keyPrefix: string): Promise&lt;Entry[]&gt;
**示例**
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
console.log('entries: ' + entries);
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
await kvStore.getEntries('batch_test_string_key').then((entrys) => {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
console.log('entrys[0].value: ' + JSON.stringify(entrys[0].value));
console.log('entrys[0].value.value: ' + entrys[0].value.value);
}).catch((err) => {
console.log('getEntries fail ' + JSON.stringify(err));
});
entries.push(entry);
}
console.log('entries: ' + entries);
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
await kvStore.getEntries('batch_test_string_key').then((entrys) => {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
console.log('entrys[0].value: ' + JSON.stringify(entrys[0].value));
console.log('entrys[0].value.value: ' + entrys[0].value.value);
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
console.log('getEntries fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('PutBatch e ' + e);
}
```
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('PutBatch e ' + e);
}
```
### getEntries<sup>8+</sup> ###
......@@ -3143,42 +3125,42 @@ getEntries(query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void
| 参数名 | 参数类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------- |
| query |[Query](#query8) | 是 |表示要匹配的键前缀。 |
| callback |AsyncCallback&lt;Entry[]&gt; | 是 |回调函数,获取指定前缀的键值对列表。 |
| callback |AsyncCallback&lt;[Entry](#entry)[]&gt; | 是 |回调函数,获取指定前缀的键值对列表。 |
**示例**
```
let kvStore;
try {
var arr = new Uint8Array([21,31]);
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_bool_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.BYTE_ARRAY,
value : arr
}
```
let kvStore;
try {
var arr = new Uint8Array([21,31]);
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_bool_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.BYTE_ARRAY,
value : arr
}
entries.push(entry);
}
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getEntries(query, function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
console.log('GetEntries success');
}catch(e) {
console.log('GetEntries e ' + e);
entries.push(entry);
}
```
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getEntries(query, function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
console.log('GetEntries success');
}catch(e) {
console.log('GetEntries e ' + e);
}
```
### getEntries<sup>8+</sup> ###
......@@ -3203,39 +3185,39 @@ getEntries(query: Query): Promise&lt;Entry[]&gt;
**示例**
```
try {
var arr = new Uint8Array([21,31]);
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_bool_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.BYTE_ARRAY,
value : arr
}
```
try {
var arr = new Uint8Array([21,31]);
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_bool_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.BYTE_ARRAY,
value : arr
}
entries.push(entry);
}
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getEntries(query).then((entrys) => {
console.log('getEntries success');
}).catch((err) => {
console.log('getEntries fail ' + JSON.stringify(err));
});
entries.push(entry);
}
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getEntries(query).then((entrys) => {
console.log('getEntries success');
}).catch((err) => {
console.log('GetEntries putBatch fail ' + JSON.stringify(err))
console.log('getEntries fail ' + JSON.stringify(err));
});
console.log('GetEntries success');
}catch(e) {
console.log('GetEntries e ' + e);
}
```
}).catch((err) => {
console.log('GetEntries putBatch fail ' + JSON.stringify(err))
});
console.log('GetEntries success');
}catch(e) {
console.log('GetEntries e ' + e);
}
```
### getResultSet<sup>8+</sup> ###
......@@ -3255,36 +3237,36 @@ getResultSet(keyPrefix: string, callback: AsyncCallback&lt;KvStoreResultSet&gt;)
**示例**
```
let kvStore;
try {
let resultSet;
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let resultSet;
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
kvStore.putBatch(entries, async function (err, data) {
console.log('GetResultSet putBatch success');
await kvStore.getResultSet('batch_test_string_key', async function (err, result) {
console.log('GetResultSet getResultSet success');
resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) {
console.log('GetResultSet closeResultSet success');
})
});
});
}catch(e) {
console.log('GetResultSet e ' + e);
entries.push(entry);
}
```
kvStore.putBatch(entries, async function (err, data) {
console.log('GetResultSet putBatch success');
await kvStore.getResultSet('batch_test_string_key', async function (err, result) {
console.log('GetResultSet getResultSet success');
resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) {
console.log('GetResultSet closeResultSet success');
})
});
});
}catch(e) {
console.log('GetResultSet e ' + e);
}
```
### getResultSet<sup>8+</sup> ###
......@@ -3309,42 +3291,42 @@ getResultSet(keyPrefix: string): Promise&lt;KvStoreResultSet&gt;
**示例**
```
let kvStore;
try {
let resultSet;
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let resultSet;
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
}).catch((err) => {
console.log('PutBatch putBatch fail ' + JSON.stringify(err));
});
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('GetResult getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('GetResult closeResultSet success');
}).catch((err) => {
console.log('closeResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResult e ' + e);
entries.push(entry);
}
```
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
}).catch((err) => {
console.log('PutBatch putBatch fail ' + JSON.stringify(err));
});
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('GetResult getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('GetResult closeResultSet success');
}).catch((err) => {
console.log('closeResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResult e ' + e);
}
```
### getResultSet<sup>8+</sup> ###
......@@ -3364,35 +3346,35 @@ getResultSet(query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): voi
**示例**
```
let kvStore;
try {
let resultSet;
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let resultSet;
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
kvStore.putBatch(entries, async function (err, data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSet(query, async function (err, result) {
console.log('getResultSet success');
resultSet = result;
});
});
} catch(e) {
console.log('GetResultSet e ' + e);
entries.push(entry);
}
```
kvStore.putBatch(entries, async function (err, data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSet(query, async function (err, result) {
console.log('getResultSet success');
resultSet = result;
});
});
} catch(e) {
console.log('GetResultSet e ' + e);
}
```
### getResultSet<sup>8+</sup> ###
......@@ -3417,39 +3399,39 @@ getResultSet(query: Query): Promise&lt;KvStoreResultSet&gt;
**示例**
```
let kvStore;
try {
let resultSet;
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let resultSet;
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
const query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSet(query).then((result) => {
console.log(' getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSet e ' + e);
entries.push(entry);
}
```
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
const query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSet(query).then((result) => {
console.log(' getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSet e ' + e);
}
```
### closeResultSet<sup>8+</sup> ###
......@@ -3468,21 +3450,21 @@ closeResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback&lt;void&gt;)
**示例**
```
let kvStore;
try {
let resultSet = null;
kvStore.closeResultSet(resultSet, function (err, data) {
if (err == undefined) {
console.log('closeResultSet success');
} else {
console.log('closeResultSet fail');
}
});
}catch(e) {
console.log('CloseResultSet e ' + e);
}
```
```
let kvStore;
try {
let resultSet = null;
kvStore.closeResultSet(resultSet, function (err, data) {
if (err == undefined) {
console.log('closeResultSet success');
} else {
console.log('closeResultSet fail');
}
});
}catch(e) {
console.log('CloseResultSet e ' + e);
}
```
### closeResultSet<sup>8+</sup> ###
......@@ -3507,19 +3489,19 @@ closeResultSet(resultSet: KvStoreResultSet): Promise&lt;void&gt;
**示例**
```
let kvStore;
try {
let resultSet = null;
kvStore.closeResultSet(resultSet).then(() => {
console.log('closeResultSet success');
}).catch((err) => {
console.log('closeResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('CloseResultSet e ' + e);
}
```
```
let kvStore;
try {
let resultSet = null;
kvStore.closeResultSet(resultSet).then(() => {
console.log('closeResultSet success');
}).catch((err) => {
console.log('closeResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('CloseResultSet e ' + e);
}
```
### getResultSize<sup>8+</sup> ###
......@@ -3539,33 +3521,33 @@ getResultSize(query: Query, callback: AsyncCallback&lt;number&gt;): void
**示例**
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
kvStore.putBatch(entries, async function (err, data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSize(query, async function (err, resultSize) {
console.log('getResultSet success');
});
});
} catch(e) {
console.log('GetResultSize e ' + e);
entries.push(entry);
}
```
kvStore.putBatch(entries, async function (err, data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSize(query, async function (err, resultSize) {
console.log('getResultSet success');
});
});
} catch(e) {
console.log('GetResultSize e ' + e);
}
```
### getResultSize<sup>8+</sup> ###
......@@ -3590,37 +3572,37 @@ getResultSize(query: Query): Promise&lt;number&gt;
**示例**
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
const query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSize(query).then((resultSize) => {
console.log('getResultSet success');
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSize e ' + e);
entries.push(entry);
}
```
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
const query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSize(query).then((resultSize) => {
console.log('getResultSet success');
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSize e ' + e);
}
```
### removeDeviceData<sup>8+</sup> ###
......@@ -3640,29 +3622,29 @@ removeDeviceData(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
**示例**
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
const VALUE_TEST_STRING_ELEMENT = 'value-string-002';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) {
console.log('put success');
const deviceid = 'no_exist_device_id';
await kvStore.removeDeviceData(deviceid, async function (err,data) {
if (err == undefined) {
console.log('removeDeviceData success');
} else {
console.log('removeDeviceData fail');
await kvStore.get(KEY_TEST_STRING_ELEMENT, async function (err,data) {
console.log('RemoveDeviceData get success');
});
}
});
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
const VALUE_TEST_STRING_ELEMENT = 'value-string-002';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) {
console.log('put success');
const deviceid = 'no_exist_device_id';
await kvStore.removeDeviceData(deviceid, async function (err,data) {
if (err == undefined) {
console.log('removeDeviceData success');
} else {
console.log('removeDeviceData fail');
await kvStore.get(KEY_TEST_STRING_ELEMENT, async function (err,data) {
console.log('RemoveDeviceData get success');
});
}
});
}catch(e) {
console.log('RemoveDeviceData e ' + e);
}
```
});
}catch(e) {
console.log('RemoveDeviceData e ' + e);
}
```
### removeDeviceData<sup>8+</sup> ###
......@@ -3687,31 +3669,31 @@ removeDeviceData(deviceId: string): Promise&lt;void&gt;
**示例**
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
const VALUE_TEST_STRING_ELEMENT = 'value-string-001';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((err) => {
console.log('removeDeviceData put success');
}).catch((err) => {
console.log('put fail ' + JSON.stringify(err));
});
const deviceid = 'no_exist_device_id';
kvStore.removeDeviceData(deviceid).then((err) => {
console.log('removeDeviceData success');
}).catch((err) => {
console.log('removeDeviceData fail ' + JSON.stringify(err));
});
kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => {
console.log('get success data:' + data);
}).catch((err) => {
console.log('RemoveDeviceData get fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('RemoveDeviceData e ' + e);
}
```
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
const VALUE_TEST_STRING_ELEMENT = 'value-string-001';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((err) => {
console.log('removeDeviceData put success');
}).catch((err) => {
console.log('put fail ' + JSON.stringify(err));
});
const deviceid = 'no_exist_device_id';
kvStore.removeDeviceData(deviceid).then((err) => {
console.log('removeDeviceData success');
}).catch((err) => {
console.log('removeDeviceData fail ' + JSON.stringify(err));
});
kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => {
console.log('get success data:' + data);
}).catch((err) => {
console.log('RemoveDeviceData get fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('RemoveDeviceData e ' + e);
}
```
### on<sup>8+</sup> ###
......@@ -3731,23 +3713,23 @@ on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt
**示例**
```
let kvStore;
const KEY_TEST_FLOAT_ELEMENT = 'key_test_float';
const VALUE_TEST_FLOAT_ELEMENT = 321.12;
try {
kvStore.on('syncComplete', function (data) {
console.log('syncComplete ' + data)
});
kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then((data) => {
console.log('syncComplete put success');
}).catch((error) => {
console.log('syncComplete put fail ' + error);
});
}catch(e) {
console.log('syncComplete put e ' + e);
}
```
```
let kvStore;
const KEY_TEST_FLOAT_ELEMENT = 'key_test_float';
const VALUE_TEST_FLOAT_ELEMENT = 321.12;
try {
kvStore.on('syncComplete', function (data) {
console.log('syncComplete ' + data)
});
kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then((data) => {
console.log('syncComplete put success');
}).catch((error) => {
console.log('syncComplete put fail ' + error);
});
}catch(e) {
console.log('syncComplete put e ' + e);
}
```
### off<sup>8+</sup> ###
......@@ -3765,21 +3747,20 @@ off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&
| event |'syncComplete' | 是 |同步完成时触发的事件名。 |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | 否 |用于向调用方发送同步结果的回调。 |
**示例**
```
let kvStore;
try {
const func = function (data) {
console.log('syncComplete ' + data)
};
kvStore.on('syncComplete', func);
kvStore.off('syncComplete', func);
}catch(e) {
console.log('syncComplete e ' + e);
}
```
```
let kvStore;
try {
const func = function (data) {
console.log('syncComplete ' + data)
};
kvStore.on('syncComplete', func);
kvStore.off('syncComplete', func);
}catch(e) {
console.log('syncComplete e ' + e);
}
```
### sync
......@@ -3801,10 +3782,10 @@ sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void
**示例**
```
let kvStore;
kvStore.sync('deviceIds', distributedData.SyncMode.PULL_ONLY, 1000);
```
```
let kvStore;
kvStore.sync('deviceIds', distributedData.SyncMode.PULL_ONLY, 1000);
```
### setSyncParam<sup>8+</sup> ###
......@@ -3821,20 +3802,19 @@ setSyncParam(defaultAllowedDelayMs: number, callback: AsyncCallback&lt;void&gt;)
| defaultAllowedDelayMs |number | 是 |表示数据库同步允许的默认延迟,以毫秒为单位。 |
| callback |AsyncCallback&lt;void&gt; | 是 |回调函数。 |
**示例**
```
let kvStore;
try {
const defaultAllowedDelayMs = 500;
kvStore.setSyncParam(defaultAllowedDelayMs, function (err,data) {
console.log('SetSyncParam put success');
});
}catch(e) {
console.log('testSingleKvStoreSetSyncParam e ' + e);
}
```
```
let kvStore;
try {
const defaultAllowedDelayMs = 500;
kvStore.setSyncParam(defaultAllowedDelayMs, function (err,data) {
console.log('SetSyncParam put success');
});
}catch(e) {
console.log('testSingleKvStoreSetSyncParam e ' + e);
}
```
### setSyncParam<sup>8+</sup> ###
......@@ -3860,19 +3840,19 @@ setSyncParam(defaultAllowedDelayMs: number): Promise&lt;void&gt;
**示例**
```
let kvStore;
try {
const defaultAllowedDelayMs = 500;
kvStore.setSyncParam(defaultAllowedDelayMs).then((err) => {
console.log('SetSyncParam put success');
}).catch((err) => {
console.log('SetSyncParam put fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('SetSyncParam e ' + e);
}
```
```
let kvStore;
try {
const defaultAllowedDelayMs = 500;
kvStore.setSyncParam(defaultAllowedDelayMs).then((err) => {
console.log('SetSyncParam put success');
}).catch((err) => {
console.log('SetSyncParam put fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('SetSyncParam e ' + e);
}
```
### getSecurityLevel<sup>8+</sup> ###
......@@ -3891,16 +3871,16 @@ getSecurityLevel(callback: AsyncCallback&lt;SecurityLevel&gt;): void
**示例**
```
let kvStore;
try {
kvStore.getSecurityLevel(function (err,data) {
console.log('getSecurityLevel success');
});
}catch(e) {
console.log('GetSecurityLeve e ' + e);
}
```
```
let kvStore;
try {
kvStore.getSecurityLevel(function (err,data) {
console.log('getSecurityLevel success');
});
}catch(e) {
console.log('GetSecurityLeve e ' + e);
}
```
### getSecurityLevel<sup>8+</sup> ###
......@@ -3917,21 +3897,20 @@ getSecurityLevel(): Promise&lt;SecurityLevel&gt;
| ------ | ------- |
|Promise&lt;[SecurityLevel](#securitylevel)&gt; |Promise实例,用于获取异步返回结果。|
**示例**
```
let kvStore;
try {
kvStore.getSecurityLevel().then((data) => {
console.log(' getSecurityLevel success');
}).catch((err) => {
console.log('getSecurityLevel fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetSecurityLeve e ' + e);
}
```
```
let kvStore;
try {
kvStore.getSecurityLevel().then((data) => {
console.log(' getSecurityLevel success');
}).catch((err) => {
console.log('getSecurityLevel fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetSecurityLeve e ' + e);
}
```
## DeviceKVStore<sup>8+</sup> ##
......@@ -3954,26 +3933,25 @@ get(deviceId: string, key: string, callback: AsyncCallback&lt;boolean|string|num
| ----- | ------ | ---- | ----------------------- |
| deviceId |string | 是 |标识要查询其数据的设备。 |
| key |string | 是 |表示要查询 key 值的键。 |
| callback |AsyncCallback&lt;boolean/string/number/Uint8Array&gt; | 是 |回调函数,返回匹配给定条件的字符串值。 |
| callback |AsyncCallback&lt;boolean\|string\|number\|Uint8Array&gt; | 是 |回调函数,返回匹配给定条件的字符串值。 |
**示例**
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
const VALUE_TEST_STRING_ELEMENT = 'value-string-002';
try{
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) {
console.log('put success');
kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT, function (err,data) {
console.log('get success');
});
})
}catch(e) {
console.log('get e' + e);
}
```
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
const VALUE_TEST_STRING_ELEMENT = 'value-string-002';
try{
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) {
console.log('put success');
kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT, function (err,data) {
console.log('get success');
});
})
}catch(e) {
console.log('get e' + e);
}
```
### get<sup>8+</sup> ###
......@@ -3995,29 +3973,29 @@ get(deviceId: string, key: string): Promise&lt;boolean|string|number|Uint8Array&
| 类型 | 说明 |
| ------ | ------- |
|Promise&lt;boolean/string/number/Uint8Array&gt; |Promise实例,用于获取异步返回结果。|
|Promise&lt;boolean\|string\|number\|Uint8Array&gt; |Promise实例,用于获取异步返回结果。|
**示例**
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
const VALUE_TEST_STRING_ELEMENT = 'value-string-002';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then(async (data) => {
console.log(' put success');
kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT).then((data) => {
console.log('get success');
}).catch((err) => {
console.log('get fail ' + JSON.stringify(err));
});
}).catch((error) => {
console.log('put error' + error);
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
const VALUE_TEST_STRING_ELEMENT = 'value-string-002';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then(async (data) => {
console.log(' put success');
kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT).then((data) => {
console.log('get success');
}).catch((err) => {
console.log('get fail ' + JSON.stringify(err));
});
} catch (e) {
console.log('Get e ' + e);
}
```
}).catch((error) => {
console.log('put error' + error);
});
} catch (e) {
console.log('Get e ' + e);
}
```
### getEntries<sup>8+</sup> ###
......@@ -4038,34 +4016,34 @@ getEntries(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;Entry
**示例**
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
console.log('entries: ' + entries);
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
await kvStore.getEntries('localDeviceId', 'batch_test_string_key', function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
}catch(e) {
console.log('PutBatch e ' + e);
entries.push(entry);
}
```
console.log('entries: ' + entries);
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
await kvStore.getEntries('localDeviceId', 'batch_test_string_key', function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
}catch(e) {
console.log('PutBatch e ' + e);
}
```
### getEntries<sup>8+</sup> ###
......@@ -4091,40 +4069,40 @@ getEntries(deviceId: string, keyPrefix: string): Promise&lt;Entry[]&gt;
**示例**
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
console.log('entries: ' + entries);
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
await kvStore.getEntries('localDeviceId', 'batch_test_string_key').then((entrys) => {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
console.log('entrys[0].value: ' + JSON.stringify(entrys[0].value));
console.log('entrys[0].value.value: ' + entrys[0].value.value);
}).catch((err) => {
console.log('getEntries fail ' + JSON.stringify(err));
});
entries.push(entry);
}
console.log('entries: ' + entries);
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
await kvStore.getEntries('localDeviceId', 'batch_test_string_key').then((entrys) => {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
console.log('entrys[0].value: ' + JSON.stringify(entrys[0].value));
console.log('entrys[0].value.value: ' + entrys[0].value.value);
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
console.log('getEntries fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('PutBatch e ' + e);
}
```
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('PutBatch e ' + e);
}
```
### getEntries<sup>8+</sup> ###
......@@ -4144,40 +4122,40 @@ getEntries(query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void
**示例**
```
let kvStore;
try {
var arr = new Uint8Array([21,31]);
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_bool_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.BYTE_ARRAY,
value : arr
}
```
let kvStore;
try {
var arr = new Uint8Array([21,31]);
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_bool_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.BYTE_ARRAY,
value : arr
}
entries.push(entry);
}
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
expect(err == undefined).assertTrue();
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
await kvStore.getEntries(query, function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
console.log('GetEntries success');
}catch(e) {
console.log('GetEntries e ' + e);
entries.push(entry);
}
```
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
expect(err == undefined).assertTrue();
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
await kvStore.getEntries(query, function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
console.log('GetEntries success');
}catch(e) {
console.log('GetEntries e ' + e);
}
```
### getEntries<sup>8+</sup> ###
......@@ -4202,40 +4180,40 @@ getEntries(query: Query): Promise&lt;Entry[]&gt;
**示例**
```
let kvStore;
try {
var arr = new Uint8Array([21,31]);
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_bool_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.BYTE_ARRAY,
value : arr
}
```
let kvStore;
try {
var arr = new Uint8Array([21,31]);
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_bool_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.BYTE_ARRAY,
value : arr
}
entries.push(entry);
}
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getEntries(query).then((entrys) => {
console.log('getEntries success');
}).catch((err) => {
console.log('getEntries fail ' + JSON.stringify(err));
});
entries.push(entry);
}
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getEntries(query).then((entrys) => {
console.log('getEntries success');
}).catch((err) => {
console.log('GetEntries putBatch fail ' + JSON.stringify(err))
console.log('getEntries fail ' + JSON.stringify(err));
});
console.log('GetEntries success');
}catch(e) {
console.log('GetEntries e ' + e);
}
```
}).catch((err) => {
console.log('GetEntries putBatch fail ' + JSON.stringify(err))
});
console.log('GetEntries success');
}catch(e) {
console.log('GetEntries e ' + e);
}
```
### getEntries<sup>8+</sup> ###
......@@ -4256,40 +4234,40 @@ getEntries(deviceId: string, query: Query, callback: AsyncCallback&lt;Entry[]&gt
**示例**
```
let kvStore;
try {
var arr = new Uint8Array([21,31]);
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_bool_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.BYTE_ARRAY,
value : arr
}
```
let kvStore;
try {
var arr = new Uint8Array([21,31]);
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_bool_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.BYTE_ARRAY,
value : arr
}
entries.push(entry);
}
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
expect(err == undefined).assertTrue();
var query = new distributedData.Query();
query.deviceId('localDeviceId');
query.prefixKey("batch_test");
await kvStore.getEntries('localDeviceId', query, function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
})
});
console.log('GetEntries success');
}catch(e) {
console.log('GetEntries e ' + e);
entries.push(entry);
}
```
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
expect(err == undefined).assertTrue();
var query = new distributedData.Query();
query.deviceId('localDeviceId');
query.prefixKey("batch_test");
await kvStore.getEntries('localDeviceId', query, function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
})
});
console.log('GetEntries success');
}catch(e) {
console.log('GetEntries e ' + e);
}
```
### getEntries<sup>8+</sup> ###
......@@ -4315,41 +4293,41 @@ getEntries(deviceId: string, query: Query): Promise&lt;Entry[]&gt;
**示例**
```
let kvStore;
try {
var arr = new Uint8Array([21,31]);
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_bool_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.BYTE_ARRAY,
value : arr
}
```
let kvStore;
try {
var arr = new Uint8Array([21,31]);
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_bool_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.BYTE_ARRAY,
value : arr
}
entries.push(entry);
}
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
var query = new distributedData.Query();
query.deviceId('localDeviceId');
query.prefixKey("batch_test");
await kvStore.getEntries('localDeviceId', query).then((entrys) => {
console.log('getEntries success');
}).catch((err) => {
console.log('getEntries fail ' + JSON.stringify(err));
});
entries.push(entry);
}
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
var query = new distributedData.Query();
query.deviceId('localDeviceId');
query.prefixKey("batch_test");
await kvStore.getEntries('localDeviceId', query).then((entrys) => {
console.log('getEntries success');
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
console.log('getEntries fail ' + JSON.stringify(err));
});
console.log('GetEntries success');
}catch(e) {
console.log('GetEntries e ' + e);
}
```
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
console.log('GetEntries success');
}catch(e) {
console.log('GetEntries e ' + e);
}
```
### getResultSet<sup>8+</sup> ###
......@@ -4370,21 +4348,21 @@ getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;KvS
**示例**
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('localDeviceId', 'batch_test_string_key', async function (err, result) {
console.log('getResultSet success');
resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success');
})
});
}catch(e) {
console.log('GetResultSet e ' + e);
}
```
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('localDeviceId', 'batch_test_string_key', async function (err, result) {
console.log('getResultSet success');
resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success');
})
});
}catch(e) {
console.log('GetResultSet e ' + e);
}
```
### getResultSet<sup>8+</sup> ###
......@@ -4410,25 +4388,25 @@ getResultSet(deviceId: string, keyPrefix: string): Promise&lt;KvStoreResultSet&g
**示例**
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('localDeviceId', 'batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('closeResultSet success');
}).catch((err) => {
console.log('closeResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSet e ' + e);
}
```
```
let kvStore;
try {
let resultSet;
kvStore.getResultSet('localDeviceId', 'batch_test_string_key').then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('closeResultSet success');
}).catch((err) => {
console.log('closeResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSet e ' + e);
}
```
### getResultSet<sup>8+</sup> ###
......@@ -4448,39 +4426,39 @@ getResultSet(query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): voi
**示例**
```
let kvStore;
try {
let resultSet;
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let resultSet;
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
kvStore.putBatch(entries, async function (err, data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
await kvStore.getResultSet(query, async function (err, result) {
console.log('getResultSet success');
resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success');
})
});
});
} catch(e) {
console.log('GetResultSet e ' + e);
entries.push(entry);
}
```
kvStore.putBatch(entries, async function (err, data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
await kvStore.getResultSet(query, async function (err, result) {
console.log('getResultSet success');
resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success');
})
});
});
} catch(e) {
console.log('GetResultSet e ' + e);
}
```
### getResultSet<sup>8+</sup> ###
......@@ -4505,46 +4483,46 @@ getResultSet(query: Query): Promise&lt;KvStoreResultSet&gt;
**示例**
```
let kvStore;
try {
let resultSet;
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let resultSet;
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + err);
});
const query = new distributedData.Query();
query.deviceId('localDeviceId');
query.prefixKey("batch_test");
console.log("GetResultSet " + query.getSqlLike());
kvStore.getResultSet(query).then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('closeResultSet success');
}).catch((err) => {
console.log('closeResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSet e ' + e);
entries.push(entry);
}
```
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + err);
});
const query = new distributedData.Query();
query.deviceId('localDeviceId');
query.prefixKey("batch_test");
console.log("GetResultSet " + query.getSqlLike());
kvStore.getResultSet(query).then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('closeResultSet success');
}).catch((err) => {
console.log('closeResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSet e ' + e);
}
```
### getResultSet<sup>8+</sup> ###
......@@ -4565,38 +4543,38 @@ getResultSet(deviceId: string, query: Query, callback: AsyncCallback&lt;KvStoreR
**示例**
```
let kvStore;
try {
let resultSet;
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let resultSet;
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
kvStore.putBatch(entries, async function (err, data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSet('localDeviceId', query, async function (err, result) {
console.log('getResultSet success');
resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success');
})
});
});
} catch(e) {
console.log('GetResultSet e ' + e);
entries.push(entry);
}
```
kvStore.putBatch(entries, async function (err, data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSet('localDeviceId', query, async function (err, result) {
console.log('getResultSet success');
resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success');
})
});
});
} catch(e) {
console.log('GetResultSet e ' + e);
}
```
### getResultSet<sup>8+</sup> ###
......@@ -4622,47 +4600,47 @@ getResultSet(deviceId: string, query: Query): Promise&lt;KvStoreResultSet&gt;
**示例**
```
let kvStore;
try {
let resultSet;
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let resultSet;
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('GetResultSet putBatch success');
}).catch((err) => {
console.log('PutBatch putBatch fail ' + JSON.stringify(err));
});
const query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSet('localDeviceId', query).then((result) => {
console.log('GetResultSet getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('GetResultSet getResultSet fail ' + JSON.stringify(err));
});
query.deviceId('localDeviceId');
console.log("GetResultSet " + query.getSqlLike());
kvStore.closeResultSet(resultSet).then((err) => {
console.log('GetResultSet closeResultSet success');
}).catch((err) => {
console.log('GetResultSet closeResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSet e ' + e);
entries.push(entry);
}
```
kvStore.putBatch(entries).then(async (err) => {
console.log('GetResultSet putBatch success');
}).catch((err) => {
console.log('PutBatch putBatch fail ' + JSON.stringify(err));
});
const query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSet('localDeviceId', query).then((result) => {
console.log('GetResultSet getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('GetResultSet getResultSet fail ' + JSON.stringify(err));
});
query.deviceId('localDeviceId');
console.log("GetResultSet " + query.getSqlLike());
kvStore.closeResultSet(resultSet).then((err) => {
console.log('GetResultSet closeResultSet success');
}).catch((err) => {
console.log('GetResultSet closeResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSet e ' + e);
}
```
### closeResultSet<sup>8+</sup> ###
......@@ -4682,22 +4660,22 @@ closeResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback&lt;void&gt;)
**示例**
```
let kvStore;
try {
console.log('CloseResultSet success');
let resultSet = null;
kvStore.closeResultSet(resultSet, function (err, data) {
if (err == undefined) {
console.log('closeResultSet success');
} else {
console.log('closeResultSet fail');
}
});
}catch(e) {
console.log('CloseResultSet e ' + e);
}
```
```
let kvStore;
try {
console.log('CloseResultSet success');
let resultSet = null;
kvStore.closeResultSet(resultSet, function (err, data) {
if (err == undefined) {
console.log('closeResultSet success');
} else {
console.log('closeResultSet fail');
}
});
}catch(e) {
console.log('CloseResultSet e ' + e);
}
```
### closeResultSet<sup>8+</sup> ###
......@@ -4722,20 +4700,20 @@ closeResultSet(resultSet: KvStoreResultSet): Promise&lt;void&gt;
**示例**
```
let kvStore;
try {
console.log('CloseResultSet success');
let resultSet = null;
kvStore.closeResultSet(resultSet).then(() => {
console.log('closeResultSet success');
}).catch((err) => {
console.log('closeResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('CloseResultSet e ' + e);
}
```
```
let kvStore;
try {
console.log('CloseResultSet success');
let resultSet = null;
kvStore.closeResultSet(resultSet).then(() => {
console.log('closeResultSet success');
}).catch((err) => {
console.log('closeResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('CloseResultSet e ' + e);
}
```
### getResultSize<sup>8+</sup> ###
......@@ -4755,34 +4733,34 @@ getResultSize(query: Query, callback: AsyncCallback&lt;number&gt;): void
**示例**
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
kvStore.putBatch(entries, async function (err, data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
await kvStore.getResultSize(query, async function (err, resultSize) {
console.log('getResultSet success');
});
});
} catch(e) {
console.log('GetResultSize e ' + e);
entries.push(entry);
}
```
kvStore.putBatch(entries, async function (err, data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
await kvStore.getResultSize(query, async function (err, resultSize) {
console.log('getResultSet success');
});
});
} catch(e) {
console.log('GetResultSize e ' + e);
}
```
### getResultSize<sup>8+</sup> ###
......@@ -4807,38 +4785,38 @@ getResultSize(query: Query): Promise&lt;number&gt;
**示例**
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
kvStore.getResultSize(query).then((resultSize) => {
console.log('getResultSet success');
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSize e ' + e);
entries.push(entry);
}
```
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
kvStore.getResultSize(query).then((resultSize) => {
console.log('getResultSet success');
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSize e ' + e);
}
```
### getResultSize<sup>8+</sup> ###
......@@ -4859,33 +4837,33 @@ getResultSize(deviceId: string, query: Query, callback: AsyncCallback&lt;number&
**示例**
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
kvStore.putBatch(entries, async function (err, data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSize('localDeviceId', query, async function (err, resultSize) {
console.log('getResultSet success');
});
});
} catch(e) {
console.log('GetResultSize e ' + e);
entries.push(entry);
}
```
kvStore.putBatch(entries, async function (err, data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSize('localDeviceId', query, async function (err, resultSize) {
console.log('getResultSet success');
});
});
} catch(e) {
console.log('GetResultSize e ' + e);
}
```
### getResultSize<sup>8+</sup> ###
......@@ -4911,37 +4889,37 @@ getResultSize(deviceId: string, query: Query): Promise&lt;number&gt;
**示例**
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
```
let kvStore;
try {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key : key + i,
value : {
type : distributedData.ValueType.STRING,
value : 'batch_test_string_value'
}
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
var query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSize('localDeviceId', query).then((resultSize) => {
console.log('getResultSet success');
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSize e ' + e);
entries.push(entry);
}
```
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
var query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSize('localDeviceId', query).then((resultSize) => {
console.log('getResultSet success');
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSize e ' + e);
}
```
### removeDeviceData<sup>8+</sup> ###
......@@ -4961,29 +4939,29 @@ removeDeviceData(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
**示例**
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-string-001';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) {
console.log('RemoveDeviceData put success');
const deviceid = 'no_exist_device_id';
await kvStore.removeDeviceData(deviceid, async function (err,data) {
if (err == undefined) {
console.log('removeDeviceData success');
} else {
console.log('removeDeviceData fail');
await kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT, async function (err,data) {
console.log('RemoveDeviceData get success');
});
}
});
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-string-001';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) {
console.log('RemoveDeviceData put success');
const deviceid = 'no_exist_device_id';
await kvStore.removeDeviceData(deviceid, async function (err,data) {
if (err == undefined) {
console.log('removeDeviceData success');
} else {
console.log('removeDeviceData fail');
await kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT, async function (err,data) {
console.log('RemoveDeviceData get success');
});
}
});
}catch(e) {
console.log('RemoveDeviceData e ' + e);
}
```
});
}catch(e) {
console.log('RemoveDeviceData e ' + e);
}
```
### removeDeviceData<sup>8+</sup> ###
......@@ -5008,31 +4986,31 @@ removeDeviceData(deviceId: string): Promise&lt;void&gt;
**示例**
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-string-001';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((err) => {
console.log('RemoveDeviceData put success');
}).catch((err) => {
console.log('RemoveDeviceData put fail ' + JSON.stringify(err));
});
const deviceid = 'no_exist_device_id';
kvStore.removeDeviceData(deviceid).then((err) => {
console.log('removeDeviceData success');
}).catch((err) => {
console.log('removeDeviceData fail ' + JSON.stringify(err));
});
kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT).then((data) => {
console.log('RemoveDeviceData get success data:' + data);
}).catch((err) => {
console.log('RemoveDeviceData get fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('RemoveDeviceData e ' + e);
}
```
```
let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-string-001';
try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((err) => {
console.log('RemoveDeviceData put success');
}).catch((err) => {
console.log('RemoveDeviceData put fail ' + JSON.stringify(err));
});
const deviceid = 'no_exist_device_id';
kvStore.removeDeviceData(deviceid).then((err) => {
console.log('removeDeviceData success');
}).catch((err) => {
console.log('removeDeviceData fail ' + JSON.stringify(err));
});
kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT).then((data) => {
console.log('RemoveDeviceData get success data:' + data);
}).catch((err) => {
console.log('RemoveDeviceData get fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('RemoveDeviceData e ' + e);
}
```
### sync<sup>8+</sup> ###
......@@ -5052,27 +5030,26 @@ sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void
| mode |[SyncMode](#syncmode) | 是 |表示同步方式,PUSH、PULL或PUSH_PULL。 |
| allowedDelayMs |number | 否 |可选参数,允许延时时间,单位:ms(毫秒)。 |
**示例**
```
let kvStore;
const KEY_TEST_SYNC_ELEMENT = 'key_test_sync';
const VALUE_TEST_SYNC_ELEMENT = 'value-string-001';
try {
kvStore.on('syncComplete', function (data) {
console.log('Sync dataChange');
});
kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err,data) {
console.log('Sync put success');
const devices = ['deviceList'];
const mode = distributedData.SyncMode.PULL_ONLY;
kvStore.sync(devices, mode);
});
}catch(e) {
console.log('Sync e' + e);
}
```
```
let kvStore;
const KEY_TEST_SYNC_ELEMENT = 'key_test_sync';
const VALUE_TEST_SYNC_ELEMENT = 'value-string-001';
try {
kvStore.on('syncComplete', function (data) {
console.log('Sync dataChange');
});
kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err,data) {
console.log('Sync put success');
const devices = ['deviceList'];
const mode = distributedData.SyncMode.PULL_ONLY;
kvStore.sync(devices, mode);
});
}catch(e) {
console.log('Sync e' + e);
}
```
### on<sup>8+</sup> ###
......@@ -5091,22 +5068,22 @@ on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt
**示例**
```
const KEY_TEST_FLOAT_ELEMENT = 'key_test_float';
const VALUE_TEST_FLOAT_ELEMENT = 321.12;
try {
kvStore.on('syncComplete', function (data) {
console.log('syncComplete ' + data)
});
kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then((data) => {
console.log('syncComplete put success');
}).catch((error) => {
console.log('syncComplete put fail ' + error);
});
}catch(e) {
console.log('syncComplete put e ' + e);
}
```
```
const KEY_TEST_FLOAT_ELEMENT = 'key_test_float';
const VALUE_TEST_FLOAT_ELEMENT = 321.12;
try {
kvStore.on('syncComplete', function (data) {
console.log('syncComplete ' + data)
});
kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then((data) => {
console.log('syncComplete put success');
}).catch((error) => {
console.log('syncComplete put fail ' + error);
});
}catch(e) {
console.log('syncComplete put e ' + e);
}
```
### off<sup>8+</sup> ###
......@@ -5124,21 +5101,20 @@ off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&
| event |'syncComplete' | 是 |同步完成时触发的事件名。 |
| syncCallback |Callback<Array&lt;[string, number]&gt;&gt; | 否 |用于向调用方发送同步结果的回调。 |
**示例**
```
let kvStore;
try {
const func = function (data) {
console.log('syncComplete ' + data)
};
kvStore.on('syncComplete', func);
kvStore.off('syncComplete', func);
}catch(e) {
console.log('syncComplete e ' + e);
}
```
```
let kvStore;
try {
const func = function (data) {
console.log('syncComplete ' + data)
};
kvStore.on('syncComplete', func);
kvStore.off('syncComplete', func);
}catch(e) {
console.log('syncComplete e ' + e);
}
```
## SyncMode
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册