Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
3da9c254
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,发现更多精彩内容 >>
提交
3da9c254
编写于
6月 20, 2022
作者:
W
wangkai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
"示例代码更改"
Signed-off-by:
N
wangkai
<
wangkai424@huawei.com
>
上级
eeddf4c7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
36 addition
and
36 deletion
+36
-36
zh-cn/application-dev/reference/apis/js-apis-distributed-data.md
...pplication-dev/reference/apis/js-apis-distributed-data.md
+36
-36
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-distributed-data.md
浏览文件 @
3da9c254
...
...
@@ -261,7 +261,7 @@ const options = {
kvManager
.
getKVStore
(
'
storeId
'
,
options
,
async
function
(
err
,
store
)
{
console
.
log
(
'
getKVStore success
'
);
kvStore
=
store
;
await
kvManager
.
closeKVStore
(
'
appId
'
,
'
storeId
'
,
kvStore
,
function
(
err
,
data
)
{
kvManager
.
closeKVStore
(
'
appId
'
,
'
storeId
'
,
kvStore
,
function
(
err
,
data
)
{
console
.
log
(
'
closeKVStore success
'
);
});
});
...
...
@@ -311,7 +311,7 @@ const options = {
kvManager
.
getKVStore
(
'
storeId
'
,
options
).
then
(
async
(
store
)
=>
{
console
.
log
(
'
getKVStore success
'
);
kvStore
=
store
;
await
kvManager
.
closeKVStore
(
'
appId
'
,
'
storeId
'
,
kvStore
).
then
(()
=>
{
kvManager
.
closeKVStore
(
'
appId
'
,
'
storeId
'
,
kvStore
).
then
(()
=>
{
console
.
log
(
'
closeKVStore success
'
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
closeKVStore err
'
+
JSON
.
stringify
(
err
));
...
...
@@ -359,7 +359,7 @@ try {
kvManager
.
getKVStore
(
'
store
'
,
options
,
async
function
(
err
,
store
)
{
console
.
log
(
'
getKVStore success
'
);
kvStore
=
store
;
await
kvManager
.
deleteKVStore
(
'
appId
'
,
'
storeId
'
,
function
(
err
,
data
)
{
kvManager
.
deleteKVStore
(
'
appId
'
,
'
storeId
'
,
function
(
err
,
data
)
{
console
.
log
(
'
deleteKVStore success
'
);
});
});
...
...
@@ -408,7 +408,7 @@ try {
kvManager
.
getKVStore
(
'
storeId
'
,
options
).
then
(
async
(
store
)
=>
{
console
.
log
(
'
getKVStore success
'
);
kvStore
=
store
;
await
kvManager
.
deleteKVStore
(
'
appId
'
,
'
storeId
'
).
then
(()
=>
{
kvManager
.
deleteKVStore
(
'
appId
'
,
'
storeId
'
).
then
(()
=>
{
console
.
log
(
'
deleteKVStore success
'
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
deleteKVStore err
'
+
JSON
.
stringify
(
err
));
...
...
@@ -695,7 +695,7 @@ try {
node
.
appendChild
(
child1
);
node
.
appendChild
(
child2
);
node
.
appendChild
(
child3
);
console
.
log
(
"
appendNode
"
+
node
.
toJson
(
));
console
.
log
(
"
appendNode
"
+
JSON
.
stringify
(
node
));
child1
=
null
;
child2
=
null
;
child3
=
null
;
...
...
@@ -2333,7 +2333,7 @@ try {
console
.
log
(
'
entries:
'
+
JSON
.
stringify
(
entries
));
kvStore
.
putBatch
(
entries
,
async
function
(
err
,
data
)
{
console
.
log
(
'
putBatch success
'
);
await
kvStore
.
getEntries
(
'
batch_test_string_key
'
,
function
(
err
,
entrys
)
{
kvStore
.
getEntries
(
'
batch_test_string_key
'
,
function
(
err
,
entrys
)
{
console
.
log
(
'
getEntries success
'
);
console
.
log
(
'
entrys.length:
'
+
entrys
.
length
);
console
.
log
(
'
entrys[0]:
'
+
JSON
.
stringify
(
entrys
[
0
]));
...
...
@@ -2385,7 +2385,7 @@ try {
console
.
log
(
'
entries:
'
+
JSON
.
stringify
(
entries
));
kvStore
.
putBatch
(
entries
).
then
(
async
(
err
)
=>
{
console
.
log
(
'
putBatch success
'
);
await
kvStore
.
getEntries
(
'
batch_test_string_key
'
).
then
((
entrys
)
=>
{
kvStore
.
getEntries
(
'
batch_test_string_key
'
).
then
((
entrys
)
=>
{
console
.
log
(
'
getEntries success
'
);
console
.
log
(
'
PutBatch
'
+
JSON
.
stringify
(
entries
));
}).
catch
((
err
)
=>
{
...
...
@@ -2437,7 +2437,7 @@ try {
console
.
log
(
'
entries:
'
+
JSON
.
stringify
(
entries
));
kvStore
.
putBatch
(
entries
,
async
function
(
err
,
data
)
{
console
.
log
(
'
putBatch success
'
);
await
kvStore
.
deleteBatch
(
keys
,
async
function
(
err
,
data
)
{
kvStore
.
deleteBatch
(
keys
,
async
function
(
err
,
data
)
{
console
.
log
(
'
deleteBatch success
'
);
});
});
...
...
@@ -2489,7 +2489,7 @@ try {
console
.
log
(
'
entries:
'
+
JSON
.
stringify
(
entries
));
kvStore
.
putBatch
(
entries
).
then
(
async
(
err
)
=>
{
console
.
log
(
'
putBatch success
'
);
await
kvStore
.
deleteBatch
(
keys
).
then
((
err
)
=>
{
kvStore
.
deleteBatch
(
keys
).
then
((
err
)
=>
{
console
.
log
(
'
deleteBatch success
'
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
deleteBatch fail
'
+
JSON
.
stringify
(
err
));
...
...
@@ -2545,7 +2545,7 @@ try {
console
.
log
(
'
startTransaction success
'
);
let
entries
=
putBatchString
(
10
,
'
batch_test_string_key
'
);
console
.
log
(
'
entries:
'
+
JSON
.
stringify
(
entries
));
await
kvStore
.
putBatch
(
entries
,
async
function
(
err
,
data
)
{
kvStore
.
putBatch
(
entries
,
async
function
(
err
,
data
)
{
console
.
log
(
'
putBatch success
'
);
});
});
...
...
@@ -3039,7 +3039,7 @@ try {
}
kvStore
.
putBatch
(
entries
,
async
function
(
err
,
data
)
{
console
.
log
(
'
putBatch success
'
);
await
kvStore
.
getEntries
(
'
batch_test_number_key
'
,
function
(
err
,
entrys
)
{
kvStore
.
getEntries
(
'
batch_test_number_key
'
,
function
(
err
,
entrys
)
{
console
.
log
(
'
getEntries success
'
);
console
.
log
(
'
entrys.length:
'
+
entrys
.
length
);
console
.
log
(
'
entrys[0]:
'
+
JSON
.
stringify
(
entrys
[
0
]));
...
...
@@ -3091,7 +3091,7 @@ try {
console
.
log
(
'
entries:
'
+
entries
);
kvStore
.
putBatch
(
entries
).
then
(
async
(
err
)
=>
{
console
.
log
(
'
putBatch success
'
);
await
kvStore
.
getEntries
(
'
batch_test_string_key
'
).
then
((
entrys
)
=>
{
kvStore
.
getEntries
(
'
batch_test_string_key
'
).
then
((
entrys
)
=>
{
console
.
log
(
'
getEntries success
'
);
console
.
log
(
'
entrys.length:
'
+
entrys
.
length
);
console
.
log
(
'
entrys[0]:
'
+
JSON
.
stringify
(
entrys
[
0
]));
...
...
@@ -3147,7 +3147,7 @@ try {
console
.
log
(
'
putBatch success
'
);
const
query
=
new
distributedData
.
Query
();
query
.
prefixKey
(
"
batch_test
"
);
await
kvStore
.
getEntries
(
query
,
function
(
err
,
entrys
)
{
kvStore
.
getEntries
(
query
,
function
(
err
,
entrys
)
{
console
.
log
(
'
getEntries success
'
);
console
.
log
(
'
entrys.length:
'
+
entrys
.
length
);
console
.
log
(
'
entrys[0]:
'
+
JSON
.
stringify
(
entrys
[
0
]));
...
...
@@ -3183,6 +3183,7 @@ getEntries(query: Query): Promise<Entry[]>
**示例:**
```
js
let
kvStore
;
try
{
var
arr
=
new
Uint8Array
([
21
,
31
]);
let
entries
=
[];
...
...
@@ -3202,7 +3203,7 @@ try {
console
.
log
(
'
putBatch success
'
);
const
query
=
new
distributedData
.
Query
();
query
.
prefixKey
(
"
batch_test
"
);
await
kvStore
.
getEntries
(
query
).
then
((
entrys
)
=>
{
kvStore
.
getEntries
(
query
).
then
((
entrys
)
=>
{
console
.
log
(
'
getEntries success
'
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
getEntries fail
'
+
JSON
.
stringify
(
err
));
...
...
@@ -3252,7 +3253,7 @@ try {
}
kvStore
.
putBatch
(
entries
,
async
function
(
err
,
data
)
{
console
.
log
(
'
GetResultSet putBatch success
'
);
await
kvStore
.
getResultSet
(
'
batch_test_string_key
'
,
async
function
(
err
,
result
)
{
kvStore
.
getResultSet
(
'
batch_test_string_key
'
,
async
function
(
err
,
result
)
{
console
.
log
(
'
GetResultSet getResultSet succeed.
'
);
resultSet
=
result
;
kvStore
.
closeResultSet
(
resultSet
,
function
(
err
,
data
)
{
...
...
@@ -3363,7 +3364,7 @@ try {
console
.
log
(
'
putBatch success
'
);
const
query
=
new
distributedData
.
Query
();
query
.
prefixKey
(
"
batch_test
"
);
await
kvStore
.
getResultSet
(
query
,
async
function
(
err
,
result
)
{
kvStore
.
getResultSet
(
query
,
async
function
(
err
,
result
)
{
console
.
log
(
'
getResultSet succeed.
'
);
resultSet
=
result
;
});
...
...
@@ -3537,7 +3538,7 @@ try {
console
.
log
(
'
putBatch success
'
);
const
query
=
new
distributedData
.
Query
();
query
.
prefixKey
(
"
batch_test
"
);
await
kvStore
.
getResultSize
(
query
,
async
function
(
err
,
resultSize
)
{
kvStore
.
getResultSize
(
query
,
async
function
(
err
,
resultSize
)
{
console
.
log
(
'
getResultSet succeed.
'
);
});
});
...
...
@@ -3627,12 +3628,12 @@ try {
kvStore
.
put
(
KEY_TEST_STRING_ELEMENT
,
VALUE_TEST_STRING_ELEMENT
,
async
function
(
err
,
data
)
{
console
.
log
(
'
put success
'
);
const
deviceid
=
'
no_exist_device_id
'
;
await
kvStore
.
removeDeviceData
(
deviceid
,
async
function
(
err
,
data
)
{
kvStore
.
removeDeviceData
(
deviceid
,
async
function
(
err
,
data
)
{
if
(
err
==
undefined
)
{
console
.
log
(
'
removeDeviceData success
'
);
}
else
{
console
.
log
(
'
removeDeviceData fail
'
);
await
kvStore
.
get
(
KEY_TEST_STRING_ELEMENT
,
async
function
(
err
,
data
)
{
kvStore
.
get
(
KEY_TEST_STRING_ELEMENT
,
async
function
(
err
,
data
)
{
console
.
log
(
'
RemoveDeviceData get success
'
);
});
}
...
...
@@ -4030,7 +4031,7 @@ try {
console
.
log
(
'
entries:
'
+
entries
);
kvStore
.
putBatch
(
entries
,
async
function
(
err
,
data
)
{
console
.
log
(
'
putBatch success
'
);
await
kvStore
.
getEntries
(
'
localDeviceId
'
,
'
batch_test_string_key
'
,
function
(
err
,
entrys
)
{
kvStore
.
getEntries
(
'
localDeviceId
'
,
'
batch_test_string_key
'
,
function
(
err
,
entrys
)
{
console
.
log
(
'
getEntries success
'
);
console
.
log
(
'
entrys.length:
'
+
entrys
.
length
);
console
.
log
(
'
entrys[0]:
'
+
JSON
.
stringify
(
entrys
[
0
]));
...
...
@@ -4083,7 +4084,7 @@ try {
console
.
log
(
'
entries:
'
+
entries
);
kvStore
.
putBatch
(
entries
).
then
(
async
(
err
)
=>
{
console
.
log
(
'
putBatch success
'
);
await
kvStore
.
getEntries
(
'
localDeviceId
'
,
'
batch_test_string_key
'
).
then
((
entrys
)
=>
{
kvStore
.
getEntries
(
'
localDeviceId
'
,
'
batch_test_string_key
'
).
then
((
entrys
)
=>
{
console
.
log
(
'
getEntries success
'
);
console
.
log
(
'
entrys.length:
'
+
entrys
.
length
);
console
.
log
(
'
entrys[0]:
'
+
JSON
.
stringify
(
entrys
[
0
]));
...
...
@@ -4137,11 +4138,10 @@ try {
console
.
log
(
'
entries:
'
+
JSON
.
stringify
(
entries
));
kvStore
.
putBatch
(
entries
,
async
function
(
err
,
data
)
{
console
.
log
(
'
putBatch success
'
);
expect
(
err
==
undefined
).
assertTrue
();
const
query
=
new
distributedData
.
Query
();
query
.
prefixKey
(
"
batch_test
"
);
query
.
deviceId
(
'
localDeviceId
'
);
await
kvStore
.
getEntries
(
query
,
function
(
err
,
entrys
)
{
kvStore
.
getEntries
(
query
,
function
(
err
,
entrys
)
{
console
.
log
(
'
getEntries success
'
);
console
.
log
(
'
entrys.length:
'
+
entrys
.
length
);
console
.
log
(
'
entrys[0]:
'
+
JSON
.
stringify
(
entrys
[
0
]));
...
...
@@ -4197,7 +4197,7 @@ try {
console
.
log
(
'
putBatch success
'
);
const
query
=
new
distributedData
.
Query
();
query
.
prefixKey
(
"
batch_test
"
);
await
kvStore
.
getEntries
(
query
).
then
((
entrys
)
=>
{
kvStore
.
getEntries
(
query
).
then
((
entrys
)
=>
{
console
.
log
(
'
getEntries success
'
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
getEntries fail
'
+
JSON
.
stringify
(
err
));
...
...
@@ -4249,11 +4249,10 @@ try {
console
.
log
(
'
entries:
'
+
JSON
.
stringify
(
entries
));
kvStore
.
putBatch
(
entries
,
async
function
(
err
,
data
)
{
console
.
log
(
'
putBatch success
'
);
expect
(
err
==
undefined
).
assertTrue
();
var
query
=
new
distributedData
.
Query
();
query
.
deviceId
(
'
localDeviceId
'
);
query
.
prefixKey
(
"
batch_test
"
);
await
kvStore
.
getEntries
(
'
localDeviceId
'
,
query
,
function
(
err
,
entrys
)
{
kvStore
.
getEntries
(
'
localDeviceId
'
,
query
,
function
(
err
,
entrys
)
{
console
.
log
(
'
getEntries success
'
);
console
.
log
(
'
entrys.length:
'
+
entrys
.
length
);
console
.
log
(
'
entrys[0]:
'
+
JSON
.
stringify
(
entrys
[
0
]));
...
...
@@ -4311,7 +4310,7 @@ try {
var
query
=
new
distributedData
.
Query
();
query
.
deviceId
(
'
localDeviceId
'
);
query
.
prefixKey
(
"
batch_test
"
);
await
kvStore
.
getEntries
(
'
localDeviceId
'
,
query
).
then
((
entrys
)
=>
{
kvStore
.
getEntries
(
'
localDeviceId
'
,
query
).
then
((
entrys
)
=>
{
console
.
log
(
'
getEntries success
'
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
getEntries fail
'
+
JSON
.
stringify
(
err
));
...
...
@@ -4351,7 +4350,7 @@ try {
kvStore
.
getResultSet
(
'
localDeviceId
'
,
'
batch_test_string_key
'
,
async
function
(
err
,
result
)
{
console
.
log
(
'
getResultSet succeed.
'
);
resultSet
=
result
;
await
kvStore
.
closeResultSet
(
resultSet
,
function
(
err
,
data
)
{
kvStore
.
closeResultSet
(
resultSet
,
function
(
err
,
data
)
{
console
.
log
(
'
closeResultSet success
'
);
})
});
...
...
@@ -4443,10 +4442,10 @@ try {
const
query
=
new
distributedData
.
Query
();
query
.
prefixKey
(
"
batch_test
"
);
query
.
deviceId
(
'
localDeviceId
'
);
await
kvStore
.
getResultSet
(
query
,
async
function
(
err
,
result
)
{
kvStore
.
getResultSet
(
query
,
async
function
(
err
,
result
)
{
console
.
log
(
'
getResultSet succeed.
'
);
resultSet
=
result
;
await
kvStore
.
closeResultSet
(
resultSet
,
function
(
err
,
data
)
{
kvStore
.
closeResultSet
(
resultSet
,
function
(
err
,
data
)
{
console
.
log
(
'
closeResultSet success
'
);
})
});
...
...
@@ -4559,10 +4558,10 @@ try {
console
.
log
(
'
putBatch success
'
);
const
query
=
new
distributedData
.
Query
();
query
.
prefixKey
(
"
batch_test
"
);
await
kvStore
.
getResultSet
(
'
localDeviceId
'
,
query
,
async
function
(
err
,
result
)
{
kvStore
.
getResultSet
(
'
localDeviceId
'
,
query
,
async
function
(
err
,
result
)
{
console
.
log
(
'
getResultSet succeed.
'
);
resultSet
=
result
;
await
kvStore
.
closeResultSet
(
resultSet
,
function
(
err
,
data
)
{
kvStore
.
closeResultSet
(
resultSet
,
function
(
err
,
data
)
{
console
.
log
(
'
closeResultSet success
'
);
})
});
...
...
@@ -4749,7 +4748,7 @@ try {
const
query
=
new
distributedData
.
Query
();
query
.
prefixKey
(
"
batch_test
"
);
query
.
deviceId
(
'
localDeviceId
'
);
await
kvStore
.
getResultSize
(
query
,
async
function
(
err
,
resultSize
)
{
kvStore
.
getResultSize
(
query
,
async
function
(
err
,
resultSize
)
{
console
.
log
(
'
getResultSet succeed.
'
);
});
});
...
...
@@ -4852,7 +4851,7 @@ try {
console
.
log
(
'
putBatch success
'
);
const
query
=
new
distributedData
.
Query
();
query
.
prefixKey
(
"
batch_test
"
);
await
kvStore
.
getResultSize
(
'
localDeviceId
'
,
query
,
async
function
(
err
,
resultSize
)
{
kvStore
.
getResultSize
(
'
localDeviceId
'
,
query
,
async
function
(
err
,
resultSize
)
{
console
.
log
(
'
getResultSet succeed.
'
);
});
});
...
...
@@ -4943,12 +4942,12 @@ try {
kvStore
.
put
(
KEY_TEST_STRING_ELEMENT
,
VALUE_TEST_STRING_ELEMENT
,
async
function
(
err
,
data
)
{
console
.
log
(
'
RemoveDeviceData put success
'
);
const
deviceid
=
'
no_exist_device_id
'
;
await
kvStore
.
removeDeviceData
(
deviceid
,
async
function
(
err
,
data
)
{
kvStore
.
removeDeviceData
(
deviceid
,
async
function
(
err
,
data
)
{
if
(
err
==
undefined
)
{
console
.
log
(
'
removeDeviceData success
'
);
}
else
{
console
.
log
(
'
removeDeviceData fail
'
);
await
kvStore
.
get
(
'
localDeviceId
'
,
KEY_TEST_STRING_ELEMENT
,
async
function
(
err
,
data
)
{
kvStore
.
get
(
'
localDeviceId
'
,
KEY_TEST_STRING_ELEMENT
,
async
function
(
err
,
data
)
{
console
.
log
(
'
RemoveDeviceData get success
'
);
});
}
...
...
@@ -5066,6 +5065,7 @@ on(event: 'syncComplete', syncCallback: Callback<Array<[string, number]>
**示例:**
```
js
let
kvStore
;
const
KEY_TEST_FLOAT_ELEMENT
=
'
key_test_float
'
;
const
VALUE_TEST_FLOAT_ELEMENT
=
321.12
;
try
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录