Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
729ada92
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,发现更多精彩内容 >>
未验证
提交
729ada92
编写于
6月 22, 2022
作者:
O
openharmony_ci
提交者:
Gitee
6月 22, 2022
浏览文件
操作
浏览文件
下载
差异文件
!5687 3.1-Release分布式数据示例代码更改
Merge pull request !5687 from Wangkai/OpenHarmony-3.1-Release
上级
96757e5b
62474094
变更
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
浏览文件 @
729ada92
...
...
@@ -270,7 +270,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
'
);
});
});
...
...
@@ -320,7 +320,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
));
...
...
@@ -368,7 +368,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
'
);
});
});
...
...
@@ -417,7 +417,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
));
...
...
@@ -704,7 +704,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
;
...
...
@@ -2341,7 +2341,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
]));
...
...
@@ -2393,7 +2393,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
)
=>
{
...
...
@@ -2445,7 +2445,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
'
);
});
});
...
...
@@ -2497,7 +2497,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
));
...
...
@@ -2553,7 +2553,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
'
);
});
});
...
...
@@ -3049,7 +3049,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
]));
...
...
@@ -3101,7 +3101,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
]));
...
...
@@ -3157,7 +3157,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
]));
...
...
@@ -3193,6 +3193,7 @@ getEntries(query: Query): Promise<Entry[]>
**示例:**
```
js
let
kvStore
;
try
{
var
arr
=
new
Uint8Array
([
21
,
31
]);
let
entries
=
[];
...
...
@@ -3212,7 +3213,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
));
...
...
@@ -3262,7 +3263,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
)
{
...
...
@@ -3373,7 +3374,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
;
});
...
...
@@ -3547,7 +3548,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.
'
);
});
});
...
...
@@ -3637,12 +3638,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
'
);
});
}
...
...
@@ -4046,7 +4047,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
]));
...
...
@@ -4099,7 +4100,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
]));
...
...
@@ -4153,11 +4154,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
]));
...
...
@@ -4213,7 +4213,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
));
...
...
@@ -4265,11 +4265,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
]));
...
...
@@ -4327,7 +4326,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
));
...
...
@@ -4367,7 +4366,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
'
);
})
});
...
...
@@ -4459,10 +4458,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
'
);
})
});
...
...
@@ -4575,10 +4574,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
'
);
})
});
...
...
@@ -4765,7 +4764,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.
'
);
});
});
...
...
@@ -4868,7 +4867,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.
'
);
});
});
...
...
@@ -4959,12 +4958,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
'
);
});
}
...
...
@@ -5082,6 +5081,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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录