Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
285251a3
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,发现更多精彩内容 >>
提交
285251a3
编写于
6月 30, 2022
作者:
W
wangkai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
接口文档更改
Signed-off-by:
N
wangkai
<
wangkai424@huawei.com
>
上级
4255689e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
51 addition
and
25 deletion
+51
-25
zh-cn/application-dev/reference/apis/js-apis-distributed-data.md
...pplication-dev/reference/apis/js-apis-distributed-data.md
+51
-25
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-distributed-data.md
浏览文件 @
285251a3
...
...
@@ -2230,7 +2230,7 @@ try {
### delete<sup>9+</sup>
delete(predicates: Predicates, callback: AsyncCallback
<
void
>
): void
delete(predicates:
dataSharePredicates.DataShare
Predicates, callback: AsyncCallback
<
void
>
): void
从数据库中删除符合predicates条件的键值对,并通过callback方式返回,此方法为异步方法。
...
...
@@ -2246,10 +2246,11 @@ delete(predicates: Predicates, callback: AsyncCallback<void>): void
**示例:**
```
js
import
dataSharePredicates
from
'
./@ohos.data.dataSharePredicates
'
;
let
kvStore
;
try
{
let
predicates
=
new
dataShare
.
DataSharePredicates
();
await
kvStore
.
delete
(
predicates
,
function
(
err
,
data
)
{
let
predicates
=
new
dataShare
Predicates
.
DataSharePredicates
();
kvStore
.
delete
(
predicates
,
function
(
err
,
data
)
{
if
(
err
==
undefined
)
{
console
.
log
(
'
delete success
'
);
}
else
{
...
...
@@ -2263,7 +2264,7 @@ try {
### delete<sup>9+</sup>
delete(predicates: Predicates): Promise
<
void
>
delete(predicates:
dataSharePredicates.DataShare
Predicates): Promise
<
void
>
从数据库中删除符合predicates条件的键值对,并通过Promise方式返回,此方法为异步方法。
...
...
@@ -2285,15 +2286,28 @@ delete(predicates: Predicates): Promise<void>
**示例:**
```
js
import
dataSharePredicates
from
'
./@ohos.data.dataSharePredicates
'
;
let
kvStore
;
try
{
let
predicates
=
new
dataShare
.
DataSharePredicates
();
let
predicates
=
new
dataShare
Predicates
.
DataSharePredicates
();
let
arr
=
[
"
name
"
];
predicates
.
inKeys
(
arr
);
kvStore
.
put
(
"
name
"
,
"
bob
"
).
then
((
data
)
=>
{
console
.
log
(
'
put success
'
+
JSON
.
stringify
(
data
));
kvStore
.
delete
(
predicates
).
then
((
data
)
=>
{
console
.
log
(
'
delete success
'
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
delete fail
'
+
JSON
.
stringify
(
err
));
});
})
.
catch
((
err
)
=>
{
console
.
log
(
'
put fail
'
+
err
);
});
}
catch
(
e
)
{
console
.
log
(
"
An unexpected error occurred. Error:
"
+
e
);
}
```
### on('dataChange')
on(event: 'dataChange', type: SubscribeType, observer: Callback
<
ChangeNotification
>
): void
...
...
@@ -2523,11 +2537,16 @@ putBatch(value: Array<ValuesBucket>, callback: AsyncCallback<void>):
```
js
let
kvStore
;
try
{
var arr = new Uint8Array([21,31]);
let entries = new Array({"name": "roe11", "age": 21, "salary": 20.5, "blobType": u8,},
{"name": "roe12", "age": 21, "salary": 20.5, "blobType": u8,},
{"name": "roe13", "age": 21, "salary": 20.5, "blobType": u8,})
kvStore.putBatch(entries, async function (err,data) {
let
v8Arr
=
[];
let
arr
=
new
Uint8Array
([
4
,
5
,
6
,
7
]);
let
vb1
=
{
key
:
"
name_1
"
,
value
:
32
}
let
vb2
=
{
key
:
"
name_2
"
,
value
:
arr
};
let
vb3
=
{
key
:
"
name_3
"
,
value
:
"
lisi
"
};
v8Arr
.
push
(
vb1
);
v8Arr
.
push
(
vb2
);
v8Arr
.
push
(
vb3
);
kvStore
.
putBatch
(
v8Arr
,
async
function
(
err
,
data
)
{
console
.
log
(
'
putBatch success
'
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
putBatch fail
'
+
JSON
.
stringify
(
err
));
...
...
@@ -2562,12 +2581,17 @@ putBatch(value: Array<ValuesBucket>): Promise<void>
```
js
let
kvStore
;
try
{
var arr = new Uint8Array([21,31]);
let entries = new Array({"name": "roe11", "age": 21, "salary": 20.5, "blobType": u8,},
{"name": "roe12", "age": 21, "salary": 20.5, "blobType": u8,},
{"name": "roe13", "age": 21, "salary": 20.5, "blobType": u8,})
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
let
v8Arr
=
[];
let
arr
=
new
Uint8Array
([
4
,
5
,
6
,
7
]);
let
vb1
=
{
key
:
"
name_1
"
,
value
:
32
}
let
vb2
=
{
key
:
"
name_2
"
,
value
:
arr
};
let
vb3
=
{
key
:
"
name_3
"
,
value
:
"
lisi
"
};
v8Arr
.
push
(
vb1
);
v8Arr
.
push
(
vb2
);
v8Arr
.
push
(
vb3
);
kvStore
.
putBatch
(
v8Arr
).
then
(
async
(
err
)
=>
{
console
.
log
(
'
putBatch success
'
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
putBatch fail
'
+
JSON
.
stringify
(
err
));
});
...
...
@@ -3612,7 +3636,7 @@ try {
### getResultSet<sup>9+</sup> ###
getResultSet(predicates: Predicates, callback: AsyncCallback<KvStoreResultSet>): void
getResultSet(predicates:
dataSharePredicates.DataShare
Predicates, callback: AsyncCallback
<
KvStoreResultSet
>
): void
获取与指定Predicate对象匹配的KvStoreResultSet对象,并通过callback方式返回,此方法为异步方法。
...
...
@@ -3628,15 +3652,16 @@ getResultSet(predicates: Predicates, callback: AsyncCallback<KvStoreResultSet
**示例:**
```
js
import
dataSharePredicates
from
'
./@ohos.data.dataSharePredicates
'
;
let
kvStore
;
try
{
let
resultSet
;
let predicates = new dataShare.DataSharePredicates();
let
predicates
=
new
dataShare
Predicates
.
DataSharePredicates
();
predicates
.
prefixKey
(
"
batch_test_string_key
"
);
await
kvStore.getResultSet(predicates, async function (err, result) {
kvStore
.
getResultSet
(
predicates
,
async
function
(
err
,
result
)
{
console
.
log
(
'
GetResultSet success
'
);
resultSet
=
result
;
await
kvStore.closeResultSet(resultSet, function (err, data) {
kvStore
.
closeResultSet
(
resultSet
,
function
(
err
,
data
)
{
console
.
log
(
'
closeResultSet success
'
);
})
});
...
...
@@ -3646,7 +3671,7 @@ try {
```
### getResultSet<sup>9+</sup> ###
getResultSet(predicates: Predicates): Promise<KvStoreResultSet>
getResultSet(predicates:
dataSharePredicates.DataShare
Predicates): Promise
<
KvStoreResultSet
>
获取与指定Predicate对象匹配的KvStoreResultSet对象,并通过Promise方式返回,此方法为异步方法。
...
...
@@ -3667,15 +3692,16 @@ getResultSet(predicates: Predicates): Promise<KvStoreResultSet>
**示例:**
```
js
import
dataSharePredicates
from
'
./@ohos.data.dataSharePredicates
'
;
let
kvStore
;
try
{
let
resultSet
;
let predicates = new dataShare
.DataSharePredicates();
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
prefixKey
(
"
batch_test_string_key
"
);
await
kvStore.getResultSet(predicates) .then((result) => {
kvStore
.
getResultSet
(
predicates
)
.
then
((
result
)
=>
{
console
.
log
(
'
GetResultSet success
'
);
resultSet
=
result
;
await
kvStore.closeResultSet(resultSet, fun ction (err, data) {
kvStore
.
closeResultSet
(
resultSet
,
fun
ction
(
err
,
data
)
{
console
.
log
(
'
closeResultSet success
'
);
})
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录