Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
8e219ebe
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看板
提交
8e219ebe
编写于
6月 15, 2023
作者:
S
srr101
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
datashare文档修改
Signed-off-by:
N
srr101
<
songruirui1@huawei.com
>
上级
ca03218b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
35 addition
and
57 deletion
+35
-57
zh-cn/application-dev/reference/apis/js-apis-application-dataShareExtensionAbility.md
...nce/apis/js-apis-application-dataShareExtensionAbility.md
+7
-29
zh-cn/application-dev/reference/apis/js-apis-data-dataShare.md
.../application-dev/reference/apis/js-apis-data-dataShare.md
+21
-21
zh-cn/application-dev/reference/apis/js-apis-data-dataSharePredicates.md
...on-dev/reference/apis/js-apis-data-dataSharePredicates.md
+6
-6
zh-cn/application-dev/reference/apis/js-apis-data-valuesBucket.md
...plication-dev/reference/apis/js-apis-data-valuesBucket.md
+1
-1
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-application-dataShareExtensionAbility.md
浏览文件 @
8e219ebe
...
...
@@ -17,26 +17,6 @@
import
DataShareExtensionAbility
from
'
@ohos.application.DataShareExtensionAbility
'
;
```
## uri命名规则
标准uri定义结构如下:
**Scheme://authority/path**
-
Scheme: 协议名,对于data share统一为datashare
-
authority: [userinfo@]host[:port]
-
userinfo: 登录信息,不需要填写。
-
host: 服务器地址,如果跨设备访问则为目标设备的ID,如果为本设备则为空。
-
port: 服务器端口,不需要填写。
-
path: data share的标识信息和资源的路径信息,需要包含data share的标识信息,资源的路径信息可以不填写。
uri示例:
-
不包含资源路径:
`datashare:///com.samples.datasharetest.DataShare`
-
包含资源路径:
`datashare:///com.samples.datasharetest.DataShare/DB00/TBL00`
其中,data share的标识信息为
`com.samples.datasharetest.DataShare`
,资源路径为
`DB00/TBL00`
。
## 属性
**系统能力**
:SystemCapability.DistributedDataManager.DataShare.Provider
...
...
@@ -78,7 +58,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
name
:
DB_NAME
,
securityLevel
:
rdb
.
SecurityLevel
.
S1
},
function
(
err
,
data
)
{
console
.
log
(
'
getRdbStore done, data : ${data}
'
);
console
.
info
(
`getRdbStore done, data :
${
data
}
`
);
rdbStore
=
data
;
rdbStore
.
executeSql
(
DDL_TBL_CREATE
,
[],
function
(
err
)
{
console
.
error
(
'
executeSql done, error message : ${err}
'
);
...
...
@@ -126,7 +106,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
return
;
}
rdbStore
.
insert
(
TBL_NAME
,
valueBucket
,
function
(
err
,
ret
)
{
console
.
info
(
'
callback ret: ${ret}
'
);
console
.
info
(
`callback ret:
${
ret
}
`
);
if
(
callback
!==
undefined
)
{
callback
(
err
,
ret
);
}
...
...
@@ -256,7 +236,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
}
rdbStore
.
query
(
TBL_NAME
,
predicates
,
columns
,
function
(
err
,
resultSet
)
{
if
(
resultSet
!==
undefined
)
{
console
.
info
(
'
resultSet.rowCount: ${resultSet.rowCount}
'
);
console
.
info
(
`resultSet.rowCount:
${
resultSet
.
rowCount
}
`
);
}
if
(
callback
!==
undefined
)
{
callback
(
err
,
resultSet
);
...
...
@@ -300,11 +280,9 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
console
.
info
(
'
invalid valueBuckets
'
);
return
;
}
let
resultNum
=
valueBuckets
.
length
;
valueBuckets
.
forEach
(
vb
=>
{
rdbStore
.
insert
(
TBL_NAME
,
vb
,
function
(
err
,
ret
)
{
rdbStore
.
batchInsert
(
TBL_NAME
,
valueBuckets
,
function
(
err
,
ret
)
{
if
(
callback
!==
undefined
)
{
callback
(
err
,
re
sultNum
);
callback
(
err
,
re
t
);
}
});
});
...
...
@@ -333,7 +311,7 @@ normalizeUri?(uri: string, callback: AsyncCallback<string>): void
export
default
class
DataShareExtAbility
extends
DataShareExtensionAbility
{
normalizeUri
(
uri
,
callback
)
{
let
err
=
{
'
code
'
:
0
};
let
ret
=
'
normalize+${uri}
'
;
let
ret
=
`normalize+
${
uri
}
`
;
callback
(
err
,
ret
);
}
};
...
...
@@ -360,7 +338,7 @@ denormalizeUri?(uri: string, callback: AsyncCallback<string>): void
export
default
class
DataShareExtAbility
extends
DataShareExtensionAbility
{
denormalizeUri
(
uri
,
callback
)
{
let
err
=
{
'
code
'
:
0
};
let
ret
=
'
denormalize+${uri}
'
;
let
ret
=
`denormalize+
${
uri
}
`
;
callback
(
err
,
ret
);
}
};
...
...
zh-cn/application-dev/reference/apis/js-apis-data-dataShare.md
浏览文件 @
8e219ebe
...
...
@@ -593,7 +593,7 @@ let data : Array<dataShare.PublishedItem> = [
{
key
:
"
empty
"
,
subscriberId
:
"
11
"
,
data
:
"
nobody sub
"
}];
let
nums
:
number
[]
=
[
1
,
2
,
3
];
function
publishCallback
(
err
,
result
:
Array
<
dataShare
.
OperationResult
>
)
{
console
.
log
(
"
publishCallback
"
+
JSON
.
stringify
(
result
));
console
.
info
(
"
publishCallback
"
+
JSON
.
stringify
(
result
));
ashmem
.
closeAshmem
();
}
try
{
...
...
@@ -605,10 +605,10 @@ try {
"
data
"
:
ashmem
,
"
subscriberId
"
:
"
11
"
,
});
console
.
log
(
"
data length is:
"
,
data
.
length
);
console
.
info
(
"
data length is:
"
,
data
.
length
);
dataShareHelper
.
publish
(
data
,
"
com.acts.ohos.data.datasharetest
"
,
version
,
publishCallback
);
}
catch
(
e
)
{
console
.
log
(
"
publish error
"
+
JSON
.
stringify
(
e
));
console
.
info
(
"
publish error
"
+
JSON
.
stringify
(
e
));
}
```
...
...
@@ -640,7 +640,7 @@ publish(data: Array<PublishedItem>, bundleName: string, callback: AsyncCal
```
ts
function
publishCallback
(
err
,
result
:
Array
<
dataShare
.
OperationResult
>
)
{
console
.
log
(
"
publishCallback
"
+
JSON
.
stringify
(
result
));
console
.
info
(
"
publishCallback
"
+
JSON
.
stringify
(
result
));
}
let
data
:
Array
<
dataShare
.
PublishedItem
>
=
[
{
key
:
"
city
"
,
subscriberId
:
"
11
"
,
data
:
"
xian
"
},
...
...
@@ -825,7 +825,7 @@ const valueBucket = {
}
try
{
dataShareHelper
.
insert
(
uri
,
valueBucket
).
then
((
data
)
=>
{
console
.
log
(
"
insert succeed, data :
"
+
data
);
console
.
info
(
"
insert succeed, data :
"
+
data
);
}).
catch
((
err
)
=>
{
console
.
error
(
`insert error: code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
});
...
...
@@ -902,7 +902,7 @@ let da = new dataSharePredicates.DataSharePredicates();
da
.
equalTo
(
"
name
"
,
"
ZhangSan
"
);
try
{
dataShareHelper
.
delete
(
uri
,
da
).
then
((
data
)
=>
{
console
.
log
(
"
delete succeed, data :
"
+
data
);
console
.
info
(
"
delete succeed, data :
"
+
data
);
}).
catch
((
err
)
=>
{
console
.
error
(
`delete error: code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
});
...
...
@@ -943,7 +943,7 @@ try {
console
.
error
(
`query error: code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
return
;
}
console
.
log
(
"
query succeed, rowCount :
"
+
data
.
rowCount
);
console
.
info
(
"
query succeed, rowCount :
"
+
data
.
rowCount
);
});
}
catch
(
err
)
{
console
.
error
(
`query error: code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
...
...
@@ -983,7 +983,7 @@ let da = new dataSharePredicates.DataSharePredicates();
da
.
equalTo
(
"
name
"
,
"
ZhangSan
"
);
try
{
dataShareHelper
.
query
(
uri
,
da
,
columns
).
then
((
data
)
=>
{
console
.
log
(
"
query succeed, rowCount :
"
+
data
.
rowCount
);
console
.
info
(
"
query succeed, rowCount :
"
+
data
.
rowCount
);
}).
catch
((
err
)
=>
{
console
.
error
(
`query error: code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
});
...
...
@@ -1029,7 +1029,7 @@ try {
console
.
error
(
`update error: code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
return
;
}
console
.
log
(
"
update succeed, data :
"
+
data
);
console
.
info
(
"
update succeed, data :
"
+
data
);
});
}
catch
(
err
)
{
console
.
error
(
`update error: code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
...
...
@@ -1074,7 +1074,7 @@ const va = {
}
try
{
dataShareHelper
.
update
(
uri
,
da
,
va
).
then
((
data
)
=>
{
console
.
log
(
"
update succeed, data :
"
+
data
);
console
.
info
(
"
update succeed, data :
"
+
data
);
}).
catch
((
err
)
=>
{
console
.
error
(
`update error: code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
});
...
...
@@ -1112,7 +1112,7 @@ try {
console
.
error
(
`batchInsert error: code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
return
;
}
console
.
log
(
"
batchInsert succeed, data :
"
+
data
);
console
.
info
(
"
batchInsert succeed, data :
"
+
data
);
});
}
catch
(
err
)
{
console
.
error
(
`batchInsert error: code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
...
...
@@ -1149,7 +1149,7 @@ let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5,},
{
"
name
"
:
"
roe13
"
,
"
age
"
:
21
,
"
salary
"
:
20.5
,})
try
{
dataShareHelper
.
batchInsert
(
uri
,
vbs
).
then
((
data
)
=>
{
console
.
log
(
"
batchInsert succeed, data :
"
+
data
);
console
.
info
(
"
batchInsert succeed, data :
"
+
data
);
}).
catch
((
err
)
=>
{
console
.
error
(
`batchInsert error: code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
});
...
...
@@ -1179,9 +1179,9 @@ normalizeUri(uri: string, callback: AsyncCallback<string>): void
let
uri
=
(
"
datashare:///com.samples.datasharetest.DataShare
"
);
dataShareHelper
.
normalizeUri
(
uri
,
(
err
,
data
)
=>
{
if
(
err
!==
undefined
)
{
console
.
log
(
"
normalizeUri failed, error message :
"
+
err
);
console
.
info
(
"
normalizeUri failed, error message :
"
+
err
);
}
else
{
console
.
log
(
"
normalizeUri =
"
+
data
);
console
.
info
(
"
normalizeUri =
"
+
data
);
}
});
```
...
...
@@ -1211,9 +1211,9 @@ normalizeUri(uri: string): Promise<string>
```
ts
let
uri
=
(
"
datashare:///com.samples.datasharetest.DataShare
"
);
dataShareHelper
.
normalizeUri
(
uri
).
then
((
data
)
=>
{
console
.
log
(
"
normalizeUri =
"
+
data
);
console
.
info
(
"
normalizeUri =
"
+
data
);
}).
catch
((
err
)
=>
{
console
.
log
(
"
normalizeUri failed, error message :
"
+
err
);
console
.
info
(
"
normalizeUri failed, error message :
"
+
err
);
});
```
...
...
@@ -1238,9 +1238,9 @@ denormalizeUri(uri: string, callback: AsyncCallback<string>): void
let
uri
=
(
"
datashare:///com.samples.datasharetest.DataShare
"
);
dataShareHelper
.
denormalizeUri
(
uri
,
(
err
,
data
)
=>
{
if
(
err
!==
undefined
)
{
console
.
log
(
"
denormalizeUri failed, error message :
"
+
err
);
console
.
info
(
"
denormalizeUri failed, error message :
"
+
err
);
}
else
{
console
.
log
(
"
denormalizeUri =
"
+
data
);
console
.
info
(
"
denormalizeUri =
"
+
data
);
}
});
```
...
...
@@ -1270,9 +1270,9 @@ denormalizeUri(uri: string): Promise<string>
```
ts
let
uri
=
(
"
datashare:///com.samples.datasharetest.DataShare
"
);
dataShareHelper
.
denormalizeUri
(
uri
).
then
((
data
)
=>
{
console
.
log
(
"
denormalizeUri =
"
+
data
);
console
.
info
(
"
denormalizeUri =
"
+
data
);
}).
catch
((
err
)
=>
{
console
.
log
(
"
denormalizeUri failed, error message :
"
+
err
);
console
.
info
(
"
denormalizeUri failed, error message :
"
+
err
);
});
```
...
...
@@ -1296,7 +1296,7 @@ notifyChange(uri: string, callback: AsyncCallback<void>): void
```
ts
let
uri
=
(
"
datashare:///com.samples.datasharetest.DataShare
"
);
dataShareHelper
.
notifyChange
(
uri
,
()
=>
{
console
.
log
(
"
***** notifyChange *****
"
);
console
.
info
(
"
***** notifyChange *****
"
);
});
```
...
...
zh-cn/application-dev/reference/apis/js-apis-data-dataSharePredicates.md
浏览文件 @
8e219ebe
...
...
@@ -19,7 +19,7 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
## DataSharePredicates
提供用于不同实现不同查询方法的数据共享谓词。该类型不是多线程安全的,如果应用中存在多线程同时操作该类派生出的实例,注意加锁保护。
### equalTo
### equalTo
<sup>10+</sup>
equalTo(field: string, value: ValueType): DataSharePredicates
...
...
@@ -168,7 +168,7 @@ predicates.equalTo("NAME", "lisi")
.
equalTo
(
"
NAME
"
,
"
Rose
"
)
```
### and
### and
<sup>10+</sup>
and(): DataSharePredicates
...
...
@@ -641,7 +641,7 @@ let predicates = new dataSharePredicates.DataSharePredicates()
predicates
.
lessThanOrEqualTo
(
"
AGE
"
,
50
)
```
### orderByAsc
### orderByAsc
<sup>10+</sup>
orderByAsc(field: string): DataSharePredicates
...
...
@@ -670,7 +670,7 @@ let predicates = new dataSharePredicates.DataSharePredicates()
predicates
.
orderByAsc
(
"
AGE
"
)
```
### orderByDesc
### orderByDesc
<sup>10+</sup>
orderByDesc(field: string): DataSharePredicates
...
...
@@ -724,7 +724,7 @@ let predicates = new dataSharePredicates.DataSharePredicates()
predicates
.
equalTo
(
"
NAME
"
,
"
Rose
"
).
distinct
()
```
### limit
### limit
<sup>10+</sup>
limit(total: number, offset: number): DataSharePredicates
...
...
@@ -816,7 +816,7 @@ let predicates = new dataSharePredicates.DataSharePredicates()
predicates
.
indexedBy
(
"
SALARY_INDEX
"
)
```
### in
### in
<sup>10+</sup>
in(field: string, value: Array
<
ValueType
>
): DataSharePredicates
...
...
zh-cn/application-dev/reference/apis/js-apis-data-valuesBucket.md
浏览文件 @
8e219ebe
...
...
@@ -4,7 +4,7 @@
> **说明:**
>
> 本模块首批接口从API version
9
开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块首批接口从API version
10
开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录