Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
75ad3c14
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看板
未验证
提交
75ad3c14
编写于
9月 27, 2022
作者:
W
Wangkai
提交者:
Gitee
9月 27, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update zh-cn/application-dev/database/database-mdds-guidelines.md.
Signed-off-by:
N
Wangkai
<
wangkai424@huawei.com
>
上级
91f7b492
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
44 addition
and
63 deletion
+44
-63
zh-cn/application-dev/database/database-mdds-guidelines.md
zh-cn/application-dev/database/database-mdds-guidelines.md
+44
-63
未找到文件。
zh-cn/application-dev/database/database-mdds-guidelines.md
浏览文件 @
75ad3c14
...
...
@@ -52,59 +52,40 @@
```js
// FA模型
import featureAbility from '@ohos.ability.featureAbility';
function grantPermission() {
console.info('grantPermission');
let context = featureAbility.getContext();
context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result)
{
console.info(`result.requestCode=${result.requestCode}`)
})
console.info('end grantPermission');
console.info('grantPermission');
let context = featureAbility.getContext();
context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666).then((data) =>
{
console.info('success: ${data}');
}).catch((error) => {
console.info('failed: ${error}');
})
}
grantPermission();
// Stage模型
import AbilityStage from '@ohos.application.Ability';
import accessControl from '@ohos.abilityAccessCtrl';
import bundle from '@ohos.bundle';
let appId = "appId";
async function requestPermissions () {
let permissions: Array<string> = [
"ohos.permission.DISTRIBUTED_DATASYNC"
];
let needGrantPermission = false
let accessManger = accessControl.createAtManager()
console.info("[JSDemo]: app permission get bundle info")
let bundleInfo = bundle.getApplicationInfo(appId, 0, 100)
console.info(`[JSDemo]: app permission query permission ${bundleInfo.accessTokenId.toString()}`)
for (const permission of permissions) {
console.info(`[JSDemo]: app permission query grant status ${permission}`)
try {
let grantStatus = accessManger.verifyAccessToken(bundleInfo.accessTokenId, permission)
if (grantStatus === accessControl.GrantStatus.PERMISSION_DENIED) {
needGrantPermission = true
break;
}
} catch (err) {
console.error(`[JSDemo]: app permission query grant status error ${permission} ${JSON.stringify(err)}`)
needGrantPermission = true
break;
}
}
if (needGrantPermission) {
console.info("[JSDemo]: app permission needGrantPermission")
try {
globalThis.abilityContext.requestPermissionsFromUser(permissions)
} catch (err) {
console.error(`[JSDemo]: app permission ${JSON.stringify(err)}`)
import Ability from '@ohos.application.Ability';
let context = null;
function grantPermission() {
class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
let context = this.context;
}
} else {
console.info("[JSDemo]: app permission already granted")
}
}
let permissions = ['ohos.permission.DISTRIBUTED_DATASYNC'];
context.requestPermissionsFromUser(permissions).then((data) => {
console.log('success: ${data}');
}).catch((error) => {
console.log('failed: ${error}');
});
}
grantPermission();
```
3.
根据配置构造分布式数据库管理类实例。
...
...
@@ -120,7 +101,7 @@
let
context
=
featureAbility
.
getContext
();
// Stage模型获取context
import
AbilityStage
from
'
@ohos.application.Ability
'
import
AbilityStage
from
'
@ohos.application.Ability
'
;
let
context
=
null
;
class
MainAbility
extends
AbilityStage
{
onWindowStageCreate
(
windowStage
){
...
...
@@ -140,14 +121,14 @@
}
distributedData
.
createKVManager
(
kvManagerConfig
,
function
(
err
,
manager
)
{
if
(
err
)
{
console
.
log
(
"
createKVManager err:
"
+
JSON
.
stringify
(
err
)
);
console
.
log
(
'
createKVManager err: ${error}
'
);
return
;
}
console
.
log
(
"
createKVManager success
"
);
console
.
log
(
'
createKVManager success
'
);
kvManager
=
manager
;
});
}
catch
(
e
)
{
console
.
log
(
"
An unexpected error occurred. Error:
"
+
e
);
console
.
log
(
'
An unexpected error occurred. Error: ${e}
'
);
}
```
...
...
@@ -171,14 +152,14 @@
};
kvManager
.
getKVStore
(
'
storeId
'
,
options
,
function
(
err
,
store
)
{
if
(
err
)
{
console
.
log
(
"
getKVStore err:
"
+
JSON
.
stringify
(
err
)
);
console
.
log
(
'
getKVStore err: ${err}
'
);
return
;
}
console
.
log
(
"
getKVStore success
"
);
console
.
log
(
'
getKVStore success
'
);
kvStore
=
store
;
});
}
catch
(
e
)
{
console
.
log
(
"
An unexpected error occurred. Error:
"
+
e
);
console
.
log
(
'
An unexpected error occurred. Error: ${e}
'
);
}
```
...
...
@@ -192,7 +173,7 @@
```
js
kvStore
.
on
(
'
dataChange
'
,
distributedData
.
SubscribeType
.
SUBSCRIBE_TYPE_ALL
,
function
(
data
)
{
console
.
log
(
"
dataChange callback call data:
"
+
JSON
.
stringify
(
data
)
);
console
.
log
(
"
dataChange callback call data:
${data}
"
);
});
```
...
...
@@ -209,13 +190,13 @@
try
{
kvStore
.
put
(
KEY_TEST_STRING_ELEMENT
,
VALUE_TEST_STRING_ELEMENT
,
function
(
err
,
data
)
{
if
(
err
!=
undefined
)
{
console
.
log
(
"
put err:
"
+
JSON
.
stringify
(
err
)
);
console
.
log
(
'
put err: ${error}
'
);
return
;
}
console
.
log
(
"
put success
"
);
console
.
log
(
'
put success
'
);
});
}
catch
(
e
)
{
console
.
log
(
"
An unexpected error occurred. Error:
"
+
e
);
console
.
log
(
'
An unexpected error occurred. Error: ${e}
'
);
}
```
...
...
@@ -232,16 +213,16 @@
try
{
kvStore
.
put
(
KEY_TEST_STRING_ELEMENT
,
VALUE_TEST_STRING_ELEMENT
,
function
(
err
,
data
)
{
if
(
err
!=
undefined
)
{
console
.
log
(
"
put err:
"
+
JSON
.
stringify
(
err
)
);
console
.
log
(
'
put err: ${error}
'
);
return
;
}
console
.
log
(
"
put success
"
);
console
.
log
(
'
put success
'
);
kvStore
.
get
(
KEY_TEST_STRING_ELEMENT
,
function
(
err
,
data
)
{
console
.
log
(
"
get success data:
"
+
data
);
console
.
log
(
'
get success data: ${data}
'
);
});
});
}
catch
(
e
)
{
console
.
log
(
"
An unexpected error occurred. Error:
"
+
e
);
console
.
log
(
'
An unexpected error occurred. Error: ${e}
'
);
}
```
...
...
@@ -260,7 +241,7 @@
let
devManager
;
// create deviceManager
deviceManager
.
createDeviceManager
(
"
bundleName
"
,
(
err
,
value
)
=>
{
deviceManager
.
createDeviceManager
(
'
bundleName
'
,
(
err
,
value
)
=>
{
if
(
!
err
)
{
devManager
=
value
;
// deviceIds由deviceManager调用getTrustedDeviceListSync方法得到
...
...
@@ -275,7 +256,7 @@
// 1000表示最大延迟时间为1000ms
kvStore
.
sync
(
deviceIds
,
distributedData
.
SyncMode
.
PUSH_ONLY
,
1000
);
}
catch
(
e
)
{
console
.
log
(
"
An unexpected error occurred. Error:
"
+
e
);
console
.
log
(
'
An unexpected error occurred. Error: ${e}
'
);
}
}
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录