Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
50420599
D
Docs
项目概览
OpenHarmony
/
Docs
大约 1 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
50420599
编写于
11月 29, 2022
作者:
Y
ylq121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
xiugai
Signed-off-by:
N
ylq121
<
yangqing89@huawei.com
>
上级
ee3914ba
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
1405 addition
and
274 deletion
+1405
-274
zh-cn/application-dev/reference/apis/js-apis-distributed-data.md
...pplication-dev/reference/apis/js-apis-distributed-data.md
+223
-66
zh-cn/application-dev/reference/apis/js-apis-distributedKVStore.md
...lication-dev/reference/apis/js-apis-distributedKVStore.md
+1181
-188
zh-cn/application-dev/reference/errorcodes/errorcode-distributedKVStore.md
...-dev/reference/errorcodes/errorcode-distributedKVStore.md
+1
-20
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-distributed-data.md
浏览文件 @
50420599
...
...
@@ -509,7 +509,7 @@ try {
on(event: 'distributedDataServiceDie', deathCallback: Callback
<
void
>
): void
订阅服务状态变更通知
,此方法为同步方法
。
订阅服务状态变更通知。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...
...
@@ -540,7 +540,7 @@ try {
off(event: 'distributedDataServiceDie', deathCallback?: Callback
<
void
>
): void
取消订阅服务状态变更通知
,此方法为同步方法
。
取消订阅服务状态变更通知。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...
...
@@ -2234,17 +2234,17 @@ try {
on(event: 'dataChange', type: SubscribeType, listener: Callback
<
ChangeNotification
>
): void
订阅指定类型的数据变更通知
,此方法为同步方法
。
订阅指定类型的数据变更通知。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -----
| ------ | ---- |
----------------------- |
| event
|string | 是 |订阅的事件名,固定为'dataChange',表示数据变更事件。
|
| type
|
[
SubscribeType
](
#subscribetype
)
| 是 |表示订阅的类型。
|
| listener |
Callback
<
[ChangeNotification](#changenotification)
>
| 是 |回调函数。
|
| -----
--- | --------------------------------------------------------- | ---- | -----------------------------
----------------------- |
| event
| string | 是 | 订阅的事件名,固定为'dataChange',表示数据变更事件。
|
| type
|
[
SubscribeType
](
#subscribetype
)
| 是 | 表示订阅的类型。
|
| listener |
Callback
<
[ChangeNotification](#changenotification)
>
| 是 | 回调函数。
|
**示例:**
...
...
@@ -2259,16 +2259,16 @@ kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, fun
on(event: 'syncComplete', syncCallback: Callback
<
Array
<
[string, number]
>>
): void
订阅同步完成事件回调通知
,此方法为同步方法
。
订阅同步完成事件回调通知。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -----
| ------ | ---- |
----------------------- |
| event
|string | 是 |订阅的事件名,固定为'syncComplete',表示同步完成事件。
|
| syncCallback
|Callback
<
Array
<
[string, number]
>>
| 是 |回调函数。
|
| -----
------- | --------------------------------------------- | ---- | -------------------------------
----------------------- |
| event
| string | 是 | 订阅的事件名,固定为'syncComplete',表示同步完成事件。
|
| syncCallback
| Callback
<
Array
<
[string, number]
>>
| 是 | 回调函数。用于向调用方发送同步结果的回调。
|
**示例:**
...
...
@@ -2283,16 +2283,18 @@ kvStore.on('syncComplete', function (data) {
off(event:'dataChange', listener?: Callback
<
ChangeNotification
>
): void
取消订阅数据变更通知
,此方法为同步方法
。
取消订阅数据变更通知。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------- |
| event |string | 是 |取消订阅的事件名,固定为'dataChange',表示数据变更事件。 |
| listener |Callback
<
[ChangeNotification](#changenotification)
>
|否 |回调函数。 |
| -------- | --------------------------------------------------------- | ---- | -------------------------------------------------------- |
| event | string | 是 | 取消订阅的事件名,固定为'dataChange',表示数据变更事件。 |
| listener | Callback
<
[ChangeNotification](#changenotification)
>
| 否 | 回调函数。 |
**示例:**
...
...
@@ -2315,6 +2317,42 @@ class KvstoreModel {
}
```
### off('syncComplete')<sup>8+</sup>
off(event: 'syncComplete', syncCallback?: Callback
<
Array
<
[string, number]
>>
): void
取消订阅同步完成事件回调通知。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | --------------------------------------------- | ---- | ---------------------------------------------------------- |
| event | string | 是 | 取消订阅的事件名,固定为'syncComplete',表示同步完成事件。 |
| syncCallback | Callback
<
Array
<
[string, number]
>>
| 否 | 回调函数。用于向调用方发送同步结果的回调。 |
**示例:**
```
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
<
void
>
): 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
<
ChangeNotification
>
): void
订阅指定类型的数据变更通知。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------------- | ---- | ---------------------------------------------------- |
| event | string | 是 | 订阅的事件名,固定为'dataChange',表示数据变更事件。 |
| type |
[
SubscribeType
](
#subscribetype
)
| 是 | 表示订阅的类型。 |
| listener | Callback
<
[ChangeNotification](#changenotification)
>
| 是 | 回调函数。 |
**示例:**
```
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
<
Array
<
[string, number]
>>
): void
订阅同步完成事件回调通知
,此方法为同步方法
。
订阅同步完成事件回调通知。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -----
| ------ | ---- |
----------------------- |
| event
|string | 是 |订阅的事件名,固定为'syncComplete',表示同步完成事件。
|
| syncCallback
|Callback
<
Array
<
[string, number]
>>
| 是 |回调函数。用于向调用方发送同步结果的回调。
|
| -----
------- | --------------------------------------------- | ---- | -------------------------------
----------------------- |
| event
| string | 是 | 订阅的事件名,固定为'syncComplete',表示同步完成事件。
|
| syncCallback
| Callback
<
Array
<
[string, number]
>>
| 是 | 回调函数。用于向调用方发送同步结果的回调。
|
**示例:**
...
...
@@ -3747,21 +3835,20 @@ try {
}
```
### off('dataChange')<sup>8+</sup>
### off('syncComplete')<sup>8+</sup>
off(event: 'syncComplete', syncCallback?: Callback
<
Array
<
[string, number]
>>
): void
off(event:'dataChange', listener?: Callback
<
ChangeNotification
>
): void
取消订阅
同步完成事件回调通知,此方法为同步方法
。
取消订阅
数据变更通知
。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -----
| ------ | ---- |
----------------------- |
| event
|string | 是 |取消订阅的事件名,固定为'syncComplete',表示同步完成事件。
|
|
syncCallback |Callback
<
Array
<
[string, number]
>>
| 否 |回调函数。用于向调用方发送同步结果的回调。
|
| -----
--- | --------------------------------------------------------- | ---- | ---------------------------------
----------------------- |
| event
| string | 是 | 取消订阅的事件名,固定为'dataChange',表示数据变更事件。
|
|
listener | Callback
<
[ChangeNotification](#changenotification)
>
| 否 | 回调函数。
|
**示例:**
...
...
@@ -3769,45 +3856,55 @@ off(event: 'syncComplete', syncCallback?: Callback<Array<[string, number]&
let
kvStore
;
class
KvstoreModel
{
call
(
data
)
{
console
.
log
(
"
syncComplet
e:
"
+
data
);
console
.
log
(
"
dataChang
e:
"
+
data
);
}
subscribe
SyncComplet
e
()
{
subscribe
DataChang
e
()
{
if
(
kvStore
!=
null
)
{
kvStore
.
on
(
'
syncComplete
'
,
this
.
call
);
kvStore
.
on
(
'
dataChange
'
,
distributedData
.
SubscribeType
.
SUBSCRIBE_TYPE_REMOTE
,
this
.
call
);
}
}
unsubscribe
SyncComplet
e
()
{
unsubscribe
DataChang
e
()
{
if
(
kvStore
!=
null
)
{
kvStore
.
off
(
'
syncComplet
e
'
,
this
.
call
);
kvStore
.
off
(
'
dataChang
e
'
,
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
<
Array
<
[string, number]
>>
): void
**需要权限**
: ohos.permission.DISTRIBUTED_DATASYNC
。
取消订阅同步完成事件回调通知
。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------- |
| deviceIds |string[] | 是 |同一组网环境下,需要同步的设备的deviceId列表。 |
| mode |
[
SyncMode
](
#syncmode
)
| 是 |同步模式。 |
| delayMs |number | 否 |可选参数,允许延时时间,单位:ms(毫秒)。 |
| ------------ | --------------------------------------------- | ---- | ---------------------------------------------------------- |
| event | string | 是 | 取消订阅的事件名,固定为'syncComplete',表示同步完成事件。 |
| syncCallback | Callback
<
Array
<
[string, number]
>>
| 否 | 回调函数。用于向调用方发送同步结果的回调。 |
**示例:**
```
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
<
ChangeNotification
>
): void
订阅指定类型的数据变更通知。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------------- | ---- | ---------------------------------------------------- |
| event | string | 是 | 订阅的事件名,固定为'dataChange',表示数据变更事件。 |
| type |
[
SubscribeType
](
#subscribetype
)
| 是 | 表示订阅的类型。 |
| listener | Callback
<
[ChangeNotification](#changenotification)
>
| 是 | 回调函数。 |
**示例:**
```
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
<
Array
<
[string, number]
>>
): void
订阅同步完成事件回调通知
,此方法为同步方法
。
订阅同步完成事件回调通知。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -----
| ------ | ---- |
----------------------- |
| event
|string | 是 |
订阅的事件名,固定为'syncComplete',表示同步完成事件。 |
| syncCallback
|Callback
<Array
&
lt
;[
string
,
number
]&
gt
;
>
| 是 |回调函数。用于向调用方发送同步结果的回调。
|
| -----
------- | --------------------------------------------- | ---- | -------------------------------
----------------------- |
| event
| string | 是 |
订阅的事件名,固定为'syncComplete',表示同步完成事件。 |
| syncCallback
| Callback
<
Array
<
[string, number]
>>
| 是 | 回调函数。用于向调用方发送同步结果的回调。
|
**示例:**
...
...
@@ -5112,21 +5234,56 @@ try {
}
```
### off('dataChange')<sup>8+</sup>
off(event:'dataChange', listener?: Callback
<
ChangeNotification
>
): void
取消订阅数据变更通知。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------------- | ---- | -------------------------------------------------------- |
| event | string | 是 | 取消订阅的事件名,固定为'dataChange',表示数据变更事件。 |
| listener | Callback
<
[ChangeNotification](#changenotification)
>
| 否 | 回调函数。 |
**示例:**
```
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
<
Array
<
[string, number]
>>
): void
取消订阅同步完成事件回调通知
,此方法为同步方法
。
取消订阅同步完成事件回调通知。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -----
| ------ | ---- |
----------------------- |
| event
|string | 是 |
取消订阅的事件名,固定为'syncComplete',表示同步完成事件。 |
| syncCallback
|Callback<Array
<
[string, number]
>>
| 否 |回调函数。用于向调用方发送同步结果的回调。
|
| -----
------- | --------------------------------------------- | ---- | -----------------------------------
----------------------- |
| event
| string | 是 |
取消订阅的事件名,固定为'syncComplete',表示同步完成事件。 |
| syncCallback
| Callback
<
Array
<
[string, number]
>>
| 否 | 回调函数。用于向调用方发送同步结果的回调。
|
**示例:**
...
...
zh-cn/application-dev/reference/apis/js-apis-distributedKVStore.md
浏览文件 @
50420599
...
...
@@ -790,7 +790,7 @@ try {
on(event: 'distributedDataServiceDie', deathCallback: Callback
<
void
>
): void
订阅服务状态变更通知
,此方法为同步方法
。
订阅服务状态变更通知。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...
...
@@ -820,7 +820,7 @@ try {
off(event: 'distributedDataServiceDie', deathCallback?: Callback
<
void
>
): void
取消订阅服务状态变更通知
,此方法为同步方法
。
取消订阅服务状态变更通知。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...
...
@@ -2188,7 +2188,7 @@ put(key: string, value: Uint8Array | string | number | boolean, callback: AsyncC
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -2237,7 +2237,7 @@ put(key: string, value: Uint8Array | string | number | boolean): Promise<void
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -2278,7 +2278,7 @@ putBatch(entries: Entry[], callback: AsyncCallback<void>): void
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -2345,7 +2345,7 @@ putBatch(entries: Entry[]): Promise<void>
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -2405,7 +2405,7 @@ putBatch(value: Array<ValuesBucket>, callback: AsyncCallback<void>):
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -2462,7 +2462,7 @@ putBatch(value: Array<ValuesBucket>): Promise<void>
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -2510,8 +2510,7 @@ delete(key: string, callback: AsyncCallback<void>): 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<void>
|
**错误码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<void>
|
**错误码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<void>): 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<void>
|
**错误码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<void>): void
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -2898,7 +2892,7 @@ removeDeviceData(deviceId: string): Promise<void>
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| 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. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -3007,7 +3001,7 @@ get(key: string): Promise<boolean | string| number | Uint8Array>
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100004 | Not found. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -3053,7 +3047,7 @@ getEntries(keyPrefix: string, callback: AsyncCallback<Entry[]>): void
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -3121,7 +3115,7 @@ getEntries(keyPrefix: string): Promise<Entry[]>
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -3179,8 +3173,7 @@ getEntries(query: Query, callback: AsyncCallback<Entry[]>): 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<Entry[]>
|
**错误码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<KVStoreResultSet>)
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -3383,7 +3375,7 @@ getResultSet(keyPrefix: string): Promise<KVStoreResultSet>
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -3446,7 +3438,7 @@ getResultSet(query: Query, callback: AsyncCallback<KVStoreResultSet>): voi
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -3514,7 +3506,7 @@ getResultSet(query: Query): Promise<KVStoreResultSet>
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -3576,7 +3568,7 @@ getResultSet(predicates: dataSharePredicates.DataSharePredicates, callback: Asyn
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -3637,7 +3629,7 @@ getResultSet(predicates: dataSharePredicates.DataSharePredicates): Promise<KV
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -3756,7 +3748,7 @@ getResultSize(query: Query, callback: AsyncCallback<number>): void
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -3819,7 +3811,7 @@ getResultSize(query: Query): Promise<number>
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -3876,8 +3868,7 @@ backup(file:string, callback: AsyncCallback<void>):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<void>
|
**错误码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<void>):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<void>
|
**错误码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<void>): void
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -4186,7 +4174,7 @@ startTransaction(): Promise<void>
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -4228,7 +4216,7 @@ commit(callback: AsyncCallback<void>): void
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -4267,7 +4255,7 @@ commit(): Promise<void>
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -4304,7 +4292,7 @@ rollback(callback: AsyncCallback<void>): void
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -4343,7 +4331,7 @@ rollback(): Promise<void>
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| 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
<
ChangeNotification
>
): void
订阅指定类型的数据变更通知
,此方法为同步方法
。
订阅指定类型的数据变更通知。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
...
...
@@ -4686,7 +4688,7 @@ on(event: 'dataChange', type: SubscribeType, listener: Callback<ChangeNotific
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100001 | Over max subscribe limits. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -4705,7 +4707,7 @@ try {
on(event: 'syncComplete', syncCallback: Callback
<
Array
<
[string, number]
>>
): void
订阅同步完成事件回调通知
,此方法为同步方法
。
订阅同步完成事件回调通知。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
...
...
@@ -4740,7 +4742,7 @@ try {
off(event:'dataChange', listener?: Callback
<
ChangeNotification
>
): void
取消订阅数据变更通知
,此方法为同步方法
。
取消订阅数据变更通知。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
...
...
@@ -4757,7 +4759,7 @@ off(event:'dataChange', listener?: Callback<ChangeNotification>): void
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -4794,7 +4796,7 @@ class KvstoreModel {
off(event: 'syncComplete', syncCallback?: Callback
<
Array
<
[string, number]
>>
): void
取消订阅同步完成事件回调通知
,此方法为同步方法
。
取消订阅同步完成事件回调通知。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
...
...
@@ -4856,7 +4858,7 @@ getSecurityLevel(callback: AsyncCallback<SecurityLevel>): void
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -4895,7 +4897,7 @@ getSecurityLevel(): Promise<SecurityLevel>
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| 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
<
boolean
\|
string
\|
number
\|
Uint8Array
>
) | 是 | 回调函数。返回获取查询的值。 |
**错误码:**
以下错误码的详细介绍请参见
[
分布式键值数据库错误码
](
../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
<
boolean | string| number | Uint8Array
>
获取本设备指定键的值,使用Promise异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| key | string | 是 | 要查询数据的key,不能为空且长度不大于
[
MAX_KEY_LENGTH
](
#constants
)
。 |
**返回值:**
| 类型 | 说明 |
| -------------------------------------------------------- | ------------------------------- |
| Promise
<
Uint8Array
\|
string
\|
boolean
\|
number
>
| 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
<
boolean|string|number|Uint8Array
>
): void
获取与指定设备ID和key匹配的string值,使用callback异步回调。
...
...
@@ -4946,7 +5051,7 @@ get(deviceId: string, key: string, callback: AsyncCallback<boolean|string|num
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100004 | Not found. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -5003,7 +5108,7 @@ get(deviceId: string, key: string): Promise<boolean|string|number|Uint8Array&
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 15100004 | Not found. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -5029,19 +5134,18 @@ try {
### getEntries
getEntries(
deviceId: string,
keyPrefix: string, callback: AsyncCallback
<
Entry[]
>
): void
getEntries(keyPrefix: string, callback: AsyncCallback
<
Entry[]
>
): void
获取
与指定设备ID和key前缀匹配
的所有键值对,使用callback异步回调。
获取
匹配本设备指定键前缀
的所有键值对,使用callback异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.
DistributedKVSt
ore
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.
C
ore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | -------------------------------------- | ---- | ---------------------------------------------- |
| deviceId | string | 是 | 标识要查询其数据的设备。 |
| --------- | -------------------------------------- | ---- | ---------------------------------------- |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
| callback | AsyncCallback
<
[Entry](#entry)[]
>
| 是 | 回调函数
,返回满足给定条件的所有键值对的
列表。 |
| callback | AsyncCallback
<
[Entry](#entry)[]
>
| 是 | 回调函数
。返回匹配指定前缀的键值对
列表。 |
**错误码:**
...
...
@@ -5050,7 +5154,7 @@ getEntries(deviceId: string, keyPrefix: string, callback: AsyncCallback<Entry
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| 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
b
atch.code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
console
.
error
(
`Fail to put
B
atch.code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
return
;
}
console
.
log
(
'
Succeeded in putting
b
atch
'
);
kvStore
.
getEntries
(
'
localDeviceId
'
,
'
batch_test_string_key
'
,
function
(
err
,
entries
)
{
console
.
log
(
'
Succeeded in putting
B
atch
'
);
kvStore
.
getEntries
(
'
batch_test_string_key
'
,
function
(
err
,
entries
)
{
if
(
err
!=
undefined
)
{
console
.
error
(
`Fail to get
e
ntries.code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
console
.
error
(
`Fail to get
E
ntries.code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
return
;
}
console
.
log
(
'
Succeeded in getting
e
ntries
'
);
console
.
log
(
'
Succeeded in getting
E
ntries
'
);
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
<
Entry[]
>
getEntries(keyPrefix: string): Promise
<
Entry[]
>
获取
与指定设备ID和key前缀匹配
的所有键值对,使用Promise异步回调。
获取
匹配本设备指定键前缀
的所有键值对,使用Promise异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.
DistributedKVSt
ore
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.
C
ore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | -------- | ---- | ------------------------ |
| deviceId | string | 是 | 标识要查询其数据的设备。 |
| --------- | ------ | ---- | -------------------- |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
**返回值:**
| 类型 | 说明 |
| -------------------------------- | -------------------------------------------
------
|
| Promise
<
[Entry](#entry)[]
>
| Promise对象。返回匹配
给定条件的所有键值对的
列表。 |
| -------------------------------- | ------------------------------------------- |
| Promise
<
[Entry](#entry)[]
>
| Promise对象。返回匹配
指定前缀的键值对
列表。 |
**错误码:**
...
...
@@ -5119,7 +5222,7 @@ getEntries(deviceId: string, keyPrefix: string): Promise<Entry[]>
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| 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
e
ntries.code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
console
.
error
(
`Fail to get
E
ntries.code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
});
}).
catch
((
err
)
=>
{
console
.
error
(
`Fail to put
b
atch.code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
console
.
error
(
`Fail to put
B
atch.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
<
Entry[]
>
): void
getEntries(deviceId: string,
keyPrefix: string
, callback: AsyncCallback
<
Entry[]
>
): void
获取与指定设备ID和
Query对象匹配的键值对列表
,使用callback异步回调。
获取与指定设备ID和
key前缀匹配的所有键值对
,使用callback异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------
| -------------------------------------- | ---- | ---------
---------------------------------------------- |
| deviceId
| string | 是 | 键值对所属的设备ID。
|
|
query |
[
Query
](
query
)
| 是 | 表示查询对象。
|
| callback
| AsyncCallback
<
[Entry](#entry)[]
>
| 是 | 回调函数。返回与指定设备ID和Query对象匹配的键值对
列表。 |
| --------
- | -------------------------------------- | ---- |
---------------------------------------------- |
| deviceId
| string | 是 | 标识要查询其数据的设备。
|
|
keyPrefix | string | 是 | 表示要匹配的键前缀。
|
| callback
| AsyncCallback
<
[Entry](#entry)[]
>
| 是 | 回调函数,返回满足给定条件的所有键值对的
列表。 |
**错误码:**
...
...
@@ -5181,38 +5281,33 @@ getEntries(deviceId: string, query: Query, callback: AsyncCallback<Entry[]>
|
**错误码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
<
Entry[]
>
getEntries(deviceId: string,
keyPrefix: string
): Promise
<
Entry[]
>
获取与指定设备ID和
Query对象匹配的键值对列表
,使用Promise异步回调。
获取与指定设备ID和
key前缀匹配的所有键值对
,使用Promise异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------
| -------------- | ---- |
-------------------- |
| deviceId
| string | 是 | 键值对所属的设备ID
。 |
|
query |
[
Query
](
query
)
| 是 | 表示查询对象。
|
| --------
- | -------- | ---- | ----
-------------------- |
| deviceId
| string | 是 | 标识要查询其数据的设备
。 |
|
keyPrefix | string | 是 | 表示要匹配的键前缀。
|
**返回值:**
| 类型 | 说明 |
| -------------------------------- | -------------------------------------------------
---------
|
| Promise
<
[Entry](#entry)[]
>
| Promise对象。返回
与指定设备ID和Query对象匹配的键值对
列表。 |
| -------------------------------- | ------------------------------------------------- |
| Promise
<
[Entry](#entry)[]
>
| Promise对象。返回
匹配给定条件的所有键值对的
列表。 |
**错误码:**
...
...
@@ -5256,23 +5350,21 @@ getEntries(deviceId: string, query: Query): Promise<Entry[]>
|
**错误码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
}
`
);
}
```
### get
ResultSet
### get
Entries
get
ResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback
<
KVStoreResultSet
>
): void
get
Entries(query: Query, callback: AsyncCallback
<
Entry[]
>
): void
获取
与指定设备ID和key前缀匹配的KVStoreResultSet对象
,使用callback异步回调。
获取
本设备与指定Query对象匹配的键值对列表
,使用callback异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.
DistributedKVSt
ore
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.
C
ore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| deviceId | string | 是 | 标识要查询其数据的设备。 |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
| callback | AsyncCallback
<
[KVStoreResultSet](#kvstoreresultset)
>
| 是 | 回调函数。返回与指定设备ID和key前缀匹配的KVStoreResultSet对象。 |
| -------- | -------------------------------------- | ---- | ----------------------------------------------------- |
| query |
[
Query
](
query
)
| 是 | 表示要匹配的键前缀。 |
| callback | AsyncCallback
<
[Entry](#entry)[]
>
| 是 | 回调函数。返回本设备与指定Query对象匹配的键值对列表。 |
**错误码:**
...
...
@@ -5320,22 +5411,674 @@ getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback<KVS
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| 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
<
Entry[]
>
获取本设备与指定Query对象匹配的键值对列表,使用Promise异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | -------------- | ---- | -------------- |
| query |
[
Query
](
query
)
| 是 | 表示查询对象。 |
**返回值:**
| 类型 | 说明 |
| -------------------------------- | -------------------------------------------------------- |
| Promise
<
[Entry](#entry)[]
>
| 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
<
Entry[]
>
): void
获取与指定设备ID和Query对象匹配的键值对列表,使用callback异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------- | ---- | ------------------------------------------------------- |
| deviceId | string | 是 | 键值对所属的设备ID。 |
| query |
[
Query
](
query
)
| 是 | 表示查询对象。 |
| callback | AsyncCallback
<
[Entry](#entry)[]
>
| 是 | 回调函数。返回与指定设备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
<
Entry[]
>
获取与指定设备ID和Query对象匹配的键值对列表,使用Promise异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------- | ---- | -------------------- |
| deviceId | string | 是 | 键值对所属的设备ID。 |
| query |
[
Query
](
query
)
| 是 | 表示查询对象。 |
**返回值:**
| 类型 | 说明 |
| -------------------------------- | ---------------------------------------------------------- |
| Promise
<
[Entry](#entry)[]
>
| 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
<
Entry[]
>
): void
获取匹配本设备指定键前缀的所有键值对,使用callback异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | -------------------------------------- | ---- | ---------------------------------------- |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
| callback | AsyncCallback
<
[Entry](#entry)[]
>
| 是 | 回调函数。返回匹配指定前缀的键值对列表。 |
**错误码:**
以下错误码的详细介绍请参见
[
分布式键值数据库错误码
](
../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
<
Entry[]
>
获取匹配本设备指定键前缀的所有键值对,使用Promise异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | -------------------- |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
**返回值:**
| 类型 | 说明 |
| -------------------------------- | ------------------------------------------- |
| Promise
<
[Entry](#entry)[]
>
| 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
<
KVStoreResultSet
>
): void
从DeviceKVStore数据库中获取本设备具有指定前缀的结果集,使用callback异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------------------------- | ---- | ------------------------------------ |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
| callback | AsyncCallback
<
[KVStoreResultSet](#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
'
);
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
<
KVStoreResultSet
>
从DeviceKVStore数据库中获取本设备具有指定前缀的结果集,使用Promise异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | -------------------- |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
**返回值:**
| 类型 | 说明 |
| ---------------------------------------------------- | --------------------------------------- |
| Promise
<
[KVStoreResultSet](#kvstoreresultset)
>
| 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
<
KVStoreResultSet
>
): void
获取与指定设备ID和key前缀匹配的KVStoreResultSet对象,使用callback异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| deviceId | string | 是 | 标识要查询其数据的设备。 |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
| callback | AsyncCallback
<
[KVStoreResultSet](#kvstoreresultset)
>
| 是 | 回调函数。返回与指定设备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
<
KVStoreResultSet
>
获取与指定设备ID和key前缀匹配的KVStoreResultSet对象,使用Promise异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | -------- | ---- | ------------------------ |
| deviceId | string | 是 | 标识要查询其数据的设备。 |
| keyPrefix | string | 是 | 表示要匹配的键前缀。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------------------------ | ------------------------------------------------------------ |
| Promise
<
[KVStoreResultSet](#kvstoreresultset)
>
| 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
<
KVStoreResultSet
>
): void
获取与指定设备ID和Query对象匹配的KVStoreResultSet对象,使用callback异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| deviceId | string | 是 | KVStoreResultSet对象所属的设备ID。 |
| query |
[
Query
](
query
)
| 是 | 表示查询对象。 |
| callback | AsyncCallback
<
[KVStoreResultSet](#kvstoreresultset)
>
| 是 | 回调函数。返回与指定设备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
<
KVStoreResultSet
>
获取与指定设备ID和Query对象匹配的KVStoreResultSet对象,使用Promise异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------- | ---- | ---------------------------------- |
| deviceId | string | 是 | KVStoreResultSet对象所属的设备ID。 |
| query |
[
Query
](
query
)
| 是 | 表示查询对象。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------------------------ | ------------------------------------------------------------ |
| Promise
<
[KVStoreResultSet](#kvstoreresultset)
>
| 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
<
KVStoreResultSet
>
获取与本设备指定Query对象匹配的KVStoreResultSet对象,使用Promise异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | -------------- | ---- | -------------- |
| query |
[
Query
](
query
)
| 是 | 表示查询对象。 |
**返回值:**
| 类型 | 说明 |
| ---------------------------------------------------- | ------------------------------------------------------------ |
| Promise
<
[KVStoreResultSet](#kvstoreresultset)
>
| 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
.
messag
e
}
`
);
console
.
error
(
`
An unexpected error occured.code is
${
e
.
code
}
,message is
${
e
.
cod
e
}
`
);
}
```
### getResultSet
getResultSet(deviceId: string,
keyPrefix: string
): Promise
<
KVStoreResultSet
>
getResultSet(deviceId: string,
query: Query
): Promise
<
KVStoreResultSet
>
获取与指定设备ID和
key前缀
匹配的KVStoreResultSet对象,使用Promise异步回调。
获取与指定设备ID和
Query对象
匹配的KVStoreResultSet对象,使用Promise异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------
- | -------- | ---- |
------------------------ |
| deviceId
| string | 是 | 标识要查询其数据的设备
。 |
|
keyPrefix | string | 是 | 表示要匹配的键前缀。
|
| --------
| -------------- | ---- | ----------
------------------------ |
| deviceId
| string | 是 | KVStoreResultSet对象所属的设备ID
。 |
|
query |
[
Query
](
query
)
| 是 | 表示查询对象。
|
**返回值:**
| 类型 | 说明 |
| ----------------------------------------------------
--
| ------------------------------------------------------------ |
| Promise
<
[KVStoreResultSet](#kvstoreresultset)
>
| Promise对象。返回与指定设备ID和
key前缀
匹配的KVStoreResultSet对象。 |
| ---------------------------------------------------- | ------------------------------------------------------------ |
| Promise
<
[KVStoreResultSet](#kvstoreresultset)
>
| Promise对象。返回与指定设备ID和
Query对象
匹配的KVStoreResultSet对象。 |
**错误码:**
...
...
@@ -5376,7 +6259,7 @@ getResultSet(deviceId: string, keyPrefix: string): Promise<KVStoreResultSet&g
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -5384,17 +6267,39 @@ getResultSet(deviceId: string, keyPrefix: string): Promise<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
<
KVStoreResultSet
>
): void
getResultSet(
predicates: dataSharePredicates.DataSharePredicates
, callback: AsyncCallback
<
KVStoreResultSet
>
): 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
<
[KVStoreResultSet](#kvstoreresultset)
>
| 是 | 回调函数。返回与指定设备ID和Query对象匹配的KVStoreResultSet对象。 |
| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| predicates |
[
DataSharePredicates
](
js-apis-data-dataSharePredicates.md#datasharepredicates
)
| 是 | 指示筛选条件,当此参数为null时,应定义处理逻辑。 |
| callback | AsyncCallback
<
[KVStoreResultSet](#kvstoreresultset)
>
| 是 | 回调函数,获取与指定Predicates对象匹配的KVStoreResultSet对象。 |
**错误码:**
...
...
@@ -5423,75 +6329,59 @@ getResultSet(deviceId: string, query: Query, callback: AsyncCallback<KVStoreR
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| 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 resultS
et.code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
console
.
error
(
`Fail to get results
et.code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
return
;
}
console
.
log
(
'
Succeeded in getting resultS
et
'
);
console
.
log
(
'
Succeeded in getting result s
et
'
);
resultSet
=
result
;
kvStore
.
closeResultSet
(
resultSet
,
function
(
err
,
data
)
{
if
(
err
!=
undefined
)
{
console
.
error
(
`Fail to close resultS
et.code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
console
.
error
(
`Fail to close results
et.code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
return
;
}
console
.
log
(
'
Succeeded in closing resultS
et
'
);
console
.
log
(
'
Succeeded in closing result s
et
'
);
})
});
});
}
catch
(
e
)
{
console
.
error
(
`
Fail to get resultSet.code is
${
e
.
code
}
,message is
${
e
.
messag
e
}
`
);
console
.
error
(
`
An unexpected error occured.code is
${
e
.
code
}
,message is
${
e
.
cod
e
}
`
);
}
```
### getResultSet
getResultSet(
deviceId: string, query: Query
): Promise
<
KVStoreResultSet
>
getResultSet(
predicates: dataSharePredicates.DataSharePredicates
): Promise
<
KVStoreResultSet
>
获取与
指定设备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
<
[KVStoreResultSet](#kvstoreresultset)
>
|
Promise对象。返回与指定设备ID和Query对象匹配的KVStoreResultSet
对象。 |
| ----------------------------------------------------
|
------------------------- |
| Promise
<
[KVStoreResultSet](#kvstoreresultset)
>
|
无返回结果的Promise
对象。 |
**错误码:**
...
...
@@ -5500,49 +6390,31 @@ getResultSet(deviceId: string, query: Query): Promise<KVStoreResultSet>
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| 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 result
S
et.code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
console
.
error
(
`Fail to get result
s
et.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 result
S
et
'
);
console
.
log
(
'
Succeeded in closing result
s
et
'
);
}).
catch
((
err
)
=>
{
console
.
error
(
`Fail to close result
S
et.code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
console
.
error
(
`Fail to close result
s
et.code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
});
}
catch
(
e
)
{
console
.
error
(
`
Fail to get resultSet.code is
${
e
.
code
}
,message is
${
e
.
messag
e
}
`
);
console
.
error
(
`
An unexpected error occured.code is
${
e
.
code
}
,message is
${
e
.
cod
e
}
`
);
}
```
...
...
@@ -5571,7 +6443,7 @@ getResultSet(deviceId: string, predicates: dataSharePredicates.DataSharePredicat
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -5633,7 +6505,7 @@ getResultSet(deviceId: string, predicates: dataSharePredicates.DataSharePredicat
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -5662,6 +6534,127 @@ try {
### getResultSize
getResultSize(query: Query, callback: AsyncCallback
<
number
>
): void
获取与本设备指定Query对象匹配的结果数,使用callback异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------------------------------- |
| query |
[
Query
](
query
)
| 是 | 表示查询对象。 |
| callback | AsyncCallback
<
number
>
| 是 | 回调函数。返回与本设备指定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
<
number
>
获取与本设备指定Query对象匹配的结果数,使用Promise异步回调。
**系统能力:**
SystemCapability.DistributedDataManager.KVStore.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | -------------- | ---- | -------------- |
| query |
[
Query
](
query
)
| 是 | 表示查询对象。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ---------------------------------------------------- |
| Promise
<
number
>
| 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
<
number
>
): void;
获取与指定设备ID和Query对象匹配的结果数,使用callback异步回调。
...
...
@@ -5683,7 +6676,7 @@ getResultSize(deviceId: string, query: Query, callback: AsyncCallback<number&
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
@@ -5752,7 +6745,7 @@ getResultSize(deviceId: string, query: Query): Promise<number>
|
**错误码ID**
|
**错误信息**
|
| ------------ | -------------------------------------- |
| 15100003 | Database corrupted. |
| 1510000
6
| Database or result set already closed. |
| 1510000
5
| Database or result set already closed. |
**示例:**
...
...
zh-cn/application-dev/reference/errorcodes/errorcode-distributedKVStore.md
浏览文件 @
50420599
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录