diff --git a/zh-cn/application-dev/reference/apis/Readme-CN.md b/zh-cn/application-dev/reference/apis/Readme-CN.md
index 881b254e3f1514a9d2e027cca9d24aaa1c1d9f0e..157db21889586b60b57bd25441047839e58ff8b2 100755
--- a/zh-cn/application-dev/reference/apis/Readme-CN.md
+++ b/zh-cn/application-dev/reference/apis/Readme-CN.md
@@ -227,8 +227,6 @@
- [@ohos.data.preferences (首选项)](js-apis-data-preferences.md)
- [@ohos.data.relationalStore (关系型数据库)](js-apis-data-relationalStore.md)
- [@ohos.data.ValuesBucket (数据集)](js-apis-data-valuesBucket.md)
- - data/rdb
- - [resultSet (结果集)](js-apis-data-resultset.md)
- 文件管理
- [@ohos.file.environment (目录环境能力)](js-apis-file-environment.md)
@@ -434,3 +432,5 @@
- [PermissionDef](js-apis-bundle-PermissionDef.md)
- [remoteAbilityInfo](js-apis-bundle-remoteAbilityInfo.md)
- [shortcutInfo](js-apis-bundle-ShortcutInfo.md)
+ - data/rdb
+ - [resultSet (结果集)](js-apis-data-resultset.md)
\ No newline at end of file
diff --git a/zh-cn/application-dev/reference/apis/js-apis-distributed-data.md b/zh-cn/application-dev/reference/apis/js-apis-distributed-data.md
index 0d9e28f090c17ff153c65bad60cc278b2f417f89..4fefe7329cba6c4b4df1c1e5099a4bf92af29f3a 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-distributed-data.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-distributed-data.md
@@ -37,7 +37,7 @@ createKVManager(config: KVManagerConfig, callback: AsyncCallback<KVManager>
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ------ | ------ |
-| config | [KVManagerConfig](#kvmanagerconfig) | 是 | 提供KVManager实例的配置信息,包括调用方的包名和用户信息。 |
+| config | [KVManagerConfig](#kvmanagerconfig) | 是 | 提供KVManager实例的配置信息,包括调用方的Bundle名称和用户信息。 |
| callback | AsyncCallback<[KVManager](#kvmanager)> | 是 | 回调函数。返回创建的KVManager对象实例。 |
**示例:**
@@ -112,14 +112,14 @@ try {
## KVManagerConfig
-提供KVManager实例的配置信息,包括调用方的包名和用户信息。
+提供KVManager实例的配置信息,包括调用方的Bundle名称和用户信息。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
| 名称 | 类型 | 必填 | 说明 |
| ----- | ------ | ------ | ------ |
| userInfo | [UserInfo](#userinfo) | 是 | 调用方的用户信息。 |
-| bundleName | string | 是 | 调用方的包名。 |
+| bundleName | string | 是 | 调用方的Bundle名称。 |
## UserInfo
@@ -578,7 +578,7 @@ try {
| createIfMissing | boolean | 否 | 当数据库文件不存在时是否创建数据库,默认创建。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core |
| encrypt | boolean | 否 |设置数据库文件是否加密,默认不加密。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core |
| backup | boolean | 否 |设置数据库文件是否备份,默认备份。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core |
-| autoSync | boolean | 否 |设置数据库文件是否自动同步,默认不自动同步。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**需要权限**: ohos.permission.DISTRIBUTED_DATASYNC |
+| autoSync | boolean | 否 |设置数据库文件是否自动同步。默认为false,即手动同步;设置为ture时,表示自动同步。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**需要权限**: ohos.permission.DISTRIBUTED_DATASYNC |
| kvStoreType | [KVStoreType](#kvstoretype) | 否 |设置要创建的数据库类型,默认为多设备协同数据库。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core |
| securityLevel | [SecurityLevel](#securitylevel) | 否 |设置数据库安全级别,默认不设置安全级别。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core |
| schema8+ | [Schema](#schema8) | 否 | 设置定义存储在数据库中的值。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore |
@@ -3755,6 +3755,9 @@ try {
sync(deviceIds: string[], mode: SyncMode, delayMs?: number): void
在手动同步方式下,触发数据库同步。关于分布式数据服务的同步方式说明,请见[分布式数据服务概述](../../database/database-mdds-overview.md)。
+> **说明:**
+>
+> 其中deviceIds通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。
**需要权限**: ohos.permission.DISTRIBUTED_DATASYNC。
@@ -3771,8 +3774,41 @@ sync(deviceIds: string[], mode: SyncMode, delayMs?: number): void
**示例:**
```js
+import deviceManager from '@ohos.distributedHardware.deviceManager';
+
+let devManager;
let kvStore;
-kvStore.sync(['deviceIds'], distributedData.SyncMode.PULL_ONLY, 1000);
+const KEY_TEST_SYNC_ELEMENT = 'key_test_sync';
+const VALUE_TEST_SYNC_ELEMENT = 'value-string-001';
+// create deviceManager
+deviceManager.createDeviceManager('bundleName', (err, value) => {
+ if (!err) {
+ devManager = value;
+ let deviceIds = [];
+ if (devManager != null) {
+ var devices = devManager.getTrustedDeviceListSync();
+ for (var i = 0; i < devices.length; i++) {
+ deviceIds[i] = devices[i].deviceId;
+ }
+ }
+ try {
+ kvStore.on('syncComplete', function (data) {
+ console.log('Sync dataChange');
+ });
+ kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err, data) {
+ if (err != undefined) {
+ console.log("put err: " + JSON.stringify(err));
+ return;
+ }
+ console.log('Succeeded in putting data');
+ const mode = distributedData.SyncMode.PULL_ONLY;
+ kvStore.sync(deviceIds, mode, 1000);
+ });
+ } catch (e) {
+ console.log('Sync e' + e);
+ }
+ }
+});
```
### on('dataChange')8+
@@ -5156,22 +5192,41 @@ sync(deviceIds: string[], mode: SyncMode, delayMs?: number): void
**示例:**
```js
+import deviceManager from '@ohos.distributedHardware.deviceManager';
+
+let devManager;
let kvStore;
const KEY_TEST_SYNC_ELEMENT = 'key_test_sync';
const VALUE_TEST_SYNC_ELEMENT = 'value-string-001';
-try {
- kvStore.on('syncComplete', function (data) {
+// create deviceManager
+deviceManager.createDeviceManager('bundleName', (err, value) => {
+ if (!err) {
+ devManager = value;
+ let deviceIds = [];
+ if (devManager != null) {
+ var devices = devManager.getTrustedDeviceListSync();
+ for (var i = 0; i < devices.length; i++) {
+ deviceIds[i] = devices[i].deviceId;
+ }
+ }
+ try {
+ kvStore.on('syncComplete', function (data) {
console.log('Sync dataChange');
- });
- kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err,data) {
- console.log('Sync put success');
- const devices = ['deviceList'];
+ });
+ kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err, data) {
+ if (err != undefined) {
+ console.log("put err: " + JSON.stringify(err));
+ return;
+ }
+ console.log('Succeeded in putting data');
const mode = distributedData.SyncMode.PULL_ONLY;
- kvStore.sync(devices, mode);
- });
-}catch(e) {
- console.log('Sync e' + e);
-}
+ kvStore.sync(deviceIds, mode, 1000);
+ });
+ } catch (e) {
+ console.log('Sync e' + e);
+ }
+ }
+});
```
### on('dataChange')8+
diff --git a/zh-cn/application-dev/reference/apis/js-apis-distributedKVStore.md b/zh-cn/application-dev/reference/apis/js-apis-distributedKVStore.md
index 1a7a4b34de6846e48b80f1e5ab9879462ad0cce7..657c3b86f35c4dfe3d91a1fd3aeb3996923d520a 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-distributedKVStore.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-distributedKVStore.md
@@ -151,7 +151,7 @@ import distributedKVStore from '@ohos.data.distributedKVStore';
| createIfMissing | boolean | 否 | 当数据库文件不存在时是否创建数据库,默认创建。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core |
| encrypt | boolean | 否 | 设置数据库文件是否加密,默认不加密。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core |
| backup | boolean | 否 | 设置数据库文件是否备份,默认备份。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core |
-| autoSync | boolean | 否 | 设置数据库文件是否自动同步,默认不自动同步。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**需要权限**: ohos.permission.DISTRIBUTED_DATASYNC |
+| autoSync | boolean | 否 | 设置数据库文件是否自动同步。默认为false,即手动同步;设置为ture时,表示自动同步。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core
**需要权限**: ohos.permission.DISTRIBUTED_DATASYNC |
| kvStoreType | [KVStoreType](#kvstoretype) | 否 | 设置要创建的数据库类型,默认为多设备协同数据库。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core |
| securityLevel | [SecurityLevel](#securitylevel) | 是 |设置数据库安全级别。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core |
| schema | [Schema](#schema) | 否 | 设置定义存储在数据库中的值,默认不使用Schema。
**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore |
@@ -258,7 +258,7 @@ createKVManager(config: KVManagerConfig): KVManager
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ----------------------------- | ---- | --------------------------------------------------------- |
-| config | [KVManagerConfig](#kvmanagerconfig) | 是 | 提供KVManager实例的配置信息,包括调用方的包名和应用上下文。 |
+| config | [KVManagerConfig](#kvmanagerconfig) | 是 | 提供KVManager实例的配置信息,包括调用方的包名和用户信息。 |
**返回值:**
@@ -271,7 +271,8 @@ createKVManager(config: KVManagerConfig): KVManager
Stage模型下的示例:
```js
-import UIAbility from '@ohos.app.ability.UIAbility'
+import UIAbility from '@ohos.app.ability.UIAbility';
+
let kvManager;
export default class EntryAbility extends UIAbility {
onCreate() {
@@ -294,7 +295,7 @@ export default class EntryAbility extends UIAbility {
FA模型下的示例:
```js
-import featureAbility from '@ohos.ability.featureAbility'
+import featureAbility from '@ohos.ability.featureAbility';
let kvManager;
let context = featureAbility.getContext()
const kvManagerConfig = {
@@ -4484,6 +4485,9 @@ try {
sync(deviceIds: string[], mode: SyncMode, delayMs?: number): void
在手动同步方式下,触发数据库同步。关于分布式数据服务的同步方式说明,请见[分布式数据服务概述](../../database/database-mdds-overview.md)。
+> **说明:**
+>
+> 其中deviceIds通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。
**需要权限**: ohos.permission.DISTRIBUTED_DATASYNC。
@@ -4509,26 +4513,41 @@ sync(deviceIds: string[], mode: SyncMode, delayMs?: number): void
**示例:**
```js
+import deviceManager from '@ohos.distributedHardware.deviceManager';
+
+let devManager;
let kvStore;
const KEY_TEST_SYNC_ELEMENT = 'key_test_sync';
const VALUE_TEST_SYNC_ELEMENT = 'value-string-001';
-try {
- kvStore.on('syncComplete', function (data) {
+// create deviceManager
+deviceManager.createDeviceManager('bundleName', (err, value) => {
+ if (!err) {
+ devManager = value;
+ let deviceIds = [];
+ if (devManager != null) {
+ var devices = devManager.getTrustedDeviceListSync();
+ for (var i = 0; i < devices.length; i++) {
+ deviceIds[i] = devices[i].deviceId;
+ }
+ }
+ try {
+ kvStore.on('syncComplete', function (data) {
console.log('Sync dataChange');
- });
- kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err, data) {
+ });
+ kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err, data) {
if (err != undefined) {
- console.error(`Fail to sync.code is ${err.code},message is ${err.message}`);
- return;
+ console.error(`Fail to sync.code is ${err.code},message is ${err.message}`);
+ return;
}
console.log('Succeeded in putting data');
- const devices = ['deviceList'];
const mode = distributedKVStore.SyncMode.PULL_ONLY;
- kvStore.sync(devices, mode, 1000);
- });
-} catch (e) {
- console.error(`Fail to sync.code is ${e.code},message is ${e.message}`);
-}
+ kvStore.sync(deviceIds, mode, 1000);
+ });
+ } catch (e) {
+ console.error(`Fail to sync.code is ${e.code},message is ${e.message}`);
+ }
+ }
+});
```
### sync
@@ -4536,6 +4555,9 @@ try {
sync(deviceIds: string[], query: Query, mode: SyncMode, delayMs?: number): void
在手动同步方式下,触发数据库同步,此方法为同步方法。关于分布式数据服务的同步方式说明,请见[分布式数据服务概述](../../database/database-mdds-overview.md)。
+> **说明:**
+>
+> 其中deviceIds通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。
**需要权限**: ohos.permission.DISTRIBUTED_DATASYNC。
@@ -4562,29 +4584,44 @@ sync(deviceIds: string[], query: Query, mode: SyncMode, delayMs?: number): void
**示例:**
```js
+import deviceManager from '@ohos.distributedHardware.deviceManager';
+
+let devManager;
let kvStore;
const KEY_TEST_SYNC_ELEMENT = 'key_test_sync';
const VALUE_TEST_SYNC_ELEMENT = 'value-string-001';
-try {
- kvStore.on('syncComplete', function (data) {
+// create deviceManager
+deviceManager.createDeviceManager('bundleName', (err, value) => {
+ if (!err) {
+ devManager = value;
+ let deviceIds = [];
+ if (devManager != null) {
+ var devices = devManager.getTrustedDeviceListSync();
+ for (var i = 0; i < devices.length; i++) {
+ deviceIds[i] = devices[i].deviceId;
+ }
+ }
+ try {
+ kvStore.on('syncComplete', function (data) {
console.log('Sync dataChange');
- });
- kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err, data) {
+ });
+ kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err, data) {
if (err != undefined) {
- console.error(`Fail to sync.code is ${err.code},message is ${err.message}`);
- return;
+ console.error(`Fail to sync.code is ${err.code},message is ${err.message}`);
+ return;
}
console.log('Succeeded in putting data');
- const devices = ['deviceList'];
const mode = distributedKVStore.SyncMode.PULL_ONLY;
const query = new distributedKVStore.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
- kvStore.sync(devices, query, mode, 1000);
- });
-} catch (e) {
- console.error(`Fail to sync.code is ${e.code},message is ${e.message}`);
-}
+ kvStore.sync(deviceIds, query, mode, 1000);
+ });
+ } catch (e) {
+ console.error(`Fail to sync.code is ${e.code},message is ${e.message}`);
+ }
+ }
+});
```
### on('dataChange')
diff --git a/zh-cn/application-dev/website.md b/zh-cn/application-dev/website.md
index fecef6d6597d962e5031573a999b54803d221051..9f1f013c22007f29c09d114891e37e642551bfce 100644
--- a/zh-cn/application-dev/website.md
+++ b/zh-cn/application-dev/website.md
@@ -1032,8 +1032,6 @@
- [@ohos.data.preferences (首选项)](reference/apis/js-apis-data-preferences.md)
- [@ohos.data.relationalStore (关系型数据库)](reference/apis/js-apis-data-relationalStore.md)
- [@ohos.data.ValuesBucket (数据集)](reference/apis/js-apis-data-valuesBucket.md)
- - data/rdb
- - [resultSet (结果集)](reference/apis/js-apis-data-resultset.md)
- 文件管理
- [@ohos.file.environment (目录环境能力)](reference/apis/js-apis-file-environment.md)
- [@ohos.file.fileAccess (公共文件访问与管理)](reference/apis/js-apis-fileAccess.md)
@@ -1227,6 +1225,8 @@
- [PermissionDef](reference/apis/js-apis-bundle-PermissionDef.md)
- [remoteAbilityInfo](reference/apis/js-apis-bundle-remoteAbilityInfo.md)
- [shortcutInfo](reference/apis/js-apis-bundle-ShortcutInfo.md)
+ - data/rdb
+ - [resultSet (结果集)](reference/apis/js-apis-data-resultset.md)
- 错误码参考
- [通用错误码](reference/errorcodes/errorcode-universal.md)
- Ability框架