diff --git a/en/application-dev/reference/apis/js-apis-distributed-data.md b/en/application-dev/reference/apis/js-apis-distributed-data.md index 91401eaf796ee5aca8ac30c05bf0c2a238932b89..b5a7b33fe99e113f4c8486524cf22822d68dfb87 100644 --- a/en/application-dev/reference/apis/js-apis-distributed-data.md +++ b/en/application-dev/reference/apis/js-apis-distributed-data.md @@ -1,6 +1,15 @@ # Distributed Data Management -Distributed data management provides collaboration between databases of different devices for applications. The APIs provided by distributed data management can be used to save data to the distributed database and perform operations such as adding, deleting, modifying, and querying data in the distributed database. +The distributed data management module implements collaboration between databases of different devices for applications. The APIs provided by distributed data management can be used to save data to distributed databases and perform operations such as adding, deleting, modifying, querying, and synchronizing data in distributed databases. + +This module provides the following functions: + +- [KVManager](#kvmanager): provides a **KVManager** instance to manage key-value (KV) stores. +- [KvStoreResultSet8+](#kvstoreresultset8): provides methods to obtain the KV store result set and query or move the data read position. +- [Query8+](#query8): provides methods to query data from the database through a **Query** instance by using predicates. +- [KVStore](#kvstore): provides methods to add data, delete data, and observe data changes and data synchronization through a **KVStore** instance. +- [SingleKVStore](#singlekvstore): provides methods to query and synchronize data in a single KV store. This class inherits from [KVStore](#kvstore), and data is not distinguished by device. +- [DeviceKVStore8+ ](#devicekvstore8): provides methods to query and synchronize data in a device KV store. This class inherits from [KVStore](#kvstore), and data is distinguished by device. >**NOTE**
> @@ -18,7 +27,7 @@ import distributedData from '@ohos.data.distributedData'; createKVManager(config: KVManagerConfig, callback: AsyncCallback<KVManager>): void -Creates a **KVManager** object to manage key-value (KV) stores. This API uses an asynchronous callback to return the result. +Creates a **KVManager** instance to manage KV stores. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -26,8 +35,8 @@ Creates a **KVManager** object to manage key-value (KV) stores. This API uses an | Name| Type| Mandatory| Description| | ----- | ------ | ------ | ------ | -| config | [KVManagerConfig](#kvmanagerconfig) | Yes | Configuration of the **KVManager** object, including the bundle name and user information of the caller.| -| callback | AsyncCallback<[KVManager](#kvmanager)> | Yes | Callback invoked to return the **KVManager** object created.| +| config | [KVManagerConfig](#kvmanagerconfig) | Yes | Configuration of the **KVManager** instance, including the bundle name and user information of the caller.| +| callback | AsyncCallback<[KVManager](#kvmanager)> | Yes | Callback invoked to return the **KVManager** instance created.| **Example** ```js @@ -57,7 +66,7 @@ try { createKVManager(config: KVManagerConfig): Promise<KVManager> -Creates a **KVManager** object to manage KV stores. This API uses a promise to return the result. +Creates a **KVManager** instance to manage KV stores. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -65,13 +74,13 @@ Creates a **KVManager** object to manage KV stores. This API uses a promise to r | Name| Type| Mandatory| Description| | ----- | ------ | ------ | ------ | -| config |[KVManagerConfig](#kvmanager) | Yes | Configuration of the **KVManager** object, including the bundle name and user information of the caller.| +| config |[KVManagerConfig](#kvmanager) | Yes | Configuration of the **KVManager** instance, including the bundle name and user information of the caller.| **Return value** | Type| Description| | -------- | -------- | -| Promise<[KVManager](#kvmanager)> | Promise used to return the **KVManager** object created.| +| Promise<[KVManager](#kvmanager)> | Promise used to return the **KVManager** instance created.| **Example** @@ -121,11 +130,11 @@ Defines user information. ## UserType -Defines the user type. +Enumerates the user types. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core -| Name| Default Value| Description| +| Name| Value| Description| | ----- | ------ | ------ | | SAME_USER_ID | 0 | User who logs in to different devices using the same account.| @@ -198,7 +207,7 @@ Creates and obtains a KV store. This API uses a promise to return the result. | Type | Description | | -------------------------------------- | ------------------------ | -| Promise<T> <T extends [KVStore](#kvstore)> | Promise used to return the KV store created.| +| Promise<T>, <T extends [KVStore](#kvstore)> | Promise used to return the KV store created.| **Example** @@ -241,7 +250,7 @@ Closes a KV store. This API uses an asynchronous callback to return the result. | appId | string | Yes | Bundle name of the app that invokes the KV store. | | storeId | string | Yes | Unique identifier of the KV store to close. The length cannot exceed [MAX_STORE_ID_LENGTH](#constants).| | kvStore | [KVStore](#kvstore) | Yes | KV store to close. | -| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the KV store is closed, **true** will be returned. Otherwise, **false** will be returned. | +| callback | AsyncCallback<void> | Yes | Callback used to return the result.| **Example** @@ -261,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'); }); }); @@ -291,7 +300,7 @@ Closes a KV store. This API uses a promise to return the result. | Type | Description | | ------------- | -------------- | -| Promise\ | Promise used to return the result. If the KV store is closed, **true** will be returned. Otherwise, **false** will be returned.| +| Promise\ | Promise that returns no value.| **Example** @@ -311,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)); @@ -339,7 +348,7 @@ Deletes a KV store. This API uses an asynchronous callback to return the result. | ----- | ------ | ---- | ----------------------- | | appId | string | Yes | Bundle name of the app that invokes the KV store. | | storeId | string | Yes | Unique identifier of the KV store to delete. The length cannot exceed [MAX_STORE_ID_LENGTH](#constants).| -| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the KV store is deleted, **true** will be returned. Otherwise, **false** will be returned. | +| callback | AsyncCallback<void> | Yes | Callback used to return the result.| **Example** @@ -359,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'); }); }); @@ -388,7 +397,7 @@ Deletes a KV store. This API uses a promise to return the result. | Type | Description | | ------------- | -------------- | -| Promise<void> | Promise used to return the result. If the KV store is deleted, **true** will be returned. Otherwise, **false** will be returned.| +| Promise<void> | Promise that returns no value.| **Example** @@ -408,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)); @@ -426,7 +435,7 @@ try { getAllKVStoreId(appId: string, callback: AsyncCallback<string[]>): void -Obtains the IDs of all the KV stores that are created using [getKVStore](#getkvstore) and have not been deleted using [deleteKVStore](#deletekvstore8). This API uses an asynchronous callback to return the result. +Obtains the IDs of all KV stores that are created by [getKVStore()](#getkvstore) and have not been deleted by [deleteKVStore()](#deletekvstore8). This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -435,7 +444,7 @@ Obtains the IDs of all the KV stores that are created using [getKVStore](#getkvs | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | appId | string | Yes | Bundle name of the app that invokes the KV store. | -| callback | AsyncCallback<void> | Yes |Callback used to return the KV store IDs obtained. | +| callback | AsyncCallback<string[]> | Yes |Callback used to return the KV store IDs obtained. | **Example** @@ -456,7 +465,7 @@ try { getAllKVStoreId(appId: string): Promise<string[]> -Obtains the IDs of all the KV stores that are created using [getKVStore](#getkvstore) and have not been deleted using [deleteKVStore](#deletekvstore8). This API uses a promise to return the result. +Obtains the IDs of all KV stores that are created by [getKVStore()](#getkvstore) and have not been deleted by [deleteKVStore()](#deletekvstore8). This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -495,7 +504,7 @@ try { on(event: 'distributedDataServiceDie', deathCallback: Callback<void>): void -Subscribes to the **distributedDataServiceDie** events. This API uses a synchronous callback to return the result. +Subscribes to service status changes. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -503,8 +512,8 @@ Subscribes to the **distributedDataServiceDie** events. This API uses a synchron | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| event | string | Yes | Name of the event to subscribe to. The value is **distributedDataServiceDie**, which indicates the service status change event.| -| deathCallback | Callback<void> | Yes | Callback invoked when the distributed data service is dead. | +| event | string | Yes | Event to subscribe to. The value is **distributedDataServiceDie**, which indicates service status changes.| +| deathCallback | Callback<void> | Yes | Callback invoked to return service status changes.| **Example** @@ -527,7 +536,7 @@ try { off(event: 'distributedDataServiceDie', deathCallback?: Callback<void>): void -Unsubscribes from the **distributedDataServiceDie** events. This API uses a synchronous callback to return the result. +Unsubscribes from the service status changes. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -535,8 +544,8 @@ Unsubscribes from the **distributedDataServiceDie** events. This API uses a sync | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| event | string | Yes | Name of the event to unsubscribe from. The value is **distributedDataServiceDie**, which indicates the service status change event.| -| deathCallback | Callback<void> | No | Callback used to return the **distributedDataServiceDie** events. | +| event | string | Yes | Event to unsubscribe from. The value is **distributedDataServiceDie**, which indicates service status changes.| +| deathCallback | Callback<void> | No | Callback used to return service status changes.| **Example** @@ -562,41 +571,41 @@ Provides KV store configuration. | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| createIfMissing | boolean | No| Whether to create a KV store if no database file exists. By default, a KV store is created.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | -| encrypt | boolean | No|Whether to encrypt database files. By default, database files are not encrypted.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | -| backup | boolean | No|Whether to back up database files. By default, database files are backed up.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | -| autoSync | boolean | No|Whether to automatically synchronize database files. By default, database files are not automatically synchronized.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC | -| kvStoreType | [KVStoreType](#kvstoretype) | No|Type of the KV store to create. By default, a device KV store is created. The device KV store stores data for multiple devices that collaborate with each other.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | -| securityLevel | [SecurityLevel](#securitylevel) | No|Security level of the KV store. By default, the security level is not set.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | -| schema8+ | [Schema](#schema8) | No| Schema used to define the values stored in a KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore | +| createIfMissing | boolean | No| Whether to create a KV store if no database file exists. By default, a KV store is created.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | +| encrypt | boolean | No|Whether to encrypt database files. By default, database files are not encrypted.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | +| backup | boolean | No|Whether to back up database files. By default, database files are backed up.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | +| autoSync | boolean | No|Whether database files are automatically synchronized. By default, database files are not automatically synchronized.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC | +| kvStoreType | [KVStoreType](#kvstoretype) | No|Type of the KV store to create. By default, a device KV store is created. The device KV store stores data for multiple devices that collaborate with each other.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core| +| securityLevel | [SecurityLevel](#securitylevel) | No|Security level of the KV store. By default, the security level is not set.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | +| schema8+ | [Schema](#schema8) | No| Schema used to define the values stored in a KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore| ## KVStoreType -Defines the KV store types. +Enumerates the KV store types. -| Name | Default Value| Description | +| Name | Value| Description | | --- | ---- | ----------------------- | -| DEVICE_COLLABORATION | 0 | Device KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore | -| SINGLE_VERSION | 1 | Single KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | -| MULTI_VERSION | 2 | Multi-version KV store. This type is not supported currently.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore| +| DEVICE_COLLABORATION | 0 | Device KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore | +| SINGLE_VERSION | 1 | Single KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core| +| MULTI_VERSION | 2 | Multi-version KV store. This type is not supported currently.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore| ## SecurityLevel -Defines the KV store security levels. +Enumerates the KV store security levels. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core -| Name | Default Value| Description | +| Name | Value| Description | | --- | ---- | ----------------------- | | NO_LEVEL | 0 | No security level is set for the KV store. | -| S0 | 1 | The KV store security level is public. | -| S1 | 2 | The KV store security level is low. If data leakage occurs, minor impact will be caused on the database. | -| S2 | 3 | The KV store security level is medium. If data leakage occurs, moderate impact will be caused on the database. | -| S3 | 5 | The KV store security level is high. If data leakage occurs, major impact will be caused on the database. | -| S4 | 6 | The KV store security level is critical. If data leakage occurs, severe impact will be caused on the database. | +| S0 | 1 | The KV store security level is public.| +| S1 | 2 | The KV store security level is low. If data leakage occurs, minor impact will be caused on the database. For example, a KV store that contains system data such as wallpapers.| +| S2 | 3 | The KV store security level is medium. If data leakage occurs, moderate impact will be caused on the database. For example, a KV store that contains information created by users or call records, such as audio or video clips.| +| S3 | 5 | The KV store security level is high. If data leakage occurs, major impact will be caused on the database. For example, a KV store that contains information such as user fitness, health, and location data.| +| S4 | 6 | The KV store security level is critical. If data leakage occurs, severe impact will be caused on the database. For example, a KV store that contains information such as authentication credentials and financial data.| ## Constants @@ -605,18 +614,18 @@ Defines the KV store constants. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core -| Name | Default Value| Description | +| Name | Value| Description | | --- | ---- | ----------------------- | -| MAX_KEY_LENGTH | 1024 | Maximum length (in bytes) of a key in the KV store. | -| MAX_VALUE_LENGTH | 4194303 | Maximum length (in bytes) of a value in the KV store. | -| MAX_KEY_LENGTH_DEVICE | 896 | Maximum length of the device coordinate key, in bytes.| -| MAX_STORE_ID_LENGTH | 128 | Maximum length (in bytes) of a KV store ID. | +| MAX_KEY_LENGTH | 1024 | Maximum length of a key in the KV store, in bytes. | +| MAX_VALUE_LENGTH | 4194303 | Maximum length of a value in the KV store, in bytes. | +| MAX_KEY_LENGTH_DEVICE | 896 | Maximum length of a device key, in bytes.| +| MAX_STORE_ID_LENGTH | 128 | Maximum length of a KV store ID, in bytes. | | MAX_QUERY_LENGTH | 512000 | Maximum query length, in bytes.| | MAX_BATCH_SIZE | 128 | Maximum number of batch operations.| ## Schema8+ ## -Defines the schema of a KV store. When creating or opening a KV store, you can create a **Schema** object and put it in [Options](#options). +Defines the schema of a KV store. You can create a **Schema** object and place it in [Options](#options) when creating or opening a KV store. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -645,7 +654,7 @@ Represents a **Schema** instance, which provides the methods for defining the va | --- | ---- | ----------------------- | | nullable8+ | boolean | Whether the database field can be null. | | default8+ | string | Default value of a **FieldNode**.| -| type8+ | number | Value to store.| +| type8+ | number | Value of the data type corresponding to the specified node.| ### constructor8+ ### @@ -693,7 +702,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; @@ -706,14 +715,16 @@ try { ## KvStoreResultSet8+ ## -Provides methods to obtain the KV store result set and query or move the data read position. Before calling any method in **KvStoreResultSet**, you must use **KvStore** to create a **KvStore** instance. +Provides methods to obtain the KV store result sets, and query and move the data read position. + +Before calling any method in **KvStoreResultSet**, you must use [getKVStore](#getkvstore) to obtain a **KVStore** object. ### getCount8+ ### getCount(): number -Obtains the number of rows in the result set. +Obtains the total number of rows in the result set. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -721,7 +732,7 @@ Obtains the number of rows in the result set. | Type | Description | | ------ | -------------- | -| number |Number of rows obtained. | +| number |Total number of rows obtained. | **Example** @@ -780,7 +791,7 @@ try { moveToFirst(): boolean -Moves the data read position to the first row. +Moves the data read position to the first row. If the result set is empty, **false** will be returned. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -814,7 +825,7 @@ try { moveToLast(): boolean -Moves the data read position to the last row. +Moves the data read position to the last row. If the result set is empty, **false** will be returned. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -848,7 +859,7 @@ try { moveToNext(): boolean -Moves the data read position to the next row. +Moves the data read position to the next row. If the result set is empty, **false** will be returned. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -882,7 +893,7 @@ try { moveToPrevious(): boolean -Moves the data read position to the previous row. +Moves the data read position to the previous row. If the result set is empty, **false** will be returned. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -1071,7 +1082,7 @@ Checks whether the data read position is before the first row. | Type | Description | | ------ | -------------- | -| boolean |Returns **true** if the read position is before the first row; returns **false** otherwise. | +| boolean |Returns **true** if the data read position is before the first row; returns **false** otherwise. | **Example** @@ -1131,7 +1142,7 @@ try { getEntry(): Entry -Obtains a KV pair. +Obtains the KV pair from the current position. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -1180,7 +1191,7 @@ A constructor used to create a **Schema** instance. reset(): Query -Resets the **Query** object that contains common query options. +Resets the **Query** object. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -1211,7 +1222,7 @@ try { equalTo(field: string, value: number|string|boolean): Query -Creates a **Query** object to match the specified field whose value is equal to the specified value. +Creates a **Query** object to match the specified field whose value is equal to the given value. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -1226,7 +1237,7 @@ Creates a **Query** object to match the specified field whose value is equal to | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object reset.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1237,7 +1248,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1272,7 +1283,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1296,7 +1307,7 @@ Creates a **Query** object to match the specified field whose value is greater t | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1307,7 +1318,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1331,7 +1342,7 @@ Creates a **Query** object to match the specified field whose value is less than | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1342,7 +1353,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1366,7 +1377,7 @@ Creates a **Query** object to match the specified field whose value is greater t | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1377,7 +1388,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1401,7 +1412,7 @@ Creates a **Query** object to match the specified field whose value is less than | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1412,7 +1423,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1423,7 +1434,6 @@ isNull(field: string): Query Creates a **Query** object to match the specified field whose value is **null**. - **System capability**: SystemCapability.DistributedDataManager.KVStore.Core **Parameters** @@ -1436,7 +1446,7 @@ Creates a **Query** object to match the specified field whose value is **null**. | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1447,7 +1457,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1472,7 +1482,7 @@ Creates a **Query** object to match the specified field whose value is within th | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1483,7 +1493,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1507,7 +1517,7 @@ Creates a **Query** object to match the specified field whose value is within th | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1518,7 +1528,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1542,7 +1552,7 @@ Creates a **Query** object to match the specified field whose value is not withi | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1553,7 +1563,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1577,7 +1587,7 @@ Creates a **Query** object to match the specified field whose value is not withi | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1588,7 +1598,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1605,14 +1615,14 @@ Creates a **Query** object to match the specified field whose value is similar t | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| fieId | string | Yes Field to match. It cannot contain '^'. | +| fieId | string | Yes |Field to match. It cannot contain '^'. | | value | string | Yes | String specified.| **Return value** | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1623,7 +1633,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1647,7 +1657,7 @@ Creates a **Query** object to match the specified field whose value is not simil | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1658,7 +1668,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1688,7 +1698,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1718,7 +1728,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1741,7 +1751,7 @@ Creates a **Query** object to sort the query results in ascending order. | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1753,7 +1763,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1776,7 +1786,7 @@ Creates a **Query** object to sort the query results in descending order. | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1788,7 +1798,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1812,7 +1822,7 @@ Creates a **Query** object to specify the number of results and where to start. | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1824,7 +1834,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1833,7 +1843,7 @@ try { isNotNull(field: string): Query -Creates a **Query** object with a specified field that is not null. +Creates a **Query** object to match the specified field whose value is not **null**. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -1841,13 +1851,13 @@ Creates a **Query** object with a specified field that is not null. | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| fieId | string | Yes |Field specified. | +| fieId | string | Yes |Field to match. It cannot contain '^'. | **Return value** | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1858,7 +1868,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1875,7 +1885,7 @@ Creates a **Query** object for a query condition group with a left parenthesis. | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1888,7 +1898,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1905,7 +1915,7 @@ Creates a **Query** object for a query condition group with a right parenthesis. | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1918,7 +1928,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1941,7 +1951,7 @@ Creates a **Query** object with a specified key prefix. | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1953,7 +1963,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -1976,7 +1986,7 @@ Creates a **Query** object with an index preferentially used for query. | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -1988,7 +1998,7 @@ try { console.log("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("dumplicated calls should be ok :" + e); + console.log("duplicated calls should be ok :" + e); } ``` @@ -2012,7 +2022,7 @@ Creates a **Query** object with the device ID as the key prefix. | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object Created.| +| [Query](#query8) |**Query** object created.| **Example** @@ -2049,14 +2059,16 @@ try { let sql1 = query.getSqlLike(); console.log("GetSqlLike sql=" + sql1); } catch (e) { - console.log("dumplicated calls should be ok : " + e); + console.log("duplicated calls should be ok : " + e); } ``` ## KVStore -Provides methods to manage data in a KV store, for example, adding or deleting data and subscribing to data changes or completion of data synchronization. Before calling any method in **KVStore**, you must use [getKVStore](#getkvstore) to obtain a **KVStore** object. +Provides methods to manage data in a KV store, for example, adding or deleting data and subscribing to data changes or completion of data synchronization. + +Before calling any method in **KVStore**, you must use [getKVStore](#getkvstore) to obtain a **KVStore** object. ### put @@ -2113,7 +2125,7 @@ Adds a KV pair of the specified type to this KV store. This API uses a promise t | Type | Description | | ------ | ------- | -| Promise<void> |Promise used to return the result.| +| Promise<void> |Promise that returns no value.| **Example** @@ -2132,7 +2144,6 @@ try { } ``` - ### delete delete(key: string, callback: AsyncCallback<void>): void @@ -2174,7 +2185,6 @@ try { } ``` - ### delete delete(key: string): Promise<void> @@ -2193,7 +2203,7 @@ Deletes a KV pair from this KV store. This API uses a promise to return the resu | Type | Description | | ------ | ------- | -| Promise<void> |Promise used to return the result.| +| Promise<void> |Promise that returns no value.| **Example** @@ -2216,13 +2226,11 @@ try { console.log("An unexpected error occurred. Error:" + e); } ``` - - ### on('dataChange') on(event: 'dataChange', type: SubscribeType, observer: Callback<ChangeNotification>): void -Subscribes to data changes of the specified type. This API uses a synchronous callback to return the result. +Subscribes to data change notifications of the specified type. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2230,9 +2238,9 @@ Subscribes to data changes of the specified type. This API uses a synchronous ca | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| event |string | Yes |Name of the event to subscribe to. The value is **dataChange**, which indicates the data change event. | +| event |string | Yes |Event to subscribe to. The value is **dataChange**, which indicates data changes. | | type |[SubscribeType](#subscribetype) | Yes |Type of data changes. | -| observer |Callback<[ChangeNotification](#changenotification)> | Yes |Callback used to return the result.| +| observer |Callback<[ChangeNotification](#changenotification)> | Yes |Callback used to return the data changes.| **Example** @@ -2248,7 +2256,7 @@ kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, fun on(event: 'syncComplete', syncCallback: Callback<Array<[string, number]>>): void -Subscribes to data synchronization completion events. This API uses a synchronous callback to return the result. +Subscribes to data synchronization complete events. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2256,8 +2264,8 @@ Subscribes to data synchronization completion events. This API uses a synchronou | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| event |string | Yes |Name of the event to subscribe to. The value is **syncComplete**, which indicates the synchronization complete event. | -| syncCallback |Callback<Array<[string, number]>> | Yes |Callback used to return the result. | +| event |string | Yes |Event to subscribe to. The value is **syncComplete**, which indicates completion of a data synchronization. | +| syncCallback |Callback<Array<[string, number]>> | Yes |Callback used to return the data synchronization result. | **Example** @@ -2272,7 +2280,7 @@ kvStore.on('syncComplete', function (data) { off(event:'dataChange', observer?: Callback<ChangeNotification>): void -Unsubscribes from data change events. This API uses a synchronous callback to return the result. +Unsubscribes from data change notifications. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2280,8 +2288,8 @@ Unsubscribes from data change events. This API uses a synchronous callback to re | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| event |string | Yes |Name of the event to unsubscribe from. The value is **dataChange**, which indicates the data change event. | -| observer |Callback<[ChangeNotification](#changenotification)> |No |Callback used to return the result.| +| event |string | Yes |Event to unsubscribe from. The value is **dataChange**, which indicates data changes. | +| observer |Callback<[ChangeNotification](#changenotification)> |No |Callback used to return the data changes.| **Example** @@ -2331,14 +2339,14 @@ 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])); }); }); }catch(e) { - console.log('PutBatch e ' + e); + console.log('PutBatch e ' + JSON.stringify(e)); } ``` @@ -2361,7 +2369,7 @@ Inserts KV pairs in batches to this KV store. This API uses a promise to return | Type | Description | | ------ | ------- | -| Promise<void> |Promise used to return the result.| +| Promise<void> |Promise that returns no value.| **Example** @@ -2383,7 +2391,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) => { @@ -2393,7 +2401,7 @@ try { console.log('putBatch fail ' + JSON.stringify(err)); }); }catch(e) { - console.log('PutBatch e ' + e); + console.log('PutBatch e ' + JSON.stringify(e)); } ``` @@ -2435,7 +2443,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'); }); }); @@ -2463,7 +2471,7 @@ Deletes KV pairs in batches from this KV store. This API uses a promise to retur | Type | Description | | ------ | ------- | -| Promise<void> |Promise used to return the result.| +| Promise<void> |Promise that returns no value.| **Example** @@ -2487,7 +2495,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)); @@ -2543,7 +2551,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'); }); }); @@ -2565,7 +2573,7 @@ Starts the transaction in this KV store. This API uses a promise to return the r | Type | Description | | ------ | ------- | -| Promise<void> |Promise used to return the result.| +| Promise<void> |Promise that returns no value.| **Example** @@ -2632,7 +2640,7 @@ Commits the transaction in this KV store. This API uses a promise to return the | Type | Description | | ------ | ------- | -| Promise<void> |Promise used to return the result.| +| Promise<void> |Promise that returns no value.| **Example** @@ -2694,7 +2702,7 @@ Rolls back the transaction in this KV store. This API uses a promise to return t | Type | Description | | ------ | ------- | -| Promise<void> |Promise used to return the result.| +| Promise<void> |Promise that returns no value.| **Example** @@ -2716,7 +2724,7 @@ try { enableSync(enabled: boolean, callback: AsyncCallback<void>): void -Sets data synchronization, which can be enabled or disable. This API uses an asynchronous callback to return the result. +Sets data synchronization, which can be enabled or disabled. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2749,7 +2757,7 @@ try { enableSync(enabled: boolean): Promise<void> -Enables or disables data synchronization. This API uses a promise to return the result. +Sets data synchronization, which can be enabled or disabled. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2763,7 +2771,7 @@ Enables or disables data synchronization. This API uses a promise to return the | Type | Description | | ------ | ------- | -| Promise<void> |Promise used to return the result.| +| Promise<void> |Promise that returns no value.| **Example** @@ -2833,7 +2841,7 @@ Sets the data synchronization range. This API uses a promise to return the resul | Type | Description | | ------ | ------- | -| Promise<void> |Promise used to return the result.| +| Promise<void> |Promise that returns no value.| **Example** @@ -2855,11 +2863,11 @@ try { ## SubscribeType -Defines the subscription type. +Enumerates the subscription types. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core -| Name | Default Value | Description | +| Name | Value | Description | | ----- | ------ | ----------------------- | | SUBSCRIBE_TYPE_LOCAL |0 |Local data changes. | | SUBSCRIBE_TYPE_REMOTE |1 |Remote data changes. | @@ -2892,7 +2900,7 @@ Defines the KV pairs stored in the KV store. ## Value -Defines the value in a KV pair. +Defines the **value** object in a KV store. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2903,13 +2911,11 @@ Defines the value in a KV pair. ## ValueType -Enumerates the types of values in KV pairs. - -These value types can be used only by internal applications. +Enumerates the data types. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core -| Name | Default Value | Description | +| Name | Value | Description | | ----- | ------ | ----------------------- | | STRING |0 |String. | | INTEGER |1 |Integer. | @@ -2918,16 +2924,19 @@ These value types can be used only by internal applications. | BOOLEAN |4 |Boolean. | | DOUBLE |5 |Double (double-precision floating point). | - ## SingleKVStore -Provides methods to query and synchronize data in a single KV store. This class inherits from **KVStore**. Before calling any method in **SingleKVStore**, you must use [getKVStore](#getkvstore) to obtain a **SingleKVStore** object. +Provides methods to query and synchronize data in a single KV store. This class inherits from [KVStore](#kvstore). + +Data is not distinguished by device in a single KV store. The data written to different devices using the same key will be overwritten. For example, a single KV store can be used to synchronize a user's calendar and contact data between different devices. + +Before calling any method in **SingleKVStore**, you must use [getKVStore](#getkvstore) to obtain a **SingleKVStore** instance. ### get get(key: string, callback: AsyncCallback<Uint8Array | string | boolean | number>): void -Obtains the value of a specified key. This API uses an asynchronous callback to return the result. +Obtains the value of the specified key. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2936,7 +2945,7 @@ Obtains the value of a specified key. This API uses an asynchronous callback to | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | key |string | Yes |Key of the value to obtain. It cannot be empty, and the length cannot exceed [MAX_KEY_LENGTH](#constants). | -| callback |AsyncCallback<Uint8Array \| string \| boolean \| number>) | Yes |Callback used to return the value obtained. | +| callback |AsyncCallback<Uint8Array \| string \| boolean \| number>) | Yes |Callback invoked to return the value obtained. | **Example** @@ -2965,7 +2974,7 @@ try { get(key: string): Promise<Uint8Array | string | boolean | number> -Obtains the value of a specified key. This API uses a promise to return the result. +Obtains the value of the specified key. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3008,7 +3017,7 @@ try { getEntries(keyPrefix: string, callback: AsyncCallback<Entry[]>): void -Obtains the KV pairs that match the specified key prefix. This API uses an asynchronous callback to return the result. +Obtains all KV pairs that match the specified key prefix. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3017,7 +3026,7 @@ Obtains the KV pairs that match the specified key prefix. This API uses an async | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | keyPrefix |string | Yes |Key prefix to match. | -| callback |AsyncCallback<[Entry](#entry)[]> | Yes |Callback used to return the KV pairs obtained. | +| callback |AsyncCallback<[Entry](#entry)[]> | Yes |Callback invoked to return the KV pairs obtained. | **Example** @@ -3038,7 +3047,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])); @@ -3054,7 +3063,7 @@ try { getEntries(keyPrefix: string): Promise<Entry[]> -Obtains the KV pairs that match the specified key prefix. This API uses a promise to return the result. +Obtains all KV pairs that match the specified key prefix. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3090,7 +3099,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])); @@ -3120,7 +3129,7 @@ Obtains the KV pairs that match the specified **Query** object. This API uses an | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| query |[Query](#query8) | Yes |**Query** object to match. | +| query |[Query](#query8) | Yes |Key prefix to match. | | callback |AsyncCallback<[Entry](#entry)[]> | Yes |Callback used to return the KV pairs obtained. | **Example** @@ -3146,7 +3155,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])); @@ -3182,6 +3191,7 @@ Obtains the KV pairs that match the specified **Query** object. This API uses a **Example** ```js +let kvStore; try { var arr = new Uint8Array([21,31]); let entries = []; @@ -3201,7 +3211,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)); @@ -3220,7 +3230,7 @@ try { getResultSet(keyPrefix: string, callback: AsyncCallback<KvStoreResultSet>): void -Obtains the result set with the specified key prefix from this single KV store. This API uses an asynchronous callback to return the result. +Obtains the result set with the specified prefix. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3229,7 +3239,7 @@ Obtains the result set with the specified key prefix from this single KV store. | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | keyPrefix |string | Yes |Key prefix to match.| -| callback |AsyncCallback<[KvStoreResultSet](#kvstoreresultset8)> | Yes |Callback used to return the result set obtained.| +| callback |AsyncCallback<[KvStoreResultSet](#kvstoreresultset8)> | Yes |Callback invoked to return the result set obtained.| **Example** @@ -3251,7 +3261,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) { @@ -3269,7 +3279,7 @@ try { getResultSet(keyPrefix: string): Promise<KvStoreResultSet> -Obtains the result set with the specified key prefix from this single KV store. This API uses a promise to return the result. +Obtains the result set with the specified prefix. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3329,7 +3339,7 @@ try { getResultSet(query: Query, callback: AsyncCallback<KvStoreResultSet>): void -Obtains the **KvStoreResultSet** object that matches the specified **Query** object. This API uses an asynchronous callback to return the result. +Obtains a **KvStoreResultSet** object that matches the specified **Query** object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3338,7 +3348,7 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | query |Query | Yes |**Query** object to match. | -| callback |AsyncCallback<[KvStoreResultSet](#kvstoreresultset8)> | Yes |Callback used to return the **KvStoreResultSet** object obtained.| +| callback |AsyncCallback<[KvStoreResultSet](#kvstoreresultset8)> | Yes |Callback invoked to return the **KvStoreResultSet** object obtained.| **Example** @@ -3362,7 +3372,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; }); @@ -3377,7 +3387,7 @@ try { getResultSet(query: Query): Promise<KvStoreResultSet> -Obtains the **KvStoreResultSet** object that matches the specified **Query** object. This API uses a promise to return the result. +Obtains a **KvStoreResultSet** object that matches the specified **Query** object. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3481,7 +3491,7 @@ Closes the **KvStoreResultSet** object obtained by [SingleKvStore.getResultSet]( | Type | Description | | ------ | ------- | -|Promise<void> |Promise used to return the result.| +|Promise<void> |Promise that returns no value.| **Example** @@ -3513,7 +3523,7 @@ Obtains the number of results that matches the specified **Query** object. This | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | query |[Query](#query8) | Yes |**Query** object to match. | -| callback |AsyncCallback<number> | Yes |Callback used to return the number of results obtained. | +| callback |AsyncCallback<number> | Yes |Callback invoked to return the number of results obtained. | **Example** @@ -3536,7 +3546,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.'); }); }); @@ -3626,12 +3636,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'); }); } @@ -3661,7 +3671,7 @@ Deletes data of a device. This API uses a promise to return the result. | Type | Description | | ------ | ------- | -|Promise<void> |Promise used to return the result.| +|Promise<void> |Promise that returns no value.| **Example** @@ -3696,7 +3706,7 @@ try { on(event: 'syncComplete', syncCallback: Callback<Array<[string, number]>>): void -Subscribes to the synchronization completion events. This API uses a synchronous callback to return the result. +Subscribes to the data synchronization complete events. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3704,8 +3714,8 @@ Subscribes to the synchronization completion events. This API uses a synchronous | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| event |string | Yes |Name of the event to subscribe to. The value is **syncComplete**, which indicates the synchronization complete event. | -| syncCallback |Callback<Array<[string, number]>> | Yes |Callback used to return the synchronization result. | +| event |string | Yes |Event to subscribe to. The value is **syncComplete**, which indicates completion of a data synchronization. | +| syncCallback |Callback<Array<[string, number]>> | Yes |Callback invoked to return the synchronization result. | **Example** @@ -3732,7 +3742,7 @@ try { off(event: 'syncComplete', syncCallback?: Callback<Array<[string, number]>>): void -Unsubscribes from the synchronization completion events. This API uses a synchronous callback to return the result. +Unsubscribes from the data synchronization complete events. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3740,7 +3750,7 @@ Unsubscribes from the synchronization completion events. This API uses a synchro | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| event |string | Yes |Name of the event to unsubscribe from. The value is **syncComplete**, which indicates the synchronization complete event. | +| event |string | Yes |Event to unsubscribe from. The value is **syncComplete**, which indicates completion of a data synchronization. | | syncCallback |Callback<Array<[string, number]>> | No |Callback used to return the synchronization result. | **Example** @@ -3763,7 +3773,7 @@ try { sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void -Manually triggers KV store synchronization synchronously. For details about the synchronization mode of the distributed data service, see [Distributed Data Service Overview] (../../database/database-mdds-overview.md). +Synchronizes the KV store manually. For details about the synchronization modes of the distributed data service, see [Distributed Data Service Overview] (../../database/database-mdds-overview.md). **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC @@ -3773,8 +3783,8 @@ Manually triggers KV store synchronization synchronously. For details about the | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| deviceIdList |string[] | Yes |IDs of the devices to be synchronized. These devices must be in the same networking environment. | -| mode |[SyncMode](#syncmode) | Yes |Data synchronization mode. | +| deviceIdList |string[] | Yes |IDs of the devices to be synchronized. These devices must be in the same networking environment. | +| mode |[SyncMode](#syncmode) | Yes |Synchronization mode. | | allowedDelayMs |number | No |Allowed synchronization delay time, in ms. | **Example** @@ -3833,7 +3843,7 @@ Sets the default delay allowed for KV store synchronization. This API uses a pro | Type | Description | | ------ | ------- | -|Promise<void> |Promise used to return the result.| +|Promise<void> |Promise that returns no value.| **Example** @@ -3864,7 +3874,7 @@ Obtains the security level of this KV store. This API uses an asynchronous callb | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| callback |AsyncCallback<[SecurityLevel](#securitylevel)> | Yes |Callback used to return the security level obtained. | +| callback |AsyncCallback<[SecurityLevel](#securitylevel)> | Yes |Callback invoked to return the security level obtained. | **Example** @@ -3892,7 +3902,7 @@ Obtains the security level of this KV store. This API uses a promise to return t | Type | Description | | ------ | ------- | -|Promise<[SecurityLevel](#securitylevel)> |Promise used to return the value obtained.| +|Promise<[SecurityLevel](#securitylevel)> |Promise used to return the security level obtained.| **Example** @@ -3912,13 +3922,19 @@ try { ## DeviceKVStore8+ ## -Provides methods to manage distributed data by device in the distributed system. This class inherits from **KVStore** and provides data query and synchronization methods. Before calling any method in **DeviceKVStore**, you must use [getKVStore](#getkvstore) to obtain a **DeviceKVStore** object. +Provides methods to query and synchronize data in a device KV store. This class inherits from [KVStore](#kvstore). + +Data is distinguished by device in a device KV store. Each device can only write and modify its own data. Data of other devices is read-only and cannot be modified. + +For example, a device KV store can be used to implement image sharing between devices. The images of other devices can be viewed, but not be modified or deleted. + +Before calling any method in **DeviceKVStore**, you must use [getKVStore](#getkvstore) to obtain a **DeviceKVStore** object. ### get8+ ### get(deviceId: string, key: string, callback: AsyncCallback<boolean|string|number|Uint8Array>): void -Obtains the string value that matches the specified key for a device. This API uses an asynchronous callback to return the result. +Obtains a string value that matches the specified device ID and key. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -3953,7 +3969,7 @@ try{ get(deviceId: string, key: string): Promise<boolean|string|number|Uint8Array> -Obtains the string value that matches the specified key for a device. This API uses a promise to return the result. +Obtains a string value that matches the specified device ID and key. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -3968,7 +3984,7 @@ Obtains the string value that matches the specified key for a device. This API u | Type | Description | | ------ | ------- | -|Promise<boolean\|string\|number\|Uint8Array> |Promise used to return the value obtained.| +|Promise<boolean\|string\|number\|Uint8Array> |Promise used to return the string value obtained.| **Example** @@ -3997,7 +4013,7 @@ try { getEntries(deviceId: string, keyPrefix: string, callback: AsyncCallback<Entry[]>): void -Obtains the KV pairs that match the specified key prefix for a device. This API uses an asynchronous callback to return the result. +Obtains all KV pairs that match the specified device ID and key prefix. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4029,7 +4045,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])); @@ -4045,7 +4061,7 @@ try { getEntries(deviceId: string, keyPrefix: string): Promise<Entry[]> -Obtains the KV pairs that match the specified key prefix for a device. This API uses a promise to return the result. +Obtains all KV pairs that match the specified device ID and key prefix. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4082,7 +4098,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])); @@ -4136,11 +4152,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])); @@ -4196,7 +4211,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)); @@ -4215,7 +4230,7 @@ try { getEntries(deviceId: string, query: Query, callback: AsyncCallback<Entry[]>): void -Obtains the KV pairs that match the specified **Query** object for a device. This API uses an asynchronous callback to return the result. +Obtains the KV pairs that match the specified device ID and **Query** object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4225,7 +4240,7 @@ Obtains the KV pairs that match the specified **Query** object for a device. Thi | ----- | ------ | ---- | ----------------------- | | deviceId |string | Yes |ID of the target device. | | query |[Query](#query8) | Yes |**Query** object to match. | -| callback |AsyncCallback<[Entry](#entry)[]> | Yes |Callback used to return the KV pairs obtained. | +| callback |AsyncCallback<[Entry](#entry)[]> | Yes |Callback invoked to return the KV pairs obtained. | **Example** @@ -4248,11 +4263,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])); @@ -4269,7 +4283,7 @@ try { getEntries(deviceId: string, query: Query): Promise<Entry[]> -Obtains the KV pairs that match the specified **Query** object for a device. This API uses a promise to return the result. +Obtains the KV pairs that match the specified device ID and **Query** object. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4310,7 +4324,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)); @@ -4329,7 +4343,7 @@ try { getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback<KvStoreResultSet>): void -Obtains the **KvStoreResultSet** object that matches the specified key prefix for a device. This API uses an asynchronous callback to return the result. +Obtains a **KvStoreResultSet** object that matches the specified device ID and key prefix. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4339,7 +4353,7 @@ Obtains the **KvStoreResultSet** object that matches the specified key prefix fo | ----- | ------ | ---- | ----------------------- | | deviceId |string | Yes |ID of the target device. | | keyPrefix |string | Yes |Key prefix to match. | -| callback |AsyncCallback<[KvStoreResultSet](#kvstoreresultset8)[]> | Yes |Callback used to return the **KvStoreResultSet** object obtained. | +| callback |AsyncCallback<[KvStoreResultSet](#kvstoreresultset8)[]> | Yes |Callback invoked to return the **KvStoreResultSet** object obtained. | **Example** @@ -4350,7 +4364,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'); }) }); @@ -4364,7 +4378,7 @@ try { getResultSet(deviceId: string, keyPrefix: string): Promise<KvStoreResultSet> -Obtains the **KvStoreResultSet** object that matches the specified key prefix for a device. This API uses a promise to return the result. +Obtains a **KvStoreResultSet** object that matches the specified device ID and key prefix. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4408,7 +4422,7 @@ try { getResultSet(query: Query, callback: AsyncCallback<KvStoreResultSet>): void -Obtains the **KvStoreResultSet** object that matches the specified **Query** object. This API uses an asynchronous callback to return the result. +Obtains a **KvStoreResultSet** object that matches the specified **Query** object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4417,7 +4431,7 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | query |[Query](#query8) | Yes |**Query** object to match. | -| callback |AsyncCallback<[KvStoreResultSet](#kvstoreresultset8)[]> | Yes |Callback used to return the **KvStoreResultSet** object obtained. | +| callback |AsyncCallback<[KvStoreResultSet](#kvstoreresultset8)[]> | Yes |Callback invoked to return the **KvStoreResultSet** object obtained. | **Example** @@ -4442,10 +4456,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'); }) }); @@ -4460,7 +4474,7 @@ try { getResultSet(query: Query): Promise<KvStoreResultSet> -Obtains the **KvStoreResultSet** object that matches the specified **Query** object. This API uses a promise to return the result. +Obtains a **KvStoreResultSet** object that matches the specified **Query** object. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4524,7 +4538,7 @@ try { getResultSet(deviceId: string, query: Query, callback: AsyncCallback<KvStoreResultSet>): void -Obtains the **KvStoreResultSet** object that matches the specified **Query** object for a device. This API uses an asynchronous callback to return the result. +Obtains a **KvStoreResultSet** object that matches the specified device ID and **Query** object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4534,7 +4548,7 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj | ----- | ------ | ---- | ----------------------- | | deviceId |string | Yes |ID of the target device. | | query |[Query](#query8) | Yes |**Query** object to match. | -| callback |AsyncCallback<[KvStoreResultSet](#kvstoreresultset8)[]> | Yes |Callback used to return the **KvStoreResultSet** object obtained. | +| callback |AsyncCallback<[KvStoreResultSet](#kvstoreresultset8)[]> | Yes |Callback invoked to return the **KvStoreResultSet** object obtained. | **Example** @@ -4558,10 +4572,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'); }) }); @@ -4576,7 +4590,7 @@ try { getResultSet(deviceId: string, query: Query): Promise<KvStoreResultSet> -Obtains the **KvStoreResultSet** object that matches the specified **Query** object for a device. This API uses a promise to return the result. +Obtains a **KvStoreResultSet** object that matches the specified device ID and **Query** object. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4691,7 +4705,7 @@ Closes the **KvStoreResultSet** object obtained by [DeviceKVStore.getResultSet]( | Type | Description | | ------ | ------- | -|Promise<void> |Promise used to return the result.| +|Promise<void> |Promise that returns no value.| **Example** @@ -4724,7 +4738,7 @@ Obtains the number of results that matches the specified **Query** object. This | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | query |[Query](#query8) | Yes |**Query** object to match. | -| callback |AsyncCallback<number> | Yes |Callback used to return the number of results obtained. | +| callback |AsyncCallback<number> | Yes |Callback invoked to return the number of results obtained. | **Example** @@ -4748,7 +4762,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.'); }); }); @@ -4818,7 +4832,7 @@ try { getResultSize(deviceId: string, query: Query, callback: AsyncCallback<number>): void; -Obtains the number of results that matches the specified **Query** object for a device. This API uses an asynchronous callback to return the result. +Obtains the number of results that matches the specified device ID and **Query** object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4828,7 +4842,7 @@ Obtains the number of results that matches the specified **Query** object for a | ----- | ------ | ---- | ----------------------- | | deviceId |string | Yes |ID of the target device. | | query |[Query](#query8) | Yes |**Query** object to match. | -| callback |AsyncCallback<number> | Yes |Callback used to return the number of results obtained. | +| callback |AsyncCallback<number> | Yes |Callback invoked to return the number of results obtained. | **Example** @@ -4851,7 +4865,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.'); }); }); @@ -4865,7 +4879,7 @@ try { getResultSize(deviceId: string, query: Query): Promise<number> -Obtains the number of results that matches the specified **Query** object for a device. This API uses a promise to return the result. +Obtains the number of results that matches the specified device ID and **Query** object. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4921,7 +4935,7 @@ try { removeDeviceData(deviceId: string, callback: AsyncCallback<void>): void -Removes data of a device from this KV store. This API uses an asynchronous callback to return the result. +Deletes data of the specified device from this KV store. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4942,12 +4956,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'); }); } @@ -4963,7 +4977,7 @@ try { removeDeviceData(deviceId: string): Promise<void> -Removes data of a device from this KV store. This API uses a promise to return the result. +Deletes data of the specified device from this KV store. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4977,7 +4991,7 @@ Removes data of a device from this KV store. This API uses a promise to return t | Type | Description | | ------ | ------- | -|Promise<void> |Promise used to return the result.| +|Promise<void> |Promise that returns no value.| **Example** @@ -5012,7 +5026,7 @@ try { sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void -Manually triggers KV store synchronization synchronously. For details about the synchronization mode of the distributed data service, see [Distributed Data Service Overview] (../../database/database-mdds-overview.md). +Synchronizes the KV store manually. For details about the synchronization modes of the distributed data service, see [Distributed Data Service Overview] (../../database/database-mdds-overview.md). **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC @@ -5051,7 +5065,7 @@ try { on(event: 'syncComplete', syncCallback: Callback<Array<[string, number]>>): void -Subscribes to the synchronization completion events. This API uses a synchronous callback to return the result. +Subscribes to the data synchronization complete events. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -5059,12 +5073,13 @@ Subscribes to the synchronization completion events. This API uses a synchronous | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| event |string | Yes |Name of the event to subscribe to. The value is **syncComplete**, which indicates the synchronization complete event.| +| event |string | Yes |Event to subscribe to. The value is **syncComplete**, which indicates the data synchronization complete event.| | syncCallback |Callback | Yes |Callback used to return the synchronization result. | **Example** ```js +let kvStore; const KEY_TEST_FLOAT_ELEMENT = 'key_test_float'; const VALUE_TEST_FLOAT_ELEMENT = 321.12; try { @@ -5086,7 +5101,7 @@ try { off(event: 'syncComplete', syncCallback?: Callback<Array<[string, number]>>): void -Unsubscribes from the synchronization completion events. This API uses a synchronous callback to return the result. +Unsubscribes from the synchronization complete events. This API uses a synchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -5094,7 +5109,7 @@ Unsubscribes from the synchronization completion events. This API uses a synchro | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| event |string | Yes |Name of the event to unsubscribe from. The value is **syncComplete**, which indicates the synchronization complete event.| +| event |string | Yes |Event to unsubscribe from. The value is **syncComplete**, which indicates the data synchronization complete event.| | syncCallback |Callback