提交 50420599 编写于 作者: Y ylq121

xiugai

Signed-off-by: Nylq121 <yangqing89@huawei.com>
上级 ee3914ba
......@@ -509,7 +509,7 @@ try {
on(event: 'distributedDataServiceDie', deathCallback: Callback&lt;void&gt;): void
订阅服务状态变更通知,此方法为同步方法
订阅服务状态变更通知。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
......@@ -540,7 +540,7 @@ try {
off(event: 'distributedDataServiceDie', deathCallback?: Callback&lt;void&gt;): void
取消订阅服务状态变更通知,此方法为同步方法
取消订阅服务状态变更通知。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
......@@ -2234,17 +2234,17 @@ try {
on(event: 'dataChange', type: SubscribeType, listener: Callback&lt;ChangeNotification&gt;): void
订阅指定类型的数据变更通知,此方法为同步方法
订阅指定类型的数据变更通知。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------- |
| event |string | 是 |订阅的事件名,固定为'dataChange',表示数据变更事件。 |
| type |[SubscribeType](#subscribetype) | 是 |表示订阅的类型。 |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; | 是 |回调函数。 |
| -------- | --------------------------------------------------------- | ---- | ---------------------------------------------------- |
| event | string | 是 | 订阅的事件名,固定为'dataChange',表示数据变更事件。 |
| type | [SubscribeType](#subscribetype) | 是 | 表示订阅的类型。 |
| listener | Callback&lt;[ChangeNotification](#changenotification)&gt; | 是 | 回调函数。 |
**示例:**
......@@ -2259,16 +2259,16 @@ kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, fun
on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
订阅同步完成事件回调通知,此方法为同步方法
订阅同步完成事件回调通知。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------- |
| event |string | 是 |订阅的事件名,固定为'syncComplete',表示同步完成事件。 |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | 是 |回调函数。 |
| ------------ | --------------------------------------------- | ---- | ------------------------------------------------------ |
| event | string | 是 | 订阅的事件名,固定为'syncComplete',表示同步完成事件。 |
| syncCallback | Callback&lt;Array&lt;[string, number]&gt;&gt; | 是 | 回调函数。用于向调用方发送同步结果的回调。 |
**示例:**
......@@ -2283,16 +2283,18 @@ kvStore.on('syncComplete', function (data) {
off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void
取消订阅数据变更通知,此方法为同步方法
取消订阅数据变更通知。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------- |
| event |string | 是 |取消订阅的事件名,固定为'dataChange',表示数据变更事件。 |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; |否 |回调函数。 |
| -------- | --------------------------------------------------------- | ---- | -------------------------------------------------------- |
| event | string | 是 | 取消订阅的事件名,固定为'dataChange',表示数据变更事件。 |
| listener | Callback&lt;[ChangeNotification](#changenotification)&gt; | 否 | 回调函数。 |
**示例:**
......@@ -2315,6 +2317,42 @@ class KvstoreModel {
}
```
### off('syncComplete')<sup>8+</sup>
off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
取消订阅同步完成事件回调通知。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | --------------------------------------------- | ---- | ---------------------------------------------------------- |
| event | string | 是 | 取消订阅的事件名,固定为'syncComplete',表示同步完成事件。 |
| syncCallback | Callback&lt;Array&lt;[string, number]&gt;&gt; | 否 | 回调函数。用于向调用方发送同步结果的回调。 |
**示例:**
```js
let kvStore;
class KvstoreModel {
call(data) {
console.log("syncComplete: " + data);
}
subscribeSyncComplete() {
if (kvStore != null) {
kvStore.on('syncComplete', this.call);
}
}
unsubscribeSyncComplete() {
if (kvStore != null) {
kvStore.off('syncComplete', this.call);
}
}
}
```
### putBatch<sup>8+</sup>
putBatch(entries: Entry[], callback: AsyncCallback&lt;void&gt;): void
......@@ -3711,21 +3749,71 @@ try {
}
```
### sync
sync(deviceIds: string[], mode: SyncMode, delayMs?: number): void
在手动同步方式下,触发数据库同步。关于分布式数据服务的同步方式说明,请见[分布式数据服务概述](../../database/database-mdds-overview.md)
**需要权限**: ohos.permission.DISTRIBUTED_DATASYNC。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | --------------------- | ---- | ---------------------------------------------- |
| deviceIds | string[] | 是 | 同一组网环境下,需要同步的设备的deviceId列表。 |
| mode | [SyncMode](#syncmode) | 是 | 同步模式。 |
| delayMs | number | 否 | 可选参数,允许延时时间,单位:ms(毫秒)。 |
**示例:**
```js
let kvStore;
kvStore.sync(['deviceIds'], distributedData.SyncMode.PULL_ONLY, 1000);
```
### on('dataChange')<sup>8+</sup>
on(event: 'dataChange', type: SubscribeType, listener: Callback&lt;ChangeNotification&gt;): void
订阅指定类型的数据变更通知。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------------- | ---- | ---------------------------------------------------- |
| event | string | 是 | 订阅的事件名,固定为'dataChange',表示数据变更事件。 |
| type | [SubscribeType](#subscribetype) | 是 | 表示订阅的类型。 |
| listener | Callback&lt;[ChangeNotification](#changenotification)&gt; | 是 | 回调函数。 |
**示例:**
```js
let kvStore;
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, function (data) {
console.log("dataChange callback call data: " + JSON.stringify(data));
});
```
### on('syncComplete')<sup>8+</sup>
on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
订阅同步完成事件回调通知,此方法为同步方法
订阅同步完成事件回调通知。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------- |
| event |string | 是 |订阅的事件名,固定为'syncComplete',表示同步完成事件。 |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | 是 |回调函数。用于向调用方发送同步结果的回调。 |
| ------------ | --------------------------------------------- | ---- | ------------------------------------------------------ |
| event | string | 是 | 订阅的事件名,固定为'syncComplete',表示同步完成事件。 |
| syncCallback | Callback&lt;Array&lt;[string, number]&gt;&gt; | 是 | 回调函数。用于向调用方发送同步结果的回调。 |
**示例:**
......@@ -3747,21 +3835,20 @@ try {
}
```
### off('dataChange')<sup>8+</sup>
### off('syncComplete')<sup>8+</sup>
off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void
取消订阅同步完成事件回调通知,此方法为同步方法
取消订阅数据变更通知
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------- |
| event |string | 是 |取消订阅的事件名,固定为'syncComplete',表示同步完成事件。 |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | 否 |回调函数。用于向调用方发送同步结果的回调。 |
| -------- | --------------------------------------------------------- | ---- | -------------------------------------------------------- |
| event | string | 是 | 取消订阅的事件名,固定为'dataChange',表示数据变更事件。 |
| listener | Callback&lt;[ChangeNotification](#changenotification)&gt; | 否 | 回调函数。 |
**示例:**
......@@ -3769,45 +3856,55 @@ off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&
let kvStore;
class KvstoreModel {
call(data) {
console.log("syncComplete: " + data);
console.log("dataChange: " + data);
}
subscribeSyncComplete() {
subscribeDataChange() {
if (kvStore != null) {
kvStore.on('syncComplete', this.call);
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_REMOTE, this.call);
}
}
unsubscribeSyncComplete() {
unsubscribeDataChange() {
if (kvStore != null) {
kvStore.off('syncComplete', this.call);
kvStore.off('dataChange', this.call);
}
}
}
```
### sync<sup>7+</sup>
sync(deviceIds: string[], mode: SyncMode, delayMs?: number): void
### off('syncComplete')<sup>8+</sup>
在手动同步方式下,触发数据库同步。关于分布式数据服务的同步方式说明,请见[分布式数据服务概述](../../database/database-mdds-overview.md)
off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
**需要权限**: ohos.permission.DISTRIBUTED_DATASYNC
取消订阅同步完成事件回调通知
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------- |
| deviceIds |string[] | 是 |同一组网环境下,需要同步的设备的deviceId列表。 |
| mode |[SyncMode](#syncmode) | 是 |同步模式。 |
| delayMs |number | 否 |可选参数,允许延时时间,单位:ms(毫秒)。 |
| ------------ | --------------------------------------------- | ---- | ---------------------------------------------------------- |
| event | string | 是 | 取消订阅的事件名,固定为'syncComplete',表示同步完成事件。 |
| syncCallback | Callback&lt;Array&lt;[string, number]&gt;&gt; | 否 | 回调函数。用于向调用方发送同步结果的回调。 |
**示例:**
```js
let kvStore;
kvStore.sync('deviceIds', distributedData.SyncMode.PULL_ONLY, 1000);
class KvstoreModel {
call(data) {
console.log("syncComplete: " + data);
}
subscribeSyncComplete() {
if (kvStore != null) {
kvStore.on('syncComplete', this.call);
}
}
unsubscribeSyncComplete() {
if (kvStore != null) {
kvStore.off('syncComplete', this.call);
}
}
}
```
### setSyncParam<sup>8+</sup>
......@@ -5077,20 +5174,45 @@ try {
}
```
### on('dataChange')<sup>8+</sup>
on(event: 'dataChange', type: SubscribeType, listener: Callback&lt;ChangeNotification&gt;): void
订阅指定类型的数据变更通知。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------------- | ---- | ---------------------------------------------------- |
| event | string | 是 | 订阅的事件名,固定为'dataChange',表示数据变更事件。 |
| type | [SubscribeType](#subscribetype) | 是 | 表示订阅的类型。 |
| listener | Callback&lt;[ChangeNotification](#changenotification)&gt; | 是 | 回调函数。 |
**示例:**
```js
let kvStore;
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, function (data) {
console.log("dataChange callback call data: " + JSON.stringify(data));
});
```
### on('syncComplete')<sup>8+</sup>
on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
订阅同步完成事件回调通知,此方法为同步方法
订阅同步完成事件回调通知。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------- |
| event |string | 是 |订阅的事件名,固定为'syncComplete',表示同步完成事件。 |
| syncCallback |Callback<Array&lt;[string, number]&gt;> | 是 |回调函数。用于向调用方发送同步结果的回调。 |
| ------------ | --------------------------------------------- | ---- | ------------------------------------------------------ |
| event | string | 是 | 订阅的事件名,固定为'syncComplete',表示同步完成事件。 |
| syncCallback | Callback&lt;Array&lt;[string, number]&gt;&gt; | 是 | 回调函数。用于向调用方发送同步结果的回调。 |
**示例:**
......@@ -5112,21 +5234,56 @@ try {
}
```
### off('dataChange')<sup>8+</sup>
off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void
取消订阅数据变更通知。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------------- | ---- | -------------------------------------------------------- |
| event | string | 是 | 取消订阅的事件名,固定为'dataChange',表示数据变更事件。 |
| listener | Callback&lt;[ChangeNotification](#changenotification)&gt; | 否 | 回调函数。 |
**示例:**
```js
let kvStore;
class KvstoreModel {
call(data) {
console.log("dataChange: " + data);
}
subscribeDataChange() {
if (kvStore != null) {
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_REMOTE, this.call);
}
}
unsubscribeDataChange() {
if (kvStore != null) {
kvStore.off('dataChange', this.call);
}
}
}
```
### off('syncComplete')<sup>8+</sup>
off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
取消订阅同步完成事件回调通知,此方法为同步方法
取消订阅同步完成事件回调通知。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------- |
| event |string | 是 |取消订阅的事件名,固定为'syncComplete',表示同步完成事件。 |
| syncCallback |Callback<Array&lt;[string, number]&gt;&gt; | 否 |回调函数。用于向调用方发送同步结果的回调。 |
| ------------ | --------------------------------------------- | ---- | ---------------------------------------------------------- |
| event | string | 是 | 取消订阅的事件名,固定为'syncComplete',表示同步完成事件。 |
| syncCallback | Callback&lt;Array&lt;[string, number]&gt;&gt; | 否 | 回调函数。用于向调用方发送同步结果的回调。 |
**示例:**
......
......@@ -790,7 +790,7 @@ try {
on(event: 'distributedDataServiceDie', deathCallback: Callback&lt;void&gt;): void
订阅服务状态变更通知,此方法为同步方法
订阅服务状态变更通知。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
......@@ -820,7 +820,7 @@ try {
off(event: 'distributedDataServiceDie', deathCallback?: Callback&lt;void&gt;): void
取消订阅服务状态变更通知,此方法为同步方法
取消订阅服务状态变更通知。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
......@@ -2188,7 +2188,7 @@ put(key: string, value: Uint8Array | string | number | boolean, callback: AsyncC
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -2237,7 +2237,7 @@ put(key: string, value: Uint8Array | string | number | boolean): Promise&lt;void
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -2278,7 +2278,7 @@ putBatch(entries: Entry[], callback: AsyncCallback&lt;void&gt;): void
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -2345,7 +2345,7 @@ putBatch(entries: Entry[]): Promise&lt;void&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -2405,7 +2405,7 @@ putBatch(value: Array&lt;ValuesBucket&gt;, callback: AsyncCallback&lt;void&gt;):
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -2462,7 +2462,7 @@ putBatch(value: Array&lt;ValuesBucket&gt;): Promise&lt;void&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -2510,8 +2510,7 @@ delete(key: string, callback: AsyncCallback&lt;void&gt;): void
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100004 | Not found. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -2566,8 +2565,7 @@ delete(key: string): Promise&lt;void&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100004 | Not found. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -2615,8 +2613,7 @@ delete(predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallb
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100004 | Not found. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -2666,8 +2663,7 @@ delete(predicates: dataSharePredicates.DataSharePredicates): Promise&lt;void&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100004 | Not found. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -2716,8 +2712,7 @@ deleteBatch(keys: string[], callback: AsyncCallback&lt;void&gt;): void
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100004 | Not found. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -2785,8 +2780,7 @@ deleteBatch(keys: string[]): Promise&lt;void&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100004 | Not found. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -2844,7 +2838,7 @@ removeDeviceData(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -2898,7 +2892,7 @@ removeDeviceData(deviceId: string): Promise&lt;void&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -2951,7 +2945,7 @@ get(key: string, callback: AsyncCallback<boolean | string| number | Uint8Array>)
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100004 | Not found. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -3007,7 +3001,7 @@ get(key: string): Promise&lt;boolean | string| number | Uint8Array&gt;
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100004 | Not found. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -3053,7 +3047,7 @@ getEntries(keyPrefix: string, callback: AsyncCallback&lt;Entry[]&gt;): void
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -3121,7 +3115,7 @@ getEntries(keyPrefix: string): Promise&lt;Entry[]&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -3179,8 +3173,7 @@ getEntries(query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100005 | Not support the operation. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -3247,8 +3240,7 @@ getEntries(query: Query): Promise&lt;Entry[]&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100005 | Not support the operation. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -3309,7 +3301,7 @@ getResultSet(keyPrefix: string, callback: AsyncCallback&lt;KVStoreResultSet&gt;)
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -3383,7 +3375,7 @@ getResultSet(keyPrefix: string): Promise&lt;KVStoreResultSet&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -3446,7 +3438,7 @@ getResultSet(query: Query, callback: AsyncCallback&lt;KVStoreResultSet&gt;): voi
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -3514,7 +3506,7 @@ getResultSet(query: Query): Promise&lt;KVStoreResultSet&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -3576,7 +3568,7 @@ getResultSet(predicates: dataSharePredicates.DataSharePredicates, callback: Asyn
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -3637,7 +3629,7 @@ getResultSet(predicates: dataSharePredicates.DataSharePredicates): Promise&lt;KV
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -3756,7 +3748,7 @@ getResultSize(query: Query, callback: AsyncCallback&lt;number&gt;): void
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -3819,7 +3811,7 @@ getResultSize(query: Query): Promise&lt;number&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -3876,8 +3868,7 @@ backup(file:string, callback: AsyncCallback&lt;void&gt;):void
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100005 | Not support the operation. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -3923,8 +3914,7 @@ backup(file:string): Promise&lt;void&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100005 | Not support the operation. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -3963,8 +3953,7 @@ restore(file:string, callback: AsyncCallback&lt;void&gt;):void
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100005 | Not support the operation. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -4010,8 +3999,7 @@ restore(file:string): Promise&lt;void&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100005 | Not support the operation. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -4118,7 +4106,7 @@ startTransaction(callback: AsyncCallback&lt;void&gt;): void
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -4186,7 +4174,7 @@ startTransaction(): Promise&lt;void&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -4228,7 +4216,7 @@ commit(callback: AsyncCallback&lt;void&gt;): void
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -4267,7 +4255,7 @@ commit(): Promise&lt;void&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -4304,7 +4292,7 @@ rollback(callback: AsyncCallback&lt;void&gt;): void
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -4343,7 +4331,7 @@ rollback(): Promise&lt;void&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -4600,10 +4588,24 @@ sync(deviceIds: string[], mode: SyncMode, delayMs?: number): void
```js
let kvStore;
const KEY_TEST_SYNC_ELEMENT = 'key_test_sync';
const VALUE_TEST_SYNC_ELEMENT = 'value-string-001';
try {
kvStore.sync('deviceIds', distributedKVStore.SyncMode.PULL_ONLY, 1000);
} catch (err) {
console.error(`Fail to syn.code is ${err.code},message is ${err.message}`);
kvStore.on('syncComplete', function (data) {
console.log('Sync dataChange');
});
kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err, data) {
if (err != undefined) {
console.error(`Fail to sync.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in putting data');
const devices = ['deviceList'];
const mode = distributedKVStore.SyncMode.PULL_ONLY;
kvStore.sync(devices, mode, 1000);
});
} catch (e) {
console.error(`Fail to sync.code is ${e.code},message is ${e.message}`);
}
```
......@@ -4667,7 +4669,7 @@ try {
on(event: 'dataChange', type: SubscribeType, listener: Callback&lt;ChangeNotification&gt;): void
订阅指定类型的数据变更通知,此方法为同步方法
订阅指定类型的数据变更通知。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
......@@ -4686,7 +4688,7 @@ on(event: 'dataChange', type: SubscribeType, listener: Callback&lt;ChangeNotific
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100001 | Over max subscribe limits. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -4705,7 +4707,7 @@ try {
on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
订阅同步完成事件回调通知,此方法为同步方法
订阅同步完成事件回调通知。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
......@@ -4740,7 +4742,7 @@ try {
off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void
取消订阅数据变更通知,此方法为同步方法
取消订阅数据变更通知。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
......@@ -4757,7 +4759,7 @@ off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -4794,7 +4796,7 @@ class KvstoreModel {
off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
取消订阅同步完成事件回调通知,此方法为同步方法
取消订阅同步完成事件回调通知。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
......@@ -4856,7 +4858,7 @@ getSecurityLevel(callback: AsyncCallback&lt;SecurityLevel&gt;): void
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -4895,7 +4897,7 @@ getSecurityLevel(): Promise&lt;SecurityLevel&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -4924,6 +4926,109 @@ try {
### get
get(key: string, callback: AsyncCallback<boolean | string| number | Uint8Array>): void
获取本设备指定键的值,使用callback异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| key | string | 是 | 要查询数据的key,不能为空且长度不大于[MAX_KEY_LENGTH](#constants)。 |
| callback | AsyncCallback&lt;boolean \| string \| number \| Uint8Array&gt;) | 是 | 回调函数。返回获取查询的值。 |
**错误码:**
以下错误码的详细介绍请参见[分布式键值数据库错误码](../errorcodes/errorcode-distributedKVStore.md)
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100004 | Not found. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
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.error(`Fail to put.code is ${err.code},message is ${err.message}`);
return;
}
console.log("Succeeded in putting");
kvStore.get(KEY_TEST_STRING_ELEMENT, function (err, data) {
if (err != undefined) {
console.error(`Fail to get.code is ${err.code},message is ${err.message}`);
return;
}
console.log(`Succeeded in getting data.data=${data}`);
});
});
} catch (e) {
console.error(`Fail to get.code is ${e.code},message is ${e.message}`);
}
```
### get
get(key: string): Promise&lt;boolean | string| number | Uint8Array&gt;
获取本设备指定键的值,使用Promise异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| key | string | 是 | 要查询数据的key,不能为空且长度不大于[MAX_KEY_LENGTH](#constants)。 |
**返回值:**
| 类型 | 说明 |
| -------------------------------------------------------- | ------------------------------- |
| Promise&lt;Uint8Array \| string \| boolean \| number&gt; | Promise对象。返回获取查询的值。 |
**错误码:**
以下错误码的详细介绍请参见[分布式键值数据库错误码](../errorcodes/errorcode-distributedKVStore.md)
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100004 | Not found. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
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(`Succeeded in putting data.data=${data}`);
kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => {
console.log(`Succeeded in getting data.data=${data}`);
}).catch((err) => {
console.error(`Fail to get.code is ${err.code},message is ${err.message}`);
});
}).catch((err) => {
console.error(`Fail to put.code is ${err.code},message is ${err.message}`);
});
} catch (e) {
console.error(`Fail to get.code is ${e.code},message is ${e.message}`);
}
```
### get
get(deviceId: string, key: string, callback: AsyncCallback&lt;boolean|string|number|Uint8Array&gt;): void
获取与指定设备ID和key匹配的string值,使用callback异步回调。
......@@ -4946,7 +5051,7 @@ get(deviceId: string, key: string, callback: AsyncCallback&lt;boolean|string|num
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100004 | Not found. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -5003,7 +5108,7 @@ get(deviceId: string, key: string): Promise&lt;boolean|string|number|Uint8Array&
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100004 | Not found. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -5029,19 +5134,18 @@ try {
### getEntries
getEntries(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;Entry[]&gt;): void
getEntries(keyPrefix: string, callback: AsyncCallback&lt;Entry[]&gt;): void
获取与指定设备ID和key前缀匹配的所有键值对,使用callback异步回调。
获取匹配本设备指定键前缀的所有键值对,使用callback异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | -------------------------------------- | ---- | ---------------------------------------------- |
| deviceId | string | 是 | 标识要查询其数据的设备。 |
| --------- | -------------------------------------- | ---- | ---------------------------------------- |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
| callback | AsyncCallback&lt;[Entry](#entry)[]&gt; | 是 | 回调函数,返回满足给定条件的所有键值对的列表。 |
| callback | AsyncCallback&lt;[Entry](#entry)[]&gt; | 是 | 回调函数。返回匹配指定前缀的键值对列表。 |
**错误码:**
......@@ -5050,7 +5154,7 @@ getEntries(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;Entry
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -5069,48 +5173,47 @@ try {
}
entries.push(entry);
}
console.log(`entries : ${entries}`);
console.log(`entries: ${entries}`);
kvStore.putBatch(entries, async function (err, data) {
if (err != undefined) {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
console.error(`Fail to put Batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in putting batch');
kvStore.getEntries('localDeviceId', 'batch_test_string_key', function (err, entries) {
console.log('Succeeded in putting Batch');
kvStore.getEntries('batch_test_string_key', function (err, entries) {
if (err != undefined) {
console.error(`Fail to get entries.code is ${err.code},message is ${err.message}`);
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in getting entries');
console.log('Succeeded in getting Entries');
console.log(`entries.length: ${entries.length}`);
console.log(`entries[0]: ${entries[0]}`);
});
});
} catch (e) {
console.error(`Fail to put batch.code is ${e.code},message is ${e.message}`);
console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message} `);
}
```
### getEntries
getEntries(deviceId: string, keyPrefix: string): Promise&lt;Entry[]&gt;
getEntries(keyPrefix: string): Promise&lt;Entry[]&gt;
获取与指定设备ID和key前缀匹配的所有键值对,使用Promise异步回调。
获取匹配本设备指定键前缀的所有键值对,使用Promise异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | -------- | ---- | ------------------------ |
| deviceId | string | 是 | 标识要查询其数据的设备。 |
| --------- | ------ | ---- | -------------------- |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
**返回值:**
| 类型 | 说明 |
| -------------------------------- | ------------------------------------------------- |
| Promise&lt;[Entry](#entry)[]&gt; | Promise对象。返回匹配给定条件的所有键值对的列表。 |
| -------------------------------- | ------------------------------------------- |
| Promise&lt;[Entry](#entry)[]&gt; | Promise对象。返回匹配指定前缀的键值对列表。 |
**错误码:**
......@@ -5119,7 +5222,7 @@ getEntries(deviceId: string, keyPrefix: string): Promise&lt;Entry[]&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -5139,40 +5242,37 @@ try {
entries.push(entry);
}
console.log(`entries: ${entries}`);
kvStore.putBatch(entries).then(async (err) => {
console.log('Succeeded in putting batch');
kvStore.getEntries('localDeviceId', 'batch_test_string_key').then((entries) => {
console.log('Succeeded in getting entries');
console.log(`entries.length: ${entries.length}`);
console.log(`entries[0]: ${entries[0]}`);
console.log(`entries[0].value: ${entries[0].value}`);
console.log(`entries[0].value.value: ${entries[0].value.value}`);
kvStore.putBatch(entries).then(async (entries) => {
console.log('Succeeded in putting Batch');
kvStore.getEntries('batch_test_string_key').then((entries) => {
console.log('Succeeded in getting Entries');
console.log(`PutBatch ${entries}`);
}).catch((err) => {
console.error(`Fail to get entries.code is ${err.code},message is ${err.message}`);
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`);
});
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
console.error(`Fail to put Batch.code is ${err.code},message is ${err.message}`);
});
} catch (e) {
console.error(`Fail to put batch.code is ${e.code},message is ${e.message}`);
console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message} `);
}
```
### getEntries
getEntries(deviceId: string, query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void
getEntries(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;Entry[]&gt;): void
获取与指定设备ID和Query对象匹配的键值对列表,使用callback异步回调。
获取与指定设备ID和key前缀匹配的所有键值对,使用callback异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------- | ---- | ------------------------------------------------------- |
| deviceId | string | 是 | 键值对所属的设备ID。 |
| query | [Query](query) | 是 | 表示查询对象。 |
| callback | AsyncCallback&lt;[Entry](#entry)[]&gt; | 是 | 回调函数。返回与指定设备ID和Query对象匹配的键值对列表。 |
| --------- | -------------------------------------- | ---- | ---------------------------------------------- |
| deviceId | string | 是 | 标识要查询其数据的设备。 |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
| callback | AsyncCallback&lt;[Entry](#entry)[]&gt; | 是 | 回调函数,返回满足给定条件的所有键值对的列表。 |
**错误码:**
......@@ -5181,38 +5281,33 @@ getEntries(deviceId: string, query: Query, callback: AsyncCallback&lt;Entry[]&gt
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100005 | Not support the operation. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
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 key = 'batch_test_string_key';
var entry = {
key: key + i,
value: {
type: distributedKVStore.ValueType.BYTE_ARRAY,
value: arr
type: distributedKVStore.ValueType.STRING,
value: 'batch_test_string_value'
}
}
entries.push(entry);
}
console.log(`entries: ${entries}`);
console.log(`entries : ${entries}`);
kvStore.putBatch(entries, async function (err, data) {
if (err != undefined) {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in putting batch');
var query = new distributedKVStore.Query();
query.deviceId('localDeviceId');
query.prefixKey("batch_test");
kvStore.getEntries('localDeviceId', query, function (err, entries) {
kvStore.getEntries('localDeviceId', 'batch_test_string_key', function (err, entries) {
if (err != undefined) {
console.error(`Fail to get entries.code is ${err.code},message is ${err.message}`);
return;
......@@ -5220,34 +5315,33 @@ try {
console.log('Succeeded in getting entries');
console.log(`entries.length: ${entries.length}`);
console.log(`entries[0]: ${entries[0]}`);
})
});
console.log('Succeeded in getting entries');
});
} catch (e) {
console.error(`Fail to get entries.code is ${e.code},message is ${e.message}`);
console.error(`Fail to put batch.code is ${e.code},message is ${e.message}`);
}
```
### getEntries
getEntries(deviceId: string, query: Query): Promise&lt;Entry[]&gt;
getEntries(deviceId: string, keyPrefix: string): Promise&lt;Entry[]&gt;
获取与指定设备ID和Query对象匹配的键值对列表,使用Promise异步回调。
获取与指定设备ID和key前缀匹配的所有键值对,使用Promise异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------- | ---- | -------------------- |
| deviceId | string | 是 | 键值对所属的设备ID。 |
| query | [Query](query) | 是 | 表示查询对象。 |
| --------- | -------- | ---- | ------------------------ |
| deviceId | string | 是 | 标识要查询其数据的设备。 |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
**返回值:**
| 类型 | 说明 |
| -------------------------------- | ---------------------------------------------------------- |
| Promise&lt;[Entry](#entry)[]&gt; | Promise对象。返回与指定设备ID和Query对象匹配的键值对列表。 |
| -------------------------------- | ------------------------------------------------- |
| Promise&lt;[Entry](#entry)[]&gt; | Promise对象。返回匹配给定条件的所有键值对的列表。 |
**错误码:**
......@@ -5256,23 +5350,21 @@ getEntries(deviceId: string, query: Query): Promise&lt;Entry[]&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100005 | Not support the operation. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
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 key = 'batch_test_string_key';
var entry = {
key: key + i,
value: {
type: distributedKVStore.ValueType.BYTE_ARRAY,
value: arr
type: distributedKVStore.ValueType.STRING,
value: 'batch_test_string_value'
}
}
entries.push(entry);
......@@ -5280,38 +5372,37 @@ try {
console.log(`entries: ${entries}`);
kvStore.putBatch(entries).then(async (err) => {
console.log('Succeeded in putting batch');
var query = new distributedKVStore.Query();
query.deviceId('localDeviceId');
query.prefixKey("batch_test");
kvStore.getEntries('localDeviceId', query).then((entries) => {
kvStore.getEntries('localDeviceId', 'batch_test_string_key').then((entries) => {
console.log('Succeeded in getting entries');
console.log(`entries.length: ${entries.length}`);
console.log(`entries[0]: ${entries[0]}`);
console.log(`entries[0].value: ${entries[0].value}`);
console.log(`entries[0].value.value: ${entries[0].value.value}`);
}).catch((err) => {
console.error(`Fail to get entries.code is ${err.code},message is ${err.message}`);
});
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
});
console.log('Succeeded in getting entries');
} catch (e) {
console.error(`Fail to get entries.code is ${e.code},message is ${e.message}`);
console.error(`Fail to put batch.code is ${e.code},message is ${e.message}`);
}
```
### getResultSet
### getEntries
getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;KVStoreResultSet&gt;): void
getEntries(query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void
获取与指定设备ID和key前缀匹配的KVStoreResultSet对象,使用callback异步回调。
获取本设备与指定Query对象匹配的键值对列表,使用callback异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| deviceId | string | 是 | 标识要查询其数据的设备。 |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
| callback | AsyncCallback&lt;[KVStoreResultSet](#kvstoreresultset)&gt; | 是 | 回调函数。返回与指定设备ID和key前缀匹配的KVStoreResultSet对象。 |
| -------- | -------------------------------------- | ---- | ----------------------------------------------------- |
| query | [Query](query) | 是 | 表示要匹配的键前缀。 |
| callback | AsyncCallback&lt;[Entry](#entry)[]&gt; | 是 | 回调函数。返回本设备与指定Query对象匹配的键值对列表。 |
**错误码:**
......@@ -5320,22 +5411,674 @@ getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;KVS
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
let kvStore;
try {
let resultSet;
kvStore.getResultSet('localDeviceId', 'batch_test_string_key', async function (err, result) {
if (err != undefined) {
console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in getting resultSet');
resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) {
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: distributedKVStore.ValueType.BYTE_ARRAY,
value: arr
}
}
entries.push(entry);
}
console.log(`entries: {entries}`);
kvStore.putBatch(entries, async function (err, data) {
console.log('Succeeded in putting Batch');
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getEntries(query, function (err, entries) {
if (err != undefined) {
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in getting Entries');
console.log(`entries.length: ${entries.length}`);
console.log(`entries[0]: ${entries[0]}`);
});
});
} catch (e) {
console.error(`Fail to get Entries.code is ${e.code},message is ${e.message}`);
}
```
### getEntries
getEntries(query: Query): Promise&lt;Entry[]&gt;
获取本设备与指定Query对象匹配的键值对列表,使用Promise异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | -------------- | ---- | -------------- |
| query | [Query](query) | 是 | 表示查询对象。 |
**返回值:**
| 类型 | 说明 |
| -------------------------------- | -------------------------------------------------------- |
| Promise&lt;[Entry](#entry)[]&gt; | Promise对象。返回本设备与指定Query对象匹配的键值对列表。 |
**错误码:**
以下错误码的详细介绍请参见[分布式键值数据库错误码](../errorcodes/errorcode-distributedKVStore.md)
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
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: distributedKVStore.ValueType.BYTE_ARRAY,
value: arr
}
}
entries.push(entry);
}
console.log(`entries: {entries}`);
kvStore.putBatch(entries).then(async (err) => {
console.log('Succeeded in putting Batch');
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getEntries(query).then((entries) => {
console.log('Succeeded in getting Entries');
}).catch((err) => {
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`);
});
}).catch((err) => {
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`)
});
console.log('Succeeded in getting Entries');
} catch (e) {
console.error(`Fail to get Entries.code is ${e.code},message is ${e.message}`);
}
```
### getEntries
getEntries(deviceId: string, query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void
获取与指定设备ID和Query对象匹配的键值对列表,使用callback异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------- | ---- | ------------------------------------------------------- |
| deviceId | string | 是 | 键值对所属的设备ID。 |
| query | [Query](query) | 是 | 表示查询对象。 |
| callback | AsyncCallback&lt;[Entry](#entry)[]&gt; | 是 | 回调函数。返回与指定设备ID和Query对象匹配的键值对列表。 |
**错误码:**
以下错误码的详细介绍请参见[分布式键值数据库错误码](../errorcodes/errorcode-distributedKVStore.md)
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
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: distributedKVStore.ValueType.BYTE_ARRAY,
value: arr
}
}
entries.push(entry);
}
console.log(`entries: ${entries}`);
kvStore.putBatch(entries, async function (err, data) {
if (err != undefined) {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in putting batch');
var query = new distributedKVStore.Query();
query.deviceId('localDeviceId');
query.prefixKey("batch_test");
kvStore.getEntries('localDeviceId', query, function (err, entries) {
if (err != undefined) {
console.error(`Fail to get entries.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in getting entries');
console.log(`entries.length: ${entries.length}`);
console.log(`entries[0]: ${entries[0]}`);
})
});
console.log('Succeeded in getting entries');
} catch (e) {
console.error(`Fail to get entries.code is ${e.code},message is ${e.message}`);
}
```
### getEntries
getEntries(deviceId: string, query: Query): Promise&lt;Entry[]&gt;
获取与指定设备ID和Query对象匹配的键值对列表,使用Promise异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------- | ---- | -------------------- |
| deviceId | string | 是 | 键值对所属的设备ID。 |
| query | [Query](query) | 是 | 表示查询对象。 |
**返回值:**
| 类型 | 说明 |
| -------------------------------- | ---------------------------------------------------------- |
| Promise&lt;[Entry](#entry)[]&gt; | Promise对象。返回与指定设备ID和Query对象匹配的键值对列表。 |
**错误码:**
以下错误码的详细介绍请参见[分布式键值数据库错误码](../errorcodes/errorcode-distributedKVStore.md)
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
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: distributedKVStore.ValueType.BYTE_ARRAY,
value: arr
}
}
entries.push(entry);
}
console.log(`entries: ${entries}`);
kvStore.putBatch(entries).then(async (err) => {
console.log('Succeeded in putting batch');
var query = new distributedKVStore.Query();
query.deviceId('localDeviceId');
query.prefixKey("batch_test");
kvStore.getEntries('localDeviceId', query).then((entries) => {
console.log('Succeeded in getting entries');
}).catch((err) => {
console.error(`Fail to get entries.code is ${err.code},message is ${err.message}`);
});
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
});
console.log('Succeeded in getting entries');
} catch (e) {
console.error(`Fail to get entries.code is ${e.code},message is ${e.message}`);
}
```
### getEntries
getEntries(keyPrefix: string, callback: AsyncCallback&lt;Entry[]&gt;): void
获取匹配本设备指定键前缀的所有键值对,使用callback异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | -------------------------------------- | ---- | ---------------------------------------- |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
| callback | AsyncCallback&lt;[Entry](#entry)[]&gt; | 是 | 回调函数。返回匹配指定前缀的键值对列表。 |
**错误码:**
以下错误码的详细介绍请参见[分布式键值数据库错误码](../errorcodes/errorcode-distributedKVStore.md)
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
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: distributedKVStore.ValueType.STRING,
value: 'batch_test_string_value'
}
}
entries.push(entry);
}
console.log(`entries: ${entries}`);
kvStore.putBatch(entries, async function (err, data) {
if (err != undefined) {
console.error(`Fail to put Batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in putting Batch');
kvStore.getEntries('batch_test_string_key', function (err, entries) {
if (err != undefined) {
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in getting Entries');
console.log(`entries.length: ${entries.length}`);
console.log(`entries[0]: ${entries[0]}`);
});
});
} catch (e) {
console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message} `);
}
```
### getEntries
getEntries(keyPrefix: string): Promise&lt;Entry[]&gt;
获取匹配本设备指定键前缀的所有键值对,使用Promise异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | -------------------- |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
**返回值:**
| 类型 | 说明 |
| -------------------------------- | ------------------------------------------- |
| Promise&lt;[Entry](#entry)[]&gt; | Promise对象。返回匹配指定前缀的键值对列表。 |
**错误码:**
以下错误码的详细介绍请参见[分布式键值数据库错误码](../errorcodes/errorcode-distributedKVStore.md)
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
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: distributedKVStore.ValueType.STRING,
value: 'batch_test_string_value'
}
}
entries.push(entry);
}
console.log(`entries: ${entries}`);
kvStore.putBatch(entries).then(async (entries) => {
console.log('Succeeded in putting Batch');
kvStore.getEntries('batch_test_string_key').then((entries) => {
console.log('Succeeded in getting Entries');
console.log(`PutBatch ${entries}`);
}).catch((err) => {
console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`);
});
}).catch((err) => {
console.error(`Fail to put Batch.code is ${err.code},message is ${err.message}`);
});
} catch (e) {
console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message} `);
}
```
### getResultSet
getResultSet(keyPrefix: string, callback: AsyncCallback&lt;KVStoreResultSet&gt;): void
从DeviceKVStore数据库中获取本设备具有指定前缀的结果集,使用callback异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------------------------- | ---- | ------------------------------------ |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
| callback | AsyncCallback&lt;[KVStoreResultSet](#kvstoreresultset)&gt; | 是 | 回调函数。返回具有指定前缀的结果集。 |
**错误码:**
以下错误码的详细介绍请参见[分布式键值数据库错误码](../errorcodes/errorcode-distributedKVStore.md)
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
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: distributedKVStore.ValueType.STRING,
value: 'batch_test_string_value'
}
}
entries.push(entry);
}
kvStore.putBatch(entries, async function (err, data) {
if (err != undefined) {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in putting batch');
kvStore.getResultSet('batch_test_string_key', async function (err, result) {
if (err != undefined) {
console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in getting result set');
resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) {
if (err != undefined) {
console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in closing result set');
})
});
});
} catch (e) {
console.error(`An unexpected error occured.code is ${e.code},message is ${e.message}`);
}
```
### getResultSet
getResultSet(keyPrefix: string): Promise&lt;KVStoreResultSet&gt;
从DeviceKVStore数据库中获取本设备具有指定前缀的结果集,使用Promise异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | -------------------- |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
**返回值:**
| 类型 | 说明 |
| ---------------------------------------------------- | --------------------------------------- |
| Promise&lt;[KVStoreResultSet](#kvstoreresultset)&gt; | Promise对象。返回具有指定前缀的结果集。 |
**错误码:**
以下错误码的详细介绍请参见[分布式键值数据库错误码](../errorcodes/errorcode-distributedKVStore.md)
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
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: distributedKVStore.ValueType.STRING,
value: 'batch_test_string_value'
}
}
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('Succeeded in putting batch');
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
});
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('Succeeded in getting result set');
resultSet = result;
}).catch((err) => {
console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`);
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('Succeeded in closing result set');
}).catch((err) => {
console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`);
});
} catch (e) {
console.error(`An unexpected error occured.code is ${e.code},message is ${e.code}`);
}
```
### getResultSet
getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;KVStoreResultSet&gt;): void
获取与指定设备ID和key前缀匹配的KVStoreResultSet对象,使用callback异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| deviceId | string | 是 | 标识要查询其数据的设备。 |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
| callback | AsyncCallback&lt;[KVStoreResultSet](#kvstoreresultset)&gt; | 是 | 回调函数。返回与指定设备ID和key前缀匹配的KVStoreResultSet对象。 |
**错误码:**
以下错误码的详细介绍请参见[分布式键值数据库错误码](../errorcodes/errorcode-distributedKVStore.md)
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
let kvStore;
try {
let resultSet;
kvStore.getResultSet('localDeviceId', 'batch_test_string_key', async function (err, result) {
if (err != undefined) {
console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in getting resultSet');
resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) {
if (err != undefined) {
console.error(`Fail to close resultSet.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in closing resultSet');
})
});
} catch (e) {
console.error(`Fail to get resultSet.code is ${e.code},message is ${e.message}`);
}
```
### getResultSet
getResultSet(deviceId: string, keyPrefix: string): Promise&lt;KVStoreResultSet&gt;
获取与指定设备ID和key前缀匹配的KVStoreResultSet对象,使用Promise异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | -------- | ---- | ------------------------ |
| deviceId | string | 是 | 标识要查询其数据的设备。 |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------------------------ | ------------------------------------------------------------ |
| Promise&lt;[KVStoreResultSet](#kvstoreresultset)&gt; | Promise对象。返回与指定设备ID和key前缀匹配的KVStoreResultSet对象。 |
**错误码:**
以下错误码的详细介绍请参见[分布式键值数据库错误码](../errorcodes/errorcode-distributedKVStore.md)
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
let kvStore;
try {
let resultSet;
kvStore.getResultSet('localDeviceId', 'batch_test_string_key').then((result) => {
console.log('Succeeded in getting resultSet');
resultSet = result;
}).catch((err) => {
console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`);
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('Succeeded in closing resultSet');
}).catch((err) => {
console.error(`Fail to close resultSet.code is ${err.code},message is ${err.message}`);
});
} catch (e) {
console.error(`Fail to get resultSet.code is ${e.code},message is ${e.message}`);
}
```
### getResultSet
getResultSet(deviceId: string, query: Query, callback: AsyncCallback&lt;KVStoreResultSet&gt;): void
获取与指定设备ID和Query对象匹配的KVStoreResultSet对象,使用callback异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| deviceId | string | 是 | KVStoreResultSet对象所属的设备ID。 |
| query | [Query](query) | 是 | 表示查询对象。 |
| callback | AsyncCallback&lt;[KVStoreResultSet](#kvstoreresultset)&gt; | 是 | 回调函数。返回与指定设备ID和Query对象匹配的KVStoreResultSet对象。 |
**错误码:**
以下错误码的详细介绍请参见[分布式键值数据库错误码](../errorcodes/errorcode-distributedKVStore.md)
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
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: distributedKVStore.ValueType.STRING,
value: 'batch_test_string_value'
}
}
entries.push(entry);
}
kvStore.putBatch(entries, async function (err, data) {
if (err != undefined) {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in putting batch');
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSet('localDeviceId', query, async function (err, result) {
if (err != undefined) {
console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in getting resultSet');
resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) {
if (err != undefined) {
console.error(`Fail to close resultSet.code is ${err.code},message is ${err.message}`);
return;
......@@ -5343,31 +6086,171 @@ try {
console.log('Succeeded in closing resultSet');
})
});
});
} catch (e) {
console.error(`Fail to get resultSet.code is ${e.code},message is ${e.message}`);
}
```
### getResultSet
getResultSet(deviceId: string, query: Query): Promise&lt;KVStoreResultSet&gt;
获取与指定设备ID和Query对象匹配的KVStoreResultSet对象,使用Promise异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------- | ---- | ---------------------------------- |
| deviceId | string | 是 | KVStoreResultSet对象所属的设备ID。 |
| query | [Query](query) | 是 | 表示查询对象。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------------------------ | ------------------------------------------------------------ |
| Promise&lt;[KVStoreResultSet](#kvstoreresultset)&gt; | Promise对象。返回与指定设备ID和Query对象匹配的KVStoreResultSet对象。 |
**错误码:**
以下错误码的详细介绍请参见[分布式键值数据库错误码](../errorcodes/errorcode-distributedKVStore.md)
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
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: distributedKVStore.ValueType.STRING,
value: 'batch_test_string_value'
}
}
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('Succeeded in putting batch');
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
});
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSet('localDeviceId', query).then((result) => {
console.log('Succeeded in getting resultSet');
resultSet = result;
}).catch((err) => {
console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`);
});
query.deviceId('localDeviceId');
console.log("GetResultSet " + query.getSqlLike());
kvStore.closeResultSet(resultSet).then((err) => {
console.log('Succeeded in closing resultSet');
}).catch((err) => {
console.error(`Fail to close resultSet.code is ${err.code},message is ${err.message}`);
});
} catch (e) {
console.error(`Fail to get resultSet.code is ${e.code},message is ${e.message}`);
}
```
### getResultSet
getResultSet(query: Query): Promise&lt;KVStoreResultSet&gt;
获取与本设备指定Query对象匹配的KVStoreResultSet对象,使用Promise异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | -------------- | ---- | -------------- |
| query | [Query](query) | 是 | 表示查询对象。 |
**返回值:**
| 类型 | 说明 |
| ---------------------------------------------------- | ------------------------------------------------------------ |
| Promise&lt;[KVStoreResultSet](#kvstoreresultset)&gt; | Promise对象。获取与本设备指定Query对象匹配的KVStoreResultSet对象。 |
**错误码:**
以下错误码的详细介绍请参见[分布式键值数据库错误码](../errorcodes/errorcode-distributedKVStore.md)
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
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: distributedKVStore.ValueType.STRING,
value: 'batch_test_string_value'
}
}
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('Succeeded in putting batch');
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
});
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSet(query).then((result) => {
console.log('Succeeded in getting result set');
resultSet = result;
}).catch((err) => {
console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`);
});
} catch (e) {
console.error(`Fail to get resultSet.code is ${e.code},message is ${e.message}`);
console.error(`An unexpected error occured.code is ${e.code},message is ${e.code}`);
}
```
### getResultSet
getResultSet(deviceId: string, keyPrefix: string): Promise&lt;KVStoreResultSet&gt;
getResultSet(deviceId: string, query: Query): Promise&lt;KVStoreResultSet&gt;
获取与指定设备ID和key前缀匹配的KVStoreResultSet对象,使用Promise异步回调。
获取与指定设备ID和Query对象匹配的KVStoreResultSet对象,使用Promise异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | -------- | ---- | ------------------------ |
| deviceId | string | 是 | 标识要查询其数据的设备。 |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
| -------- | -------------- | ---- | ---------------------------------- |
| deviceId | string | 是 | KVStoreResultSet对象所属的设备ID。 |
| query | [Query](query) | 是 | 表示查询对象。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------------------------ | ------------------------------------------------------------ |
| Promise&lt;[KVStoreResultSet](#kvstoreresultset)&gt; | Promise对象。返回与指定设备ID和key前缀匹配的KVStoreResultSet对象。 |
| ---------------------------------------------------- | ------------------------------------------------------------ |
| Promise&lt;[KVStoreResultSet](#kvstoreresultset)&gt; | Promise对象。返回与指定设备ID和Query对象匹配的KVStoreResultSet对象。 |
**错误码:**
......@@ -5376,7 +6259,7 @@ getResultSet(deviceId: string, keyPrefix: string): Promise&lt;KVStoreResultSet&g
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -5384,17 +6267,39 @@ getResultSet(deviceId: string, keyPrefix: string): Promise&lt;KVStoreResultSet&g
let kvStore;
try {
let resultSet;
kvStore.getResultSet('localDeviceId', 'batch_test_string_key').then((result) => {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key';
var entry = {
key: key + i,
value: {
type: distributedKVStore.ValueType.STRING,
value: 'batch_test_string_value'
}
}
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('Succeeded in putting batch');
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
});
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSet('localDeviceId', query).then((result) => {
console.log('Succeeded in getting resultSet');
resultSet = result;
}).catch((err) => {
console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`);
});
query.deviceId('localDeviceId');
console.log("GetResultSet " + query.getSqlLike());
kvStore.closeResultSet(resultSet).then((err) => {
console.log('Succeeded in closing resultSet');
}).catch((err) => {
console.error(`Fail to close resultSet.code is ${err.code},message is ${err.message}`);
});
} catch (e) {
console.error(`Fail to get resultSet.code is ${e.code},message is ${e.message}`);
}
......@@ -5402,19 +6307,20 @@ try {
### getResultSet
getResultSet(deviceId: string, query: Query, callback: AsyncCallback&lt;KVStoreResultSet&gt;): void
getResultSet(predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;KVStoreResultSet&gt;): void
获取与指定设备ID和Query对象匹配的KVStoreResultSet对象,使用callback异步回调。
获取与本设备指定Predicate对象匹配的KVStoreResultSet对象,使用callback异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| deviceId | string | 是 | KVStoreResultSet对象所属的设备ID。 |
| query | [Query](query) | 是 | 表示查询对象。 |
| callback | AsyncCallback&lt;[KVStoreResultSet](#kvstoreresultset)&gt; | 是 | 回调函数。返回与指定设备ID和Query对象匹配的KVStoreResultSet对象。 |
| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| predicates | [DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | 指示筛选条件,当此参数为null时,应定义处理逻辑。 |
| callback | AsyncCallback&lt;[KVStoreResultSet](#kvstoreresultset)&gt; | 是 | 回调函数,获取与指定Predicates对象匹配的KVStoreResultSet对象。 |
**错误码:**
......@@ -5423,75 +6329,59 @@ getResultSet(deviceId: string, query: Query, callback: AsyncCallback&lt;KVStoreR
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
import dataSharePredicates from '@ohos.data.dataSharePredicates';
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: distributedKVStore.ValueType.STRING,
value: 'batch_test_string_value'
}
}
entries.push(entry);
}
kvStore.putBatch(entries, async function (err, data) {
if (err != undefined) {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in putting batch');
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSet('localDeviceId', query, async function (err, result) {
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.prefixKey("batch_test_string_key");
kvStore.getResultSet(predicates, async function (err, result) {
if (err != undefined) {
console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`);
console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in getting resultSet');
console.log('Succeeded in getting result set');
resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) {
if (err != undefined) {
console.error(`Fail to close resultSet.code is ${err.code},message is ${err.message}`);
console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in closing resultSet');
console.log('Succeeded in closing result set');
})
});
});
} catch (e) {
console.error(`Fail to get resultSet.code is ${e.code},message is ${e.message}`);
console.error(`An unexpected error occured.code is ${e.code},message is ${e.code}`);
}
```
### getResultSet
getResultSet(deviceId: string, query: Query): Promise&lt;KVStoreResultSet&gt;
getResultSet(predicates: dataSharePredicates.DataSharePredicates): Promise&lt;KVStoreResultSet&gt;
获取与指定设备ID和Query对象匹配的KVStoreResultSet对象,使用Promise异步回调。
获取与本设备指定Predicate对象匹配的KVStoreResultSet对象,使用Promise异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------- | ---- | ---------------------------------- |
| deviceId | string | 是 | KVStoreResultSet对象所属的设备ID。 |
| query | [Query](query) | 是 | 表示查询对象。 |
| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------- |
| predicates | [DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | 指示筛选条件,当此参数为null时,应定义处理逻辑。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------------------------ | ------------------------------------------------------------ |
| Promise&lt;[KVStoreResultSet](#kvstoreresultset)&gt; | Promise对象。返回与指定设备ID和Query对象匹配的KVStoreResultSet对象。 |
| ---------------------------------------------------- | ------------------------- |
| Promise&lt;[KVStoreResultSet](#kvstoreresultset)&gt; | 无返回结果的Promise对象。 |
**错误码:**
......@@ -5500,49 +6390,31 @@ getResultSet(deviceId: string, query: Query): Promise&lt;KVStoreResultSet&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
import dataSharePredicates from '@ohos.data.dataSharePredicates';
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: distributedKVStore.ValueType.STRING,
value: 'batch_test_string_value'
}
}
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('Succeeded in putting batch');
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
});
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSet('localDeviceId', query).then((result) => {
console.log('Succeeded in getting resultSet');
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.prefixKey("batch_test_string_key");
kvStore.getResultSet(predicates).then((result) => {
console.log('Succeeded in getting result set');
resultSet = result;
}).catch((err) => {
console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`);
console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`);
});
query.deviceId('localDeviceId');
console.log("GetResultSet " + query.getSqlLike());
kvStore.closeResultSet(resultSet).then((err) => {
console.log('Succeeded in closing resultSet');
console.log('Succeeded in closing result set');
}).catch((err) => {
console.error(`Fail to close resultSet.code is ${err.code},message is ${err.message}`);
console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`);
});
} catch (e) {
console.error(`Fail to get resultSet.code is ${e.code},message is ${e.message}`);
console.error(`An unexpected error occured.code is ${e.code},message is ${e.code}`);
}
```
......@@ -5571,7 +6443,7 @@ getResultSet(deviceId: string, predicates: dataSharePredicates.DataSharePredicat
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -5633,7 +6505,7 @@ getResultSet(deviceId: string, predicates: dataSharePredicates.DataSharePredicat
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -5662,6 +6534,127 @@ try {
### getResultSize
getResultSize(query: Query, callback: AsyncCallback&lt;number&gt;): void
获取与本设备指定Query对象匹配的结果数,使用callback异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------------------------------- |
| query | [Query](query) | 是 | 表示查询对象。 |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数。返回与本设备指定Query对象匹配的结果数。 |
**错误码:**
以下错误码的详细介绍请参见[分布式键值数据库错误码](../errorcodes/errorcode-distributedKVStore.md)
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
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: distributedKVStore.ValueType.STRING,
value: 'batch_test_string_value'
}
}
entries.push(entry);
}
kvStore.putBatch(entries, async function (err, data) {
console.log('Succeeded in putting batch');
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSize(query, async function (err, resultSize) {
if (err != undefined) {
console.error(`Fail to get result size.code is ${err.code},message is ${err.message}`);
return;
}
console.log('Succeeded in getting result set size');
});
});
} catch (e) {
console.error(`An unexpected error occured.code is ${e.code},message is ${e.code}`);
}
```
### getResultSize
getResultSize(query: Query): Promise&lt;number&gt;
获取与本设备指定Query对象匹配的结果数,使用Promise异步回调。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | -------------- | ---- | -------------- |
| query | [Query](query) | 是 | 表示查询对象。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ---------------------------------------------------- |
| Promise&lt;number&gt; | Promise对象。获取与本设备指定Query对象匹配的结果数。 |
**错误码:**
以下错误码的详细介绍请参见[分布式键值数据库错误码](../errorcodes/errorcode-distributedKVStore.md)
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100005 | Database or result set already closed. |
**示例:**
```js
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: distributedKVStore.ValueType.STRING,
value: 'batch_test_string_value'
}
}
entries.push(entry);
}
kvStore.putBatch(entries).then(async (err) => {
console.log('Succeeded in putting batch');
}).catch((err) => {
console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`);
});
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
kvStore.getResultSize(query).then((resultSize) => {
console.log('Succeeded in getting result set size');
}).catch((err) => {
console.error(`Fail to get result size.code is ${err.code},message is ${err.message}`);
});
} catch (e) {
console.error(`An unexpected error occured.code is ${e.code},message is ${e.code}`);
}
```
### getResultSize
getResultSize(deviceId: string, query: Query, callback: AsyncCallback&lt;number&gt;): void;
获取与指定设备ID和Query对象匹配的结果数,使用callback异步回调。
......@@ -5683,7 +6676,7 @@ getResultSize(deviceId: string, query: Query, callback: AsyncCallback&lt;number&
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......@@ -5752,7 +6745,7 @@ getResultSize(deviceId: string, query: Query): Promise&lt;number&gt;
| **错误码ID** | **错误信息** |
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100006 | Database or result set already closed. |
| 15100005 | Database or result set already closed. |
**示例:**
......
......@@ -81,26 +81,7 @@ Not found.
2. 在数据库数据查询操作前,请检查查询关键字是否正确。
3. 在数据库数据删除操作前,请检查删除关键字是否正确或是否重复删除。
## 15100005 不支持当前操作
**错误信息**
Not support the operation.
**错误描述**
该错误码表示在调用数据库backup、restore等接口时,当前数据库不支持该操作。
**可能原因**
在调用数据库备份、恢复等接口时,当前数据库不支持该操作。
**处理步骤**
检查当前数据库是否支持备份、恢复操作。
## 15100006 数据库或查询结果集已关闭
## 15100005 数据库或查询结果集已关闭
**错误信息**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册