提交 ecb8bf73 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 a4fbbf90
# Distributed Data Management # 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.
- [KvStoreResultSet<sup>8+</sup>](#kvstoreresultset8): provides methods to obtain the KV store result set and query or move the data read position.
- [Query<sup>8+</sup>](#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.
- [DeviceKVStore<sup>8+</sup> ](#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**<br/> >**NOTE**<br/>
> >
...@@ -18,7 +27,7 @@ import distributedData from '@ohos.data.distributedData'; ...@@ -18,7 +27,7 @@ import distributedData from '@ohos.data.distributedData';
createKVManager(config: KVManagerConfig, callback: AsyncCallback&lt;KVManager&gt;): void createKVManager(config: KVManagerConfig, callback: AsyncCallback&lt;KVManager&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -26,8 +35,8 @@ Creates a **KVManager** object to manage key-value (KV) stores. This API uses an ...@@ -26,8 +35,8 @@ Creates a **KVManager** object to manage key-value (KV) stores. This API uses an
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ----- | ------ | ------ | ------ | | ----- | ------ | ------ | ------ |
| config | [KVManagerConfig](#kvmanagerconfig) | Yes | Configuration of the **KVManager** object, including the bundle name and user information of the caller.| | config | [KVManagerConfig](#kvmanagerconfig) | Yes | Configuration of the **KVManager** instance, including the bundle name and user information of the caller.|
| callback | AsyncCallback&lt;[KVManager](#kvmanager)&gt; | Yes | Callback invoked to return the **KVManager** object created.| | callback | AsyncCallback&lt;[KVManager](#kvmanager)&gt; | Yes | Callback invoked to return the **KVManager** instance created.|
**Example** **Example**
```js ```js
...@@ -57,7 +66,7 @@ try { ...@@ -57,7 +66,7 @@ try {
createKVManager(config: KVManagerConfig): Promise&lt;KVManager&gt; createKVManager(config: KVManagerConfig): Promise&lt;KVManager&gt;
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 **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 ...@@ -65,13 +74,13 @@ Creates a **KVManager** object to manage KV stores. This API uses a promise to r
| Name| Type| Mandatory| Description| | 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** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[KVManager](#kvmanager)&gt; | Promise used to return the **KVManager** object created.| | Promise&lt;[KVManager](#kvmanager)&gt; | Promise used to return the **KVManager** instance created.|
**Example** **Example**
...@@ -121,11 +130,11 @@ Defines user information. ...@@ -121,11 +130,11 @@ Defines user information.
## UserType ## UserType
Defines the user type. Enumerates the user types.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **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.| | 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. ...@@ -198,7 +207,7 @@ Creates and obtains a KV store. This API uses a promise to return the result.
| Type | Description | | Type | Description |
| -------------------------------------- | ------------------------ | | -------------------------------------- | ------------------------ |
| Promise&lt;T&gt; &lt;T extends [KVStore](#kvstore)&gt; | Promise used to return the KV store created.| | Promise&lt;T&gt;, &lt;T extends [KVStore](#kvstore)&gt; | Promise used to return the KV store created.|
**Example** **Example**
...@@ -241,7 +250,7 @@ Closes a KV store. This API uses an asynchronous callback to return the result. ...@@ -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. | | 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).| | 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. | | kvStore | [KVStore](#kvstore) | Yes | KV store to close. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the KV store is closed, **true** will be returned. Otherwise, **false** will be returned. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -261,7 +270,7 @@ const options = { ...@@ -261,7 +270,7 @@ const options = {
kvManager.getKVStore('storeId', options, async function (err, store) { kvManager.getKVStore('storeId', options, async function (err, store) {
console.log('getKVStore success'); console.log('getKVStore success');
kvStore = store; kvStore = store;
await kvManager.closeKVStore('appId', 'storeId', kvStore, function (err, data) { kvManager.closeKVStore('appId', 'storeId', kvStore, function (err, data) {
console.log('closeKVStore success'); console.log('closeKVStore success');
}); });
}); });
...@@ -291,7 +300,7 @@ Closes a KV store. This API uses a promise to return the result. ...@@ -291,7 +300,7 @@ Closes a KV store. This API uses a promise to return the result.
| Type | Description | | Type | Description |
| ------------- | -------------- | | ------------- | -------------- |
| Promise\<void> | Promise used to return the result. If the KV store is closed, **true** will be returned. Otherwise, **false** will be returned.| | Promise\<void> | Promise that returns no value.|
**Example** **Example**
...@@ -311,7 +320,7 @@ const options = { ...@@ -311,7 +320,7 @@ const options = {
kvManager.getKVStore('storeId', options).then(async (store) => { kvManager.getKVStore('storeId', options).then(async (store) => {
console.log('getKVStore success'); console.log('getKVStore success');
kvStore = store; kvStore = store;
await kvManager.closeKVStore('appId', 'storeId', kvStore).then(() => { kvManager.closeKVStore('appId', 'storeId', kvStore).then(() => {
console.log('closeKVStore success'); console.log('closeKVStore success');
}).catch((err) => { }).catch((err) => {
console.log('closeKVStore err ' + JSON.stringify(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. ...@@ -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. | | 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).| | storeId | string | Yes | Unique identifier of the KV store to delete. The length cannot exceed [MAX_STORE_ID_LENGTH](#constants).|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the KV store is deleted, **true** will be returned. Otherwise, **false** will be returned. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -359,7 +368,7 @@ try { ...@@ -359,7 +368,7 @@ try {
kvManager.getKVStore('store', options, async function (err, store) { kvManager.getKVStore('store', options, async function (err, store) {
console.log('getKVStore success'); console.log('getKVStore success');
kvStore = store; kvStore = store;
await kvManager.deleteKVStore('appId', 'storeId', function (err, data) { kvManager.deleteKVStore('appId', 'storeId', function (err, data) {
console.log('deleteKVStore success'); console.log('deleteKVStore success');
}); });
}); });
...@@ -388,7 +397,7 @@ Deletes a KV store. This API uses a promise to return the result. ...@@ -388,7 +397,7 @@ Deletes a KV store. This API uses a promise to return the result.
| Type | Description | | Type | Description |
| ------------- | -------------- | | ------------- | -------------- |
| Promise&lt;void&gt; | Promise used to return the result. If the KV store is deleted, **true** will be returned. Otherwise, **false** will be returned.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -408,7 +417,7 @@ try { ...@@ -408,7 +417,7 @@ try {
kvManager.getKVStore('storeId', options).then(async (store) => { kvManager.getKVStore('storeId', options).then(async (store) => {
console.log('getKVStore success'); console.log('getKVStore success');
kvStore = store; kvStore = store;
await kvManager.deleteKVStore('appId', 'storeId').then(() => { kvManager.deleteKVStore('appId', 'storeId').then(() => {
console.log('deleteKVStore success'); console.log('deleteKVStore success');
}).catch((err) => { }).catch((err) => {
console.log('deleteKVStore err ' + JSON.stringify(err)); console.log('deleteKVStore err ' + JSON.stringify(err));
...@@ -426,7 +435,7 @@ try { ...@@ -426,7 +435,7 @@ try {
getAllKVStoreId(appId: string, callback: AsyncCallback&lt;string[]&gt;): void getAllKVStoreId(appId: string, callback: AsyncCallback&lt;string[]&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -435,7 +444,7 @@ Obtains the IDs of all the KV stores that are created using [getKVStore](#getkvs ...@@ -435,7 +444,7 @@ Obtains the IDs of all the KV stores that are created using [getKVStore](#getkvs
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| appId | string | Yes | Bundle name of the app that invokes the KV store. | | appId | string | Yes | Bundle name of the app that invokes the KV store. |
| callback | AsyncCallback&lt;void&gt; | Yes |Callback used to return the KV store IDs obtained. | | callback | AsyncCallback&lt;string[]&gt; | Yes |Callback used to return the KV store IDs obtained. |
**Example** **Example**
...@@ -456,7 +465,7 @@ try { ...@@ -456,7 +465,7 @@ try {
getAllKVStoreId(appId: string): Promise&lt;string[]&gt; getAllKVStoreId(appId: string): Promise&lt;string[]&gt;
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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -495,7 +504,7 @@ try { ...@@ -495,7 +504,7 @@ try {
on(event: 'distributedDataServiceDie', deathCallback: Callback&lt;void&gt;): void on(event: 'distributedDataServiceDie', deathCallback: Callback&lt;void&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -503,8 +512,8 @@ Subscribes to the **distributedDataServiceDie** events. This API uses a synchron ...@@ -503,8 +512,8 @@ Subscribes to the **distributedDataServiceDie** events. This API uses a synchron
| Name | Type| Mandatory | Description | | 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.| | event | string | Yes | Event to subscribe to. The value is **distributedDataServiceDie**, which indicates service status changes.|
| deathCallback | Callback&lt;void&gt; | Yes | Callback invoked when the distributed data service is dead. | | deathCallback | Callback&lt;void&gt; | Yes | Callback invoked to return service status changes.|
**Example** **Example**
...@@ -527,7 +536,7 @@ try { ...@@ -527,7 +536,7 @@ try {
off(event: 'distributedDataServiceDie', deathCallback?: Callback&lt;void&gt;): void off(event: 'distributedDataServiceDie', deathCallback?: Callback&lt;void&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -535,8 +544,8 @@ Unsubscribes from the **distributedDataServiceDie** events. This API uses a sync ...@@ -535,8 +544,8 @@ Unsubscribes from the **distributedDataServiceDie** events. This API uses a sync
| Name | Type| Mandatory | Description | | 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.| | event | string | Yes | Event to unsubscribe from. The value is **distributedDataServiceDie**, which indicates service status changes.|
| deathCallback | Callback&lt;void&gt; | No | Callback used to return the **distributedDataServiceDie** events. | | deathCallback | Callback&lt;void&gt; | No | Callback used to return service status changes.|
**Example** **Example**
...@@ -562,41 +571,41 @@ Provides KV store configuration. ...@@ -562,41 +571,41 @@ Provides KV store configuration.
| Name | Type| Mandatory | Description | | 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. <br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | | createIfMissing | boolean | No| Whether to create a KV store if no database file exists. By default, a KV store is created.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core |
| encrypt | boolean | No|Whether to encrypt database files. By default, database files are not encrypted. <br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | | encrypt | boolean | No|Whether to encrypt database files. By default, database files are not encrypted.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core |
| backup | boolean | No|Whether to back up database files. By default, database files are backed up. <br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | | backup | boolean | No|Whether to back up database files. By default, database files are backed up. <br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core |
| autoSync | boolean | No|Whether to automatically synchronize database files. By default, database files are not automatically synchronized.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core <br>**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC | | autoSync | boolean | No|Whether database files are automatically synchronized. By default, database files are not automatically synchronized.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core<br>**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.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | | 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.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core|
| securityLevel | [SecurityLevel](#securitylevel) | No|Security level of the KV store. By default, the security level is not set.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | | securityLevel | [SecurityLevel](#securitylevel) | No|Security level of the KV store. By default, the security level is not set.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core |
| schema<sup>8+</sup> | [Schema](#schema8) | No| Schema used to define the values stored in a KV store.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore | | schema<sup>8+</sup> | [Schema](#schema8) | No| Schema used to define the values stored in a KV store.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore|
## KVStoreType ## KVStoreType
Defines the KV store types. Enumerates the KV store types.
| Name | Default Value| Description | | Name | Value| Description |
| --- | ---- | ----------------------- | | --- | ---- | ----------------------- |
| DEVICE_COLLABORATION | 0 | Device KV store. <br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore | | DEVICE_COLLABORATION | 0 | Device KV store.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore |
| SINGLE_VERSION | 1 | Single KV store.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | | SINGLE_VERSION | 1 | Single KV store.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core|
| MULTI_VERSION | 2 | Multi-version KV store. This type is not supported currently. <br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore| | MULTI_VERSION | 2 | Multi-version KV store. This type is not supported currently.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore|
## SecurityLevel ## SecurityLevel
Defines the KV store security levels. Enumerates the KV store security levels.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **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. | | NO_LEVEL | 0 | No security level is set for the KV store. |
| S0 | 1 | The KV store security level is public. | | 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. | | 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. | | 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. | | 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. | | 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 ## Constants
...@@ -605,18 +614,18 @@ Defines the KV store constants. ...@@ -605,18 +614,18 @@ Defines the KV store constants.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **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_KEY_LENGTH | 1024 | Maximum length of a key in the KV store, in bytes. |
| MAX_VALUE_LENGTH | 4194303 | Maximum length (in bytes) of a value in the KV store. | | MAX_VALUE_LENGTH | 4194303 | Maximum length of a value in the KV store, in bytes. |
| MAX_KEY_LENGTH_DEVICE | 896 | Maximum length of the device coordinate key, in bytes.| | MAX_KEY_LENGTH_DEVICE | 896 | Maximum length of a device key, in bytes.|
| MAX_STORE_ID_LENGTH | 128 | Maximum length (in bytes) of a KV store ID. | | MAX_STORE_ID_LENGTH | 128 | Maximum length of a KV store ID, in bytes. |
| MAX_QUERY_LENGTH | 512000 | Maximum query length, in bytes.| | MAX_QUERY_LENGTH | 512000 | Maximum query length, in bytes.|
| MAX_BATCH_SIZE | 128 | Maximum number of batch operations.| | MAX_BATCH_SIZE | 128 | Maximum number of batch operations.|
## Schema<sup>8+</sup> ## ## Schema<sup>8+</sup> ##
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 **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -645,7 +654,7 @@ Represents a **Schema** instance, which provides the methods for defining the va ...@@ -645,7 +654,7 @@ Represents a **Schema** instance, which provides the methods for defining the va
| --- | ---- | ----------------------- | | --- | ---- | ----------------------- |
| nullable<sup>8+</sup> | boolean | Whether the database field can be null. | | nullable<sup>8+</sup> | boolean | Whether the database field can be null. |
| default<sup>8+</sup> | string | Default value of a **FieldNode**.| | default<sup>8+</sup> | string | Default value of a **FieldNode**.|
| type<sup>8+</sup> | number | Value to store.| | type<sup>8+</sup> | number | Value of the data type corresponding to the specified node.|
### constructor<sup>8+</sup> ### ### constructor<sup>8+</sup> ###
...@@ -693,7 +702,7 @@ try { ...@@ -693,7 +702,7 @@ try {
node.appendChild(child1); node.appendChild(child1);
node.appendChild(child2); node.appendChild(child2);
node.appendChild(child3); node.appendChild(child3);
console.log("appendNode " + node.toJson()); console.log("appendNode " + JSON.stringify(node));
child1 = null; child1 = null;
child2 = null; child2 = null;
child3 = null; child3 = null;
...@@ -706,14 +715,16 @@ try { ...@@ -706,14 +715,16 @@ try {
## KvStoreResultSet<sup>8+</sup> ## ## KvStoreResultSet<sup>8+</sup> ##
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.
### getCount<sup>8+</sup> ### ### getCount<sup>8+</sup> ###
getCount(): number 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -721,7 +732,7 @@ Obtains the number of rows in the result set. ...@@ -721,7 +732,7 @@ Obtains the number of rows in the result set.
| Type | Description | | Type | Description |
| ------ | -------------- | | ------ | -------------- |
| number |Number of rows obtained. | | number |Total number of rows obtained. |
**Example** **Example**
...@@ -780,7 +791,7 @@ try { ...@@ -780,7 +791,7 @@ try {
moveToFirst(): boolean 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -814,7 +825,7 @@ try { ...@@ -814,7 +825,7 @@ try {
moveToLast(): boolean 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -848,7 +859,7 @@ try { ...@@ -848,7 +859,7 @@ try {
moveToNext(): boolean 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -882,7 +893,7 @@ try { ...@@ -882,7 +893,7 @@ try {
moveToPrevious(): boolean 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -1071,7 +1082,7 @@ Checks whether the data read position is before the first row. ...@@ -1071,7 +1082,7 @@ Checks whether the data read position is before the first row.
| Type | Description | | 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** **Example**
...@@ -1131,7 +1142,7 @@ try { ...@@ -1131,7 +1142,7 @@ try {
getEntry(): Entry getEntry(): Entry
Obtains a KV pair. Obtains the KV pair from the current position.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -1180,7 +1191,7 @@ A constructor used to create a **Schema** instance. ...@@ -1180,7 +1191,7 @@ A constructor used to create a **Schema** instance.
reset(): Query reset(): Query
Resets the **Query** object that contains common query options. Resets the **Query** object.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -1211,7 +1222,7 @@ try { ...@@ -1211,7 +1222,7 @@ try {
equalTo(field: string, value: number|string|boolean): Query 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -1226,7 +1237,7 @@ Creates a **Query** object to match the specified field whose value is equal to ...@@ -1226,7 +1237,7 @@ Creates a **Query** object to match the specified field whose value is equal to
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object reset.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1237,7 +1248,7 @@ try { ...@@ -1237,7 +1248,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("duplicated calls should be ok :" + e);
} }
``` ```
...@@ -1272,7 +1283,7 @@ try { ...@@ -1272,7 +1283,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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 ...@@ -1296,7 +1307,7 @@ Creates a **Query** object to match the specified field whose value is greater t
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1307,7 +1318,7 @@ try { ...@@ -1307,7 +1318,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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 ...@@ -1331,7 +1342,7 @@ Creates a **Query** object to match the specified field whose value is less than
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1342,7 +1353,7 @@ try { ...@@ -1342,7 +1353,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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 ...@@ -1366,7 +1377,7 @@ Creates a **Query** object to match the specified field whose value is greater t
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1377,7 +1388,7 @@ try { ...@@ -1377,7 +1388,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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 ...@@ -1401,7 +1412,7 @@ Creates a **Query** object to match the specified field whose value is less than
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1412,7 +1423,7 @@ try { ...@@ -1412,7 +1423,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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 ...@@ -1423,7 +1434,6 @@ isNull(field: string): Query
Creates a **Query** object to match the specified field whose value is **null**. Creates a **Query** object to match the specified field whose value is **null**.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters** **Parameters**
...@@ -1436,7 +1446,7 @@ Creates a **Query** object to match the specified field whose value is **null**. ...@@ -1436,7 +1446,7 @@ Creates a **Query** object to match the specified field whose value is **null**.
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1447,7 +1457,7 @@ try { ...@@ -1447,7 +1457,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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 ...@@ -1472,7 +1482,7 @@ Creates a **Query** object to match the specified field whose value is within th
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1483,7 +1493,7 @@ try { ...@@ -1483,7 +1493,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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 ...@@ -1507,7 +1517,7 @@ Creates a **Query** object to match the specified field whose value is within th
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1518,7 +1528,7 @@ try { ...@@ -1518,7 +1528,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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 ...@@ -1542,7 +1552,7 @@ Creates a **Query** object to match the specified field whose value is not withi
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1553,7 +1563,7 @@ try { ...@@ -1553,7 +1563,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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 ...@@ -1577,7 +1587,7 @@ Creates a **Query** object to match the specified field whose value is not withi
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1588,7 +1598,7 @@ try { ...@@ -1588,7 +1598,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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 ...@@ -1605,14 +1615,14 @@ Creates a **Query** object to match the specified field whose value is similar t
| Name | Type| Mandatory | Description | | 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.| | value | string | Yes | String specified.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1623,7 +1633,7 @@ try { ...@@ -1623,7 +1633,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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 ...@@ -1647,7 +1657,7 @@ Creates a **Query** object to match the specified field whose value is not simil
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1658,7 +1668,7 @@ try { ...@@ -1658,7 +1668,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("duplicated calls should be ok :" + e);
} }
``` ```
...@@ -1688,7 +1698,7 @@ try { ...@@ -1688,7 +1698,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("duplicated calls should be ok :" + e);
} }
``` ```
...@@ -1718,7 +1728,7 @@ try { ...@@ -1718,7 +1728,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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. ...@@ -1741,7 +1751,7 @@ Creates a **Query** object to sort the query results in ascending order.
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1753,7 +1763,7 @@ try { ...@@ -1753,7 +1763,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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. ...@@ -1776,7 +1786,7 @@ Creates a **Query** object to sort the query results in descending order.
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1788,7 +1798,7 @@ try { ...@@ -1788,7 +1798,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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. ...@@ -1812,7 +1822,7 @@ Creates a **Query** object to specify the number of results and where to start.
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1824,7 +1834,7 @@ try { ...@@ -1824,7 +1834,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("duplicated calls should be ok :" + e);
} }
``` ```
...@@ -1833,7 +1843,7 @@ try { ...@@ -1833,7 +1843,7 @@ try {
isNotNull(field: string): Query 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -1841,13 +1851,13 @@ Creates a **Query** object with a specified field that is not null. ...@@ -1841,13 +1851,13 @@ Creates a **Query** object with a specified field that is not null.
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field specified. | | fieId | string | Yes |Field to match. It cannot contain '^'. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1858,7 +1868,7 @@ try { ...@@ -1858,7 +1868,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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. ...@@ -1875,7 +1885,7 @@ Creates a **Query** object for a query condition group with a left parenthesis.
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1888,7 +1898,7 @@ try { ...@@ -1888,7 +1898,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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. ...@@ -1905,7 +1915,7 @@ Creates a **Query** object for a query condition group with a right parenthesis.
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1918,7 +1928,7 @@ try { ...@@ -1918,7 +1928,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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. ...@@ -1941,7 +1951,7 @@ Creates a **Query** object with a specified key prefix.
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1953,7 +1963,7 @@ try { ...@@ -1953,7 +1963,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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. ...@@ -1976,7 +1986,7 @@ Creates a **Query** object with an index preferentially used for query.
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -1988,7 +1998,7 @@ try { ...@@ -1988,7 +1998,7 @@ try {
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } 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. ...@@ -2012,7 +2022,7 @@ Creates a **Query** object with the device ID as the key prefix.
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object created.|
**Example** **Example**
...@@ -2049,14 +2059,16 @@ try { ...@@ -2049,14 +2059,16 @@ try {
let sql1 = query.getSqlLike(); let sql1 = query.getSqlLike();
console.log("GetSqlLike sql=" + sql1); console.log("GetSqlLike sql=" + sql1);
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok : " + e); console.log("duplicated calls should be ok : " + e);
} }
``` ```
## KVStore ## 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 ### put
...@@ -2113,7 +2125,7 @@ Adds a KV pair of the specified type to this KV store. This API uses a promise t ...@@ -2113,7 +2125,7 @@ Adds a KV pair of the specified type to this KV store. This API uses a promise t
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| Promise&lt;void&gt; |Promise used to return the result.| | Promise&lt;void&gt; |Promise that returns no value.|
**Example** **Example**
...@@ -2132,7 +2144,6 @@ try { ...@@ -2132,7 +2144,6 @@ try {
} }
``` ```
### delete ### delete
delete(key: string, callback: AsyncCallback&lt;void&gt;): void delete(key: string, callback: AsyncCallback&lt;void&gt;): void
...@@ -2174,7 +2185,6 @@ try { ...@@ -2174,7 +2185,6 @@ try {
} }
``` ```
### delete ### delete
delete(key: string): Promise&lt;void&gt; delete(key: string): Promise&lt;void&gt;
...@@ -2193,7 +2203,7 @@ Deletes a KV pair from this KV store. This API uses a promise to return the resu ...@@ -2193,7 +2203,7 @@ Deletes a KV pair from this KV store. This API uses a promise to return the resu
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| Promise&lt;void&gt; |Promise used to return the result.| | Promise&lt;void&gt; |Promise that returns no value.|
**Example** **Example**
...@@ -2216,13 +2226,11 @@ try { ...@@ -2216,13 +2226,11 @@ try {
console.log("An unexpected error occurred. Error:" + e); console.log("An unexpected error occurred. Error:" + e);
} }
``` ```
### on('dataChange') ### on('dataChange')
on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;ChangeNotification&gt;): void on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;ChangeNotification&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -2230,9 +2238,9 @@ Subscribes to data changes of the specified type. This API uses a synchronous ca ...@@ -2230,9 +2238,9 @@ Subscribes to data changes of the specified type. This API uses a synchronous ca
| Name | Type| Mandatory | Description | | 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. | | type |[SubscribeType](#subscribetype) | Yes |Type of data changes. |
| observer |Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes |Callback used to return the result.| | observer |Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes |Callback used to return the data changes.|
**Example** **Example**
...@@ -2248,7 +2256,7 @@ kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, fun ...@@ -2248,7 +2256,7 @@ kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, fun
on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -2256,8 +2264,8 @@ Subscribes to data synchronization completion events. This API uses a synchronou ...@@ -2256,8 +2264,8 @@ Subscribes to data synchronization completion events. This API uses a synchronou
| Name | Type| Mandatory | Description | | 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 completion of a data synchronization. |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | Yes |Callback used to return the result. | | syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | Yes |Callback used to return the data synchronization result. |
**Example** **Example**
...@@ -2272,7 +2280,7 @@ kvStore.on('syncComplete', function (data) { ...@@ -2272,7 +2280,7 @@ kvStore.on('syncComplete', function (data) {
off(event:'dataChange', observer?: Callback&lt;ChangeNotification&gt;): void off(event:'dataChange', observer?: Callback&lt;ChangeNotification&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -2280,8 +2288,8 @@ Unsubscribes from data change events. This API uses a synchronous callback to re ...@@ -2280,8 +2288,8 @@ Unsubscribes from data change events. This API uses a synchronous callback to re
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Name of the event to unsubscribe from. The value is **dataChange**, which indicates the data change event. | | event |string | Yes |Event to unsubscribe from. The value is **dataChange**, which indicates data changes. |
| observer |Callback&lt;[ChangeNotification](#changenotification)&gt; |No |Callback used to return the result.| | observer |Callback&lt;[ChangeNotification](#changenotification)&gt; |No |Callback used to return the data changes.|
**Example** **Example**
...@@ -2331,14 +2339,14 @@ try { ...@@ -2331,14 +2339,14 @@ try {
console.log('entries: ' + JSON.stringify(entries)); console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) { kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success'); 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('getEntries success');
console.log('entrys.length: ' + entrys.length); console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0])); console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
}); });
}); });
}catch(e) { }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 ...@@ -2361,7 +2369,7 @@ Inserts KV pairs in batches to this KV store. This API uses a promise to return
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| Promise&lt;void&gt; |Promise used to return the result.| | Promise&lt;void&gt; |Promise that returns no value.|
**Example** **Example**
...@@ -2383,7 +2391,7 @@ try { ...@@ -2383,7 +2391,7 @@ try {
console.log('entries: ' + JSON.stringify(entries)); console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries).then(async (err) => { kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success'); 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('getEntries success');
console.log('PutBatch ' + JSON.stringify(entries)); console.log('PutBatch ' + JSON.stringify(entries));
}).catch((err) => { }).catch((err) => {
...@@ -2393,7 +2401,7 @@ try { ...@@ -2393,7 +2401,7 @@ try {
console.log('putBatch fail ' + JSON.stringify(err)); console.log('putBatch fail ' + JSON.stringify(err));
}); });
}catch(e) { }catch(e) {
console.log('PutBatch e ' + e); console.log('PutBatch e ' + JSON.stringify(e));
} }
``` ```
...@@ -2435,7 +2443,7 @@ try { ...@@ -2435,7 +2443,7 @@ try {
console.log('entries: ' + JSON.stringify(entries)); console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) { kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success'); console.log('putBatch success');
await kvStore.deleteBatch(keys, async function (err,data) { kvStore.deleteBatch(keys, async function (err,data) {
console.log('deleteBatch success'); console.log('deleteBatch success');
}); });
}); });
...@@ -2463,7 +2471,7 @@ Deletes KV pairs in batches from this KV store. This API uses a promise to retur ...@@ -2463,7 +2471,7 @@ Deletes KV pairs in batches from this KV store. This API uses a promise to retur
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| Promise&lt;void&gt; |Promise used to return the result.| | Promise&lt;void&gt; |Promise that returns no value.|
**Example** **Example**
...@@ -2487,7 +2495,7 @@ try { ...@@ -2487,7 +2495,7 @@ try {
console.log('entries: ' + JSON.stringify(entries)); console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries).then(async (err) => { kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success'); console.log('putBatch success');
await kvStore.deleteBatch(keys).then((err) => { kvStore.deleteBatch(keys).then((err) => {
console.log('deleteBatch success'); console.log('deleteBatch success');
}).catch((err) => { }).catch((err) => {
console.log('deleteBatch fail ' + JSON.stringify(err)); console.log('deleteBatch fail ' + JSON.stringify(err));
...@@ -2543,7 +2551,7 @@ try { ...@@ -2543,7 +2551,7 @@ try {
console.log('startTransaction success'); console.log('startTransaction success');
let entries = putBatchString(10, 'batch_test_string_key'); let entries = putBatchString(10, 'batch_test_string_key');
console.log('entries: ' + JSON.stringify(entries)); 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'); console.log('putBatch success');
}); });
}); });
...@@ -2565,7 +2573,7 @@ Starts the transaction in this KV store. This API uses a promise to return the r ...@@ -2565,7 +2573,7 @@ Starts the transaction in this KV store. This API uses a promise to return the r
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| Promise&lt;void&gt; |Promise used to return the result.| | Promise&lt;void&gt; |Promise that returns no value.|
**Example** **Example**
...@@ -2632,7 +2640,7 @@ Commits the transaction in this KV store. This API uses a promise to return the ...@@ -2632,7 +2640,7 @@ Commits the transaction in this KV store. This API uses a promise to return the
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| Promise&lt;void&gt; |Promise used to return the result.| | Promise&lt;void&gt; |Promise that returns no value.|
**Example** **Example**
...@@ -2694,7 +2702,7 @@ Rolls back the transaction in this KV store. This API uses a promise to return t ...@@ -2694,7 +2702,7 @@ Rolls back the transaction in this KV store. This API uses a promise to return t
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| Promise&lt;void&gt; |Promise used to return the result.| | Promise&lt;void&gt; |Promise that returns no value.|
**Example** **Example**
...@@ -2716,7 +2724,7 @@ try { ...@@ -2716,7 +2724,7 @@ try {
enableSync(enabled: boolean, callback: AsyncCallback&lt;void&gt;): void enableSync(enabled: boolean, callback: AsyncCallback&lt;void&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -2749,7 +2757,7 @@ try { ...@@ -2749,7 +2757,7 @@ try {
enableSync(enabled: boolean): Promise&lt;void&gt; enableSync(enabled: boolean): Promise&lt;void&gt;
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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -2763,7 +2771,7 @@ Enables or disables data synchronization. This API uses a promise to return the ...@@ -2763,7 +2771,7 @@ Enables or disables data synchronization. This API uses a promise to return the
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| Promise&lt;void&gt; |Promise used to return the result.| | Promise&lt;void&gt; |Promise that returns no value.|
**Example** **Example**
...@@ -2833,7 +2841,7 @@ Sets the data synchronization range. This API uses a promise to return the resul ...@@ -2833,7 +2841,7 @@ Sets the data synchronization range. This API uses a promise to return the resul
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| Promise&lt;void&gt; |Promise used to return the result.| | Promise&lt;void&gt; |Promise that returns no value.|
**Example** **Example**
...@@ -2855,11 +2863,11 @@ try { ...@@ -2855,11 +2863,11 @@ try {
## SubscribeType ## SubscribeType
Defines the subscription type. Enumerates the subscription types.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
| Name | Default Value | Description | | Name | Value | Description |
| ----- | ------ | ----------------------- | | ----- | ------ | ----------------------- |
| SUBSCRIBE_TYPE_LOCAL |0 |Local data changes. | | SUBSCRIBE_TYPE_LOCAL |0 |Local data changes. |
| SUBSCRIBE_TYPE_REMOTE |1 |Remote data changes. | | SUBSCRIBE_TYPE_REMOTE |1 |Remote data changes. |
...@@ -2892,7 +2900,7 @@ Defines the KV pairs stored in the KV store. ...@@ -2892,7 +2900,7 @@ Defines the KV pairs stored in the KV store.
## Value ## Value
Defines the value in a KV pair. Defines the **value** object in a KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -2903,13 +2911,11 @@ Defines the value in a KV pair. ...@@ -2903,13 +2911,11 @@ Defines the value in a KV pair.
## ValueType ## ValueType
Enumerates the types of values in KV pairs. Enumerates the data types.
These value types can be used only by internal applications.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
| Name | Default Value | Description | | Name | Value | Description |
| ----- | ------ | ----------------------- | | ----- | ------ | ----------------------- |
| STRING |0 |String. | | STRING |0 |String. |
| INTEGER |1 |Integer. | | INTEGER |1 |Integer. |
...@@ -2918,16 +2924,19 @@ These value types can be used only by internal applications. ...@@ -2918,16 +2924,19 @@ These value types can be used only by internal applications.
| BOOLEAN |4 |Boolean. | | BOOLEAN |4 |Boolean. |
| DOUBLE |5 |Double (double-precision floating point). | | DOUBLE |5 |Double (double-precision floating point). |
## SingleKVStore ## 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
get(key: string, callback: AsyncCallback&lt;Uint8Array | string | boolean | number&gt;): void get(key: string, callback: AsyncCallback&lt;Uint8Array | string | boolean | number&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -2936,7 +2945,7 @@ Obtains the value of a specified key. This API uses an asynchronous callback to ...@@ -2936,7 +2945,7 @@ Obtains the value of a specified key. This API uses an asynchronous callback to
| Name | Type| Mandatory | Description | | 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). | | key |string | Yes |Key of the value to obtain. It cannot be empty, and the length cannot exceed [MAX_KEY_LENGTH](#constants). |
| callback |AsyncCallback&lt;Uint8Array \| string \| boolean \| number&gt;) | Yes |Callback used to return the value obtained. | | callback |AsyncCallback&lt;Uint8Array \| string \| boolean \| number&gt;) | Yes |Callback invoked to return the value obtained. |
**Example** **Example**
...@@ -2965,7 +2974,7 @@ try { ...@@ -2965,7 +2974,7 @@ try {
get(key: string): Promise&lt;Uint8Array | string | boolean | number&gt; get(key: string): Promise&lt;Uint8Array | string | boolean | number&gt;
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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -3008,7 +3017,7 @@ try { ...@@ -3008,7 +3017,7 @@ try {
getEntries(keyPrefix: string, callback: AsyncCallback&lt;Entry[]&gt;): void getEntries(keyPrefix: string, callback: AsyncCallback&lt;Entry[]&gt;): 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 **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 ...@@ -3017,7 +3026,7 @@ Obtains the KV pairs that match the specified key prefix. This API uses an async
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| keyPrefix |string | Yes |Key prefix to match. | | keyPrefix |string | Yes |Key prefix to match. |
| callback |AsyncCallback&lt;[Entry](#entry)[]&gt; | Yes |Callback used to return the KV pairs obtained. | | callback |AsyncCallback&lt;[Entry](#entry)[]&gt; | Yes |Callback invoked to return the KV pairs obtained. |
**Example** **Example**
...@@ -3038,7 +3047,7 @@ try { ...@@ -3038,7 +3047,7 @@ try {
} }
kvStore.putBatch(entries, async function (err,data) { kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success'); 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('getEntries success');
console.log('entrys.length: ' + entrys.length); console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0])); console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
...@@ -3054,7 +3063,7 @@ try { ...@@ -3054,7 +3063,7 @@ try {
getEntries(keyPrefix: string): Promise&lt;Entry[]&gt; getEntries(keyPrefix: string): Promise&lt;Entry[]&gt;
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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -3090,7 +3099,7 @@ try { ...@@ -3090,7 +3099,7 @@ try {
console.log('entries: ' + entries); console.log('entries: ' + entries);
kvStore.putBatch(entries).then(async (err) => { kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success'); 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('getEntries success');
console.log('entrys.length: ' + entrys.length); console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0])); 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 ...@@ -3120,7 +3129,7 @@ Obtains the KV pairs that match the specified **Query** object. This API uses an
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| query |[Query](#query8) | Yes |**Query** object to match. | | query |[Query](#query8) | Yes |Key prefix to match. |
| callback |AsyncCallback&lt;[Entry](#entry)[]&gt; | Yes |Callback used to return the KV pairs obtained. | | callback |AsyncCallback&lt;[Entry](#entry)[]&gt; | Yes |Callback used to return the KV pairs obtained. |
**Example** **Example**
...@@ -3146,7 +3155,7 @@ try { ...@@ -3146,7 +3155,7 @@ try {
console.log('putBatch success'); console.log('putBatch success');
const query = new distributedData.Query(); const query = new distributedData.Query();
query.prefixKey("batch_test"); query.prefixKey("batch_test");
await kvStore.getEntries(query, function (err,entrys) { kvStore.getEntries(query, function (err,entrys) {
console.log('getEntries success'); console.log('getEntries success');
console.log('entrys.length: ' + entrys.length); console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0])); 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 ...@@ -3182,6 +3191,7 @@ Obtains the KV pairs that match the specified **Query** object. This API uses a
**Example** **Example**
```js ```js
let kvStore;
try { try {
var arr = new Uint8Array([21,31]); var arr = new Uint8Array([21,31]);
let entries = []; let entries = [];
...@@ -3201,7 +3211,7 @@ try { ...@@ -3201,7 +3211,7 @@ try {
console.log('putBatch success'); console.log('putBatch success');
const query = new distributedData.Query(); const query = new distributedData.Query();
query.prefixKey("batch_test"); query.prefixKey("batch_test");
await kvStore.getEntries(query).then((entrys) => { kvStore.getEntries(query).then((entrys) => {
console.log('getEntries success'); console.log('getEntries success');
}).catch((err) => { }).catch((err) => {
console.log('getEntries fail ' + JSON.stringify(err)); console.log('getEntries fail ' + JSON.stringify(err));
...@@ -3220,7 +3230,7 @@ try { ...@@ -3220,7 +3230,7 @@ try {
getResultSet(keyPrefix: string, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void getResultSet(keyPrefix: string, callback: AsyncCallback&lt;KvStoreResultSet&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -3229,7 +3239,7 @@ Obtains the result set with the specified key prefix from this single KV store. ...@@ -3229,7 +3239,7 @@ Obtains the result set with the specified key prefix from this single KV store.
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| keyPrefix |string | Yes |Key prefix to match.| | keyPrefix |string | Yes |Key prefix to match.|
| callback |AsyncCallback&lt;[KvStoreResultSet](#kvstoreresultset8)&gt; | Yes |Callback used to return the result set obtained.| | callback |AsyncCallback&lt;[KvStoreResultSet](#kvstoreresultset8)&gt; | Yes |Callback invoked to return the result set obtained.|
**Example** **Example**
...@@ -3251,7 +3261,7 @@ try { ...@@ -3251,7 +3261,7 @@ try {
} }
kvStore.putBatch(entries, async function (err, data) { kvStore.putBatch(entries, async function (err, data) {
console.log('GetResultSet putBatch success'); 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.'); console.log('GetResultSet getResultSet succeed.');
resultSet = result; resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) { kvStore.closeResultSet(resultSet, function (err, data) {
...@@ -3269,7 +3279,7 @@ try { ...@@ -3269,7 +3279,7 @@ try {
getResultSet(keyPrefix: string): Promise&lt;KvStoreResultSet&gt; getResultSet(keyPrefix: string): Promise&lt;KvStoreResultSet&gt;
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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -3329,7 +3339,7 @@ try { ...@@ -3329,7 +3339,7 @@ try {
getResultSet(query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void getResultSet(query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -3338,7 +3348,7 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj ...@@ -3338,7 +3348,7 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| query |Query | Yes |**Query** object to match. | | query |Query | Yes |**Query** object to match. |
| callback |AsyncCallback&lt;[KvStoreResultSet](#kvstoreresultset8)&gt; | Yes |Callback used to return the **KvStoreResultSet** object obtained.| | callback |AsyncCallback&lt;[KvStoreResultSet](#kvstoreresultset8)&gt; | Yes |Callback invoked to return the **KvStoreResultSet** object obtained.|
**Example** **Example**
...@@ -3362,7 +3372,7 @@ try { ...@@ -3362,7 +3372,7 @@ try {
console.log('putBatch success'); console.log('putBatch success');
const query = new distributedData.Query(); const query = new distributedData.Query();
query.prefixKey("batch_test"); query.prefixKey("batch_test");
await kvStore.getResultSet(query, async function (err, result) { kvStore.getResultSet(query, async function (err, result) {
console.log('getResultSet succeed.'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
}); });
...@@ -3377,7 +3387,7 @@ try { ...@@ -3377,7 +3387,7 @@ try {
getResultSet(query: Query): Promise&lt;KvStoreResultSet&gt; getResultSet(query: Query): Promise&lt;KvStoreResultSet&gt;
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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -3481,7 +3491,7 @@ Closes the **KvStoreResultSet** object obtained by [SingleKvStore.getResultSet]( ...@@ -3481,7 +3491,7 @@ Closes the **KvStoreResultSet** object obtained by [SingleKvStore.getResultSet](
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
|Promise&lt;void&gt; |Promise used to return the result.| |Promise&lt;void&gt; |Promise that returns no value.|
**Example** **Example**
...@@ -3513,7 +3523,7 @@ Obtains the number of results that matches the specified **Query** object. This ...@@ -3513,7 +3523,7 @@ Obtains the number of results that matches the specified **Query** object. This
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| query |[Query](#query8) | Yes |**Query** object to match. | | query |[Query](#query8) | Yes |**Query** object to match. |
| callback |AsyncCallback&lt;number&gt; | Yes |Callback used to return the number of results obtained. | | callback |AsyncCallback&lt;number&gt; | Yes |Callback invoked to return the number of results obtained. |
**Example** **Example**
...@@ -3536,7 +3546,7 @@ try { ...@@ -3536,7 +3546,7 @@ try {
console.log('putBatch success'); console.log('putBatch success');
const query = new distributedData.Query(); const query = new distributedData.Query();
query.prefixKey("batch_test"); query.prefixKey("batch_test");
await kvStore.getResultSize(query, async function (err, resultSize) { kvStore.getResultSize(query, async function (err, resultSize) {
console.log('getResultSet succeed.'); console.log('getResultSet succeed.');
}); });
}); });
...@@ -3626,12 +3636,12 @@ try { ...@@ -3626,12 +3636,12 @@ try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) {
console.log('put success'); console.log('put success');
const deviceid = 'no_exist_device_id'; const deviceid = 'no_exist_device_id';
await kvStore.removeDeviceData(deviceid, async function (err,data) { kvStore.removeDeviceData(deviceid, async function (err,data) {
if (err == undefined) { if (err == undefined) {
console.log('removeDeviceData success'); console.log('removeDeviceData success');
} else { } else {
console.log('removeDeviceData fail'); 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'); console.log('RemoveDeviceData get success');
}); });
} }
...@@ -3661,7 +3671,7 @@ Deletes data of a device. This API uses a promise to return the result. ...@@ -3661,7 +3671,7 @@ Deletes data of a device. This API uses a promise to return the result.
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
|Promise&lt;void&gt; |Promise used to return the result.| |Promise&lt;void&gt; |Promise that returns no value.|
**Example** **Example**
...@@ -3696,7 +3706,7 @@ try { ...@@ -3696,7 +3706,7 @@ try {
on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -3704,8 +3714,8 @@ Subscribes to the synchronization completion events. This API uses a synchronous ...@@ -3704,8 +3714,8 @@ Subscribes to the synchronization completion events. This API uses a synchronous
| Name | Type| Mandatory | Description | | 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 completion of a data synchronization. |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | Yes |Callback used to return the synchronization result. | | syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | Yes |Callback invoked to return the synchronization result. |
**Example** **Example**
...@@ -3732,7 +3742,7 @@ try { ...@@ -3732,7 +3742,7 @@ try {
off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -3740,7 +3750,7 @@ Unsubscribes from the synchronization completion events. This API uses a synchro ...@@ -3740,7 +3750,7 @@ Unsubscribes from the synchronization completion events. This API uses a synchro
| Name | Type| Mandatory | Description | | 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&lt;Array&lt;[string, number]&gt;&gt; | No |Callback used to return the synchronization result. | | syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | No |Callback used to return the synchronization result. |
**Example** **Example**
...@@ -3763,7 +3773,7 @@ try { ...@@ -3763,7 +3773,7 @@ try {
sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void 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 **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
...@@ -3773,8 +3783,8 @@ Manually triggers KV store synchronization synchronously. For details about the ...@@ -3773,8 +3783,8 @@ Manually triggers KV store synchronization synchronously. For details about the
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| deviceIdList |string[] | Yes |IDs of the devices to be synchronized. These devices must be in the same networking environment. | | 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. | | mode |[SyncMode](#syncmode) | Yes |Synchronization mode. |
| allowedDelayMs |number | No |Allowed synchronization delay time, in ms. | | allowedDelayMs |number | No |Allowed synchronization delay time, in ms. |
**Example** **Example**
...@@ -3833,7 +3843,7 @@ Sets the default delay allowed for KV store synchronization. This API uses a pro ...@@ -3833,7 +3843,7 @@ Sets the default delay allowed for KV store synchronization. This API uses a pro
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
|Promise&lt;void&gt; |Promise used to return the result.| |Promise&lt;void&gt; |Promise that returns no value.|
**Example** **Example**
...@@ -3864,7 +3874,7 @@ Obtains the security level of this KV store. This API uses an asynchronous callb ...@@ -3864,7 +3874,7 @@ Obtains the security level of this KV store. This API uses an asynchronous callb
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| callback |AsyncCallback&lt;[SecurityLevel](#securitylevel)&gt; | Yes |Callback used to return the security level obtained. | | callback |AsyncCallback&lt;[SecurityLevel](#securitylevel)&gt; | Yes |Callback invoked to return the security level obtained. |
**Example** **Example**
...@@ -3892,7 +3902,7 @@ Obtains the security level of this KV store. This API uses a promise to return t ...@@ -3892,7 +3902,7 @@ Obtains the security level of this KV store. This API uses a promise to return t
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
|Promise&lt;[SecurityLevel](#securitylevel)&gt; |Promise used to return the value obtained.| |Promise&lt;[SecurityLevel](#securitylevel)&gt; |Promise used to return the security level obtained.|
**Example** **Example**
...@@ -3912,13 +3922,19 @@ try { ...@@ -3912,13 +3922,19 @@ try {
## DeviceKVStore<sup>8+</sup> ## ## DeviceKVStore<sup>8+</sup> ##
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.
### get<sup>8+</sup> ### ### get<sup>8+</sup> ###
get(deviceId: string, key: string, callback: AsyncCallback&lt;boolean|string|number|Uint8Array&gt;): void get(deviceId: string, key: string, callback: AsyncCallback&lt;boolean|string|number|Uint8Array&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -3953,7 +3969,7 @@ try{ ...@@ -3953,7 +3969,7 @@ try{
get(deviceId: string, key: string): Promise&lt;boolean|string|number|Uint8Array&gt; get(deviceId: string, key: string): Promise&lt;boolean|string|number|Uint8Array&gt;
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 **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 ...@@ -3968,7 +3984,7 @@ Obtains the string value that matches the specified key for a device. This API u
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
|Promise&lt;boolean\|string\|number\|Uint8Array&gt; |Promise used to return the value obtained.| |Promise&lt;boolean\|string\|number\|Uint8Array&gt; |Promise used to return the string value obtained.|
**Example** **Example**
...@@ -3997,7 +4013,7 @@ try { ...@@ -3997,7 +4013,7 @@ try {
getEntries(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;Entry[]&gt;): void getEntries(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;Entry[]&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -4029,7 +4045,7 @@ try { ...@@ -4029,7 +4045,7 @@ try {
console.log('entries: ' + entries); console.log('entries: ' + entries);
kvStore.putBatch(entries, async function (err,data) { kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success'); 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('getEntries success');
console.log('entrys.length: ' + entrys.length); console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0])); console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
...@@ -4045,7 +4061,7 @@ try { ...@@ -4045,7 +4061,7 @@ try {
getEntries(deviceId: string, keyPrefix: string): Promise&lt;Entry[]&gt; getEntries(deviceId: string, keyPrefix: string): Promise&lt;Entry[]&gt;
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 **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -4082,7 +4098,7 @@ try { ...@@ -4082,7 +4098,7 @@ try {
console.log('entries: ' + entries); console.log('entries: ' + entries);
kvStore.putBatch(entries).then(async (err) => { kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success'); 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('getEntries success');
console.log('entrys.length: ' + entrys.length); console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0])); console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
...@@ -4136,11 +4152,10 @@ try { ...@@ -4136,11 +4152,10 @@ try {
console.log('entries: ' + JSON.stringify(entries)); console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) { kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success'); console.log('putBatch success');
expect(err == undefined).assertTrue();
const query = new distributedData.Query(); const query = new distributedData.Query();
query.prefixKey("batch_test"); query.prefixKey("batch_test");
query.deviceId('localDeviceId'); query.deviceId('localDeviceId');
await kvStore.getEntries(query, function (err,entrys) { kvStore.getEntries(query, function (err,entrys) {
console.log('getEntries success'); console.log('getEntries success');
console.log('entrys.length: ' + entrys.length); console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0])); console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
...@@ -4196,7 +4211,7 @@ try { ...@@ -4196,7 +4211,7 @@ try {
console.log('putBatch success'); console.log('putBatch success');
const query = new distributedData.Query(); const query = new distributedData.Query();
query.prefixKey("batch_test"); query.prefixKey("batch_test");
await kvStore.getEntries(query).then((entrys) => { kvStore.getEntries(query).then((entrys) => {
console.log('getEntries success'); console.log('getEntries success');
}).catch((err) => { }).catch((err) => {
console.log('getEntries fail ' + JSON.stringify(err)); console.log('getEntries fail ' + JSON.stringify(err));
...@@ -4215,7 +4230,7 @@ try { ...@@ -4215,7 +4230,7 @@ try {
getEntries(deviceId: string, query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void getEntries(deviceId: string, query: Query, callback: AsyncCallback&lt;Entry[]&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -4225,7 +4240,7 @@ Obtains the KV pairs that match the specified **Query** object for a device. Thi ...@@ -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. | | deviceId |string | Yes |ID of the target device. |
| query |[Query](#query8) | Yes |**Query** object to match. | | query |[Query](#query8) | Yes |**Query** object to match. |
| callback |AsyncCallback&lt;[Entry](#entry)[]&gt; | Yes |Callback used to return the KV pairs obtained. | | callback |AsyncCallback&lt;[Entry](#entry)[]&gt; | Yes |Callback invoked to return the KV pairs obtained. |
**Example** **Example**
...@@ -4248,11 +4263,10 @@ try { ...@@ -4248,11 +4263,10 @@ try {
console.log('entries: ' + JSON.stringify(entries)); console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) { kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success'); console.log('putBatch success');
expect(err == undefined).assertTrue();
var query = new distributedData.Query(); var query = new distributedData.Query();
query.deviceId('localDeviceId'); query.deviceId('localDeviceId');
query.prefixKey("batch_test"); 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('getEntries success');
console.log('entrys.length: ' + entrys.length); console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0])); console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
...@@ -4269,7 +4283,7 @@ try { ...@@ -4269,7 +4283,7 @@ try {
getEntries(deviceId: string, query: Query): Promise&lt;Entry[]&gt; getEntries(deviceId: string, query: Query): Promise&lt;Entry[]&gt;
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 **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -4310,7 +4324,7 @@ try { ...@@ -4310,7 +4324,7 @@ try {
var query = new distributedData.Query(); var query = new distributedData.Query();
query.deviceId('localDeviceId'); query.deviceId('localDeviceId');
query.prefixKey("batch_test"); query.prefixKey("batch_test");
await kvStore.getEntries('localDeviceId', query).then((entrys) => { kvStore.getEntries('localDeviceId', query).then((entrys) => {
console.log('getEntries success'); console.log('getEntries success');
}).catch((err) => { }).catch((err) => {
console.log('getEntries fail ' + JSON.stringify(err)); console.log('getEntries fail ' + JSON.stringify(err));
...@@ -4329,7 +4343,7 @@ try { ...@@ -4329,7 +4343,7 @@ try {
getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;KvStoreResultSet&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -4339,7 +4353,7 @@ Obtains the **KvStoreResultSet** object that matches the specified key prefix fo ...@@ -4339,7 +4353,7 @@ Obtains the **KvStoreResultSet** object that matches the specified key prefix fo
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| deviceId |string | Yes |ID of the target device. | | deviceId |string | Yes |ID of the target device. |
| keyPrefix |string | Yes |Key prefix to match. | | keyPrefix |string | Yes |Key prefix to match. |
| callback |AsyncCallback&lt;[KvStoreResultSet](#kvstoreresultset8)[]&gt; | Yes |Callback used to return the **KvStoreResultSet** object obtained. | | callback |AsyncCallback&lt;[KvStoreResultSet](#kvstoreresultset8)[]&gt; | Yes |Callback invoked to return the **KvStoreResultSet** object obtained. |
**Example** **Example**
...@@ -4350,7 +4364,7 @@ try { ...@@ -4350,7 +4364,7 @@ try {
kvStore.getResultSet('localDeviceId', 'batch_test_string_key', async function (err, result) { kvStore.getResultSet('localDeviceId', 'batch_test_string_key', async function (err, result) {
console.log('getResultSet succeed.'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) { kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success'); console.log('closeResultSet success');
}) })
}); });
...@@ -4364,7 +4378,7 @@ try { ...@@ -4364,7 +4378,7 @@ try {
getResultSet(deviceId: string, keyPrefix: string): Promise&lt;KvStoreResultSet&gt; getResultSet(deviceId: string, keyPrefix: string): Promise&lt;KvStoreResultSet&gt;
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 **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -4408,7 +4422,7 @@ try { ...@@ -4408,7 +4422,7 @@ try {
getResultSet(query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void getResultSet(query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -4417,7 +4431,7 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj ...@@ -4417,7 +4431,7 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| query |[Query](#query8) | Yes |**Query** object to match. | | query |[Query](#query8) | Yes |**Query** object to match. |
| callback |AsyncCallback&lt;[KvStoreResultSet](#kvstoreresultset8)[]&gt; | Yes |Callback used to return the **KvStoreResultSet** object obtained. | | callback |AsyncCallback&lt;[KvStoreResultSet](#kvstoreresultset8)[]&gt; | Yes |Callback invoked to return the **KvStoreResultSet** object obtained. |
**Example** **Example**
...@@ -4442,10 +4456,10 @@ try { ...@@ -4442,10 +4456,10 @@ try {
const query = new distributedData.Query(); const query = new distributedData.Query();
query.prefixKey("batch_test"); query.prefixKey("batch_test");
query.deviceId('localDeviceId'); query.deviceId('localDeviceId');
await kvStore.getResultSet(query, async function (err, result) { kvStore.getResultSet(query, async function (err, result) {
console.log('getResultSet succeed.'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) { kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success'); console.log('closeResultSet success');
}) })
}); });
...@@ -4460,7 +4474,7 @@ try { ...@@ -4460,7 +4474,7 @@ try {
getResultSet(query: Query): Promise&lt;KvStoreResultSet&gt; getResultSet(query: Query): Promise&lt;KvStoreResultSet&gt;
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 **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -4524,7 +4538,7 @@ try { ...@@ -4524,7 +4538,7 @@ try {
getResultSet(deviceId: string, query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void getResultSet(deviceId: string, query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -4534,7 +4548,7 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj ...@@ -4534,7 +4548,7 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| deviceId |string | Yes |ID of the target device. | | deviceId |string | Yes |ID of the target device. |
| query |[Query](#query8) | Yes |**Query** object to match. | | query |[Query](#query8) | Yes |**Query** object to match. |
| callback |AsyncCallback&lt;[KvStoreResultSet](#kvstoreresultset8)[]&gt; | Yes |Callback used to return the **KvStoreResultSet** object obtained. | | callback |AsyncCallback&lt;[KvStoreResultSet](#kvstoreresultset8)[]&gt; | Yes |Callback invoked to return the **KvStoreResultSet** object obtained. |
**Example** **Example**
...@@ -4558,10 +4572,10 @@ try { ...@@ -4558,10 +4572,10 @@ try {
console.log('putBatch success'); console.log('putBatch success');
const query = new distributedData.Query(); const query = new distributedData.Query();
query.prefixKey("batch_test"); 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.'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) { kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success'); console.log('closeResultSet success');
}) })
}); });
...@@ -4576,7 +4590,7 @@ try { ...@@ -4576,7 +4590,7 @@ try {
getResultSet(deviceId: string, query: Query): Promise&lt;KvStoreResultSet&gt; getResultSet(deviceId: string, query: Query): Promise&lt;KvStoreResultSet&gt;
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 **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -4691,7 +4705,7 @@ Closes the **KvStoreResultSet** object obtained by [DeviceKVStore.getResultSet]( ...@@ -4691,7 +4705,7 @@ Closes the **KvStoreResultSet** object obtained by [DeviceKVStore.getResultSet](
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
|Promise&lt;void&gt; |Promise used to return the result.| |Promise&lt;void&gt; |Promise that returns no value.|
**Example** **Example**
...@@ -4724,7 +4738,7 @@ Obtains the number of results that matches the specified **Query** object. This ...@@ -4724,7 +4738,7 @@ Obtains the number of results that matches the specified **Query** object. This
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| query |[Query](#query8) | Yes |**Query** object to match. | | query |[Query](#query8) | Yes |**Query** object to match. |
| callback |AsyncCallback&lt;number&gt; | Yes |Callback used to return the number of results obtained. | | callback |AsyncCallback&lt;number&gt; | Yes |Callback invoked to return the number of results obtained. |
**Example** **Example**
...@@ -4748,7 +4762,7 @@ try { ...@@ -4748,7 +4762,7 @@ try {
const query = new distributedData.Query(); const query = new distributedData.Query();
query.prefixKey("batch_test"); query.prefixKey("batch_test");
query.deviceId('localDeviceId'); query.deviceId('localDeviceId');
await kvStore.getResultSize(query, async function (err, resultSize) { kvStore.getResultSize(query, async function (err, resultSize) {
console.log('getResultSet succeed.'); console.log('getResultSet succeed.');
}); });
}); });
...@@ -4818,7 +4832,7 @@ try { ...@@ -4818,7 +4832,7 @@ try {
getResultSize(deviceId: string, query: Query, callback: AsyncCallback&lt;number&gt;): void; getResultSize(deviceId: string, query: Query, callback: AsyncCallback&lt;number&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -4828,7 +4842,7 @@ Obtains the number of results that matches the specified **Query** object for a ...@@ -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. | | deviceId |string | Yes |ID of the target device. |
| query |[Query](#query8) | Yes |**Query** object to match. | | query |[Query](#query8) | Yes |**Query** object to match. |
| callback |AsyncCallback&lt;number&gt; | Yes |Callback used to return the number of results obtained. | | callback |AsyncCallback&lt;number&gt; | Yes |Callback invoked to return the number of results obtained. |
**Example** **Example**
...@@ -4851,7 +4865,7 @@ try { ...@@ -4851,7 +4865,7 @@ try {
console.log('putBatch success'); console.log('putBatch success');
const query = new distributedData.Query(); const query = new distributedData.Query();
query.prefixKey("batch_test"); 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.'); console.log('getResultSet succeed.');
}); });
}); });
...@@ -4865,7 +4879,7 @@ try { ...@@ -4865,7 +4879,7 @@ try {
getResultSize(deviceId: string, query: Query): Promise&lt;number&gt; getResultSize(deviceId: string, query: Query): Promise&lt;number&gt;
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 **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -4921,7 +4935,7 @@ try { ...@@ -4921,7 +4935,7 @@ try {
removeDeviceData(deviceId: string, callback: AsyncCallback&lt;void&gt;): void removeDeviceData(deviceId: string, callback: AsyncCallback&lt;void&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -4942,12 +4956,12 @@ try { ...@@ -4942,12 +4956,12 @@ try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) {
console.log('RemoveDeviceData put success'); console.log('RemoveDeviceData put success');
const deviceid = 'no_exist_device_id'; const deviceid = 'no_exist_device_id';
await kvStore.removeDeviceData(deviceid, async function (err,data) { kvStore.removeDeviceData(deviceid, async function (err,data) {
if (err == undefined) { if (err == undefined) {
console.log('removeDeviceData success'); console.log('removeDeviceData success');
} else { } else {
console.log('removeDeviceData fail'); 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'); console.log('RemoveDeviceData get success');
}); });
} }
...@@ -4963,7 +4977,7 @@ try { ...@@ -4963,7 +4977,7 @@ try {
removeDeviceData(deviceId: string): Promise&lt;void&gt; removeDeviceData(deviceId: string): Promise&lt;void&gt;
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 **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 ...@@ -4977,7 +4991,7 @@ Removes data of a device from this KV store. This API uses a promise to return t
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
|Promise&lt;void&gt; |Promise used to return the result.| |Promise&lt;void&gt; |Promise that returns no value.|
**Example** **Example**
...@@ -5012,7 +5026,7 @@ try { ...@@ -5012,7 +5026,7 @@ try {
sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void 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 **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
...@@ -5051,7 +5065,7 @@ try { ...@@ -5051,7 +5065,7 @@ try {
on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -5059,12 +5073,13 @@ Subscribes to the synchronization completion events. This API uses a synchronous ...@@ -5059,12 +5073,13 @@ Subscribes to the synchronization completion events. This API uses a synchronous
| Name | Type| Mandatory | Description | | 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<Array&lt;[string, number]&gt;> | Yes |Callback used to return the synchronization result. | | syncCallback |Callback<Array&lt;[string, number]&gt;> | Yes |Callback used to return the synchronization result. |
**Example** **Example**
```js ```js
let kvStore;
const KEY_TEST_FLOAT_ELEMENT = 'key_test_float'; const KEY_TEST_FLOAT_ELEMENT = 'key_test_float';
const VALUE_TEST_FLOAT_ELEMENT = 321.12; const VALUE_TEST_FLOAT_ELEMENT = 321.12;
try { try {
...@@ -5086,7 +5101,7 @@ try { ...@@ -5086,7 +5101,7 @@ try {
off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -5094,7 +5109,7 @@ Unsubscribes from the synchronization completion events. This API uses a synchro ...@@ -5094,7 +5109,7 @@ Unsubscribes from the synchronization completion events. This API uses a synchro
| Name | Type| Mandatory | Description | | 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<Array&lt;[string, number]&gt;&gt; | No |Callback used to return the synchronization result. | | syncCallback |Callback<Array&lt;[string, number]&gt;&gt; | No |Callback used to return the synchronization result. |
**Example** **Example**
...@@ -5112,14 +5127,13 @@ try { ...@@ -5112,14 +5127,13 @@ try {
} }
``` ```
## SyncMode ## SyncMode
Enumerates the synchronization modes. Enumerates the synchronization modes.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
| Name | Default Value | Description | | Name | Value | Description |
| ----- | ------ | ----------------------- | | ----- | ------ | ----------------------- |
| PULL_ONLY |0 |Pull data from the peer end to the local end only.| | PULL_ONLY |0 |Pull data from the peer end to the local end only.|
| PUSH_ONLY |1 |Push data from the local end to the peer end only.| | PUSH_ONLY |1 |Push data from the local end to the peer end only.|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册