From de2e08f96cfe76d7f2a59bc0740891e0f670e2a3 Mon Sep 17 00:00:00 2001 From: Annie_wang Date: Fri, 13 May 2022 15:15:45 +0800 Subject: [PATCH] update docs Signed-off-by: Annie_wang --- .../reference/apis/js-apis-data-ability.md | 262 ++++----- .../apis/js-apis-data-distributedobject.md | 14 +- .../reference/apis/js-apis-data-rdb.md | 322 +++++++---- .../reference/apis/js-apis-data-resultset.md | 114 ++-- .../reference/apis/js-apis-data-storage.md | 295 +++++----- .../apis/js-apis-distributed-data.md | 511 +++++++++--------- 6 files changed, 827 insertions(+), 691 deletions(-) diff --git a/en/application-dev/reference/apis/js-apis-data-ability.md b/en/application-dev/reference/apis/js-apis-data-ability.md index 2f4b695a6c..14fba24573 100644 --- a/en/application-dev/reference/apis/js-apis-data-ability.md +++ b/en/application-dev/reference/apis/js-apis-data-ability.md @@ -6,8 +6,8 @@ ## Modules to Import -``` -import dataAbility from '@ohos.data.dataAbility' +```js +import dataAbility from '@ohos.data.dataAbility'; ``` @@ -21,19 +21,19 @@ Creates an **RdbPredicates** object based on a **DataAabilityPredicates** object **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | name | string | Yes| Table name in the RDB store.| - | dataAbilityPredicates | [DataAbilityPredicates](#dataabilitypredicates) | Yes| **DataAbilityPredicates** object.| + | dataAbilityPredicates | [DataAbilityPredicates](#dataabilitypredicates) | Yes| **DataAbilityPredicates** object. | -- Return value +**Return value** | Type| Description| | -------- | -------- | | rdb.[RdbPredicates](js-apis-data-rdb.md#rdbpredicates) | **RdbPredicates** object created.| -- Example: - ``` +**Example** + ```js let dataAbilityPredicates = new dataAbility.DataAbilityPredicates() dataAbilityPredicates.equalTo("NAME", "Rose").between("AGE", 16, 30) let predicates = dataAbility.createRdbPredicates("EMPLOYEE", dataAbilityPredicates) @@ -55,19 +55,19 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| - | value | [ValueType](js-apis-data-rdb.md#valuetype) | Yes| Value to match the **DataAbilityPredicates**.| + | value | [ValueType](#valuetype) | Yes| Value to match the **DataAbilityPredicates**.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.equalTo("NAME", "lisi") ``` @@ -83,19 +83,19 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| - | value | [ValueType](js-apis-data-rdb.md#valuetype) | Yes| Value to match the **DataAbilityPredicates**.| + | value | [ValueType](#valuetype) | Yes| Value to match the **DataAbilityPredicates**.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.notEqualTo("NAME", "lisi") ``` @@ -111,13 +111,13 @@ Adds a left parenthesis to this **DataAbilityPredicates**. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object with a left parenthesis.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbilitylity.DataAbilityPredicates("EMPLOYEE") predicates.equalTo("NAME", "lisi") .beginWrap() @@ -138,13 +138,13 @@ Adds a right parenthesis to this **DataAbilityPredicates**. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object with a right parenthesis.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.equalTo("NAME", "lisi") .beginWrap() @@ -165,13 +165,13 @@ Adds the OR condition to this **DataAbilityPredicates**. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object with the OR condition.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.equalTo("NAME", "Lisa") .or() @@ -189,13 +189,13 @@ Adds the AND condition to this **DataAbilityPredicates**. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object with the AND condition.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.equalTo("NAME", "Lisa") .and() @@ -213,19 +213,19 @@ Sets a **DataAbilityPredicates** object to match a string containing the specifi **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| | value | string | Yes| Value to match the **DataAbilityPredicates**.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.contains("NAME", "os") ``` @@ -241,19 +241,19 @@ Sets a **DataAbilityPredicates** object to match a string that starts with the s **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| | value | string | Yes| Value to match the **DataAbilityPredicates**.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.beginsWith("NAME", "os") ``` @@ -269,18 +269,18 @@ Sets a **DataAbilityPredicates** object to match a string that ends with the spe **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| | value | string | Yes| Value to match the **DataAbilityPredicates**.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: +**Example** ``` let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.endsWith("NAME", "se") @@ -297,18 +297,18 @@ Sets a **DataAbilityPredicates** object to match the field whose value is null. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.isNull("NAME") ``` @@ -324,18 +324,18 @@ Sets a **DataAbilityPredicates** object to match the field whose value is not nu **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.isNotNull("NAME") ``` @@ -351,19 +351,19 @@ Sets a **DataAbilityPredicates** object to match a string that is similar to the **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| | value | string | Yes| Value to match the **DataAbilityPredicates**.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.like("NAME", "%os%") ``` @@ -379,19 +379,19 @@ Sets a **DataAbilityPredicates** object to match the specified string. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| | value | string | Yes| Value to match the **DataAbilityPredicates**.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.glob("NAME", "?h*g") ``` @@ -407,20 +407,20 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| - | low | [ValueType](js-apis-data-rdb.md#valuetype) | Yes| Minimum value to match the **DataAbilityPredicates**.| - | high | [ValueType](js-apis-data-rdb.md#valuetype) | Yes| Maximum value to match the **DataAbilityPredicates**.| + | low | [ValueType](#valuetype) | Yes| Minimum value to match the **DataAbilityPredicates**.| + | high | [ValueType](#valuetype) | Yes| Maximum value to match the **DataAbilityPredicates**.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.between("AGE", 10, 50) ``` @@ -436,20 +436,20 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| - | low | [ValueType](js-apis-data-rdb.md#valuetype) | Yes| Minimum value to match the **DataAbilityPredicates**.| - | high | [ValueType](js-apis-data-rdb.md#valuetype) | Yes| Maximum value to match the **DataAbilityPredicates**.| + | low | [ValueType](#valuetype) | Yes| Minimum value to match the **DataAbilityPredicates**.| + | high | [ValueType](#valuetype) | Yes| Maximum value to match the **DataAbilityPredicates**.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.notBetween("AGE", 10, 50) ``` @@ -465,19 +465,19 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| - | value | [ValueType](js-apis-data-rdb.md#valuetype) | Yes| Value to match the **DataAbilityPredicates**.| + | value | [ValueType](#valuetype) | Yes| Value to match the **DataAbilityPredicates**.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.greaterThan("AGE", 18) ``` @@ -493,19 +493,19 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| - | value | [ValueType](js-apis-data-rdb.md#valuetype) | Yes| Value to match the **DataAbilityPredicates**.| + | value | [ValueType](#valuetype) | Yes| Value to match the **DataAbilityPredicates**.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.lessThan("AGE", 20) ``` @@ -521,19 +521,19 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| - | value | [ValueType](js-apis-data-rdb.md#valuetype) | Yes| Value to match the **DataAbilityPredicates**.| + | value | [ValueType](#valuetype) | Yes| Value to match the **DataAbilityPredicates**.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.greaterThanOrEqualTo("AGE", 18) ``` @@ -549,19 +549,19 @@ Sets a **DataAbilityPredicates** object to match the field with data type **Valu **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| - | value | [ValueType](js-apis-data-rdb.md#valuetype) | Yes| Value to match the **DataAbilityPredicates**.| + | value | [ValueType](#valuetype) | Yes| Value to match the **DataAbilityPredicates**.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.lessThanOrEqualTo("AGE", 20) ``` @@ -577,18 +577,18 @@ Sets a **DataAbilityPredicates** object to match the column with values sorted i **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.orderByAsc("NAME") ``` @@ -604,18 +604,18 @@ Sets a **DataAbilityPredicates** object to match the column with values sorted i **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.orderByDesc("AGE") ``` @@ -631,13 +631,13 @@ Sets a **DataAbilityPredicates** object to filter out duplicate records. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that can filter out duplicate records.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.equalTo("NAME", "Rose").distinct("NAME") let promiseDistinct = rdbStore.query(predicates, ["NAME"]) @@ -659,18 +659,18 @@ Set a **DataAbilityPredicates** object to specify the maximum number of records. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | number | Yes| Maximum number of records.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that specifies the maximum number of records.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.equalTo("NAME", "Rose").limitAs(3) ``` @@ -686,18 +686,18 @@ Sets a **DataAbilityPredicates** object to specify the start position of the ret **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | rowOffset | number | Yes| Number of rows to offset from the beginning. The value is a positive integer.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that specifies the start position of the returned result.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.equalTo("NAME", "Rose").offsetAs(3) ``` @@ -713,18 +713,18 @@ Sets a **DataAbilityPredicates** object to group rows that have the same value i **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | fields | Array<string> | Yes| Names of columns to group.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that groups rows with the same value.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.groupBy(["AGE", "NAME"]) ``` @@ -738,18 +738,18 @@ indexedBy(field: string): DataAbilityPredicates Sets a **DataAbilityPredicates** object to specify the index column. -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | indexName | string | Yes| Name of the index column.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that specifies the index column.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.indexedBy("SALARY_INDEX") ``` @@ -765,20 +765,20 @@ Sets a **DataAbilityPredicates** object to match the field with data type Array< **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| - | value | Array<[ValueType](js-apis-data-rdb.md#valuetype)> | Yes| Array of **ValueType**s to match.| + | value | Array<[ValueType](#valuetype)> | Yes| Array of **ValueType**s to match.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.in("AGE", [18, 20]) ``` @@ -794,20 +794,32 @@ Sets a **DataAbilityPredicates** object to match the field with data type Array< **System capability**: SystemCapability.DistributedDataManager.DataShare.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | field | string | Yes| Column name in the table.| - | value | Array<[ValueType](js-apis-data-rdb.md#valuetype)> | Yes| Array of **ValueType**s to match.| + | value | Array<[ValueType](#valuetype)> | Yes| Array of **ValueType**s to match.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [DataAbilityPredicates](#dataabilitypredicates) | **DataAbilityPredicates** object that matches the specified field.| -- Example: - ``` +**Example** + ```js let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") predicates.notIn("NAME", ["Lisa", "Rose"]) ``` + +## ValueType + +Enumerates the value types. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Core + +| Name | Description | +| ------- | -------------------- | +| number | The value is a number. | +| string | The value is a string. | +| boolean | The value is of Boolean type.| diff --git a/en/application-dev/reference/apis/js-apis-data-distributedobject.md b/en/application-dev/reference/apis/js-apis-data-distributedobject.md index ed0829f6f6..6670e2eefa 100644 --- a/en/application-dev/reference/apis/js-apis-data-distributedobject.md +++ b/en/application-dev/reference/apis/js-apis-data-distributedobject.md @@ -7,7 +7,7 @@ ## Modules to Import ```js -import distributedObject from '@ohos.data.distributedDataObject' +import distributedObject from '@ohos.data.distributedDataObject'; ``` @@ -25,11 +25,11 @@ Creates a distributed data object. | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | source | object | Yes| Attribute of the distributed data object to create.| - + **Return Value** - | Type| Description| - | -------- | -------- | - | [DistributedObject](#distributedobject) | Distributed data object created.| +| Type| Description| +| -------- | -------- | +| [DistributedObject](#distributedobject) | Distributed data object created.| **Example** ```js @@ -83,7 +83,7 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo | Type| Description| | -------- | -------- | | boolean | Returns **true** if the session ID is set successfully;
returns **false** otherwise. | - + **Example** ```js @@ -171,8 +171,6 @@ Subscribes to the status changes (online or offline) of this distributed data ob | type | string | Yes| Event type to subscribe to. The value is "status", which indicates the status (online or offline) change events.| | callback | Callback<{ sessionId: string, networkId: string, status: 'online' \| 'offline' }> | Yes| Callback used to return the online or offline status.
**sessionId** indicates the session ID of the distributed data object.
**networkId** indicates the network ID of the device.
**status** indicates the status, which can be online or offline.| - - **Example** ```js import distributedObject from '@ohos.data.distributedDataObject' diff --git a/en/application-dev/reference/apis/js-apis-data-rdb.md b/en/application-dev/reference/apis/js-apis-data-rdb.md index dbc00546fe..ab9445c95f 100644 --- a/en/application-dev/reference/apis/js-apis-data-rdb.md +++ b/en/application-dev/reference/apis/js-apis-data-rdb.md @@ -7,44 +7,111 @@ ## Modules to Import +```js +import data_rdb from '@ohos.data.rdb'; ``` -import data_rdb from '@ohos.data.rdb' -``` +## data_rdb.getRdbStore + +getRdbStore(config: StoreConfig, version: number, callback: AsyncCallback<RdbStore>): void + +Obtains a relational database (RDB) store. This API uses an asynchronous callback to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations. + +**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| config | [StoreConfig](#storeconfig) | Yes| Configuration of the RDB store.| +| version | number | Yes| RDB store version.| +| callback | AsyncCallback<[RdbStore](#rdbstore)> | Yes| Callback invoked to return the RDB store obtained.| + +**Example** + +```js +const STORE_CONFIG = { name: "RdbTest.db"} +const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" +data_rdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) { + rdbStore.executeSql(SQL_CREATE_TABLE, null, function() { + console.info('create table done.') + }) +}) +``` ## data_rdb.getRdbStore +getRdbStore(config: StoreConfig, version: number): Promise<RdbStore> + +Obtains an RDB store. This API uses a promise to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations. + +**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| config | [StoreConfig](#storeconfig) | Yes| Configuration of the RDB store.| +| version | number | Yes| RDB store version.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| Promise<[RdbStore](#rdbstore)> | Promise used to return the RDB store obtained.| + +**Example** + +```js +const STORE_CONFIG = { name: "RdbTest.db" } +const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" +let promisegetRdb = data_rdb.getRdbStore(STORE_CONFIG, 1); +promisegetRdb.then(async (rdbStore) => { + let promiseExecSql = rdbStore.executeSql(SQL_CREATE_TABLE, null) + promiseExecSql.then(() => { + console.info('executeSql creat done.') + }).catch((err) => { + console.log("executeSql creat err.") + }) +}).catch((err) => { + console.log("getRdbStore err.") +}) +``` + + +## data_rdb.getRdbStore8+ + getRdbStore(context: Context, config: StoreConfig, version: number, callback: AsyncCallback<RdbStore>): void -Obtains a relational database (RDB) store. This method uses an asynchronous callback to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations. +Obtains a relational database (RDB) store. This API uses an asynchronous callback to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| context8+ | Context | Yes| Context of the app or functionality.| +| context8+ | Context | Yes| Context of the app or functionality.
For the definition of **Context** of API version 8, see [Context](js-apis-Context.md).
For the definition of **Context** of API version 9, see [Context](js-apis-ability-context.md).| | config | [StoreConfig](#storeconfig) | Yes| Configuration of the RDB store.| | version | number | Yes| RDB store version.| | callback | AsyncCallback<[RdbStore](#rdbstore)> | Yes| Callback invoked to return the RDB store obtained.| **Example** -``` -import data_rdb from '@ohos.data.rdb' +```js const STORE_CONFIG = { name: "RdbTest.db"} const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" -data_rdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) { - rdbStore.executeSql(SQL_CREATE_TABLE) - console.info('create table done.') +data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) { + rdbStore.executeSql(SQL_CREATE_TABLE, null, function() { + console.info('create table done.') + }) }) ``` -## data_rdb.getRdbStore +## data_rdb.getRdbStore8+ getRdbStore(context: Context, config: StoreConfig, version: number): Promise<RdbStore> -Obtains an RDB store. This method uses a promise to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations. +Obtains an RDB store. This API uses a promise to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -52,7 +119,7 @@ Obtains an RDB store. This method uses a promise to return the result. You can s | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| context8+ | Context | Yes| Context of the app or functionality.| +| context8+ | Context | Yes| Context of the app or functionality.
For the definition of **Context** of API version 8, see [Context](js-apis-Context.md).
For the definition of **Context** of API version 9, see [Context](js-apis-ability-context.md).| | config | [StoreConfig](#storeconfig) | Yes| Configuration of the RDB store.| | version | number | Yes| RDB store version.| @@ -64,11 +131,10 @@ Obtains an RDB store. This method uses a promise to return the result. You can s **Example** -``` -import data_rdb from '@ohos.data.rdb' +```js const STORE_CONFIG = { name: "RdbTest.db" } const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" -let promisegetRdb = data_rdb.getRdbStore(STORE_CONFIG, 1); +let promisegetRdb = data_rdb.getRdbStore(this.context, STORE_CONFIG, 1); promisegetRdb.then(async (rdbStore) => { let promiseExecSql = rdbStore.executeSql(SQL_CREATE_TABLE, null) promiseExecSql.then(() => { @@ -83,49 +149,95 @@ promisegetRdb.then(async (rdbStore) => { ## data_rdb.deleteRdbStore -deleteRdbStore(context: Context, name: string, callback: AsyncCallback<void>): void +deleteRdbStore(name: string, callback: AsyncCallback<void>): void -Deletes an RDB store. This method uses a callback to return the result. +Deletes an RDB store. This API uses a callback to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| context8+ | Context | Yes| Context of the app or functionality.| | name | string | Yes| Name of the RDB store to delete.| | callback | AsyncCallback<void> | Yes| Callback invoked to return the result.| **Example** - ``` - import data_rdb from '@ohos.data.rdb' + ```js data_rdb.deleteRdbStore("RdbTest.db", function (err, rdbStore) { console.info('delete store done.') }) ``` + ## data_rdb.deleteRdbStore -## data_rdb.deleteRdbStore +deleteRdbStore(name: string): Promise<void> + +Deletes an RDB store. This API uses a promise to return the result. + +**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core + +**Parameters** +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| name | string | Yes| Name of the RDB store to delete.| + +**Return value** +| Type| Description| +| -------- | -------- | +| Promise<void> | Promise used to| + +**Example** + ```js + let promisedeleteRdb = data_rdb.deleteRdbStore("RdbTest.db") + promisedeleteRdb.then(()=>{ + console.info('delete store done.') + }).catch((err) => { + console.log("deleteRdbStore err.") + }) + ``` + +## data_rdb.deleteRdbStore8+ + +deleteRdbStore(context: Context, name: string, callback: AsyncCallback<void>): void + +Deletes an RDB store. This API uses a callback to return the result. + +**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core + +**Parameters** +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| context8+ | Context | Yes| Context of the app or functionality.
For the definition of **Context** of API version 8, see [Context](js-apis-Context.md).
For the definition of **Context** of API version 9, see [Context](js-apis-ability-context.md).| +| name | string | Yes| Name of the RDB store to delete.| +| callback | AsyncCallback<void> | Yes| Callback invoked to return the result.| + +**Example** + ```js + data_rdb.deleteRdbStore(this.context, "RdbTest.db", function (err, rdbStore) { + console.info('delete store done.') + }) + ``` + +## data_rdb.deleteRdbStore8+ deleteRdbStore(context: Context, name: string): Promise<void> -Deletes an RDB store. This method uses a promise to return the result. +Deletes an RDB store. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| context8+ | Context | Yes| Context of the app or functionality.| +| context8+ | Context | Yes| Context of the app or functionality.
For the definition of **Context** of API version 8, see [Context](js-apis-Context.md).
For the definition of **Context** of API version 9, see [Context](js-apis-ability-context.md).| | name | string | Yes| Name of the RDB store to delete.| **Return value** | Type| Description| | -------- | -------- | -| Promise<void> | Promise used to return the result.| +| Promise<void> | Promise used to| **Example** - ``` - import data_rdb from '@ohos.data.rdb' + ```js let promisedeleteRdb = data_rdb.deleteRdbStore("RdbTest.db") promisedeleteRdb.then(()=>{ console.info('delete store done.') @@ -134,6 +246,7 @@ Deletes an RDB store. This method uses a promise to return the result. }) ``` + ## RdbPredicates Defines predicates for an RDB store. This class determines whether the conditional expression for the RDB store is true or false. @@ -154,7 +267,7 @@ A constructor used to create an **RdbPredicates** object. | name | string | Yes| Database table name.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") ``` @@ -178,9 +291,9 @@ Specifies a remote device on the network during distributed database synchroniza | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicate.inDevices(['12345678abcde']) + predicates.inDevices(['12345678abcde']) ``` ### inAllDevices8+ @@ -198,7 +311,7 @@ Connects to all remote devices on the network during distributed database synchr | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.inAllDevices() ``` @@ -224,7 +337,7 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.equalTo("NAME", "lisi") ``` @@ -251,7 +364,7 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.notEqualTo("NAME", "lisi") ``` @@ -272,7 +385,7 @@ Adds a left parenthesis to the **RdbPredicates**. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a left parenthesis.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.equalTo("NAME", "lisi") .beginWrap() @@ -298,7 +411,7 @@ Adds a right parenthesis to the **RdbPredicates**. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a right parenthesis.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.equalTo("NAME", "lisi") .beginWrap() @@ -324,7 +437,7 @@ Adds the OR condition to the **RdbPredicates**. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the OR condition.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.equalTo("NAME", "Lisa") .or() @@ -347,7 +460,7 @@ Adds the AND condition to the **RdbPredicates**. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the AND condition.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.equalTo("NAME", "Lisa") .and() @@ -375,7 +488,7 @@ Sets the **RdbPredicates** to match a string containing the specified value. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.contains("NAME", "os") ``` @@ -402,7 +515,7 @@ Sets the **RdbPredicates** to match a string that starts with the specified valu | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.beginsWith("NAME", "os") ``` @@ -429,7 +542,7 @@ Sets the **RdbPredicates** to match a string that ends with the specified value. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.endsWith("NAME", "se") ``` @@ -455,7 +568,7 @@ Sets the **RdbPredicates** to match the field whose value is null. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| - Example - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.isNull("NAME") ``` @@ -481,7 +594,7 @@ Sets the **RdbPredicates** to match the field whose value is not null. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.isNotNull("NAME") ``` @@ -508,7 +621,7 @@ Sets the **RdbPredicates** to match a string that is similar to the specified va | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.like("NAME", "%os%") ``` @@ -535,7 +648,7 @@ Sets the **RdbPredicates** to match the specified string. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.glob("NAME", "?h*g") ``` @@ -563,7 +676,7 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.between("AGE", 10, 50) ``` @@ -591,7 +704,7 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.notBetween("AGE", 10, 50) ``` @@ -617,7 +730,7 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.greaterThan("AGE", 18) ``` @@ -644,7 +757,7 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.lessThan("AGE", 20) ``` @@ -672,7 +785,7 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.greaterThanOrEqualTo("AGE", 18) ``` @@ -700,7 +813,7 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.lessThanOrEqualTo("AGE", 20) ``` @@ -727,7 +840,7 @@ Sets the **RdbPredicates** to match the column with values sorted in ascending o | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.orderByAsc("NAME") ``` @@ -754,7 +867,7 @@ Sets the **RdbPredicates** to match the column with values sorted in descending | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.orderByDesc("AGE") ``` @@ -775,7 +888,7 @@ Sets the **RdbPredicates** to filter out duplicate records. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that can filter out duplicate records.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.equalTo("NAME", "Rose").distinct("NAME") let promisequery = rdbStore.query(predicates, ["NAME"]) @@ -808,7 +921,7 @@ Sets the **RdbPredicates** to specify the maximum number of records. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the maximum number of records.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.equalTo("NAME", "Rose").limitAs(3) ``` @@ -834,7 +947,7 @@ Sets the **RdbPredicates** to specify the start position of the returned result. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the start position of the returned result.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.equalTo("NAME", "Rose").offsetAs(3) ``` @@ -860,7 +973,7 @@ Sets the **RdbPredicates** to group rows that have the same value into summary r | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that groups rows with the same value.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.groupBy(["AGE", "NAME"]) ``` @@ -886,7 +999,7 @@ Sets the **RdbPredicates** object to specify the index column. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the index column.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.indexedBy("SALARY_INDEX") ``` @@ -914,7 +1027,7 @@ Sets the **RdbPredicates** to match the field with data type **Array<ValueTy | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.in("AGE", [18, 20]) ``` @@ -942,7 +1055,7 @@ Sets the **RdbPredicates** to match the field with data type **Array<ValueTy | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.notIn("NAME", ["Lisa", "Rose"]) ``` @@ -957,7 +1070,7 @@ Provides methods to manage an RDB store. insert(name: string, values: ValuesBucket, callback: AsyncCallback<number>):void -Inserts a row of data into a table. This method uses a callback to return the result. +Inserts a row of data into a table. This API uses a callback to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -969,7 +1082,7 @@ Inserts a row of data into a table. This method uses a callback to return the re | callback | AsyncCallback<number> | Yes| Callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| **Example** - ``` + ```js const valueBucket = { "NAME": "Lisa", "AGE": 18, @@ -986,7 +1099,7 @@ Inserts a row of data into a table. This method uses a callback to return the re insert(name: string, values: ValuesBucket):Promise<number> -Inserts a row of data into a table. This method uses a promise to return the result. +Inserts a row of data into a table. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1002,7 +1115,7 @@ Inserts a row of data into a table. This method uses a promise to return the res | Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| **Example** - ``` + ```js const valueBucket = { "NAME": "Lisa", "AGE": 18, @@ -1022,7 +1135,7 @@ Inserts a row of data into a table. This method uses a promise to return the res update(values: ValuesBucket, rdbPredicates: RdbPredicates, callback: AsyncCallback<number>):void -Updates data in the database based on the specified RdbPredicates object. This method uses a callback to return the result. +Updates data in the database based on the specified RdbPredicates object. This API uses a callback to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1034,7 +1147,7 @@ Updates data in the database based on the specified RdbPredicates object. This m | callback | AsyncCallback<number> | Yes| Callback used to return the number of rows updated.| **Example** - ``` + ```js const valueBucket = { "NAME": "Rose", "AGE": 22, @@ -1044,7 +1157,7 @@ Updates data in the database based on the specified RdbPredicates object. This m let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.equalTo("NAME", "Lisa") rdbStore.update(valueBucket, predicates, function (err, ret) { - console.log("updated row count: " + changedRows)}) + console.log("updated row count: " + ret)}) ``` @@ -1052,7 +1165,7 @@ Updates data in the database based on the specified RdbPredicates object. This m update(values: ValuesBucket, rdbPredicates: RdbPredicates):Promise<number> -Updates data in the database based on the specified RdbPredicates object. This method uses a promise to return the result. +Updates data in the database based on the specified RdbPredicates object. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1068,7 +1181,7 @@ Updates data in the database based on the specified RdbPredicates object. This m | Promise<number> | Promise used to return the number of rows updated.| **Example** - ``` + ```js const valueBucket = { "NAME": "Rose", "AGE": 22, @@ -1079,7 +1192,7 @@ Updates data in the database based on the specified RdbPredicates object. This m predicates.equalTo("NAME", "Lisa") let promiseupdate = rdbStore.update(valueBucket, predicates) promiseupdate.then(async (ret) => { - console.log("updated row count: " + changedRows) + console.log("updated row count: " + ret) }).catch((err) => { console.log("update err.") }) @@ -1091,7 +1204,7 @@ Updates data in the database based on the specified RdbPredicates object. This m delete(rdbPredicates: RdbPredicates, callback: AsyncCallback<number>):void -Deletes data from the database based on the specified RdbPredicates object. This method uses a callback to return the result. +Deletes data from the database based on the specified RdbPredicates object. This API uses a callback to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1102,7 +1215,7 @@ Deletes data from the database based on the specified RdbPredicates object. This | callback | AsyncCallback<number> | Yes| Callback invoked to return the number of rows updated.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.equalTo("NAME", "Lisa") rdbStore.delete(predicates, function (err, rows) { @@ -1115,7 +1228,7 @@ Deletes data from the database based on the specified RdbPredicates object. This delete(rdbPredicates: RdbPredicates):Promise<number> -Deletes data from the database based on the specified RdbPredicates object. This method uses a promise to return the result. +Deletes data from the database based on the specified RdbPredicates object. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1130,7 +1243,7 @@ Deletes data from the database based on the specified RdbPredicates object. This | Promise<number> | Promise used to return the number of rows updated.| **Example** - ``` + ```js let predicatesdelete = new data_rdb.RdbPredicates("EMPLOYEE") predicatesdelete.equalTo("NAME", "Lisa") let promisedelete = rdbStore.delete(predicates) @@ -1146,7 +1259,7 @@ Deletes data from the database based on the specified RdbPredicates object. This query(rdbPredicates: RdbPredicates, columns: Array<string>, callback: AsyncCallback<ResultSet>):void -Queries data in the database based on specified conditions. This method uses a callback to return the result. +Queries data in the database based on specified conditions. This API uses a callback to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1158,7 +1271,7 @@ Queries data in the database based on specified conditions. This method uses a c | callback | AsyncCallback<[ResultSet](js-apis-data-resultset.md)> | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.equalTo("NAME", "Rose") rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) { @@ -1172,7 +1285,7 @@ Queries data in the database based on specified conditions. This method uses a c query(rdbPredicates: RdbPredicates, columns?: Array<string>):Promise<ResultSet> -Queries data in the database based on specified conditions. This method uses a promise to return the result. +Queries data in the database based on specified conditions. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1188,7 +1301,7 @@ Queries data in the database based on specified conditions. This method uses a p | Promise<[ResultSet](../apis/js-apis-data-resultset.md)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| **Example** - ``` + ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.equalTo("NAME", "Rose") let promisequery = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) @@ -1205,7 +1318,7 @@ Queries data in the database based on specified conditions. This method uses a p querySql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<ResultSet>):void -Queries data in the RDB store using the specified SQL statement. This method uses a callback to return the result. +Queries data in the RDB store using the specified SQL statement. This API uses a callback to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1217,7 +1330,7 @@ Queries data in the RDB store using the specified SQL statement. This method use | callback | AsyncCallback<[ResultSet](js-apis-data-resultset.md)> | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| **Example** - ``` + ```js rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) { console.log("resultSet column names:" + resultSet.columnNames) console.log("resultSet column count:" + resultSet.columnCount) @@ -1229,7 +1342,7 @@ Queries data in the RDB store using the specified SQL statement. This method use querySql(sql: string, bindArgs?: Array<ValueType>):Promise<ResultSet> -Queries data in the RDB store using the specified SQL statement. This method uses a promise to return the result. +Queries data in the RDB store using the specified SQL statement. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1245,7 +1358,7 @@ Queries data in the RDB store using the specified SQL statement. This method use | Promise<[ResultSet](../apis/js-apis-data-resultset.md)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| **Example** - ``` + ```js let promisequerySql = rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo']) promisequerySql.then((resultSet) => { console.log("resultSet column names:" + resultSet.columnNames) @@ -1260,7 +1373,7 @@ Queries data in the RDB store using the specified SQL statement. This method use executeSql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<void>):void -Runs the SQL statement that contains the specified parameters but does not return a value. This method uses a callback to return the execution result. +Runs the SQL statement that contains the specified parameters but does not return a value. This API uses a callback to return the execution result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1272,7 +1385,7 @@ Runs the SQL statement that contains the specified parameters but does not retur | callback | AsyncCallback<void> | Yes| Callback invoked to return the result.| **Example** - ``` + ```js rdbStore.executeSql("DELETE FROM EMPLOYEE", null, function () { console.info('delete done.') }) @@ -1283,7 +1396,7 @@ Runs the SQL statement that contains the specified parameters but does not retur executeSql(sql: string, bindArgs?: Array<ValueType>):Promise<void> -Runs the SQL statement that contains the specified parameters but does not return a value. This method uses a promise to return the execution result. +Runs the SQL statement that contains the specified parameters but does not return a value. This API uses a promise to return the execution result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1299,7 +1412,7 @@ Runs the SQL statement that contains the specified parameters but does not retur | Promise<void> | Promise used to return the result.| **Example** - ``` + ```js let promiseexecuteSql = rdbStore.executeSql("DELETE FROM EMPLOYEE") promiseexecuteSql.then(() => { console.info('delete done.') @@ -1317,7 +1430,7 @@ Starts the transaction before executing an SQL statement. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **Example** -``` +```js rdbStore.beginTransaction() const valueBucket = { "name": "lisi", @@ -1341,7 +1454,7 @@ Commits the executed SQL statements. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **Example** -``` +```js rdbStore.beginTransaction() const valueBucket = { "name": "lisi", @@ -1366,7 +1479,7 @@ Rolls back the SQL statements that have been executed. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **Example** -``` +```js try { rdbStore.beginTransaction() const valueBucket = { @@ -1390,7 +1503,7 @@ Rolls back the SQL statements that have been executed. setDistributedTables(tables: Array<string>, callback: AsyncCallback<void>): void -Sets a list of distributed tables. This method uses a callback to return the result. +Sets a list of distributed tables. This API uses a callback to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1401,7 +1514,7 @@ Sets a list of distributed tables. This method uses a callback to return the res | callback | AsyncCallback<void> | Yes| Callback invoked to return the result.| **Example** - ``` + ```js rdbStore.setDistributedTables(["EMPLOYEE"], function (err) { if (err) { console.info('setDistributedTables failed.') @@ -1416,7 +1529,7 @@ Sets a list of distributed tables. This method uses a callback to return the res setDistributedTables(tables: Array<string>): Promise<void> -Sets a list of distributed tables. This method uses a promise to return the result. +Sets a list of distributed tables. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1431,7 +1544,7 @@ Sets a list of distributed tables. This method uses a promise to return the resu | Promise<void> | Promise used to return the result.| **Example** - ``` + ```js let promiseset = rdbStore.setDistributedTables(["EMPLOYEE"]) promiseset.then(() => { console.info("setDistributedTables success.") @@ -1444,7 +1557,7 @@ Sets a list of distributed tables. This method uses a promise to return the resu obtainDistributedTableName(device: string, table: string, callback: AsyncCallback<string>): void -Obtains the distributed table name for a remote device based on the local table name. The distributed table name is required when the database of a remote device is queried. This method uses a callback to return the result. +Obtains the distributed table name for a remote device based on the local table name. The distributed table name is required when the database of a remote device is queried. This API uses a callback to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1456,7 +1569,7 @@ Obtains the distributed table name for a remote device based on the local table | callback | AsyncCallback<string> | Yes| Callback invoked to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| **Example** - ``` + ```js rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) { if (err) { console.info('obtainDistributedTableName failed.') @@ -1471,7 +1584,7 @@ Obtains the distributed table name for a remote device based on the local table obtainDistributedTableName(device: string, table: string): Promise<string> -Obtains the distributed table name for a remote device based on the local table name. The distributed table name is required when the database of a remote device is queried. This method uses a promise to return the result. +Obtains the distributed table name for a remote device based on the local table name. The distributed table name is required when the database of a remote device is queried. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1487,7 +1600,7 @@ Obtains the distributed table name for a remote device based on the local table | Promise<string> | Promise used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| **Example** - ``` + ```js let promiseDistr = rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE") promiseDistr.then((tableName) => { console.info('obtainDistributedTableName success, tableName=' + tableName) @@ -1500,7 +1613,7 @@ Obtains the distributed table name for a remote device based on the local table sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback<Array<[string, number]>>): void -Synchronizes data between devices. This method uses a callback to return the result. +Synchronizes data between devices. This API uses a callback to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1512,7 +1625,7 @@ Synchronizes data between devices. This method uses a callback to return the res | callback | AsyncCallback<Array<[string, number]>> | Yes| Callback invoked to send the synchronization result to the caller.
**string** indicates the device ID.
**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. | **Example** - ``` + ```js let predicate = new rdb.RdbPredicates('EMPLOYEE') predicate.inDevices(['12345678abcde']) rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH, predicate, function (err, result) { @@ -1532,7 +1645,7 @@ Synchronizes data between devices. This method uses a callback to return the res sync(mode: SyncMode, predicates: RdbPredicates): Promise<Array<[string, number]>> -Synchronizes data between devices. This method uses a promise to return the result. +Synchronizes data between devices. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1549,7 +1662,7 @@ Synchronizes data between devices. This method uses a promise to return the resu | Promise<Array<[string, number]>> | Promise used to return the synchronization result to the caller.
**string** indicates the device ID.
**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. | **Example** - ``` + ```js let predicatesync = new data_rdb.RdbPredicates('EMPLOYEE') predicatesync.inDevices(['12345678abcde']) let promisesync = rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicatesync) @@ -1580,10 +1693,10 @@ Registers an observer for this RDB store. When the data in the RDB store changes | observer | Callback<Array<string>> | Yes| Observer that listens for the data changes in the RDB store.| **Example** - ``` + ```js function storeObserver(devices) { for (let i = 0; i < devices.length; i++) { - console.log('device=' + device[i] + ' data changed') + console.log('device=' + devices[i] + ' data changed') } } try { @@ -1597,7 +1710,7 @@ Registers an observer for this RDB store. When the data in the RDB store changes off(event:'dataChange', type: SubscribeType, observer: Callback<Array<string>>): void -Deletes the specified observer of the RDB store. This method uses a callback to return the result. +Deletes the specified observer of the RDB store. This API uses a callback to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1611,10 +1724,10 @@ Deletes the specified observer of the RDB store. This method uses a callback to **Example** - ``` + ```js function storeObserver(devices) { for (let i = 0; i < devices.length; i++) { - console.log('device=' + device[i] + ' data changed') + console.log('device=' + devices[i] + ' data changed') } } try { @@ -1624,7 +1737,6 @@ Deletes the specified observer of the RDB store. This method uses a callback to } ``` - ## StoreConfig Manages the configuration of an RDB store. diff --git a/en/application-dev/reference/apis/js-apis-data-resultset.md b/en/application-dev/reference/apis/js-apis-data-resultset.md index e383a53035..3dca6cfcb0 100644 --- a/en/application-dev/reference/apis/js-apis-data-resultset.md +++ b/en/application-dev/reference/apis/js-apis-data-resultset.md @@ -8,7 +8,7 @@ You need to use [RdbStore.query()](js-apis-data-rdb.md#query) to obtain the **resultSet** object. -``` +```js import dataRdb from '@ohos.data.rdb'; let predicates = new dataRdb.RdbPredicates("EMPLOYEE") predicates.equalTo("AGE", 18) @@ -18,10 +18,6 @@ promise.then((resultSet) => { console.log(TAG + "resultSet columnCount:" + resultSet.columnCount);}) ``` - - - - ## ResultSet Provides methods to access the result set, which is obtained by querying the relational database (RDB) store. @@ -52,18 +48,18 @@ Obtains the column index based on the column name. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | columnName | string | Yes| Column name specified.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | number | Index of the column obtained.| -- Example - ``` +**Example** + ```js resultSet.goToFirstRow() const id = resultSet.getLong(resultSet.getColumnIndex("ID")) const name = resultSet.getString(resultSet.getColumnIndex("NAME")) @@ -80,18 +76,18 @@ Obtains the column name based on the column index. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | columnIndex | number | Yes| Column index specified.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | string | Column name obtained.| -- Example - ``` +**Example** + ```js const id = resultSet.getColumnName(0) const name = resultSet.getColumnName(1) const age = resultSet.getColumnName(2) @@ -106,18 +102,18 @@ Moves the cursor to the row based on the specified offset. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | offset | number | Yes| Offset relative to the current position.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| -- Example - ``` +**Example** + ```js let predicatesgoto = new dataRdb.RdbPredicates("EMPLOYEE") let promisequerygoto = rdbStore.query(predicatesgoto, ["ID", "NAME", "AGE", "SALARY", "CODES"]) promisequerygoto.then((resultSet) { @@ -137,18 +133,18 @@ Moves the cursor to the specified row in the result set. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | position | number | Yes| Position to which the cursor is to be moved.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| -- Example - ``` +**Example** + ```js let predicatesgotorow = new dataRdb.RdbPredicates("EMPLOYEE") let promisequerygotorow = rdbStore.query(predicatesgotorow, ["ID", "NAME", "AGE", "SALARY", "CODES"]) promisequerygotorow.then((resultSet) { @@ -169,13 +165,13 @@ Moves the cursor to the first row of the result set. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core -- Return value +**Return value** | Type| Description| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| -- Example - ``` +**Example** + ```js let predicatesgoFirst = new dataRdb.RdbPredicates("EMPLOYEE") let promisequerygoFirst = rdbStore.query(predicatesgoFirst, ["ID", "NAME", "AGE", "SALARY", "CODES"]) promisequerygoFirst.then((resultSet) { @@ -195,13 +191,13 @@ Moves the cursor to the last row of the result set. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core -- Return value +**Return value** | Type| Description| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| -- Example - ``` +**Example** + ```js let predicatesgoLast = new dataRdb.RdbPredicates("EMPLOYEE") let promisequerygoLast = rdbStore.query(predicatesgoLast, ["ID", "NAME", "AGE", "SALARY", "CODES"]) promisequerygoLast.then((resultSet) { @@ -221,13 +217,13 @@ Moves the cursor to the next row in the result set. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core -- Return value +**Return value** | Type| Description| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| -- Example - ``` +**Example** + ```js let predicatesgoNext = new dataRdb.RdbPredicates("EMPLOYEE") let promisequerygoNext = rdbStore.query(predicatesgoNext, ["ID", "NAME", "AGE", "SALARY", "CODES"]) promisequerygoNext.then((resultSet) { @@ -247,13 +243,13 @@ Moves the cursor to the previous row in the result set. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core -- Return value +**Return value** | Type| Description| | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| -- Example - ``` +**Example** + ```js let predicatesgoPrev = new dataRdb.RdbPredicates("EMPLOYEE") let promisequerygoPrev = rdbStore.query(predicatesgoPrev, ["ID", "NAME", "AGE", "SALARY", "CODES"]) promisequerygoPrev.then((resultSet) { @@ -273,18 +269,18 @@ Obtains the value in the specified column in the current row as a byte array. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | columnIndex | number | Yes| Index of the specified column, starting from 0.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | Uint8Array | Value in the specified column as a byte array.| -- Example - ``` +**Example** + ```js const codes = resultSet.getBlob(resultSet.getColumnIndex("CODES")) ``` @@ -297,18 +293,18 @@ Obtains the value in the specified column in the current row as a string. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | columnIndex | number | Yes| Index of the specified column, starting from 0.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | string | Value in the specified column as a string.| -- Example - ``` +**Example** + ```js const name = resultSet.getString(resultSet.getColumnIndex("NAME")) ``` @@ -321,18 +317,18 @@ Obtains the value in the specified column in the current row as a Long. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | columnIndex | number | Yes| Index of the specified column, starting from 0.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | number | Value in the specified column as a Long.| -- Example - ``` +**Example** + ```js const age = resultSet.getLong(resultSet.getColumnIndex("AGE")) ``` @@ -345,18 +341,18 @@ Obtains the value in the specified column in the current row as a double. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | columnIndex | number | Yes| Index of the specified column, starting from 0.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | number | Value in the specified column as a double.| -- Example - ``` +**Example** + ```js const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")) ``` @@ -369,18 +365,18 @@ Checks whether the value in the specified column of the current row is null. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | columnIndex | number | Yes| Index of the specified column, starting from 0.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | boolean | Returns **true** if the value is null; returns **false** otherwise.| -- Example - ``` +**Example** + ```js const isColumnNull = resultSet.isColumnNull(resultSet.getColumnIndex("CODES")) ``` @@ -393,13 +389,13 @@ Closes this result set. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core -- Example - ``` - let predicatesclose = new dataRdb.RdbPredicates("EMPLOYEE") - let predicatesclose = rdbStore.query(predicatesclose, ["ID", "NAME", "AGE", "SALARY", "CODES"]) - promisequerygoPrev.then((resultSet) { +**Example** + ```js + let predicatesClose = new dataRdb.RdbPredicates("EMPLOYEE") + let promiseClose = rdbStore.query(predicatesClose, ["ID", "NAME", "AGE", "SALARY", "CODES"]) + promiseClose.then((resultSet) { resultSet.close() }).catch((err) => { - console.log('query failed') + console.log('Failed to close resultset') }) ``` diff --git a/en/application-dev/reference/apis/js-apis-data-storage.md b/en/application-dev/reference/apis/js-apis-data-storage.md index 18cc1ce8d9..844b24576a 100644 --- a/en/application-dev/reference/apis/js-apis-data-storage.md +++ b/en/application-dev/reference/apis/js-apis-data-storage.md @@ -5,23 +5,25 @@ Lightweight storage provides applications with data processing capability and al > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> -> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> +> - The APIs of this module are no longer maintained since API Version 9. You are advised to use [`@ohos.data.preferences`](js-apis-data-preferences.md). ## Modules to Import -``` -import dataStorage from '@ohos.data.storage' +```js +import dataStorage from '@ohos.data.storage'; ``` -## Attributes +## Constants **System capability**: SystemCapability.DistributedDataManager.Preferences.Core | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | | MAX_KEY_LENGTH | string | Yes| No| Maximum length of a key. It is 80 bytes.| -| MAX_VALUE_LENGTH | string | Yes| No| Maximum length of a value of the string type. It is 8192 bytes.| +| MAX_VALUE_LENGTH | string | Yes| No| Maximum length of a value. It is 8192 bytes.| ## dataStorage.getStorageSync @@ -32,18 +34,18 @@ Reads a file and loads the data to the **Storage** instance in synchronous mode. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Path of the target file.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | [Storage](#storage) | **Storage** instance used for data storage operations.| -- Example - ``` +**Example** + ```js import dataStorage from '@ohos.data.storage' import featureAbility from '@ohos.ability.featureAbility' @@ -65,18 +67,18 @@ Reads a file and loads the data to the **Storage** instance in synchronous mode. getStorage(path: string, callback: AsyncCallback<Storage>): void -Reads a file and loads the data to the **Storage** instance. This method uses an asynchronous callback to return the execution result. +Reads a file and loads the data to the **Storage** instance. This API uses an asynchronous callback to return the execution result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Path of the target file.| | callback | AsyncCallback<[Storage](#storage)> | Yes| Callback used to return the execution result.| -- Example - ``` +**Example** + ```js import dataStorage from '@ohos.data.storage' import featureAbility from '@ohos.ability.featureAbility' @@ -103,22 +105,22 @@ Reads a file and loads the data to the **Storage** instance. This method uses an getStorage(path: string): Promise<Storage> -Reads a file and loads the data to the **Storage** instance. This method uses a promise to return the execution result. +Reads a file and loads the data to the **Storage** instance. This API uses a promise to return the execution result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Path of the target file.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | Promise<[Storage](#storage)> | Promise used to return the result.| -- Example - ``` +**Example** + ```js import dataStorage from '@ohos.data.storage' import featureAbility from '@ohos.ability.featureAbility' @@ -144,17 +146,17 @@ Reads a file and loads the data to the **Storage** instance. This method uses a deleteStorageSync(path: string): void -Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This method uses a synchronous mode. +Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses a synchronous mode. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Path of the target file.| -- Example - ``` +**Example** + ```js dataStorage.deleteStorageSync(path + '/mystore') ``` @@ -163,18 +165,18 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete deleteStorage(path: string, callback: AsyncCallback<void>): void -Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This method uses an asynchronous callback to return the execution result. +Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses an asynchronous callback to return the execution result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Path of the target file.| | callback | AsyncCallback<void> | Yes| Callback used to return the execution result.| -- Example - ``` +**Example** + ```js dataStorage.deleteStorage(path + '/mystore', function (err) { if (err) { console.info("Deleted failed with err: " + err) @@ -189,22 +191,22 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete deleteStorage(path: string): Promise<void> -Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This method uses a promise to return the execution result. +Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses a promise to return the execution result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Path of the target file.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | Promise<void> | Promise used to return the result.| -- Example - ``` +**Example** + ```js let promisedelSt = dataStorage.deleteStorage(path + '/mystore') promisedelSt.then(() => { console.info("Deleted successfully.") @@ -220,17 +222,17 @@ removeStorageFromCacheSync(path: string): void Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur. -This method uses a synchronous mode. +This API uses a synchronous mode. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Path of the target file.| -- Example - ``` +**Example** + ```js dataStorage.removeStorageFromCacheSync(path + '/mystore') ``` @@ -241,18 +243,18 @@ removeStorageFromCache(path: string, callback: AsyncCallback<void>): void Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur. -This method uses an asynchronous callback to return the result. +This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Path of the target file.| | callback | AsyncCallback<void> | Yes| Callback used to return the execution result.| -- Example - ``` +**Example** + ```js dataStorage.removeStorageFromCache(path + '/mystore', function (err) { if (err) { console.info("Removed storage from cache failed with err: " + err) @@ -269,22 +271,22 @@ removeStorageFromCache(path: string): Promise<void> Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur. -This method uses an asynchronous callback to return the result. +This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | path | string | Yes| Path of the target file.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | Promise<void> | Promise used to return the result.| -- Example - ``` +**Example** + ```js let promiserevSt = dataStorage.removeStorageFromCache(path + '/mystore') promiserevSt.then(() => { console.info("Removed storage from cache successfully.") @@ -305,23 +307,23 @@ getSync(key: string, defValue: ValueType): ValueType Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. -This method uses a synchronous mode. +This API uses a synchronous mode. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | string | Yes| Key of the data. It cannot be empty.| - | defValue | ValueType | Yes| Default value to be returned if the value of the specified key does not exist. It can be a number, string, or Boolean value.| + | defValue | [ValueType](#valuetype) | Yes| Default value to be returned if the value of the specified key does not exist. It can be a number, string, or Boolean value.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | ValueType | Value corresponding to the specified key. If the value is null or not in the default value format, the default value is returned.| -- Example - ``` +**Example** + ```js let value = storage.getSync('startup', 'default') console.info("The value of startup is " + value) ``` @@ -333,19 +335,19 @@ get(key: string, defValue: ValueType, callback: AsyncCallback<ValueType>): Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. -This method uses an asynchronous callback to return the result. +This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | string | Yes| Key of the data. It cannot be empty.| - | defValue | ValueType | Yes| Default value to be returned. It can be a number, string, or Boolean value.| + | defValue | [ValueType](#valuetype) | Yes| Default value to be returned. It can be a number, string, or Boolean value.| | callback | AsyncCallback<ValueType> | Yes| Callback used to return the execution result.| -- Example - ``` +**Example** + ```js storage.get('startup', 'default', function(err, value) { if (err) { console.info("Get the value of startup failed with err: " + err) @@ -362,23 +364,24 @@ get(key: string, defValue: ValueType): Promise<ValueType> Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. -This method uses a promise to return the result. +This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | key | string | Yes| Key of the data. It cannot be empty.| - | defValue | ValueType | Yes| Default value to be returned. It can be a number, string, or Boolean value.| +**Parameters** -- Return value +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| key | string | Yes| Key of the data. It cannot be empty.| +| defValue | [ValueType](#valuetype) | Yes| Default value to be returned. It can be a number, string, or Boolean value.| + +**Return value** | Type| Description| | -------- | -------- | | Promise<ValueType> | Promise used to return the result.| -- Example - ``` +**Example** + ```js let promiseget = storage.get('startup', 'default') promiseget.then((value) => { console.info("The value of startup is " + value) @@ -394,18 +397,18 @@ putSync(key: string, value: ValueType): void Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**. -This method uses a synchronous mode. +This API uses a synchronous mode. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | key | string | Yes| Key of the data to modify. It cannot be empty.| - | value | ValueType | Yes| New value to store. It can be a number, string, or Boolean value.| + | key | string | Yes| Key of the data. It cannot be empty.| + | value | [ValueType](#valuetype) | Yes| New value to store. It can be a number, string, or Boolean value.| -- Example - ``` +**Example** + ```js storage.putSync('startup', 'auto') ``` @@ -416,19 +419,19 @@ put(key: string, value: ValueType, callback: AsyncCallback<void>): void Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**. -This method uses an asynchronous callback to return the result. +This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | key | string | Yes| Key of the data to modify. It cannot be empty.| - | value | ValueType | Yes| New value to store. It can be a number, string, or Boolean value.| + | key | string | Yes| Key of the data. It cannot be empty.| + | value | [ValueType](#valuetype) | Yes| New value to store. It can be a number, string, or Boolean value.| | callback | AsyncCallback<void> | Yes| Callback used to return the execution result.| -- Example - ``` +**Example** + ```js storage.put('startup', 'auto', function (err) { if (err) { console.info("Put the value of startup failed with err: " + err) @@ -445,23 +448,23 @@ put(key: string, value: ValueType): Promise<void> Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**. -This method uses an asynchronous callback to return the result. +This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | key | string | Yes| Key of the data to modify. It cannot be empty.| - | value | ValueType | Yes| New value to store. It can be a number, string, or Boolean value.| + | key | string | Yes| Key of the data. It cannot be empty.| + | value | [ValueType](#valuetype) | Yes| New value to store. It can be a number, string, or Boolean value.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | Promise<void> | Promise used to return the result.| -- Example - ``` +**Example** + ```js let promiseput = storage.put('startup', 'auto') promiseput.then(() => { console.info("Put the value of startup successfully.") @@ -477,22 +480,22 @@ hasSync(key: string): boolean Checks whether the storage object contains data with a given key. -This method uses a synchronous mode. +This API uses a synchronous mode. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | string | Yes| Key of the data. It cannot be empty.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | boolean | Returns **true** if the storage object contains data with the specified key; returns **false** otherwise.| -- Example - ``` +**Example** + ```js let isExist = storage.hasSync('startup') if (isExist) { console.info("The key of startup is contained.") @@ -506,23 +509,23 @@ has(key: string, callback: AsyncCallback<boolean>): boolean Checks whether the storage object contains data with a given key. -This method uses an asynchronous callback to return the result. +This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | string | Yes| Key of the data. It cannot be empty.| | callback | AsyncCallback<boolean> | Yes| Callback used to return the execution result.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | boolean | Returns **true** if the storage object contains data with the specified key; returns **false** otherwise.| -- Example - ``` +**Example** + ```js storage.has('startup', function (err, isExist) { if (err) { console.info("Check the key of startup failed with err: " + err) @@ -541,22 +544,22 @@ has(key: string): Promise<boolean> Checks whether the storage object contains data with a given key. -This method uses an asynchronous callback to return the result. +This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | string | Yes| Key of the data. It cannot be empty.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | Promise<boolean> | Promise used to return the result.| -- Example - ``` +**Example** + ```js let promisehas = storage.has('startup') promisehas.then((isExist) => { if (isExist) { @@ -574,39 +577,39 @@ deleteSync(key: string): void Deletes data with the specified key from this storage object. -This method uses a synchronous mode. +This API uses a synchronous mode. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | string | Yes| Key of the data. It cannot be empty.| -- Example - ``` +**Example** + ```js storage.deleteSync('startup') ``` -### delete +### deletej delete(key: string, callback: AsyncCallback<void>): void Deletes data with the specified key from this storage object. -This method uses an asynchronous callback to return the result. +This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | string | Yes| Key of the data. It cannot be empty.| | callback | AsyncCallback<void> | Yes| Callback used to return the execution result.| -- Example - ``` +**Example** + ```js storage.delete('startup', function (err) { if (err) { console.info("Delete startup key failed with err: " + err) @@ -623,22 +626,22 @@ delete(key: string): Promise<void> Deletes data with the specified key from this storage object. -This method uses a promise to return the result. +This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | string | Yes| Key of the data.| -- Return value +**Return value** | Type| Description| | -------- | -------- | | Promise<void> | Promise used to return the result.| -- Example - ``` +**Example** + ```js let promisedel = storage.delete('startup') promisedel.then(() => { console.info("Deleted startup key successfully.") @@ -654,12 +657,12 @@ flushSync(): void Saves the modification of this object to the **Storage** instance and synchronizes the modification to the file. -This method uses a synchronous mode. +This API uses a synchronous mode. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Example - ``` +**Example** + ```js storage.flushSync() ``` @@ -670,17 +673,17 @@ flush(callback: AsyncCallback<void>): void Saves the modification of this object to the **Storage** instance and synchronizes the modification to the file. -This method uses an asynchronous callback to return the result. +This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | callback | AsyncCallback<void> | Yes| Callback used to return the execution result.| -- Example - ``` +**Example** + ```js storage.flush(function (err) { if (err) { console.info("Flush to file failed with err: " + err) @@ -697,17 +700,17 @@ flush(): Promise<void> Saves the modification of this object to the **Storage** instance and synchronizes the modification to the file. -This method uses an asynchronous callback to return the result. +This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Return value +**Return value** | Type| Description| | -------- | -------- | | Promise<void> | Promise used to return the result.| -- Example - ``` +**Example** + ```js let promiseflush = storage.flush() promiseflush.then(() => { console.info("Flushed to file successfully.") @@ -723,12 +726,12 @@ clearSync(): void Clears this **Storage** object. -This method uses a synchronous mode. +This API uses a synchronous mode. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Example - ``` +**Example** + ```js storage.clearSync() ``` @@ -739,17 +742,17 @@ clear(callback: AsyncCallback<void>): void Clears this **Storage** object. -This method uses an asynchronous callback to return the result. +This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | callback | AsyncCallback<void> | Yes| Callback used to return the execution result.| -- Example - ``` +**Example** + ```js storage.clear(function (err) { if (err) { console.info("Clear to file failed with err: " + err) @@ -766,17 +769,17 @@ clear(): Promise<void> Clears this **Storage** object. -This method uses an asynchronous callback to return the result. +This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Return value +**Return value** | Type| Description| | -------- | -------- | | Promise<void> | Promise used to return the result.| -- Example - ``` +**Example** + ```js let promiseclear = storage.clear() promiseclear.then(() => { console.info("Cleared to file successfully.") @@ -794,14 +797,14 @@ Subscribes to data changes. The **StorageObserver** needs to be implemented. Whe **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Description| | -------- | -------- | -------- | | type | string | Event type. The value **change** indicates data change events.| | callback | Callback<[StorageObserver](#storageobserver)> | Callback used to return data changes.| -- Example - ``` +**Example** + ```js var observer = function (key) { console.info("The key of " + key + " changed.") } @@ -819,14 +822,14 @@ Unsubscribes from data changes. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- Parameters +**Parameters** | Name| Type| Description| | -------- | -------- | -------- | | type | string | Event type. The value **change** indicates data change events.| | callback | Callback<[StorageObserver](#storageobserver)> | Callback used to return data changes.| -- Example - ``` +**Example** + ```js var observer = function (key) { console.info("The key of " + key + " changed.") } @@ -841,3 +844,15 @@ Unsubscribes from data changes. | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | string | No| Data changed.| + +## ValueType + +Enumerates the value types. + +**System capability**: SystemCapability.DistributedDataManager.Preferences.Core + +| Name | Description | +| ------- | -------------------- | +| number | The value is a number. | +| string | The value is a string. | +| boolean | The value is of Boolean type.| diff --git a/en/application-dev/reference/apis/js-apis-distributed-data.md b/en/application-dev/reference/apis/js-apis-distributed-data.md index 3001c532ea..8f5b800d57 100644 --- a/en/application-dev/reference/apis/js-apis-distributed-data.md +++ b/en/application-dev/reference/apis/js-apis-distributed-data.md @@ -1,12 +1,14 @@ # 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. + >![](../../public_sys-resources/icon-note.gif) **NOTE**
>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. ## Modules to Import -``` +```js import distributedData from '@ohos.data.distributedData'; ``` @@ -15,7 +17,7 @@ import distributedData from '@ohos.data.distributedData'; createKVManager(config: KVManagerConfig, callback: AsyncCallback<KVManager>): void -Creates a **KVManager** object to manage key-value (KV) stores. This method uses an asynchronous callback to return the result. +Creates a **KVManager** object to manage key-value (KV) stores. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -27,7 +29,7 @@ Creates a **KVManager** object to manage key-value (KV) stores. This method uses | callback | AsyncCallback<[KVManager](#kvmanager)> | Yes | Callback invoked to return the **KVManager** object created.| **Example** -``` +```js let kvManager; try { const kvManagerConfig = { @@ -54,7 +56,7 @@ try { createKVManager(config: KVManagerConfig): Promise<KVManager> -Creates a **KVManager** object to manage KV stores. This method uses a promise to return the result. +Creates a **KVManager** object to manage KV stores. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -72,7 +74,7 @@ Creates a **KVManager** object to manage KV stores. This method uses a promise t **Example** -``` +```js let kvManager; try { const kvManagerConfig = { @@ -129,13 +131,13 @@ Defines the user type. ## 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. +Creates a **KVManager** object to obtain KV store information. Before calling any method in **KVManager**, you must use [createKVManager](#distributeddatacreatekvmanager) to create a **KVManager** object. ### getKVStore getKVStore<T extends KVStore>(storeId: string, options: Options, callback: AsyncCallback<T>): void -Creates and obtains a KV store. This method uses an asynchronous callback to return the result. +Creates and obtains a KV store. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -145,11 +147,11 @@ Creates and obtains a KV store. This method uses an asynchronous callback to ret | ----- | ------ | ------ | ------ | | storeId | string | Yes | Unique identifier of the KV store. The length cannot exceed [MAX_STORE_ID_LENGTH](#constants).| | options | [Options](#options) | Yes | Configuration of the KV store.| -| callback | AsyncCallback<T>, <T extends KVStore>| Yes | Callback invoked to return the KV store created.| +| callback | AsyncCallback<T> , <T extends [KVStore](#kvstore)>| Yes | Callback invoked to return the KV store created.| **Example** -``` +```js let kvStore; let kvManager; try { @@ -179,7 +181,7 @@ try { getKVStore<T extends KVStore>(storeId: string, options: Options): Promise<T> -Creates and obtains a KV store. This method uses a promise to return the result. +Creates and obtains a KV store. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -195,11 +197,11 @@ Creates and obtains a KV store. This method uses a promise to return the result. | Type | Description | | -------------------------------------- | ------------------------ | -| Promise<T> <T extends KVStore> | Promise used to return the KV store created.| +| Promise<T> <T extends [KVStore](#kvstore)> | Promise used to return the KV store created.| **Example** -``` +```js let kvStore; let kvManager; try { @@ -226,7 +228,7 @@ try { closeKVStore(appId: string, storeId: string, kvStore: KVStore, callback: AsyncCallback<void>): void -Closes a KV store. This method uses an asynchronous callback to return the result. +Closes a KV store. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -236,13 +238,13 @@ Closes a KV store. This method uses an asynchronous callback to return the resul | Name | Type | Mandatory| Description | | ------- | ----------------- | ---- | --------------------------- | | 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. | +| storeId | string | Yes | Unique identifier of the KV store to close. The length cannot exceed [MAX_STORE_ID_LENGTH](#constants).| +| kvStore | [KVStore](#kvstore) | Yes | KV store to close. | | callback | AsyncCallback<void> | Yes | Callback used to return the result. If the KV store is closed, **true** will be returned. Otherwise, **false** will be returned. | **Example** -``` +```js let kvStore; let kvManager; const options = { @@ -272,7 +274,7 @@ const options = { closeKVStore(appId: string, storeId: string, kvStore: KVStore): Promise<void> -Closes a KV store. This method uses a promise to return the result. +Closes a KV store. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -281,18 +283,18 @@ Closes a KV store. This method uses a promise to return the result. | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------------- | | 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).| +| 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. | **Return value** | Type | Description | | ------------- | -------------- | -| Promise | Promise used to return the result. If the KV store is closed, **true** will be returned. Otherwise, **false** will be returned.| +| Promise\ | Promise used to return the result. If the KV store is closed, **true** will be returned. Otherwise, **false** will be returned.| **Example** -``` +```js let kvManager; let kvStore; const options = { @@ -326,7 +328,7 @@ const options = { deleteKVStore(appId: string, storeId: string, callback: AsyncCallback<void>): void -Deletes a KV store. This method uses an asynchronous callback to return the result. +Deletes a KV store. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -335,12 +337,12 @@ Deletes a KV store. This method uses an asynchronous callback to return the resu | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | 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).| +| storeId | string | Yes | Unique identifier of the KV store to delete. The length cannot exceed [MAX_STORE_ID_LENGTH](#constants).| | callback | AsyncCallback<void> | Yes | Callback used to return the result. If the KV store is deleted, **true** will be returned. Otherwise, **false** will be returned. | **Example** -``` +```js let kvManager; let kvStore; const options = { @@ -369,7 +371,7 @@ try { deleteKVStore(appId: string, storeId: string): Promise<void> -Deletes a KV store. This method uses a promise to return the result. +Deletes a KV store. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -378,7 +380,7 @@ Deletes a KV store. This method uses a promise to return the result. | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | 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).| +| storeId | string | Yes | Unique identifier of the KV store to delete. The length cannot exceed [MAX_STORE_ID_LENGTH](#constants).| **Return value** @@ -389,7 +391,7 @@ Deletes a KV store. This method uses a promise to return the result. **Example** -``` +```js let kvManager; let kvStore; const options = { @@ -402,7 +404,7 @@ const options = { securityLevel : distributedData.SecurityLevel.S2, } try { - kvManager.getKVStore('storId', options).then(async (store) => { + kvManager.getKVStore('storeId', options).then(async (store) => { console.log('getKVStore success'); kvStore = store; await kvManager.deleteKVStore('appId', 'storeId').then(() => { @@ -423,7 +425,7 @@ try { getAllKVStoreId(appId: string, callback: AsyncCallback<string[]>): void -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](#getkvstore) and have not been deleted using [deleteKVStore](#deletekvstore8). This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -436,7 +438,7 @@ Obtains the IDs of all the KV stores that are created using **getKvStore** and h **Example** -``` +```js let kvManager; try { kvManager.getAllKVStoreId('appId', function (err, data) { @@ -453,7 +455,7 @@ try { getAllKVStoreId(appId: string): Promise<string[]> -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. +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. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -472,7 +474,7 @@ Obtains the IDs of all the KV stores that are created using **getKvStore** and h **Example** -``` +```js let kvManager; try { console.log('GetAllKVStoreId'); @@ -488,11 +490,11 @@ try { ``` -### on8+ ### +### on('distributedDataServiceDie')8+ ### on(event: 'distributedDataServiceDie', deathCallback: Callback<void>): void -Subscribes to the **distributedDataServiceDie** events. This method uses a synchronous callback to return the result. +Subscribes to the **distributedDataServiceDie** events. This API uses a synchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -500,12 +502,12 @@ Subscribes to the **distributedDataServiceDie** events. This method uses a synch | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| event | 'distributedDataServiceDie' | Yes | Type of events to subscribe to. | +| event | string | Yes | Name of the event to subscribe to. The value is **distributedDataServiceDie**, which indicates the service status change event.| | deathCallback | Callback<void> | Yes | Callback invoked when the distributed data service is dead. | **Example** -``` +```js let kvManager; try { @@ -520,11 +522,11 @@ try { ``` -### off8+ ### +### off('distributedDataServiceDie')8+ ### off(event: 'distributedDataServiceDie', deathCallback?: Callback<void>): void -Unsubscribes from the **distributedDataServiceDie** events. This method uses a synchronous callback to return the result. +Unsubscribes from the **distributedDataServiceDie** events. This API uses a synchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -532,13 +534,13 @@ Unsubscribes from the **distributedDataServiceDie** events. This method uses a s | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| event | 'distributedDataServiceDie' | Yes | Type of events to unsubscribe from. | +| event | string | Yes | Name of the event to unsubscribe from. The value is **distributedDataServiceDie**, which indicates the service status change event.| | deathCallback | Callback<void> | No | Callback used to return the **distributedDataServiceDie** events. | **Example** -``` +```js let kvManager; try { console.log('KVManagerOff'); @@ -563,7 +565,7 @@ Provides KV store configuration. | 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.
**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.| | securityLevel | [SecurityLevel](#securitylevel) | No|Security level of the KV store. By default, the security level is not set. | | schema8+ | [Schema](#schema8) | No| Schema used to define the values stored in a KV store.| @@ -621,7 +623,7 @@ Defines a database schema. When creating or opening a KV store, you can create a | Name | Type| Description | | --- | ---- | ----------------------- | -| root8+ | [FieldNode](#fieldnode8) | JSON root object. | +| root8+ | [FieldNode](#fieldnode8) | JSON root object.| | indexes8+ | Array\ | String array in JSON format. | | mode8+ | number | Schema mode. | | skip8+ | number | Size of a skip of the schema. | @@ -674,7 +676,6 @@ Appends a child node to this **FieldNode**. | ----- | ------ | ---- | ----------------------- | | child | [FieldNode](#fieldnode8) | Yes | Child node to append. | - **Return value** | Type | Description | @@ -683,7 +684,7 @@ Appends a child node to this **FieldNode**. **Example** -``` +```js import ddm from '@ohos.data.distributedData'; try { let node = new ddm.FieldNode("root"); @@ -725,7 +726,7 @@ Obtains the number of rows in the result set. **Example** -``` +```js let kvStore; try { let resultSet; @@ -758,7 +759,7 @@ Obtains the current data read position (position from which data is read) in the **Example** -``` +```js let kvStore; try { let resultSet; @@ -792,7 +793,7 @@ Moves the data read position to the first row. **Example** -``` +```js let kvStore; try { let resultSet; @@ -826,7 +827,7 @@ Moves the data read position to the last row. **Example** -``` +```js let kvStore; try { let resultSet; @@ -860,7 +861,7 @@ Moves the data read position to the next row. **Example** -``` +```js let kvStore; try { let resultSet; @@ -894,7 +895,7 @@ Moves the data read position to the previous row. **Example** -``` +```js let kvStore; try { let resultSet; @@ -934,7 +935,7 @@ Moves the data read position with the specified offset from the current position **Example** -``` +```js let kvStore; try { let resultSet; @@ -974,7 +975,7 @@ Moves the data read position from 0 to an absolute position. **Example** -``` +```js let kvStore; try { let resultSet; @@ -1008,7 +1009,7 @@ Checks whether the data read position is the first row. **Example** -``` +```js let kvStore; try { let resultSet; @@ -1042,7 +1043,7 @@ Checks whether the data read position is the last row. **Example** -``` +```js let kvStore; try { let resultSet; @@ -1075,7 +1076,7 @@ Checks whether the data read position is before the first row. **Example** -``` +```js let kvStore; try { let resultSet; @@ -1109,7 +1110,7 @@ Checks whether the data read position is after the last row. **Example** -``` +```js let kvStore; try { let resultSet; @@ -1139,11 +1140,11 @@ Obtains a KV pair. | Type | Description | | ------ | ------- | -| Entry |KV pair obtained.| +| [Entry](#entry) |KV pair obtained.| **Example** -``` +```js let kvStore; try { let resultSet; @@ -1194,7 +1195,7 @@ Resets the **Query** object that contains common query options. **Example** -``` +```js try { let query = new distributedData.Query(); query.equalTo("key", "value"); @@ -1210,7 +1211,7 @@ try { ### equalTo8+ ### -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. @@ -1221,17 +1222,17 @@ Creates a **Query** object to match the specified field whose value is equal to | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | -| value | number/string/boolean | Yes | Value specified.| +| value | number\|string\|boolean | Yes | Value specified.| **Return value** | Type | Description | | ------ | ------- | -| [Query](#query8) |**Query** object created.| +| [Query](#query8) |**Query** object reset.| **Example** -``` +```js try { let query = new distributedData.Query(); query.equalTo("field", "value"); @@ -1256,7 +1257,7 @@ Creates a **Query** object to match the specified field whose value is not equal | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | -| value | number/string/boolean | Yes | Value specified.| +| value | number\|string\|boolean | Yes | Value specified.| **Return value** @@ -1266,7 +1267,7 @@ Creates a **Query** object to match the specified field whose value is not equal **Example** -``` +```js try { let query = new distributedData.Query(); query.notEqualTo("field", "value"); @@ -1301,7 +1302,7 @@ Creates a **Query** object to match the specified field whose value is greater t **Example** -``` +```js try { let query = new distributedData.Query(); query.greaterThan("field", "value"); @@ -1336,7 +1337,7 @@ Creates a **Query** object to match the specified field whose value is less than **Example** -``` +```js try { let query = new distributedData.Query(); query.lessThan("field", "value"); @@ -1371,7 +1372,7 @@ Creates a **Query** object to match the specified field whose value is greater t **Example** -``` +```js try { let query = new distributedData.Query(); query.greaterThanOrEqualTo("field", "value"); @@ -1406,7 +1407,7 @@ Creates a **Query** object to match the specified field whose value is less than **Example** -``` +```js try { let query = new distributedData.Query(); query.lessThanOrEqualTo("field", "value"); @@ -1441,7 +1442,7 @@ Creates a **Query** object to match the specified field whose value is **null**. **Example** -``` +```js try { let query = new distributedData.Query(); query.isNull("field"); @@ -1477,7 +1478,7 @@ Creates a **Query** object to match the specified field whose value is within th **Example** -``` +```js try { let query = new distributedData.Query(); query.inNumber("field", [0, 1]); @@ -1512,7 +1513,7 @@ Creates a **Query** object to match the specified field whose value is within th **Example** -``` +```js try { let query = new distributedData.Query(); query.inString("field", ['test1', 'test2']); @@ -1547,7 +1548,7 @@ Creates a **Query** object to match the specified field whose value is not withi **Example** -``` +```js try { let query = new distributedData.Query(); query.notInNumber("field", [0, 1]); @@ -1582,7 +1583,7 @@ Creates a **Query** object to match the specified field whose value is not withi **Example** -``` +```js try { let query = new distributedData.Query(); query.notInString("field", ['test1', 'test2']); @@ -1617,7 +1618,7 @@ Creates a **Query** object to match the specified field whose value is similar t **Example** -``` +```js try { let query = new distributedData.Query(); query.like("field", "value"); @@ -1652,7 +1653,7 @@ Creates a **Query** object to match the specified field whose value is not simil **Example** -``` +```js try { let query = new distributedData.Query(); query.unlike("field", "value"); @@ -1680,7 +1681,7 @@ Creates a **Query** object with the AND condition. **Example** -``` +```js try { let query = new distributedData.Query(); query.notEqualTo("field", "value1"); @@ -1710,7 +1711,7 @@ Creates a **Query** object with the OR condition. **Example** -``` +```js try { let query = new distributedData.Query(); query.notEqualTo("field", "value1"); @@ -1746,7 +1747,7 @@ Creates a **Query** object to sort the query results in ascending order. **Example** -``` +```js try { let query = new distributedData.Query(); query.notEqualTo("field", "value"); @@ -1781,7 +1782,7 @@ Creates a **Query** object to sort the query results in descending order. **Example** -``` +```js try { let query = new distributedData.Query(); query.notEqualTo("field", "value"); @@ -1817,7 +1818,7 @@ Creates a **Query** object to specify the number of results and where to start. **Example** -``` +```js try { let query = new distributedData.Query(); query.notEqualTo("field", "value"); @@ -1852,7 +1853,7 @@ Creates a **Query** object with a specified field that is not null. **Example** -``` +```js try { let query = new distributedData.Query(); query.isNotNull("field"); @@ -1880,7 +1881,7 @@ Creates a **Query** object for a query condition group with a left parenthesis. **Example** -``` +```js try { let query = new distributedData.Query(); query.beginGroup(); @@ -1910,7 +1911,7 @@ Creates a **Query** object for a query condition group with a right parenthesis. **Example** -``` +```js try { let query = new distributedData.Query(); query.beginGroup(); @@ -1946,7 +1947,7 @@ Creates a **Query** object with a specified key prefix. **Example** -``` +```js try { let query = new distributedData.Query(); query.prefixKey("$.name"); @@ -1981,7 +1982,7 @@ Creates a **Query** object with an index preferentially used for query. **Example** -``` +```js try { let query = new distributedData.Query(); query.setSuggestIndex("$.name"); @@ -2017,7 +2018,7 @@ Creates a **Query** object with the device ID as the key prefix. **Example** -``` +```js try { let query = new distributedData.Query(); query.deviceId("deviceId"); @@ -2044,7 +2045,7 @@ Obtains the query statement of this **Query** object. **Example** -``` +```js try { let query = new distributedData.Query(); let sql1 = query.getSqlLike(); @@ -2065,7 +2066,7 @@ Provides methods to manage data in a KV store, for example, adding or deleting d put(key: string, value: Uint8Array | string | number | boolean, callback: AsyncCallback<void>): void -Adds a KV pair of the specified type to this KV store. This method uses an asynchronous callback to return the result. +Adds a KV pair of the specified type to this KV store. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2075,11 +2076,11 @@ Adds a KV pair of the specified type to this KV store. This method uses an async | ----- | ------ | ---- | ----------------------- | | 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. | +| callback | AsyncCallback<void> | Yes |Callback used to return the result. | **Example** -``` +```js let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; @@ -2101,7 +2102,7 @@ try { put(key: string, value: Uint8Array | string | number | boolean): Promise<void> -Adds a KV pair of the specified type to this KV store. This method uses a promise to return the result. +Adds a KV pair of the specified type to this KV store. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2120,7 +2121,7 @@ Adds a KV pair of the specified type to this KV store. This method uses a promis **Example** -``` +```js let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; @@ -2140,7 +2141,7 @@ try { delete(key: string, callback: AsyncCallback<void>): void -Deletes a KV pair from this KV store. This method uses an asynchronous callback to return the result. +Deletes a KV pair from this KV store. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2149,11 +2150,11 @@ Deletes a KV pair from this KV store. This method uses an asynchronous callback | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | key | string | Yes |Key of the KV pair to delete. It cannot be empty, and the length cannot exceed [MAX_KEY_LENGTH](#constants). | -| callback | AsyncCallback<void> | Yes |Callback invoked to return the result. | +| callback | AsyncCallback<void> | Yes |Callback used to return the result. | **Example** -``` +```js let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; @@ -2182,7 +2183,7 @@ try { delete(key: string): Promise<void> -Deletes a KV pair from this KV store. This method uses a promise to return the result. +Deletes a KV pair from this KV store. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2200,7 +2201,7 @@ Deletes a KV pair from this KV store. This method uses a promise to return the r **Example** -``` +```js let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; @@ -2221,11 +2222,11 @@ try { ``` -### on +### on('dataChange') on(event: 'dataChange', type: SubscribeType, observer: Callback<ChangeNotification>): void -Subscribes to data changes of the specified type. This method uses a synchronous callback to return the result. +Subscribes to data changes of the specified type. This API uses a synchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2233,13 +2234,13 @@ Subscribes to data changes of the specified type. This method uses a synchronous | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| event |'dataChange' | Yes |Type of the events. | +| event |string | Yes |Name of the event to subscribe to. The value is **dataChange**, which indicates the data change event. | | type |[SubscribeType](#subscribetype) | Yes |Type of data changes. | -| observer |Callback<[ChangeNotification](#changenotification)> | Yes |Callback invoked to return the result.| +| observer |Callback<[ChangeNotification](#changenotification)> | Yes |Callback used to return the result.| **Example** -``` +```js let kvStore; kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, function (data) { console.log("dataChange callback call data: " + JSON.stringify(data)); @@ -2247,11 +2248,11 @@ kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, fun ``` -### on +### on('syncComplete') on(event: 'syncComplete', syncCallback: Callback<Array<[string, number]>>): void -Subscribes to data synchronization completion events. This method uses a synchronous callback to return the result. +Subscribes to data synchronization completion events. This API uses a synchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2259,8 +2260,8 @@ Subscribes to data synchronization completion events. This method uses a synchro | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| event |'syncComplete' | Yes |Type of the events. | -| syncCallback |Callback<Array<[string, number]>> | Yes |Callback invoked to return the result. | +| event |string | Yes |Name of the event to subscribe to. The value is **syncComplete**, which indicates the synchronization complete event. | +| syncCallback |Callback<Array<[string, number]>> | Yes |Callback used to return the result. | **Example** @@ -2271,11 +2272,11 @@ kvStore.on('syncComplete', function (data) { }); ``` -### off8+ +### off('dataChange')8+ off(event:'dataChange', observer?: Callback<ChangeNotification>): void -Unsubscribes from data change events. This method uses a synchronous callback to return the result. +Unsubscribes from data change events. This API uses a synchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2283,15 +2284,15 @@ Unsubscribes from data change events. This method uses a synchronous callback to | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| event |'dataChange' | Yes |Type of the events. | +| event |string | Yes |Name of the event to unsubscribe from. The value is **dataChange**, which indicates the data change event. | | observer |Callback<[ChangeNotification](#changenotification)> |No |Callback used to return the result.| **Example** -``` +```js let kvStore; kvStore.on('dataChange', function (data) { - console.log("callback call data: " + data); + console.log("callback call data: " + data); }); kvStore.off('dataChange', function (data) { console.log("callback call data: " + data); @@ -2303,7 +2304,7 @@ kvStore.off('dataChange', function (data) { putBatch(entries: Entry[], callback: AsyncCallback<void>): void -Inserts KV pairs in batches to this KV store. This method uses an asynchronous callback to return the result. +Inserts KV pairs in batches to this KV store. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2312,11 +2313,11 @@ Inserts KV pairs in batches to this KV store. This method uses an asynchronous c | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | entries |[Entry](#entry)[] | Yes |KV pairs to insert in batches. | -| callback |Asyncallback<void> |Yes |Callback invoked to return the result.| +| callback |Asyncallback<void> |Yes |Callback used to return the result.| **Example** -``` +```js let kvStore; try { let entries = []; @@ -2350,7 +2351,7 @@ try { putBatch(entries: Entry[]): Promise<void> -Inserts KV pairs in batches to this KV store. This method uses a promise to return the result. +Inserts KV pairs in batches to this KV store. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2368,7 +2369,7 @@ Inserts KV pairs in batches to this KV store. This method uses a promise to retu **Example** -``` +```js let kvStore; try { let entries = []; @@ -2405,7 +2406,7 @@ try { deleteBatch(keys: string[], callback: AsyncCallback<void>): void -Deletes KV pairs in batches from this KV store. This method uses an asynchronous callback to return the result. +Deletes KV pairs in batches from this KV store. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2414,11 +2415,11 @@ Deletes KV pairs in batches from this KV store. This method uses an asynchronous | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | keys |string[] | Yes |KV pairs to delete in batches. | -| callback |AsyncCallback<void> | Yes |Callback invoked to return the result. | +| callback |AsyncCallback<void> | Yes |Callback used to return the result. | **Example** -``` +```js let kvStore; try { let entries = []; @@ -2452,7 +2453,7 @@ try { deleteBatch(keys: string[]): Promise<void> -Deletes KV pairs in batches from this KV store. This method uses a promise to return the result. +Deletes KV pairs in batches from this KV store. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2470,7 +2471,7 @@ Deletes KV pairs in batches from this KV store. This method uses a promise to re **Example** -``` +```js let kvStore; try { let entries = []; @@ -2508,7 +2509,7 @@ try { startTransaction(callback: AsyncCallback<void>): void -Starts the transaction in this KV store. This method uses an asynchronous callback to return the result. +Starts the transaction in this KV store. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2516,11 +2517,11 @@ Starts the transaction in this KV store. This method uses an asynchronous callba | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| callback |AsyncCallback<void> | Yes |Callback invoked to return the result. | +| callback |AsyncCallback<void> | Yes |Callback used to return the result. | **Example** -``` +```js let kvStore; function putBatchString(len, prefix) { let entries = []; @@ -2560,7 +2561,7 @@ try { startTransaction(): Promise<void> -Starts the transaction in this KV store. This method uses a promise to return the result. +Starts the transaction in this KV store. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2572,7 +2573,7 @@ Starts the transaction in this KV store. This method uses a promise to return th **Example** -``` +```js let kvStore; try { var count = 0; @@ -2595,7 +2596,7 @@ try { commit(callback: AsyncCallback<void>): void -Commits the transaction in this KV store. This method uses an asynchronous callback to return the result. +Commits the transaction in this KV store. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2603,11 +2604,11 @@ Commits the transaction in this KV store. This method uses an asynchronous callb | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| callback |AsyncCallback<void> | Yes |Callback invoked to return the result. | +| callback |AsyncCallback<void> | Yes |Callback used to return the result. | **Example** -``` +```js let kvStore; try { kvStore.commit(function (err,data) { @@ -2627,7 +2628,7 @@ try { commit(): Promise<void> -Commits the transaction in this KV store. This method uses a promise to return the result. +Commits the transaction in this KV store. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2639,7 +2640,7 @@ Commits the transaction in this KV store. This method uses a promise to return t **Example** -``` +```js let kvStore; try { kvStore.commit().then(async (err) => { @@ -2657,7 +2658,7 @@ try { rollback(callback: AsyncCallback<void>): void -Rolls back the transaction in this KV store. This method uses an asynchronous callback to return the result. +Rolls back the transaction in this KV store. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2665,11 +2666,11 @@ Rolls back the transaction in this KV store. This method uses an asynchronous ca | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| callback |AsyncCallback<void> | Yes |Callback invoked to return the result. | +| callback |AsyncCallback<void> | Yes |Callback used to return the result. | **Example** -``` +```js let kvStore; try { kvStore.rollback(function (err,data) { @@ -2689,7 +2690,7 @@ try { rollback(): Promise<void> -Rolls back the transaction in this KV store. This method uses a promise to return the result. +Rolls back the transaction in this KV store. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2701,7 +2702,7 @@ Rolls back the transaction in this KV store. This method uses a promise to retur **Example** -``` +```js let kvStore; try { kvStore.rollback().then(async (err) => { @@ -2719,7 +2720,7 @@ try { enableSync(enabled: boolean, callback: AsyncCallback<void>): void -Sets data synchronization, which can be enabled or disable. This method uses an asynchronous callback to return the result. +Sets data synchronization, which can be enabled or disable. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2728,11 +2729,11 @@ Sets data synchronization, which can be enabled or disable. This method uses an | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | 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. | +| callback |AsyncCallback<void> | Yes |Callback used to return the result. | **Example** -``` +```js let kvStore; try { kvStore.enableSync(true, function (err,data) { @@ -2752,7 +2753,7 @@ try { enableSync(enabled: boolean): Promise<void> -Enables or disables data synchronization. This method uses a promise to return the result. +Enables or disables data synchronization. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2770,7 +2771,7 @@ Enables or disables data synchronization. This method uses a promise to return t **Example** -``` +```js let kvStore; try { kvStore.enableSync(true).then((err) => { @@ -2788,7 +2789,7 @@ try { setSyncRange(localLabels: string[], remoteSupportLabels: string[], callback: AsyncCallback<void>): void -Sets the data synchronization range. This method uses an asynchronous callback to return the result. +Sets the data synchronization range. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2798,11 +2799,11 @@ Sets the data synchronization range. This method uses an asynchronous callback t | ----- | ------ | ---- | ----------------------- | | localLabels |string[] | Yes |Synchronization labels set for the local device. | | remoteSupportLabels |string[] | Yes |Synchronization labels set for remote devices. | -| callback |AsyncCallback<void> | Yes |Callback invoked to return the result. | +| callback |AsyncCallback<void> | Yes |Callback used to return the result. | **Example** -``` +```js let kvStore; try { const localLabels = ['A', 'B']; @@ -2820,7 +2821,7 @@ try { setSyncRange(localLabels: string[], remoteSupportLabels: string[]): Promise<void> -Sets the data synchronization range. This method uses a promise to return the result. +Sets the data synchronization range. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2840,7 +2841,7 @@ Sets the data synchronization range. This method uses a promise to return the re **Example** -``` +```js let kvStore; try { const localLabels = ['A', 'B']; @@ -2902,7 +2903,7 @@ Defines the value in a KV pair. | Name | Type |Readable |Writable | Description | | ----- | ------- | -----| ------|------------------------ | | type | [ValueType](#value) | Yes | Yes|Type of the value. | -| value | Uint8Array / string / number / boolean| Yes | Yes|Value of the KV pair stored in the KV store. | +| value | Uint8Array \| string \| number \| boolean| Yes | Yes|Value of the KV pair stored in the KV store. | ## ValueType @@ -2923,7 +2924,7 @@ These value types can be used only by internal applications. ## 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** to obtain a **SingleKVStore** object. +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. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2931,7 +2932,7 @@ Provides methods to query and synchronize data in a single KV store. This class get(key: string, callback: AsyncCallback<Uint8Array | string | boolean | number>): void -Obtains the value of a specified key. This method uses an asynchronous callback to return the result. +Obtains the value of a specified key. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2944,7 +2945,7 @@ Obtains the value of a specified key. This method uses an asynchronous callback **Example** -``` +```js let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; @@ -2969,7 +2970,7 @@ try { get(key: string): Promise<Uint8Array | string | boolean | number> -Obtains the value of a specified key. This method uses a promise to return the result. +Obtains the value of a specified key. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -2988,7 +2989,7 @@ Obtains the value of a specified key. This method uses a promise to return the r **Example** -``` +```js let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; @@ -3012,7 +3013,7 @@ try { getEntries(keyPrefix: string, callback: AsyncCallback<Entry[]>): void -Obtains the KV pairs that match the specified key prefix. This method uses an asynchronous callback to return the result. +Obtains the KV pairs that match the specified key prefix. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3025,7 +3026,7 @@ Obtains the KV pairs that match the specified key prefix. This method uses an as **Example** -``` +```js let kvStore; try { let entries = []; @@ -3058,7 +3059,7 @@ try { getEntries(keyPrefix: string): Promise<Entry[]> -Obtains the KV pairs that match the specified key prefix. This method uses a promise to return the result. +Obtains the KV pairs that match the specified key prefix. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3076,7 +3077,7 @@ Obtains the KV pairs that match the specified key prefix. This method uses a pro **Example** -``` +```js let kvStore; try { let entries = []; @@ -3116,7 +3117,7 @@ try { getEntries(query: Query, callback: AsyncCallback<Entry[]>): void -Obtains the KV pairs that match the specified **Query** object. This method uses an asynchronous callback to return the result. +Obtains the KV pairs that match the specified **Query** object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3129,7 +3130,7 @@ Obtains the KV pairs that match the specified **Query** object. This method uses **Example** -``` +```js let kvStore; try { var arr = new Uint8Array([21,31]); @@ -3167,7 +3168,7 @@ try { getEntries(query: Query): Promise<Entry[]> -Obtains the KV pairs that match the specified **Query** object. This method uses a promise to return the result. +Obtains the KV pairs that match the specified **Query** object. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3185,7 +3186,7 @@ Obtains the KV pairs that match the specified **Query** object. This method uses **Example** -``` +```js try { var arr = new Uint8Array([21,31]); let entries = []; @@ -3224,7 +3225,7 @@ try { getResultSet(keyPrefix: string, callback: AsyncCallback<KvStoreResultSet>): void -Obtains the result set with the specified key prefix from this single KV store. This method uses an asynchronous callback to return the result. +Obtains the result set with the specified key prefix from this single KV store. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3237,7 +3238,7 @@ Obtains the result set with the specified key prefix from this single KV store. **Example** -``` +```js let kvStore; try { let resultSet; @@ -3273,7 +3274,7 @@ try { getResultSet(keyPrefix: string): Promise<KvStoreResultSet> -Obtains the result set with the specified key prefix from this single KV store. This method uses a promise to return the result. +Obtains the result set with the specified key prefix from this single KV store. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3291,7 +3292,7 @@ Obtains the result set with the specified key prefix from this single KV store. **Example** -``` +```js let kvStore; try { let resultSet; @@ -3333,7 +3334,7 @@ try { getResultSet(query: Query, callback: AsyncCallback<KvStoreResultSet>): void -Obtains the **KvStoreResultSet** object that matches the specified **Query** object. This method uses an asynchronous callback to return the result. +Obtains the **KvStoreResultSet** object that matches the specified **Query** object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3346,7 +3347,7 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj **Example** -``` +```js let kvStore; try { let resultSet; @@ -3381,7 +3382,7 @@ try { getResultSet(query: Query): Promise<KvStoreResultSet> -Obtains the **KvStoreResultSet** object that matches the specified **Query** object. This method uses a promise to return the result. +Obtains the **KvStoreResultSet** object that matches the specified **Query** object. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3399,7 +3400,7 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj **Example** -``` +```js let kvStore; try { let resultSet; @@ -3437,7 +3438,7 @@ try { closeResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback<void>): void -Closes the **KvStoreResultSet** object obtained by **getResultSet**. This method uses an asynchronous callback to return the result. +Closes the **KvStoreResultSet** object obtained by **getResultSet**. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3450,7 +3451,7 @@ Closes the **KvStoreResultSet** object obtained by **getResultSet**. This method **Example** -``` +```js let kvStore; try { let resultSet = null; @@ -3471,7 +3472,7 @@ try { closeResultSet(resultSet: KvStoreResultSet): Promise<void> -Closes the **KvStoreResultSet** object obtained by **getResultSet**. This method uses a promise to return the result. +Closes the **KvStoreResultSet** object obtained by **getResultSet**. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3489,7 +3490,7 @@ Closes the **KvStoreResultSet** object obtained by **getResultSet**. This method **Example** -``` +```js let kvStore; try { let resultSet = null; @@ -3508,7 +3509,7 @@ try { getResultSize(query: Query, callback: AsyncCallback<number>): void -Obtains the number of results that matches the specified **Query** object. This method uses an asynchronous callback to return the result. +Obtains the number of results that matches the specified **Query** object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3521,7 +3522,7 @@ Obtains the number of results that matches the specified **Query** object. This **Example** -``` +```js let kvStore; try { let entries = []; @@ -3554,7 +3555,7 @@ try { getResultSize(query: Query): Promise<number> -Obtains the number of results that matches the specified **Query** object. This method uses a promise to return the result. +Obtains the number of results that matches the specified **Query** object. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3572,7 +3573,7 @@ Obtains the number of results that matches the specified **Query** object. This **Example** -``` +```js let kvStore; try { let entries = []; @@ -3609,7 +3610,7 @@ try { removeDeviceData(deviceId: string, callback: AsyncCallback<void>): void -Deletes data of a device. This method uses an asynchronous callback to return the result. +Deletes data of a device. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3622,7 +3623,7 @@ Deletes data of a device. This method uses an asynchronous callback to return th **Example** -``` +```js let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; const VALUE_TEST_STRING_ELEMENT = 'value-string-002'; @@ -3651,7 +3652,7 @@ try { removeDeviceData(deviceId: string): Promise<void> -Deletes data of a device. This method uses a promise to return the result. +Deletes data of a device. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3669,7 +3670,7 @@ Deletes data of a device. This method uses a promise to return the result. **Example** -``` +```js let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; const VALUE_TEST_STRING_ELEMENT = 'value-string-001'; @@ -3696,11 +3697,11 @@ try { ``` -### on8+ ### +### on('syncComplete')8+ ### on(event: 'syncComplete', syncCallback: Callback<Array<[string, number]>>): void -Subscribes to the synchronization completion events. This method uses a synchronous callback to return the result. +Subscribes to the synchronization completion events. This API uses a synchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3708,12 +3709,12 @@ Subscribes to the synchronization completion events. This method uses a synchron | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| event |'syncComplete' | Yes |Event triggered when the synchronization is complete. | +| event |string | Yes |Name of the event to subscribe to. The value is **syncComplete**, which indicates the synchronization complete event. | | syncCallback |Callback<Array<[string, number]>> | Yes |Callback used to return the synchronization result. | **Example** -``` +```js let kvStore; const KEY_TEST_FLOAT_ELEMENT = 'key_test_float'; const VALUE_TEST_FLOAT_ELEMENT = 321.12; @@ -3732,11 +3733,11 @@ try { ``` -### off8+ ### +### off('syncComplete')8+ ### off(event: 'syncComplete', syncCallback?: Callback<Array<[string, number]>>): void -Unsubscribes from the synchronization completion events. This method uses a synchronous callback to return the result. +Unsubscribes from the synchronization completion events. This API uses a synchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3744,12 +3745,12 @@ Unsubscribes from the synchronization completion events. This method uses a sync | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| event |'syncComplete' | Yes |Event triggered when the synchronization is complete. | +| event |string | Yes |Name of the event to unsubscribe from. The value is **syncComplete**, which indicates the synchronization complete event. | | syncCallback |Callback<Array<[string, number]>> | No |Callback used to return the synchronization result. | **Example** -``` +```js let kvStore; try { const func = function (data) { @@ -3768,6 +3769,7 @@ try { sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void Manually triggers KV store synchronization synchronously. + **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3782,7 +3784,7 @@ Manually triggers KV store synchronization synchronously. **Example** -``` +```js let kvStore; kvStore.sync('deviceIds', distributedData.SyncMode.PULL_ONLY, 1000); ``` @@ -3791,7 +3793,7 @@ kvStore.sync('deviceIds', distributedData.SyncMode.PULL_ONLY, 1000); setSyncParam(defaultAllowedDelayMs: number, callback: AsyncCallback<void>): void -Sets the default delay of database synchronization. This method uses an asynchronous callback to return the result. +Sets the default delay of database synchronization. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3804,7 +3806,7 @@ Sets the default delay of database synchronization. This method uses an asynchro **Example** -``` +```js let kvStore; try { const defaultAllowedDelayMs = 500; @@ -3821,7 +3823,7 @@ try { setSyncParam(defaultAllowedDelayMs: number): Promise<void> -Sets the default delay of database synchronization. This method uses a promise to return the result. +Sets the default delay of database synchronization. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3840,7 +3842,7 @@ Sets the default delay of database synchronization. This method uses a promise t **Example** -``` +```js let kvStore; try { const defaultAllowedDelayMs = 500; @@ -3859,7 +3861,7 @@ try { getSecurityLevel(callback: AsyncCallback<SecurityLevel>): void -Obtains the security level of this KV store. This method uses an asynchronous callback to return the result. +Obtains the security level of this KV store. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3871,7 +3873,7 @@ Obtains the security level of this KV store. This method uses an asynchronous ca **Example** -``` +```js let kvStore; try { kvStore.getSecurityLevel(function (err,data) { @@ -3887,7 +3889,7 @@ try { getSecurityLevel(): Promise<SecurityLevel> -Obtains the security level of this KV store. This method uses a promise to return the result. +Obtains the security level of this KV store. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -3899,7 +3901,7 @@ Obtains the security level of this KV store. This method uses a promise to retur **Example** -``` +```js let kvStore; try { kvStore.getSecurityLevel().then((data) => { @@ -3915,7 +3917,7 @@ try { ## DeviceKVStore8+ ## -Provides methods to manage distributed data by device in the distributed system. This class inherits from **KvStore** and provides data query and synchronization methods. Before calling any method in **DeviceKVStore**, you must use **getKVStore** to obtain a **DeviceKVStore** object. +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. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -3923,9 +3925,9 @@ Provides methods to manage distributed data by device in the distributed system. get(deviceId: string, key: string, callback: AsyncCallback<boolean|string|number|Uint8Array>): void -Obtains the string value that matches the specified key for a device. This method uses an asynchronous callback to return the result. +Obtains the string value that matches the specified key for a device. This API uses an asynchronous callback to return the result. -**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore +**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore **Parameters** @@ -3937,7 +3939,7 @@ Obtains the string value that matches the specified key for a device. This metho **Example** -``` +```js let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; const VALUE_TEST_STRING_ELEMENT = 'value-string-002'; @@ -3958,7 +3960,7 @@ try{ get(deviceId: string, key: string): Promise<boolean|string|number|Uint8Array> -Obtains the string value that matches the specified key for a device. This method uses a promise to return the result. +Obtains the string value that matches the specified key for a device. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -3973,11 +3975,11 @@ Obtains the string value that matches the specified key for a device. This metho | Type | Description | | ------ | ------- | -|Promise<boolean/string/number/Uint8Array> |Promise used to return the value obtained.| +|Promise<boolean\|string\|number\|Uint8Array> |Promise used to return the value obtained.| **Example** -``` +```js let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; const VALUE_TEST_STRING_ELEMENT = 'value-string-002'; @@ -4002,7 +4004,7 @@ try { getEntries(deviceId: string, keyPrefix: string, callback: AsyncCallback<Entry[]>): void -Obtains the KV pairs that match the specified key prefix for a device. This method uses an asynchronous callback to return the result. +Obtains the KV pairs that match the specified key prefix for a device. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4016,7 +4018,7 @@ Obtains the KV pairs that match the specified key prefix for a device. This meth **Example** -``` +```js let kvStore; try { let entries = []; @@ -4050,7 +4052,7 @@ try { getEntries(deviceId: string, keyPrefix: string): Promise<Entry[]> -Obtains the KV pairs that match the specified key prefix for a device. This method uses a promise to return the result. +Obtains the KV pairs that match the specified key prefix for a device. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4069,7 +4071,7 @@ Obtains the KV pairs that match the specified key prefix for a device. This meth **Example** -``` +```js let kvStore; try { let entries = []; @@ -4109,7 +4111,7 @@ try { getEntries(query: Query, callback: AsyncCallback<Entry[]>): void -Obtains the KV pairs that match the specified **Query** object. This method uses an asynchronous callback to return the result. +Obtains the KV pairs that match the specified **Query** object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4122,7 +4124,7 @@ Obtains the KV pairs that match the specified **Query** object. This method uses **Example** -``` +```js let kvStore; try { var arr = new Uint8Array([21,31]); @@ -4162,7 +4164,7 @@ try { getEntries(query: Query): Promise<Entry[]> -Obtains the KV pairs that match the specified **Query** object. This method uses a promise to return the result. +Obtains the KV pairs that match the specified **Query** object. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4180,7 +4182,7 @@ Obtains the KV pairs that match the specified **Query** object. This method uses **Example** -``` +```js let kvStore; try { var arr = new Uint8Array([21,31]); @@ -4220,7 +4222,7 @@ try { getEntries(deviceId: string, query: Query, callback: AsyncCallback<Entry[]>): void -Obtains the KV pairs that match the specified **Query** object for a device. This method uses an asynchronous callback to return the result. +Obtains the KV pairs that match the specified **Query** object for a device. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4234,7 +4236,7 @@ Obtains the KV pairs that match the specified **Query** object for a device. Thi **Example** -``` +```js let kvStore; try { var arr = new Uint8Array([21,31]); @@ -4274,7 +4276,7 @@ try { getEntries(deviceId: string, query: Query): Promise<Entry[]> -Obtains the KV pairs that match the specified **Query** object for a device. This method uses a promise to return the result. +Obtains the KV pairs that match the specified **Query** object for a device. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4293,7 +4295,7 @@ Obtains the KV pairs that match the specified **Query** object for a device. Thi **Example** -``` +```js let kvStore; try { var arr = new Uint8Array([21,31]); @@ -4334,7 +4336,7 @@ try { getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback<KvStoreResultSet>): void -Obtains the **KvStoreResultSet** object that matches the specified key prefix for a device. This method uses an asynchronous callback to return the result. +Obtains the **KvStoreResultSet** object that matches the specified key prefix for a device. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4348,7 +4350,7 @@ Obtains the **KvStoreResultSet** object that matches the specified key prefix fo **Example** -``` +```js let kvStore; try { let resultSet; @@ -4369,7 +4371,7 @@ try { getResultSet(deviceId: string, keyPrefix: string): Promise<KvStoreResultSet> -Obtains the **KvStoreResultSet** object that matches the specified key prefix for a device. This method uses a promise to return the result. +Obtains the **KvStoreResultSet** object that matches the specified key prefix for a device. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4388,7 +4390,7 @@ Obtains the **KvStoreResultSet** object that matches the specified key prefix fo **Example** -``` +```js let kvStore; try { let resultSet; @@ -4413,7 +4415,7 @@ try { getResultSet(query: Query, callback: AsyncCallback<KvStoreResultSet>): void -Obtains the **KvStoreResultSet** object that matches the specified **Query** object. This method uses an asynchronous callback to return the result. +Obtains the **KvStoreResultSet** object that matches the specified **Query** object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4426,7 +4428,7 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj **Example** -``` +```js let kvStore; try { let resultSet; @@ -4465,7 +4467,7 @@ try { getResultSet(query: Query): Promise<KvStoreResultSet> -Obtains the **KvStoreResultSet** object that matches the specified **Query** object. This method uses a promise to return the result. +Obtains the **KvStoreResultSet** object that matches the specified **Query** object. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4483,7 +4485,7 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj **Example** -``` +```js let kvStore; try { let resultSet; @@ -4529,7 +4531,7 @@ try { getResultSet(deviceId: string, query: Query, callback: AsyncCallback<KvStoreResultSet>): void -Obtains the **KvStoreResultSet** object that matches the specified **Query** object for a device. This method uses an asynchronous callback to return the result. +Obtains the **KvStoreResultSet** object that matches the specified **Query** object for a device. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4543,7 +4545,7 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj **Example** -``` +```js let kvStore; try { let resultSet; @@ -4581,7 +4583,7 @@ try { getResultSet(deviceId: string, query: Query): Promise<KvStoreResultSet> -Obtains the **KvStoreResultSet** object that matches the specified **Query** object for a device. This method uses a promise to return the result. +Obtains the **KvStoreResultSet** object that matches the specified **Query** object for a device. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4600,7 +4602,7 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj **Example** -``` +```js let kvStore; try { let resultSet; @@ -4647,7 +4649,7 @@ try { closeResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback<void>): void -Closes the **KvStoreResultSet** object obtained by **getResultSet**. This method uses an asynchronous callback to return the result. +Closes the **KvStoreResultSet** object obtained by **getResultSet**. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4660,7 +4662,7 @@ Closes the **KvStoreResultSet** object obtained by **getResultSet**. This method **Example** -``` +```js let kvStore; try { console.log('CloseResultSet success'); @@ -4682,7 +4684,7 @@ try { closeResultSet(resultSet: KvStoreResultSet): Promise<void> -Closes the **KvStoreResultSet** object obtained by **getResultSet**. This method uses a promise to return the result. +Closes the **KvStoreResultSet** object obtained by **getResultSet**. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4700,7 +4702,7 @@ Closes the **KvStoreResultSet** object obtained by **getResultSet**. This method **Example** -``` +```js let kvStore; try { console.log('CloseResultSet success'); @@ -4720,7 +4722,7 @@ try { getResultSize(query: Query, callback: AsyncCallback<number>): void -Obtains the number of results that matches the specified **Query** object. This method uses an asynchronous callback to return the result. +Obtains the number of results that matches the specified **Query** object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4733,7 +4735,7 @@ Obtains the number of results that matches the specified **Query** object. This **Example** -``` +```js let kvStore; try { let entries = []; @@ -4767,7 +4769,7 @@ try { getResultSize(query: Query): Promise<number> -Obtains the number of results that matches the specified **Query** object. This method uses a promise to return the result. +Obtains the number of results that matches the specified **Query** object. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4785,7 +4787,7 @@ Obtains the number of results that matches the specified **Query** object. This **Example** -``` +```js let kvStore; try { let entries = []; @@ -4823,7 +4825,7 @@ try { getResultSize(deviceId: string, query: Query, callback: AsyncCallback<number>): void; -Obtains the number of results that matches the specified **Query** object for a device. This method uses an asynchronous callback to return the result. +Obtains the number of results that matches the specified **Query** object for a device. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4837,7 +4839,7 @@ Obtains the number of results that matches the specified **Query** object for a **Example** -``` +```js let kvStore; try { let entries = []; @@ -4870,7 +4872,7 @@ try { getResultSize(deviceId: string, query: Query): Promise<number> -Obtains the number of results that matches the specified **Query** object for a device. This method uses a promise to return the result. +Obtains the number of results that matches the specified **Query** object for a device. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4889,7 +4891,7 @@ Obtains the number of results that matches the specified **Query** object for a **Example** -``` +```js let kvStore; try { let entries = []; @@ -4926,7 +4928,7 @@ try { removeDeviceData(deviceId: string, callback: AsyncCallback<void>): void -Removes data of a device from this KV store. This method uses an asynchronous callback to return the result. +Removes data of a device from this KV store. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4939,7 +4941,7 @@ Removes data of a device from this KV store. This method uses an asynchronous ca **Example** -``` +```js let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-string-001'; @@ -4968,7 +4970,7 @@ try { removeDeviceData(deviceId: string): Promise<void> -Removes data of a device from this KV store. This method uses a promise to return the result. +Removes data of a device from this KV store. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4986,7 +4988,7 @@ Removes data of a device from this KV store. This method uses a promise to retur **Example** -``` +```js let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-string-001'; @@ -5018,6 +5020,7 @@ try { sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void Manually triggers KV store synchronization synchronously. + **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -5032,7 +5035,7 @@ Manually triggers KV store synchronization synchronously. **Example** -``` +```js let kvStore; const KEY_TEST_SYNC_ELEMENT = 'key_test_sync'; const VALUE_TEST_SYNC_ELEMENT = 'value-string-001'; @@ -5051,11 +5054,11 @@ try { } ``` -### on8+ ### +### on('syncComplete')8+ ### on(event: 'syncComplete', syncCallback: Callback<Array<[string, number]>>): void -Subscribes to the synchronization completion events. This method uses a synchronous callback to return the result. +Subscribes to the synchronization completion events. This API uses a synchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -5063,12 +5066,12 @@ Subscribes to the synchronization completion events. This method uses a synchron | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| event |'syncComplete' | Yes |Event triggered when the synchronization is complete.| -| syncCallback |Callback | Yes |Callback used to return the synchronization result. | **Example** -``` +```js const KEY_TEST_FLOAT_ELEMENT = 'key_test_float'; const VALUE_TEST_FLOAT_ELEMENT = 321.12; try { @@ -5086,11 +5089,11 @@ try { ``` -### off8+ ### +### off('syncComplete')8+ ### off(event: 'syncComplete', syncCallback?: Callback<Array<[string, number]>>): void -Unsubscribes from the synchronization completion events. This method uses a synchronous callback to return the result. +Unsubscribes from the synchronization completion events. This API uses a synchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -5098,12 +5101,12 @@ Unsubscribes from the synchronization completion events. This method uses a sync | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| event |'syncComplete' | Yes |Event triggered when the synchronization is complete.| +| event |string | Yes |Name of the event to unsubscribe from. The value is **syncComplete**, which indicates the synchronization complete event.| | syncCallback |Callback