>The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...
...
@@ -10,10 +9,6 @@
```
import distributedData from '@ohos.data.distributedData';
| config | [KVManagerConfig](#kvmanagerconfig) | Yes| Configuration of the **KVManager** object, including the bundle name and user information of the caller.|
| callback | AsyncCallback<[KVManager](#kvmanager)> | Yes| Callback invoked to return the **KVManager** object created.|
| config | [KVManagerConfig](#kvmanagerconfig) | Yes| Configuration of the **KVManager** object, including the bundle name and user information of the caller.|
| callback | AsyncCallback<[KVManager](#kvmanager)> | Yes| Callback invoked to return the **KVManager** object created.|
- Example
**Example**
```
let kvManager;
try {
const kvManagerConfig = {
...
...
@@ -53,7 +49,6 @@ Creates a **KVManager** object to manage key-value (KV) stores. This method uses
| 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** object, including the bundle name and user information of the caller.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| Promise<[KVManager](#kvmanager)> | Promise used to return the **KVManager** object created.|
- Example
**Example**
```
let kvManager;
try {
const kvManagerConfig = {
...
...
@@ -94,17 +90,18 @@ Creates a **KVManager** object to manage KV stores. This method uses a promise t
| 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.|
## KVManager
Creates a **KVManager** object to obtain KV store information. Before calling any method in **KVManager**, you must use **createKVManager** to create a **KVManager** object.
| 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 the value of [MAX\_STORE\_ID_LENGTH](#constants).|
| kvStore | [KVStore](#kvstore) | Yes| KV store to close.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the KV store is closed, **true** will be returned. Otherwise, **false** will be returned.|
| 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 the value of [MAX_STORE_ID_LENGTH](#constants).|
| kvStore | [KVStore](#kvstore) | Yes | KV store to close. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the KV store is closed, **true** will be returned. Otherwise, **false** will be returned. |
- Example
**Example**
```
let kvStore;
...
...
@@ -265,25 +274,27 @@ Closes a KV store. This method uses an asynchronous callback to return the resul
| 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 the value of [MAX\_STORE\_ID_LENGTH](#constants).|
| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the KV store is deleted, **true** will be returned. Otherwise, **false** will be returned.|
| 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 the value of [MAX_STORE_ID_LENGTH](#constants).|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the KV store is deleted, **true** will be returned. Otherwise, **false** will be returned. |
- Example
**Example**
```
let kvManager;
...
...
@@ -359,25 +372,27 @@ Deletes a KV store. This method uses an asynchronous callback to return the resu
| 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 the value of [MAX\_STORE\_ID_LENGTH](#constants).|
| 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 the value of [MAX_STORE_ID_LENGTH](#constants).|
- Return value
**Return value**
| Type| Description|
| Type | Description |
| ------------- | -------------- |
| Promise<void> | Promise used to return the result. If the KV store is deleted, **true** will be returned. Otherwise, **false** will be returned.|
- Example
**Example**
```
let kvManager;
...
...
@@ -411,18 +426,20 @@ Deletes a KV store. This method uses a promise to return the result.
Obtains the IDs of all the KV stores that are created using **getKvStore** and have not been deleted using **deleteKvStore**. This method uses an asynchronous callback to return the result.
Obtains the IDs of all the KV stores that are created using **getKvStore** and have not been deleted using **deleteKvStore**. This method uses a promise to return the result.
| createIfMissing | boolean | No| Whether to create a KV store if no database file exists. By default, a KV store is created.|
| encrypt | boolean | No|Whether to encrypt database files. By default, database files are not encrypted.|
| createIfMissing | boolean | No| Whether to create a KV store if no database file exists. By default, a KV store is created.|
| encrypt | boolean | No|Whether to encrypt database files. By default, database files are not encrypted.|
| backup | boolean | No|Whether to back up database files. By default, database files are backed up. |
| autoSync | boolean | No|Whether to automatically synchronize database files. By default, database files are not automatically synchronized.|
| autoSync | boolean | No|Whether to automatically synchronize database files. By default, database files are not automatically synchronized.|
| 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.|
| securityLevel | [SecurityLevel](#securitylevel) | No|Security level of the KV store. By default, the security level is not set.|
| securityLevel | [SecurityLevel](#securitylevel) | No|Security level of the KV store. By default, the security level is not set. |
| schema | [schema](#Schema<sup>8+</sup>) | No| Schema used to define the values stored in a KV store.|
| boolean |Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
import ddm from '@ohos.data.distributedData';
...
...
@@ -665,50 +712,28 @@ Adds a child node to this **FieldNode**.
```
### toJson<sup>8+</sup> ###
toJson(): string;
Obtains the field name.
- Return value
| Type| Description|
| ------ | -------------- |
| string |Field name obtained.|
- Example
```
import ddm from '@ohos.data.distributedData';
try {
let node = new ddm.FieldNode("root");
let child = new ddm.FieldNode("child");
node.appendChild(child);
console.log("appendNode " + node.toJson());
} catch (e) {
console.log("ToJson " + e);
}
```
## 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.
| offset | number | Yes| Offset to move the data read position. A negative value means to move backward, and a positive value means to move forward.|
| offset | number | Yes | Offset to move the data read position. A negative value means to move backward, and a positive value means to move forward. |
- Return value
**Return value**
| Type| Description|
| Type | Description |
| ------ | -------------- |
| boolean |Returns **true** if the operation is successful; returns **false** otherwise.|
| boolean |Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let kvStore;
...
...
@@ -928,23 +965,25 @@ Moves the data read position with the specified offset from the current position
### moveToPosition<sup>8+</sup> ###
moveToPosition(position: number): boolean;
moveToPosition(position: number): boolean
Moves the data read position from 0 to an absolute position.
@@ -1958,21 +2073,25 @@ Obtains the query statement of this **Query** 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** to obtain a **KVStore** object.
| key | string | Yes|Key of the KV pair to add. It cannot be empty, and the length cannot exceed [MAX\_KEY\_LENGTH](#constants).|
| value | Uint8Array / string / number / boolean | Yes|Value of the KV pair to add. The value type can be Uint8Array, number, string, or boolean. A value of the Uint8Array or string type cannot exceed [MAX\_VALUE\_LENGTH](#constants).|
| key | string | Yes |Key of the KV pair to add. It cannot be empty, and the length cannot exceed [MAX_KEY_LENGTH](#constants). |
| value | Uint8Array \| string \| number \| boolean | Yes |Value of the KV pair to add. The value type can be Uint8Array, number, string, or boolean. A value of the Uint8Array or string type cannot exceed [MAX_VALUE_LENGTH](#constants). |
| callback | AsyncCallback<void> | Yes |Callback invoked to return the result. |
| key | string | Yes|Key of the KV pair to add. It cannot be empty, and the length cannot exceed [MAX\_KEY\_LENGTH](#constants).|
| value | Uint8Array / string / number / boolean | Yes|Value of the KV pair to add. The value type can be Uint8Array, number, string, or boolean. A value of the Uint8Array or string type cannot exceed [MAX\_VALUE\_LENGTH](#constants).|
| key | string | Yes |Key of the KV pair to add. It cannot be empty, and the length cannot exceed [MAX_KEY_LENGTH](#constants). |
| value | Uint8Array \| string \| number \| boolean | Yes |Value of the KV pair to add. The value type can be Uint8Array, number, string, or boolean. A value of the Uint8Array or string type cannot exceed [MAX_VALUE_LENGTH](#constants). |
- Return value
**Return value**
| Type| Description|
| Type | Description |
| ------ | ------- |
| Promise<void> |Promise used to return the result.|
| enabled |boolean | Yes|Whether to enable data synchronization. The value **true** means to enable data synchronization, and **false** means the opposite.|
| callback |AsyncCallback<void> | Yes|Callback used to return the result.|
| enabled |boolean | Yes |Whether to enable data synchronization. The value **true** means to enable data synchronization, and **false** means the opposite. |
| callback |AsyncCallback<void> | Yes |Callback invoked to return the result. |
- Example
**Example**
```
let kvStore;
...
...
@@ -2615,23 +2768,25 @@ Sets data synchronization, which can be enabled or disable. This method uses an
| enabled |boolean | Yes|Whether to enable data synchronization. The value **true** means to enable data synchronization, and **false** means the opposite.|
| enabled |boolean | Yes |Whether to enable data synchronization. The value **true** means to enable data synchronization, and **false** means the opposite. |
- Return value
**Return value**
| Type| Description|
| Type | Description |
| ------ | ------- |
| Promise<void> |Promise used to return the result.|
- Example
**Example**
```
let kvStore;
...
...
@@ -2649,19 +2804,21 @@ Sets data synchronization, which can be enabled or disable. This method uses a p
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** to obtain a **SingleKVStore** object.
|Promise<[SecurityLevel](#securitylevel)> |Promise used to return the security level obtained.|
- Example
**Example**
```
let kvStore;
...
...
@@ -3721,22 +3939,26 @@ Obtains the security level of this KV store. This method uses a promise to retur
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** to obtain a **DeviceKVStore** object.
Obtains the **KvStoreResultSet** object that matches the specified key prefix for a device. This method uses an asynchronous callback to return the result.
Obtains the **KvStoreResultSet** object that matches the specified **Query** object for a device. This method uses an asynchronous callback to return the result.
Obtains the number of results that matches the specified **Query** object for a device. This method uses an asynchronous callback to return the result.