From e68991c0406c8a9ef768f12ed8c7f5e5a5e3ad1b Mon Sep 17 00:00:00 2001 From: Annie_wang Date: Mon, 12 Jun 2023 20:10:25 +0800 Subject: [PATCH] update docs Signed-off-by: Annie_wang --- .../apis/js-apis-data-dataSharePredicates.md | 11 +- .../apis/js-apis-data-distributedobject.md | 160 +-- .../apis/js-apis-data-preferences.md | 12 +- .../reference/apis/js-apis-data-rdb.md | 15 +- .../apis/js-apis-data-relationalStore.md | 433 ++++++-- .../apis/js-apis-data-valuesBucket.md | 5 +- .../apis/js-apis-distributed-data.md | 46 +- .../apis/js-apis-distributedKVStore.md | 966 +++++++++--------- 8 files changed, 970 insertions(+), 678 deletions(-) diff --git a/en/application-dev/reference/apis/js-apis-data-dataSharePredicates.md b/en/application-dev/reference/apis/js-apis-data-dataSharePredicates.md index 78d896c54a..6fe449189c 100644 --- a/en/application-dev/reference/apis/js-apis-data-dataSharePredicates.md +++ b/en/application-dev/reference/apis/js-apis-data-dataSharePredicates.md @@ -6,9 +6,8 @@ The APIs provided by **DataSharePredicates** correspond to the filter criteria > **NOTE** > -> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. -> -> The APIs provided by this module are system APIs. +> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. +>- The APIs provided by this module are system APIs. ## Modules to Import @@ -18,7 +17,7 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates'; ``` ## DataSharePredicates -Provides methods for setting different **DataSharePredicates** objects. +Provides methods for setting different **DataSharePredicates** objects. This type is not multi-thread safe. If a **DataSharePredicates** instance is operated by multiple threads at the same time in an application, use a lock for the instance. ### equalTo @@ -428,7 +427,7 @@ predicates.glob("NAME", "?h*g") between(field: string, low: ValueType, high: ValueType): DataSharePredicates -Sets a **DataSharePredicates** object to search for the data that is within the specified range, including the start and end values. +Sets a **DataSharePredicates** object to match the data that is within the specified range, including the start and end values. Currently, only the RDB supports this **DataSharePredicates** object. @@ -459,7 +458,7 @@ predicates.between("AGE", 10, 50) notBetween(field: string, low: ValueType, high: ValueType): DataSharePredicates -Sets a **DataSharePredicates** object to search for the data that is out of the specified range, excluding the start and end values. +Sets a **DataSharePredicates** object to match the data that is out of the specified range, excluding the start and end values. Currently, only the RDB supports this **DataSharePredicates** object. 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 978cbffcf7..8892f9ff25 100644 --- a/en/application-dev/reference/apis/js-apis-data-distributedobject.md +++ b/en/application-dev/reference/apis/js-apis-data-distributedobject.md @@ -23,10 +23,10 @@ Creates a distributed data object. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| context | Context | Yes| Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).| -| source | object | Yes| Attributes of the distributed data object.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | context | Context | Yes| Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).| + | source | object | Yes| Attributes of the distributed data object.| **Return value** @@ -75,9 +75,9 @@ Creates a random session ID. **Return value** -| Type| Description| -| -------- | -------- | -| string | Session ID created.| + | Type| Description| + | -------- | -------- | + | string | Session ID created.| **Example** @@ -124,18 +124,18 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| sessionId | string | Yes| ID of a distributed data object on a trusted network.| -| callback | AsyncCallback<void> | Yes| Asynchronous callback invoked when the session ID is successfully set.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | sessionId | string | Yes| ID of a distributed data object on a trusted network.| + | callback | AsyncCallback<void> | Yes| Asynchronous callback invoked when the session ID is successfully set.| **Error codes** For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md). -| ID| Error Message| -| -------- | -------- | -| 15400001 | Failed to create the in-memory database.| + | ID| Error Message| + | -------- | -------- | + | 15400001 | Create table failed.| **Example** @@ -158,17 +158,17 @@ Exits all joined sessions. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback<void> | Yes| Asynchronous callback invoked when the distributed data object exits all joined sessions.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | callback | AsyncCallback<void> | Yes| Asynchronous callback invoked when the distributed data object exits all joined sessions.| **Error codes** For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md). -| ID| Error Message| -| -------- | -------- | -| 15400001 | Failed to create the in-memory database.| + | ID| Error Message| + | -------- | -------- | + | 15400001 | Create table failed.| **Example** @@ -195,9 +195,9 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| sessionId | string | No| ID of a distributed data object on a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | sessionId | string | No| ID of a distributed data object on a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.| **Return value** @@ -209,9 +209,9 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md). -| ID| Error Message| -| -------- | -------- | -| 15400001 | Failed to create the in-memory database.| + | ID| Error Message| + | -------- | -------- | + | 15400001 | Create table failed.| **Example** @@ -240,10 +240,10 @@ Subscribes to data changes of this distributed data object. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type to subscribe to. The value is **change**, which indicates data changes.| -| callback | Callback<{ sessionId: string, fields: Array<string> }> | Yes| Callback invoked to return the changes of the distributed data object.
**sessionId** indicates the session ID of the distributed data object.
**fields** indicates the changed attributes of the distributed data object.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type to subscribe to. The value is **change**, which indicates data changes.| + | callback | Callback<{ sessionId: string, fields: Array<string> }> | Yes| Callback invoked to return the changes of the distributed data object.
**sessionId** indicates the session ID of the distributed data object.
**fields** indicates the changed attributes of the distributed data object.| **Example** @@ -269,10 +269,10 @@ Unsubscribes from the data changes of this distributed data object. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | | type | string | Yes| Event type to unsubscribe from. The value is **change**, which indicates data changes.| -| callback | Callback<{ sessionId: string, fields: Array<string> }> | No| Callback for data changes. If this parameter is not specified, all data change callbacks of this distributed data object will be unregistered.
**sessionId** indicates the session ID of the distributed data object.
**fields** indicates the changed attributes of the distributed data object.| + | callback | Callback<{ sessionId: string, fields: Array<string> }> | No| Callback for data changes. If this parameter is not specified, all data change callbacks of this distributed data object will be unregistered.
**sessionId** indicates the session ID of the distributed data object.
**fields** indicates the changed attributes of the distributed data object.| **Example** @@ -294,10 +294,10 @@ Subscribes to status changes of this distributed data object. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type to subscribe to. The value is **status**, which indicates the status change (online or offline) of the distributed data object.| -| callback | Callback<{ sessionId: string, networkId: string, status: 'online' \| 'offline' }> | Yes| Callback invoked to return the status change.
**sessionId** indicates the session ID of the distributed data object.
**networkId** indicates the object device ID, that is, **deviceId**.
**status** indicates the object status, which can be online or offline.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type to subscribe to. The value is **status**, which indicates the status change (online or offline) of the distributed data object.| + | callback | Callback<{ sessionId: string, networkId: string, status: 'online' \| 'offline' }> | Yes| Callback invoked to return the status change.
**sessionId** indicates the session ID of the distributed data object.
**networkId** indicates the object device ID, that is, **deviceId**.
**status** indicates the object status, which can be online or offline.| **Example** @@ -318,10 +318,10 @@ Unsubscribes from the status change of this distributed data object. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | | type | string | Yes| Event type to unsubscribe from. The value is **status**, which indicates the status change (online or offline) of the distributed data object.| -| callback | Callback<{ sessionId: string, deviceId: string, status: 'online' \| 'offline' }> | No| Callback for status changes. If this parameter is not specified, all status change callbacks of this distributed data object will be unsubscribed from.
**sessionId** indicates the session ID of the distributed data object.
**deviceId** indicates the device ID of the distributed data object.
**status** indicates the object status, which can be online or offline.| + | callback | Callback<{ sessionId: string, deviceId: string, status: 'online' \| 'offline' }> | No| Callback for status changes. If this parameter is not specified, all status change callbacks of this distributed data object will be unsubscribed from.
**sessionId** indicates the session ID of the distributed data object.
**deviceId** indicates the device ID of the distributed data object.
**status** indicates the object status, which can be online or offline.| **Example** @@ -354,10 +354,10 @@ The saved data will be released in the following cases: **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| deviceId | string | Yes| ID of the device where data is stored. The value **local** indicates the local device.| -| callback | AsyncCallback<[SaveSuccessResponse](#savesuccessresponse9)> | Yes| Callback invoked to return **SaveSuccessResponse**, which contains information such as session ID, version, and device ID.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | deviceId | string | Yes| ID of the device where data is stored. The value **local** indicates the local device.| + | callback | AsyncCallback<[SaveSuccessResponse](#savesuccessresponse9)> | Yes| Callback invoked to return **SaveSuccessResponse**, which contains information such as session ID, version, and device ID.| **Example** @@ -394,15 +394,15 @@ The saved data will be released in the following cases: **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| deviceId | string | Yes| ID of the device where the data is saved. The default value is **local**, which indicates the local device. | + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | deviceId | string | Yes| ID of the device where the data is saved. The default value is **local**, which indicates the local device. | **Return value** -| Type| Description| -| -------- | -------- | -| Promise<[SaveSuccessResponse](#savesuccessresponse9)> | Promise used to return **SaveSuccessResponse**, which contains information such as session ID, version, and device ID.| + | Type| Description| + | -------- | -------- | + | Promise<[SaveSuccessResponse](#savesuccessresponse9)> | Promise used to return **SaveSuccessResponse**, which contains information such as session ID, version, and device ID.| **Example** @@ -423,7 +423,7 @@ g_object.save("local").then((result) => { revokeSave(callback: AsyncCallback<RevokeSaveSuccessResponse>): void -Revokes the saving operation of this distributed data object. This API uses an asynchronous callback to return the result. +Revokes the data of this distributed data object saved. This API uses an asynchronous callback to return the result. If the object is saved on the local device, the data saved on all trusted devices will be deleted. If the object is stored on another device, the data on the local device will be deleted. @@ -432,9 +432,9 @@ If the object is stored on another device, the data on the local device will be **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback<[RevokeSaveSuccessResponse](#revokesavesuccessresponse9)> | Yes| Callback invoked to return **RevokeSaveSuccessResponse**, which contains the session ID.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | callback | AsyncCallback<[RevokeSaveSuccessResponse](#revokesavesuccessresponse9)> | Yes| Callback invoked to return **RevokeSaveSuccessResponse**, which contains the session ID.| **Example** @@ -468,7 +468,7 @@ g_object.revokeSave((err, result) => { revokeSave(): Promise<RevokeSaveSuccessResponse> -Revokes the saving operation of this distributed data object. This API uses a promise to return the result. +Revokes the data of this distributed data object saved. This API uses a promise to return the result. If the object is saved on the local device, the data saved on all trusted devices will be deleted. If the object is stored on another device, the data on the local device will be deleted. @@ -477,9 +477,9 @@ If the object is stored on another device, the data on the local device will be **Return value** -| Type| Description| -| -------- | -------- | -| Promise<[RevokeSaveSuccessResponse](#revokesavesuccessresponse9)> | Promise used to return **RevokeSaveSuccessResponse**, which contains the session ID.| + | Type| Description| + | -------- | -------- | + | Promise<[RevokeSaveSuccessResponse](#revokesavesuccessresponse9)> | Promise used to return **RevokeSaveSuccessResponse**, which contains the session ID.| **Example** @@ -520,9 +520,9 @@ Creates a distributed data object. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| source | object | Yes| Attributes of the distributed data object.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | source | object | Yes| Attributes of the distributed data object.| **Return value** @@ -558,15 +558,15 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| sessionId | string | No| ID of a distributed data object on a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | sessionId | string | No| ID of a distributed data object on a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.| **Return value** -| Type| Description| -| -------- | -------- | -| boolean | Returns **true** if the session ID is set successfully;
returns **false** otherwise. | + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the session ID is set successfully;
returns **false** otherwise. | **Example** @@ -593,10 +593,10 @@ Subscribes to data changes of this distributed data object. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type to subscribe to. The value is **change**, which indicates data changes.| -| callback | Callback<{ sessionId: string, fields: Array<string> }> | Yes| Callback invoked to return the changes of the distributed data object.
**sessionId** indicates the session ID of the distributed data object.
**fields** indicates the changed attributes of the distributed data object.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type to subscribe to. The value is **change**, which indicates data changes.| + | callback | Callback<{ sessionId: string, fields: Array<string> }> | Yes| Callback invoked to return the changes of the distributed data object.
**sessionId** indicates the session ID of the distributed data object.
**fields** indicates the changed attributes of the distributed data object.| **Example** @@ -628,10 +628,10 @@ Unsubscribes from the data changes of this distributed data object. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | | type | string | Yes| Event type to unsubscribe from. The value is **change**, which indicates data changes.| -| callback | Callback<{ sessionId: string, fields: Array<string> }> | No| Callback for data changes. If this parameter is not specified, all data change callbacks of this distributed data object will be unregistered.
**sessionId** indicates the session ID of the distributed data object.
**fields** indicates the changed attributes of the distributed data object.| + | callback | Callback<{ sessionId: string, fields: Array<string> }> | No| Callback for data changes. If this parameter is not specified, all data change callbacks of this distributed data object will be unregistered.
**sessionId** indicates the session ID of the distributed data object.
**fields** indicates the changed attributes of the distributed data object.| **Example** @@ -659,10 +659,10 @@ Subscribes to status changes of this distributed data object. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| type | string | Yes| Event type to subscribe to. The value is **status**, which indicates the status change (online or offline) of the distributed data object.| -| callback | Callback<{ sessionId: string, networkId: string, status: 'online' \| 'offline' }> | Yes| Callback invoked to return the status change.
**sessionId** indicates the session ID of the distributed data object.
**networkId** indicates the object device ID, that is, **deviceId**.
**status** indicates the object status, which can be online or offline.| + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | string | Yes| Event type to subscribe to. The value is **status**, which indicates the status change (online or offline) of the distributed data object.| + | callback | Callback<{ sessionId: string, networkId: string, status: 'online' \| 'offline' }> | Yes| Callback invoked to return the status change.
**sessionId** indicates the session ID of the distributed data object.
**networkId** indicates the object device ID, that is, **deviceId**.
**status** indicates the object status, which can be online or offline.| **Example** @@ -689,8 +689,8 @@ Unsubscribes from the status change of this distributed data object. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | | type | string | Yes| Event type to unsubscribe from. The value is **status**, which indicates the status change (online or offline) of the distributed data object.| | callback | Callback<{ sessionId: string, deviceId: string, status: 'online' \| 'offline' }> | No| Callback for status changes. If this parameter is not specified, all status change callbacks of this distributed data object will be unregistered.
**sessionId** indicates the session ID of the distributed data object.
**deviceId** indicates the device ID of the distributed data object.
**status** indicates the object status, which can be online or offline.| diff --git a/en/application-dev/reference/apis/js-apis-data-preferences.md b/en/application-dev/reference/apis/js-apis-data-preferences.md index 156078c63a..e2a87d1165 100644 --- a/en/application-dev/reference/apis/js-apis-data-preferences.md +++ b/en/application-dev/reference/apis/js-apis-data-preferences.md @@ -185,7 +185,7 @@ For details about the error codes, see [User Preference Error Codes](../errorcod | ID| Error Message | | -------- | ------------------------------| -| 15500010 | Failed to delete the preferences. | +| 15500010 | Failed to delete preferences. | **Example** @@ -197,7 +197,7 @@ import featureAbility from '@ohos.ability.featureAbility'; let context = featureAbility.getContext(); try { - data_preferences.deletePreferences(context, 'mystore', function (err, val) { + data_preferences.deletePreferences(context, 'mystore', function (err) { if (err) { console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message); return; @@ -217,7 +217,7 @@ import UIAbility from '@ohos.app.ability.UIAbility'; class EntryAbility extends UIAbility { onWindowStageCreate(windowStage) { try { - data_preferences.deletePreferences(this.context, 'mystore', function (err, val) { + data_preferences.deletePreferences(this.context, 'mystore', function (err) { if (err) { console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message); return; @@ -262,7 +262,7 @@ For details about the error codes, see [User Preference Error Codes](../errorcod | ID| Error Message | | -------- | ------------------------------| -| 15500010 | Failed to delete the preferences. | +| 15500010 | Failed to delete preferences. | **Example** @@ -334,7 +334,7 @@ import featureAbility from '@ohos.ability.featureAbility'; let context = featureAbility.getContext(); try { - data_preferences.removePreferencesFromCache(context, 'mystore', function (err, val) { + data_preferences.removePreferencesFromCache(context, 'mystore', function (err) { if (err) { console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message); return; @@ -354,7 +354,7 @@ import UIAbility from '@ohos.app.ability.UIAbility'; class EntryAbility extends UIAbility { onWindowStageCreate(windowStage) { try { - data_preferences.removePreferencesFromCache(this.context, 'mystore', function (err, val) { + data_preferences.removePreferencesFromCache(this.context, 'mystore', function (err) { if (err) { console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message); return; 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 2833579427..8288efbbb5 100644 --- a/en/application-dev/reference/apis/js-apis-data-rdb.md +++ b/en/application-dev/reference/apis/js-apis-data-rdb.md @@ -9,9 +9,8 @@ This module provides the following RDB-related functions: > **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. -> -> The APIs of this module are no longer maintained since API version 9. You are advised to use [@ohos.data.relationalStore](js-apis-data-relationalStore.md). +> - 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. +> - The APIs of this module are no longer maintained since API version 9. You are advised to use [@ohos.data.relationalStore](js-apis-data-relationalStore.md). ## Modules to Import @@ -1174,7 +1173,7 @@ predicates.notIn("NAME", ["Lisa", "Rose"]) Provides methods to manage an RDB store. -Before using the APIs of this class, use [executeSql](#executesql8) to initialize the database table structure and related data. +Before using the APIs of this class, use [executeSql](#executesql) to initialize the database table structure and related data. ### insert @@ -1830,7 +1829,7 @@ obtainDistributedTableName(device: string, table: string, callback: AsyncCallbac Obtains the distributed table name of a remote device based on the local table name of the device. The distributed table name is required when the RDB store of a remote device is queried. -> **NOTE**
+> **NOTE** > > The value of **device** is obtained by [deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync). The APIs of the **deviceManager** module are system interfaces and available only to system applications. @@ -1879,7 +1878,7 @@ rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableNa Obtains the distributed table name of a remote device based on the local table name of the device. The distributed table name is required when the RDB store of a remote device is queried. -> **NOTE**
+> **NOTE** > > The value of **device** is obtained by [deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync). The APIs of the **deviceManager** module are system interfaces and available only to system applications. @@ -2045,7 +2044,7 @@ Registers an observer for this RDB store. When the data in the RDB store changes | -------- | -------- | -------- | -------- | | event | string | Yes| The value is'dataChange', which indicates a data change event.| | type | [SubscribeType](#subscribetype8) | Yes| Subscription type to register.| -| observer | Callback<Array<string>> | Yes| Observer that listens for the data changes in the RDB store.| +| observer | Callback<Array<string>> | Yes| Observer that listens for the data changes in the RDB store. **Array** indicates the IDs of the peer devices whose data in the database is changed.| **Example** @@ -2076,7 +2075,7 @@ Unregisters the observer of the specified type from the RDB store. This API uses | -------- | -------- | -------- | -------- | | event | string | Yes| The value is'dataChange', which indicates a data change event.| | type | [SubscribeType](#subscribetype8) | Yes| Subscription type to unregister.| -| observer | Callback<Array<string>> | Yes| Data change observer registered.| +| observer | Callback<Array<string>> | Yes| Data change observer to unregister. **Array** indicates the IDs of the peer devices whose data in the database is changed.| **Example** diff --git a/en/application-dev/reference/apis/js-apis-data-relationalStore.md b/en/application-dev/reference/apis/js-apis-data-relationalStore.md index 36383b8856..ff821bff92 100644 --- a/en/application-dev/reference/apis/js-apis-data-relationalStore.md +++ b/en/application-dev/reference/apis/js-apis-data-relationalStore.md @@ -38,10 +38,11 @@ Obtains an RDB store. This API uses an asynchronous callback to return the resul For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). -| **ID**| **Error Message** | -| ------------ | ----------------------- | -| 14800010 | If failed delete database by invalid database name. | -| 14800011 | If failed open database by database corrupted. | +| **ID**| **Error Message** | +| ------------ | ------------------------------------------------- | +| 14800010 | Failed to open or delete database by invalid database path. | +| 14800011 | Failed open database, database corrupted. | +| 14800000 | The inner error is occurred. | **Example** @@ -64,7 +65,7 @@ const STORE_CONFIG = { relationalStore.getRdbStore(context, STORE_CONFIG, function (err, rdbStore) { store = rdbStore; if (err) { - console.error(`Get RdbStore failed, err: ${err}`); + console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); return; } console.info(`Get RdbStore successfully.`); @@ -87,7 +88,7 @@ class EntryAbility extends UIAbility { relationalStore.getRdbStore(this.context, STORE_CONFIG, function (err, rdbStore) { store = rdbStore; if (err) { - console.error(`Get RdbStore failed, err: ${err}`); + console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); return; } console.info(`Get RdbStore successfully.`); @@ -121,10 +122,11 @@ Obtains an RDB store. This API uses a promise to return the result. You can set For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). -| **ID**| **Error Message** | -| ------------ | ----------------------- | -| 14800010 | If failed delete database by invalid database name. | -| 14800011 | If failed open database by database corrupted. | +| **ID**| **Error Message** | +| ------------ | ------------------------------------------------- | +| 14800010 | Failed to open or delete database by invalid database path. | +| 14800011 | Failed open database, database corrupted. | +| 14800000 | The inner error is occurred. | **Example** @@ -148,7 +150,7 @@ promise.then(async (rdbStore) => { store = rdbStore; console.info(`Get RdbStore successfully.`); }).catch((err) => { - console.error(`Get RdbStore failed, err: ${err}`); + console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); }) ``` @@ -170,7 +172,7 @@ class EntryAbility extends UIAbility { store = rdbStore; console.info(`Get RdbStore successfully.`) }).catch((err) => { - console.error(`Get RdbStore failed, err: ${err}`); + console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); }) } } @@ -196,9 +198,10 @@ Deletes an RDB store. This API uses an asynchronous callback to return the resul For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). -| **ID**| **Error Message** | -| ------------ | ----------------------- | -| 14800010 | If failed delete database by invalid database name. | +| **ID**| **Error Message** | +| ------------ | ------------------------------------------------- | +| 14800010 | Failed to open or delete database by invalid database path. | +| 14800000 | The inner error is occurred. | **Example** @@ -212,7 +215,7 @@ let context = featureAbility.getContext() relationalStore.deleteRdbStore(context, "RdbTest.db", function (err) { if (err) { - console.error(`Delete RdbStore failed, err: ${err}`); + console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); return; } console.info(`Delete RdbStore successfully.`); @@ -228,7 +231,7 @@ class EntryAbility extends UIAbility { onWindowStageCreate(windowStage){ relationalStore.deleteRdbStore(this.context, "RdbTest.db", function (err) { if (err) { - console.error(`Delete RdbStore failed, err: ${err}`); + console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); return; } console.info(`Delete RdbStore successfully.`); @@ -262,9 +265,10 @@ Deletes an RDB store. This API uses a promise to return the result. For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). -| **ID**| **Error Message** | -| ------------ | ----------------------- | -| 14800010 | If failed delete database by invalid database name. | +| **ID**| **Error Message** | +| ------------ | ------------------------------------------------- | +| 14800010 | Failed to open or delete database by invalid database path. | +| 14800000 | The inner error is occurred. | **Example** @@ -280,7 +284,7 @@ let promise = relationalStore.deleteRdbStore(context, "RdbTest.db"); promise.then(()=>{ console.info(`Delete RdbStore successfully.`); }).catch((err) => { - console.error(`Delete RdbStore failed, err: ${err}`); + console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); }) ``` @@ -295,7 +299,7 @@ class EntryAbility extends UIAbility { promise.then(()=>{ console.info(`Delete RdbStore successfully.`); }).catch((err) => { - console.error(`Delete RdbStore failed, err: ${err}`); + console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); }) } } @@ -311,7 +315,7 @@ Defines the RDB store configuration. | ------------- | ------------- | ---- | --------------------------------------------------------- | | name | string | Yes | Database file name. | | securityLevel | [SecurityLevel](#securitylevel) | Yes | Security level of the RDB store. | -| encrypt | boolean | No | Whether to encrypt the RDB store.
The value **true** means to encrypt the RDB store;
the value **false** means the opposite.| +| encrypt | boolean | No | Whether to encrypt the RDB store.
The value **true** means to encrypt the RDB store;
the value **false** (default) means the opposite.| ## SecurityLevel @@ -319,7 +323,7 @@ Enumerates the RDB store security levels. > **NOTE** > -> To perform data synchronization operations, the RDB store security level must be lower than or equal to that of the peer device. For details, see the [Cross-Device Data Synchronization Mechanism](../../database/sync-app-data-across-devices-overview.md#cross-device-data-synchronization-mechanism). +> To perform data synchronization operations, the RDB store security level must be lower than or equal to that of the peer device. For details, see the [Access Control Mechanism in Cross-Device Synchronization](../../database/access-control-by-device-and-data-level.md#access-control-mechanism-in-cross-device-synchronization). **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -344,7 +348,7 @@ Defines the data types allowed. ## ValuesBucket -Defines the types of the key and value in a KV pair. +Defines the types of the key and value in a KV pair. This type is not multi-thread safe. If a **ValuesBucket** instance is operated by multiple threads at the same time in an application, use a lock for the instance. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -377,7 +381,7 @@ Defines the subscription type. ## RdbPredicates -Defines the predicates for an RDB store. This class determines whether the conditional expression for the RDB store is true or false. +Defines the predicates for an RDB store. This class determines whether the conditional expression for the RDB store is true or false. This type is not multi-thread safe. If a **RdbPredicates** instance is operated by multiple threads at the same time in an application, use a lock for the instance. ### constructor @@ -1264,7 +1268,7 @@ const valueBucket = { }; store.insert("EMPLOYEE", valueBucket, function (err, rowId) { if (err) { - console.error(`Insert is failed, err: ${err}`); + console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); return; } console.info(`Insert is successful, rowId = ${rowId}`); @@ -1293,6 +1297,14 @@ Inserts a row of data into a table. This API uses a promise to return the result | --------------------- | ------------------------------------------------- | | Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -1306,7 +1318,7 @@ let promise = store.insert("EMPLOYEE", valueBucket); promise.then((rowId) => { console.info(`Insert is successful, rowId = ${rowId}`); }).catch((err) => { - console.error(`Insert is failed, err: ${err}`); + console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); }) ``` @@ -1327,6 +1339,14 @@ Batch inserts data into a table. This API uses an asynchronous callback to retur | values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert. | | callback | AsyncCallback<number> | Yes | Callback invoked to return the result. If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -1352,7 +1372,7 @@ const valueBucket3 = { let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); store.batchInsert("EMPLOYEE", valueBuckets, function(err, insertNum) { if (err) { - console.error(`batchInsert is failed, err: ${err}`); + console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); return; } console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); @@ -1380,6 +1400,14 @@ Batch inserts data into a table. This API uses a promise to return the result. | --------------------- | ----------------------------------------------------------- | | Promise<number> | Promise used to return the result. If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -1407,7 +1435,7 @@ let promise = store.batchInsert("EMPLOYEE", valueBuckets); promise.then((insertNum) => { console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); }).catch((err) => { - console.error(`batchInsert is failed, err: ${err}`); + console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); }) ``` @@ -1427,6 +1455,15 @@ Updates data in the RDB store based on the specified **RdbPredicates** object. T | predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | | callback | AsyncCallback<number> | Yes | Callback invoked to return the number of rows updated. | + +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -1440,7 +1477,7 @@ let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); predicates.equalTo("NAME", "Lisa"); store.update(valueBucket, predicates, function (err, rows) { if (err) { - console.error(`Updated failed, err: ${err}`); + console.error(`Updated failed, code is ${err.code},message is ${err.message}`); return; } console.info(`Updated row count: ${rows}`); @@ -1469,6 +1506,14 @@ Updates data based on the specified **RdbPredicates** object. This API uses a pr | --------------------- | ----------------------------------------- | | Promise<number> | Promise used to return the number of rows updated.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -1484,7 +1529,7 @@ let promise = store.update(valueBucket, predicates); promise.then(async (rows) => { console.info(`Updated row count: ${rows}`); }).catch((err) => { - console.error(`Updated failed, err: ${err}`); + console.error(`Updated failed, code is ${err.code},message is ${err.message}`); }) ``` @@ -1497,6 +1542,8 @@ Updates data based on the specified **DataSharePredicates** object. This API use **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core +**Model restriction**: This API can be used only in the stage model. + **System API**: This is a system API. **Parameters** @@ -1508,6 +1555,14 @@ Updates data based on the specified **DataSharePredicates** object. This API use | predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Update conditions specified by the **DataSharePredicates** object. | | callback | AsyncCallback<number> | Yes | Callback invoked to return the number of rows updated. | +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -1522,7 +1577,7 @@ let predicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo("NAME", "Lisa"); store.update("EMPLOYEE", valueBucket, predicates, function (err, rows) { if (err) { - console.error(`Updated failed, err: ${err}`); + console.error(`Updated failed, code is ${err.code},message is ${err.message}`); return; } console.info(`Updated row count: ${rows}`); @@ -1537,6 +1592,8 @@ Updates data based on the specified **DataSharePredicates** object. This API use **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core +**Model restriction**: This API can be used only in the stage model. + **System API**: This is a system API. **Parameters** @@ -1553,6 +1610,14 @@ Updates data based on the specified **DataSharePredicates** object. This API use | --------------------- | ----------------------------------------- | | Promise<number> | Promise used to return the number of rows updated.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -1569,7 +1634,7 @@ let promise = store.update("EMPLOYEE", valueBucket, predicates); promise.then(async (rows) => { console.info(`Updated row count: ${rows}`); }).catch((err) => { - console.error(`Updated failed, err: ${err}`); + console.error(`Updated failed, code is ${err.code},message is ${err.message}`); }) ``` @@ -1588,6 +1653,14 @@ Deletes data from the RDB store based on the specified **RdbPredicates** object. | predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| | callback | AsyncCallback<number> | Yes | Callback invoked to return the number of rows deleted. | +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -1595,7 +1668,7 @@ let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); predicates.equalTo("NAME", "Lisa"); store.delete(predicates, function (err, rows) { if (err) { - console.error(`Delete failed, err: ${err}`); + console.error(`Delete failed, code is ${err.code},message is ${err.message}`); return; } console.info(`Delete rows: ${rows}`); @@ -1622,6 +1695,14 @@ Deletes data from the RDB store based on the specified **RdbPredicates** object. | --------------------- | ------------------------------- | | Promise<number> | Promise used to return the number of rows deleted. | +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -1631,7 +1712,7 @@ let promise = store.delete(predicates); promise.then((rows) => { console.info(`Delete rows: ${rows}`); }).catch((err) => { - console.error(`Delete failed, err: ${err}`); + console.error(`Delete failed, code is ${err.code},message is ${err.message}`); }) ``` @@ -1643,6 +1724,8 @@ Deletes data from the RDB store based on the specified **DataSharePredicates** o **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core +**Model restriction**: This API can be used only in the stage model. + **System API**: This is a system API. **Parameters** @@ -1653,6 +1736,14 @@ Deletes data from the RDB store based on the specified **DataSharePredicates** o | predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Conditions specified by the **DataSharePredicates** object for deleting data.| | callback | AsyncCallback<number> | Yes | Callback invoked to return the number of rows deleted. | +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -1661,7 +1752,7 @@ let predicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo("NAME", "Lisa"); store.delete("EMPLOYEE", predicates, function (err, rows) { if (err) { - console.error(`Delete failed, err: ${err}`); + console.error(`Delete failed, code is ${err.code},message is ${err.message}`); return; } console.info(`Delete rows: ${rows}`); @@ -1676,6 +1767,8 @@ Deletes data from the RDB store based on the specified **DataSharePredicates** o **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core +**Model restriction**: This API can be used only in the stage model. + **System API**: This is a system API. **Parameters** @@ -1691,6 +1784,14 @@ Deletes data from the RDB store based on the specified **DataSharePredicates** o | --------------------- | ------------------------------- | | Promise<number> | Promise used to return the number of rows deleted.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -1701,7 +1802,7 @@ let promise = store.delete("EMPLOYEE", predicates); promise.then((rows) => { console.info(`Delete rows: ${rows}`); }).catch((err) => { - console.error(`Delete failed, err: ${err}`); + console.error(`Delete failed, code is ${err.code},message is ${err.message}`); }) ``` @@ -1721,6 +1822,14 @@ Queries data from the RDB store based on specified conditions. This API uses an | columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns. | | callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -1728,7 +1837,7 @@ let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); predicates.equalTo("NAME", "Rose"); store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) { if (err) { - console.error(`Query failed, err: ${err}`); + console.error(`Query failed, code is ${err.code},message is ${err.message}`); return; } console.info(`ResultSet column names: ${resultSet.columnNames}`); @@ -1757,6 +1866,14 @@ Queries data from the RDB store based on specified conditions. This API uses a p | ------------------------------------------------------- | -------------------------------------------------- | | Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -1767,7 +1884,7 @@ promise.then((resultSet) => { console.info(`ResultSet column names: ${resultSet.columnNames}`); console.info(`ResultSet column count: ${resultSet.columnCount}`); }).catch((err) => { - console.error(`Query failed, err: ${err}`); + console.error(`Query failed, code is ${err.code},message is ${err.message}`); }) ``` @@ -1779,6 +1896,8 @@ Queries data from the RDB store based on specified conditions. This API uses an **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core +**Model restriction**: This API can be used only in the stage model. + **System API**: This is a system API. **Parameters** @@ -1790,6 +1909,14 @@ Queries data from the RDB store based on specified conditions. This API uses an | columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns. | | callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -1798,7 +1925,7 @@ let predicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo("NAME", "Rose"); store.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) { if (err) { - console.error(`Query failed, err: ${err}`); + console.error(`Query failed, code is ${err.code},message is ${err.message}`); return; } console.info(`ResultSet column names: ${resultSet.columnNames}`); @@ -1814,6 +1941,8 @@ Queries data from the RDB store based on specified conditions. This API uses a p **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core +**Model restriction**: This API can be used only in the stage model. + **System API**: This is a system API. **Parameters** @@ -1830,6 +1959,14 @@ Queries data from the RDB store based on specified conditions. This API uses a p | ------------------------------------------------------- | -------------------------------------------------- | | Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -1841,7 +1978,7 @@ promise.then((resultSet) => { console.info(`ResultSet column names: ${resultSet.columnNames}`); console.info(`ResultSet column count: ${resultSet.columnCount}`); }).catch((err) => { - console.error(`Query failed, err: ${err}`); + console.error(`Query failed, code is ${err.code},message is ${err.message}`); }) ``` @@ -1867,6 +2004,14 @@ Queries data from the RDB store of a remote device based on specified conditions | columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns. | | callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -1889,7 +2034,7 @@ predicates.greaterThan("id", 0); store.remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function(err, resultSet) { if (err) { - console.error(`Failed to remoteQuery, err: ${err}`); + console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`); return; } console.info(`ResultSet column names: ${resultSet.columnNames}`); @@ -1925,6 +2070,14 @@ Queries data from the RDB store of a remote device based on specified conditions | ------------------------------------------------------------ | -------------------------------------------------- | | Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -1949,7 +2102,7 @@ promise.then((resultSet) => { console.info(`ResultSet column names: ${resultSet.columnNames}`); console.info(`ResultSet column count: ${resultSet.columnCount}`); }).catch((err) => { - console.error(`Failed to remoteQuery, err: ${err}`); + console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`); }) ``` @@ -1969,12 +2122,20 @@ Queries data using the specified SQL statement. This API uses an asynchronous ca | bindArgs | Array<[ValueType](#valuetype)> | Yes | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, the value of this parameter must be an empty array.| | callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned. | +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) { if (err) { - console.error(`Query failed, err: ${err}`); + console.error(`Query failed, code is ${err.code},message is ${err.message}`); return; } console.info(`ResultSet column names: ${resultSet.columnNames}`); @@ -2003,6 +2164,14 @@ Queries data using the specified SQL statement. This API uses a promise to retur | ------------------------------------------------------- | -------------------------------------------------- | | Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -2011,7 +2180,7 @@ promise.then((resultSet) => { console.info(`ResultSet column names: ${resultSet.columnNames}`); console.info(`ResultSet column count: ${resultSet.columnCount}`); }).catch((err) => { - console.error(`Query failed, err: ${err}`); + console.error(`Query failed, code is ${err.code},message is ${err.message}`); }) ``` @@ -2031,13 +2200,21 @@ Executes an SQL statement that contains specified arguments but returns no value | bindArgs | Array<[ValueType](#valuetype)> | Yes | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, the value of this parameter must be an empty array.| | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = ?" store.executeSql(SQL_DELETE_TABLE, ['zhangsan'], function(err) { if (err) { - console.error(`ExecuteSql failed, err: ${err}`); + console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); return; } console.info(`Delete table done.`); @@ -2065,6 +2242,14 @@ Executes an SQL statement that contains specified arguments but returns no value | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -2073,7 +2258,7 @@ let promise = store.executeSql(SQL_DELETE_TABLE); promise.then(() => { console.info(`Delete table done.`); }).catch((err) => { - console.error(`ExecuteSql failed, err: ${err}`); + console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); }) ``` @@ -2085,6 +2270,14 @@ Starts the transaction before executing an SQL statement. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -2096,7 +2289,7 @@ const STORE_CONFIG = { }; relationalStore.getRdbStore(context, STORE_CONFIG, async function (err, store) { if (err) { - console.error(`GetRdbStore failed, err: ${err}`); + console.error(`GetRdbStore failed, code is ${err.code},message is ${err.message}`); return; } store.beginTransaction(); @@ -2130,7 +2323,7 @@ const STORE_CONFIG = { }; relationalStore.getRdbStore(context, STORE_CONFIG, async function (err, store) { if (err) { - console.error(`GetRdbStore failed, err: ${err}`); + console.error(`GetRdbStore failed, code is ${err.code},message is ${err.message}`); return; } store.beginTransaction(); @@ -2164,7 +2357,7 @@ const STORE_CONFIG = { }; relationalStore.getRdbStore(context, STORE_CONFIG, async function (err, store) { if (err) { - console.error(`GetRdbStore failed, err: ${err}`); + console.error(`GetRdbStore failed, code is ${err.code},message is ${err.message}`); return; } try { @@ -2179,7 +2372,7 @@ relationalStore.getRdbStore(context, STORE_CONFIG, async function (err, store) { await store.insert("test", valueBucket); store.commit(); } catch (err) { - console.error(`Transaction failed, err: ${err}`); + console.error(`Transaction failed, code is ${err.code},message is ${err.message}`); store.rollBack(); } }) @@ -2200,12 +2393,20 @@ Backs up an RDB store. This API uses an asynchronous callback to return the resu | destName | string | Yes | Name of the RDB store backup file.| | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js store.backup("dbBackup.db", function(err) { if (err) { - console.error(`Backup failed, err: ${err}`); + console.error(`Backup failed, code is ${err.code},message is ${err.message}`); return; } console.info(`Backup success.`); @@ -2226,6 +2427,14 @@ Backs up an RDB store. This API uses a promise to return the result. | -------- | ------ | ---- | ------------------------ | | destName | string | Yes | Name of the RDB store backup file.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Return value** | Type | Description | @@ -2239,7 +2448,7 @@ let promiseBackup = store.backup("dbBackup.db"); promiseBackup.then(()=>{ console.info(`Backup success.`); }).catch((err)=>{ - console.error(`Backup failed, err: ${err}`); + console.error(`Backup failed, code is ${err.code},message is ${err.message}`); }) ``` @@ -2258,12 +2467,20 @@ Restores an RDB store from a backup file. This API uses an asynchronous callback | srcName | string | Yes | Name of the RDB store backup file.| | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js store.restore("dbBackup.db", function(err) { if (err) { - console.error(`Restore failed, err: ${err}`); + console.error(`Restore failed, code is ${err.code},message is ${err.message}`); return; } console.info(`Restore success.`); @@ -2290,6 +2507,14 @@ Restores an RDB store from a backup file. This API uses a promise to return the | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -2297,7 +2522,7 @@ let promiseRestore = store.restore("dbBackup.db"); promiseRestore.then(()=>{ console.info(`Restore success.`); }).catch((err)=>{ - console.error(`Restore failed, err: ${err}`); + console.error(`Restore failed, code is ${err.code},message is ${err.message}`); }) ``` @@ -2318,12 +2543,20 @@ Sets distributed tables. This API uses an asynchronous callback to return the re | tables | Array<string> | Yes | Names of the distributed tables to set.| | callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js store.setDistributedTables(["EMPLOYEE"], function (err) { if (err) { - console.error(`SetDistributedTables failed, err: ${err}`); + console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); return; } console.info(`SetDistributedTables successfully.`); @@ -2352,6 +2585,14 @@ Sets distributed tables. This API uses a promise to return the result. | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -2359,7 +2600,7 @@ let promise = store.setDistributedTables(["EMPLOYEE"]); promise.then(() => { console.info(`SetDistributedTables successfully.`); }).catch((err) => { - console.error(`SetDistributedTables failed, err: ${err}`); + console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); }) ``` @@ -2385,6 +2626,14 @@ Obtains the distributed table name of a remote device based on the local table n | table | string | Yes | Local table name of the remote device. | | callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -2404,7 +2653,7 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) store.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) { if (err) { - console.error(`ObtainDistributedTableName failed, err: ${err}`); + console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`); return; } console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`); @@ -2438,6 +2687,14 @@ Obtains the distributed table name of a remote device based on the local table n | --------------------- | ----------------------------------------------------- | | Promise<string> | Promise used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -2459,7 +2716,7 @@ let promise = store.obtainDistributedTableName(deviceId, "EMPLOYEE"); promise.then((tableName) => { console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`); }).catch((err) => { - console.error(`ObtainDistributedTableName failed, err: ${err}`); + console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`); }) ``` @@ -2481,6 +2738,14 @@ Synchronizes data between devices. This API uses an asynchronous callback to ret | predicates | [RdbPredicates](#rdbpredicates) | Yes | **RdbPredicates** object that specifies the data and devices to synchronize. | | 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 that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. | +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -2504,7 +2769,7 @@ let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); predicates.inDevices(deviceIds); store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) { if (err) { - console.error(`Sync failed, err: ${err}`); + console.error(`Sync failed, code is ${err.code},message is ${err.message}`); return; } console.info(`Sync done.`); @@ -2537,6 +2802,14 @@ Synchronizes data between devices. This API uses a promise to return the result. | -------------------------------------------- | ------------------------------------------------------------ | | Promise<Array<[string, number]>> | Promise used to send the synchronization result.
**string** indicates the device ID.
**number** indicates the synchronization status of that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. | +**Error codes** + +For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md). + +| **ID**| **Error Message** | +| ------------ | -------------------------------------------- | +| 14800000 | The inner error is occurred. | + **Example** ```js @@ -2565,7 +2838,7 @@ promise.then((result) =>{ console.info(`device= ${result[i][0]}, status= ${result[i][1]}`); } }).catch((err) => { - console.error(`Sync failed, err: ${err}`); + console.error(`Sync failed, code is ${err.code},message is ${err.message}`); }) ``` @@ -2583,7 +2856,7 @@ Registers an observer for this RDB store. When the data in the RDB store changes | -------- | ----------------------------------- | ---- | ------------------------------------------- | | event | string | Yes | Event to observe. The value is **dataChange**, which indicates a data change event. | | type | [SubscribeType](#subscribetype) | Yes | Subscription type to register.| -| observer | Callback<Array<string>> | Yes | Callback invoked to return the data change. | +| observer | Callback<Array<string>> | Yes | Callback invoked to return the data change. **Array** indicates the IDs of the peer devices whose data in the database is changed.| **Example** @@ -2596,7 +2869,7 @@ function storeObserver(devices) { try { store.on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); } catch (err) { - console.error(`Register observer failed, err: ${err}`); + console.error(`Register observer failed, code is ${err.code},message is ${err.message}`); } ``` @@ -2614,7 +2887,7 @@ Unregisters the observer of the specified type from the RDB store. This API uses | -------- | ---------------------------------- | ---- | ------------------------------------------ | | event | string | Yes | Event to observe. The value is **dataChange**, which indicates a data change event. | | type | [SubscribeType](#subscribetype) | Yes | Subscription type to unregister. | -| observer | Callback<Array<string>> | Yes | Callback for the data change. | +| observer | Callback<Array<string>> | Yes | Callback for the data change. **Array** indicates the IDs of the peer devices whose data in the database is changed.| **Example** @@ -2627,7 +2900,7 @@ function storeObserver(devices) { try { store.off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); } catch (err) { - console.error(`Unregister observer failed, err: ${err}`); + console.error(`Unregister observer failed, code is ${err.code},message is ${err.message}`); } ``` @@ -2767,7 +3040,7 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode | **ID**| **Error Message** | | ------------ | ------------------------------------------------------------ | -| 14800012 | The result set is empty or the specified location is invalid. | +| 14800012 | The result set is empty, or the specified location is invalid. | **Example** @@ -2778,7 +3051,7 @@ promise.then((resultSet) => { resultSet.goTo(1); resultSet.close(); }).catch((err) => { - console.error(`query failed, err: ${err}`); + console.error(`query failed, code is ${err.code},message is ${err.message}`); }); ``` @@ -2808,7 +3081,7 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode | **ID**| **Error Message** | | ------------ | ------------------------------------------------------------ | -| 14800012 | The result set is empty or the specified location is invalid. | +| 14800012 | The result set is empty, or the specified location is invalid. | **Example** @@ -2819,7 +3092,7 @@ promise.then((resultSet) => { resultSet.goToRow(5); resultSet.close(); }).catch((err) => { - console.error(`query failed, err: ${err}`); + console.error(`query failed, code is ${err.code},message is ${err.message}`); }); ``` @@ -2844,7 +3117,7 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode | **ID**| **Error Message** | | ------------ | ------------------------------------------------------------ | -| 14800012 | The result set is empty or the specified location is invalid. | +| 14800012 | The result set is empty, or the specified location is invalid. | **Example** @@ -2855,7 +3128,7 @@ promise.then((resultSet) => { resultSet.goToFirstRow(); resultSet.close(); }).catch((err) => { - console.error(`query failed, err: ${err}`); + console.error(`query failed, code is ${err.code},message is ${err.message}`); }); ``` @@ -2879,7 +3152,7 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode | **ID**| **Error Message** | | ------------ | ------------------------------------------------------------ | -| 14800012 | The result set is empty or the specified location is invalid. | +| 14800012 | The result set is empty, or the specified location is invalid. | **Example** @@ -2890,7 +3163,7 @@ promise.then((resultSet) => { resultSet.goToLastRow(); resultSet.close(); }).catch((err) => { - console.error(`query failed, err: ${err}`); + console.error(`query failed, code is ${err.code},message is ${err.message}`); }); ``` @@ -2914,7 +3187,7 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode | **ID**| **Error Message** | | ------------ | ------------------------------------------------------------ | -| 14800012 | The result set is empty or the specified location is invalid. | +| 14800012 | The result set is empty, or the specified location is invalid. | **Example** @@ -2925,7 +3198,7 @@ promise.then((resultSet) => { resultSet.goToNextRow(); resultSet.close(); }).catch((err) => { - console.error(`query failed, err: ${err}`); + console.error(`query failed, code is ${err.code},message is ${err.message}`); }); ``` @@ -2949,7 +3222,7 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode | **ID**| **Error Message** | | ------------ | ------------------------------------------------------------ | -| 14800012 | The result set is empty or the specified location is invalid. | +| 14800012 | The result set is empty, or the specified location is invalid. | **Example** @@ -2960,7 +3233,7 @@ promise.then((resultSet) => { resultSet.goToPreviousRow(); resultSet.close(); }).catch((err) => { - console.error(`query failed, err: ${err}`); + console.error(`query failed, code is ${err.code},message is ${err.message}`); }); ``` @@ -3150,7 +3423,7 @@ let promiseClose = store.query(predicatesClose, ["ID", "NAME", "AGE", "SALARY", promiseClose.then((resultSet) => { resultSet.close(); }).catch((err) => { - console.error(`resultset close failed, err: ${err}`); + console.error(`resultset close failed, code is ${err.code},message is ${err.message}`); }); ``` @@ -3160,4 +3433,4 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode | **ID**| **Error Message** | | ------------ | ------------------------------------------------------------ | -| 14800012 | The result set is empty or the specified location is invalid. | +| 14800012 | The result set is empty, or the specified location is invalid. | diff --git a/en/application-dev/reference/apis/js-apis-data-valuesBucket.md b/en/application-dev/reference/apis/js-apis-data-valuesBucket.md index 009ff71b09..ee21647ac7 100644 --- a/en/application-dev/reference/apis/js-apis-data-valuesBucket.md +++ b/en/application-dev/reference/apis/js-apis-data-valuesBucket.md @@ -1,4 +1,4 @@ -# @ohos.data.ValuesBucket (Value Bucket) +# @ohos.data.ValuesBucket (Data Set) The **ValueBucket** module holds data in key-value (KV) pairs. You can use it to insert data into a database. @@ -6,7 +6,6 @@ The **ValueBucket** module holds data in key-value (KV) pairs. You can use it to > > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > -> The APIs provided by this module are system APIs. ## Modules to Import @@ -30,7 +29,7 @@ Enumerates the value types allowed by the database. ## ValuesBucket -Defines the types of the key and value in a KV pair. +Defines the types of the key and value in a KV pair. This type is not multi-thread safe. If a **ValuesBucket** instance is operated by multiple threads at the same time in an application, use a lock for the instance. **System capability**: SystemCapability.DistributedDataManager.DataShare.Core 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 05532a37fa..428e372637 100644 --- a/en/application-dev/reference/apis/js-apis-distributed-data.md +++ b/en/application-dev/reference/apis/js-apis-distributed-data.md @@ -129,8 +129,8 @@ Defines user information. | Name| Type| Mandatory| Description| | ----- | ------ |------ | ------ | -| userId | string | No | User ID.| -| userType | [UserType](#usertype) | No | User type.| +| userId | string | No | User ID. The default value is **0**.| +| userType | [UserType](#usertype) | No | User type. The default value is **0**.| ## UserType @@ -268,7 +268,7 @@ const options = { backup: false, autoSync: true, kvStoreType: distributedData.KVStoreType.SINGLE_VERSION, - schema: '', + schema: undefined, securityLevel: distributedData.SecurityLevel.S2, } try { @@ -318,7 +318,7 @@ const options = { backup: false, autoSync: true, kvStoreType: distributedData.KVStoreType.SINGLE_VERSION, - schema: '', + schema: undefined, securityLevel: distributedData.SecurityLevel.S2, } try { @@ -366,7 +366,7 @@ const options = { backup : false, autoSync : true, kvStoreType : distributedData.KVStoreType.SINGLE_VERSION, - schema : '', + schema : undefined, securityLevel : distributedData.SecurityLevel.S2, } try { @@ -415,7 +415,7 @@ const options = { backup : false, autoSync : true, kvStoreType : distributedData.KVStoreType.SINGLE_VERSION, - schema : '', + schema : undefined, securityLevel : distributedData.SecurityLevel.S2, } try { @@ -575,13 +575,13 @@ Provides KV store configuration. | Name | Type| Mandatory | Description | | ----- | ------ | ------ | -------------------| -| createIfMissing | boolean | No| Whether to create a KV store if no database file exists. By default, a KV store is created.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | -| encrypt | boolean | No|Whether to encrypt database files. By default, database files are not encrypted.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | -| backup | boolean | No|Whether to back up database files. By default, database files are backed up.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | -| autoSync | boolean | No|Whether to automatically synchronize database files. The value **false** (default) means to manually synchronize database files; the value **true** means to automatically synchronize database files.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC | -| kvStoreType | [KVStoreType](#kvstoretype) | No|Type of the KV store to create. By default, a device KV store is created. The device KV store stores data for multiple devices that collaborate with each other.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core| -| securityLevel | [SecurityLevel](#securitylevel) | No|Security level of the KV store. By default, the security level is not set.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | -| schema8+ | [Schema](#schema8) | No| Schema used to define the values stored in a KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore| +| createIfMissing | boolean | No| Whether to create a KV store if no database file exists. The default value is **true**, which means to create a KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | +| encrypt | boolean | No|Whether to encrypt the KV store. The default value is **false**, which means the KV store is not encrypted.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | +| backup | boolean | No|Whether to back up the KV store. The default value is **true**, which means to back up the KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | +| autoSync | boolean | No|Whether to automatically synchronize database files. The value **false** (default) means to manually synchronize database files; the value **true** means to automatically synchronize database files.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC | +| kvStoreType | [KVStoreType](#kvstoretype) | No|Type of the KV store to create. The default value is **DEVICE_COLLABORATION**, which indicates a device KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core| +| securityLevel | [SecurityLevel](#securitylevel) | Yes|Security level (S1-S4) of the KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | +| schema8+ | [Schema](#schema8) | No| Schema used to define the values stored in the KV store. The default value is **undefined**, which means the schema is not set.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore| ## KVStoreType @@ -602,8 +602,8 @@ Enumerates the KV store security levels. | Name | Value| Description | | --- | ---- | ----------------------- | -| NO_LEVEL | 0 | No security level is set for the KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore | -| S0 | 1 | The KV store security level is public.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | +| NO_LEVEL | 0 | No security level is set for the KV store (deprecated).
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore | +| S0 | 1 | The KV store security level is public (deprecated).
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | | S1 | 2 | The KV store security level is low. If data leakage occurs, minor impact will be caused on the database. For example, a KV store that contains system data such as wallpapers.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | | S2 | 3 | The KV store security level is medium. If data leakage occurs, moderate impact will be caused on the database. For example, a KV store that contains information created by users or call records, such as audio or video clips.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | | S3 | 5 | The KV store security level is high. If data leakage occurs, major impact will be caused on the database. For example, a KV store that contains information such as user fitness, health, and location data.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | @@ -2292,7 +2292,7 @@ Unsubscribes from data changes. | Name | Type | Mandatory| Description | | -------- | --------------------------------------------------------- | ---- | -------------------------------------------------------- | | event | string | Yes | Event to unsubscribe from. The value is **dataChange**, which indicates a data change event.| -| listener |Callback<[ChangeNotification](#changenotification)> |No |Callback for the data change event.| +| listener | Callback<[ChangeNotification](#changenotification)> | No | Callback for the data change event. If the callback is not specified, all subscriptions to the data change event will be canceled.| @@ -2330,7 +2330,7 @@ Unsubscribes from synchronization complete events. | Name | Type | Mandatory| Description | | ------------ | --------------------------------------------- | ---- | ---------------------------------------------------------- | | event | string | Yes | Event to unsubscribe from. The value is **syncComplete**, which indicates a synchronization complete event.| -| syncCallback |Callback<Array<[string, number]>> | No |Callback for the synchronization complete event. | +| syncCallback | Callback<Array<[string, number]>> | No | Callback for the synchronization complete event. If the callback is not specified, all subscriptions to the synchronization complete event will be canceled. | **Example** @@ -3769,7 +3769,7 @@ Synchronizes the KV store manually. | --------- | --------------------- | ---- | ---------------------------------------------- | | deviceIds | string[] | Yes | List of IDs of the devices in the same networking environment to be synchronized.| | mode | [SyncMode](#syncmode) | Yes | Synchronization mode. | -| delayMs | number | No | Allowed synchronization delay time, in ms. | +| delayMs | number | No | Allowed synchronization delay time, in ms. The default value is **0**. | **Example** @@ -3884,7 +3884,7 @@ Unsubscribes from data changes. | Name | Type | Mandatory| Description | | -------- | --------------------------------------------------------- | ---- | -------------------------------------------------------- | | event | string | Yes | Event to unsubscribe from. The value is **dataChange**, which indicates a data change event.| -| listener |Callback<[ChangeNotification](#changenotification)> |No |Callback for the data change event.| +| listener | Callback<[ChangeNotification](#changenotification)> | No | Callback for the data change event. If the callback is not specified, all subscriptions to the data change event will be canceled. | **Example** @@ -3920,7 +3920,7 @@ Unsubscribes from synchronization complete events. | Name | Type | Mandatory| Description | | ------------ | --------------------------------------------- | ---- | ---------------------------------------------------------- | | event | string | Yes | Event to unsubscribe from. The value is **syncComplete**, which indicates a synchronization complete event.| -| syncCallback | Callback<Array<[string, number]>> | No | Callback for the synchronization complete event. | +| syncCallback | Callback<Array<[string, number]>> | No | Callback for the synchronization complete event. If the callback is not specified, all subscriptions to the synchronization complete event will be canceled. | **Example** @@ -5191,7 +5191,7 @@ Synchronizes the KV store manually. | ----- | ------ | ---- | ----------------------- | | deviceIds |string[] | Yes |IDs of the devices to be synchronized.| | mode |[SyncMode](#syncmode) | Yes |Synchronization mode. | -| delayMs |number | No |Allowed synchronization delay time, in ms. | +| delayMs |number | No |Allowed synchronization delay time, in ms. The default value is **0**. | **Example** @@ -5306,7 +5306,7 @@ Unsubscribes from data changes. | Name | Type | Mandatory| Description | | -------- | --------------------------------------------------------- | ---- | -------------------------------------------------------- | | event | string | Yes | Event to unsubscribe from. The value is **dataChange**, which indicates a data change event.| -| listener |Callback<[ChangeNotification](#changenotification)> |No |Callback for the data change event.| +| listener | Callback<[ChangeNotification](#changenotification)> | No | Callback for the data change event. If the callback is not specified, all subscriptions to the data change event will be canceled.| **Example** @@ -5342,7 +5342,7 @@ Unsubscribes from synchronization complete events. | Name | Type | Mandatory| Description | | ------------ | --------------------------------------------- | ---- | ---------------------------------------------------------- | | event | string | Yes | Event to unsubscribe from. The value is **syncComplete**, which indicates a synchronization complete event.| -| syncCallback | Callback<Array<[string, number]>> | No | Callback for the synchronization complete event. | +| syncCallback | Callback<Array<[string, number]>> | No | Callback for the synchronization complete event. If the callback is not specified, all subscriptions to the synchronization complete event will be canceled. | **Example** diff --git a/en/application-dev/reference/apis/js-apis-distributedKVStore.md b/en/application-dev/reference/apis/js-apis-distributedKVStore.md index fc93034ec3..bc59b6d777 100644 --- a/en/application-dev/reference/apis/js-apis-distributedKVStore.md +++ b/en/application-dev/reference/apis/js-apis-distributedKVStore.md @@ -12,7 +12,8 @@ The **distributedKVStore** module provides the following functions: > **NOTE** > -> The initial APIs of this module are supported since API version 9. 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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> - All the APIs that need to obtain **deviceId** in this module are available only to system applications. ## Modules to Import @@ -148,13 +149,13 @@ Provides KV store configuration. | Name | Type | Mandatory| Description | | --------------- | -------------- | ---- | -------------------------| -| createIfMissing | boolean | No | Whether to create a KV store if no database file exists. By default, a KV store is created.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core| -| encrypt | boolean | No | Whether to encrypt database files. By default, database files are not encrypted.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core| -| backup | boolean | No | Whether to back up database files. By default, database files are backed up.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core| -| autoSync | boolean | No | Whether to automatically synchronize database files. The value **false** (default) means to manually synchronize database files; the value **true** means to automatically synchronize database files.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC| -| kvStoreType | [KVStoreType](#kvstoretype) | No | Type of the KV store to create. By default, a device KV store is created. The device KV store stores data for multiple devices that collaborate with each other.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core| -| securityLevel | [SecurityLevel](#securitylevel) | Yes |Security level of the KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core| -| schema | [Schema](#schema) | No | Schema used to define the values stored in the KV store. By default, **schema** is not used.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore| +| createIfMissing | boolean | No | Whether to create a KV store if no database file exists. The default value is **true**, which means to create a KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core| +| encrypt | boolean | No | Whether to encrypt the KV store. The default value is **false**, which means the KV store is not encrypted.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core| +| backup | boolean | No | Whether to back up the KV store. The default value is **true**, which means to back up the KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core| +| autoSync | boolean | No | Whether to automatically synchronize database files. The default value is **false**, which means the database files are manually synchronized.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC| +| kvStoreType | [KVStoreType](#kvstoretype) | No | Type of the KV store to create. The default value is **DEVICE_COLLABORATION**, which indicates a device KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core| +| securityLevel | [SecurityLevel](#securitylevel) | Yes | Security level of the KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core| +| schema | [Schema](#schema) | No | Schema used to define the values stored in the KV store. The default value is **undefined**, which means no schema is set.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore| ## Schema @@ -226,23 +227,23 @@ Appends a child node to this **FieldNode**. **Example** ```js -import ddm from '@ohos.data.distributedKVStore'; +import distributedKVStore from '@ohos.data.distributedKVStore'; try { - let node = new ddm.FieldNode("root"); - let child1 = new ddm.FieldNode("child1"); - let child2 = new ddm.FieldNode("child2"); - let child3 = new ddm.FieldNode("child3"); + let node = new distributedKVStore.FieldNode("root"); + let child1 = new distributedKVStore.FieldNode("child1"); + let child2 = new distributedKVStore.FieldNode("child2"); + let child3 = new distributedKVStore.FieldNode("child3"); node.appendChild(child1); node.appendChild(child2); node.appendChild(child3); - console.log("appendNode " + JSON.stringify(node)); + console.info("appendNode " + JSON.stringify(node)); child1 = null; child2 = null; child3 = null; node = null; } catch (e) { - console.log("AppendChild " + e); + console.error("AppendChild " + e); } ``` @@ -250,7 +251,7 @@ try { createKVManager(config: KVManagerConfig): KVManager -Creates a **KVManager** instance to manage KV stores. +Creates a **KVManager** instance for KV store management. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -276,7 +277,7 @@ import UIAbility from '@ohos.app.ability.UIAbility'; let kvManager; export default class EntryAbility extends UIAbility { onCreate() { - console.log("MyAbilityStage onCreate") + console.info("MyAbilityStage onCreate") let context = this.context const kvManagerConfig = { context: context, @@ -284,7 +285,7 @@ export default class EntryAbility extends UIAbility { } try { kvManager = distributedKVStore.createKVManager(kvManagerConfig); - console.log("Created KVManager successfully"); + console.info("Succeeded in creating KVManager"); } catch (e) { console.error(`Failed to create KVManager.code is ${e.code},message is ${e.message}`); } @@ -304,7 +305,7 @@ const kvManagerConfig = { } try { kvManager = distributedKVStore.createKVManager(kvManagerConfig); - console.log("Created KVManager successfully"); + console.info("Succeeded in creating KVManager"); } catch (e) { console.error(`Failed to create KVManager.code is ${e.code},message is ${e.message}`); } @@ -316,7 +317,7 @@ Provides an instance to obtain information about a distributed KV store. Before ### getKVStore -getKVStore<T >(storeId: string, options: Options, callback: AsyncCallback<T>): void +getKVStore<T>(storeId: string, options: Options, callback: AsyncCallback<T>): void Creates and obtains a distributed KV store. This API uses an asynchronous callback to return the result. @@ -358,17 +359,17 @@ try { console.error(`Failed to get KVStore.code is ${err.code},message is ${err.message}`); return; } - console.log("Succeeded in getting KVStore"); + console.info("Succeeded in getting KVStore"); kvStore = store; }); } catch (e) { - console.log(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); + console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); } ``` ### getKVStore -getKVStore<T >(storeId: string, options: Options): Promise<T> +getKVStore<T>(storeId: string, options: Options): Promise<T> Creates and obtains a distributed KV store. This API uses a promise to return the result. @@ -411,13 +412,13 @@ try { securityLevel: distributedKVStore.SecurityLevel.S2, }; kvManager.getKVStore('storeId', options).then((store) => { - console.log("Succeeded in getting KVStore"); + console.info("Succeeded in getting KVStore"); kvStore = store; }).catch((err) => { console.error(`Failed to get KVStore.code is ${err.code},message is ${err.message}`); }); } catch (e) { - console.log(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); + console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); } ``` @@ -448,19 +449,25 @@ const options = { backup: false, autoSync: true, kvStoreType: distributedKVStore.KVStoreType.SINGLE_VERSION, - schema: '', + schema: undefined, securityLevel: distributedKVStore.SecurityLevel.S2, } try { kvManager.getKVStore('storeId', options, async function (err, store) { - console.log('Succeeded in getting KVStore'); + if (err != undefined) { + console.error(`Failed to get KVStore.code is ${err.code},message is ${err.message}`); + return; + } + console.info('Succeeded in getting KVStore'); kvStore = store; - kvManager.closeKVStore('appId', 'storeId', function (err, data) { + kvStore = null; + store = null; + kvManager.closeKVStore('appId', 'storeId', function (err) { if (err != undefined) { console.error(`Failed to close KVStore.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in closing KVStore'); + console.info('Succeeded in closing KVStore'); }); }); } catch (e) { @@ -500,15 +507,17 @@ const options = { backup: false, autoSync: true, kvStoreType: distributedKVStore.KVStoreType.SINGLE_VERSION, - schema: '', + schema: undefined, securityLevel: distributedKVStore.SecurityLevel.S2, } try { kvManager.getKVStore('storeId', options).then(async (store) => { - console.log('Succeeded in getting KVStore'); + console.info('Succeeded in getting KVStore'); kvStore = store; + kvStore = null; + store = null; kvManager.closeKVStore('appId', 'storeId').then(() => { - console.log('Succeeded in closing KVStore'); + console.info('Succeeded in closing KVStore'); }).catch((err) => { console.error(`Failed to close KVStore.code is ${err.code},message is ${err.message}`); }); @@ -555,7 +564,7 @@ const options = { backup: false, autoSync: true, kvStoreType: distributedKVStore.KVStoreType.SINGLE_VERSION, - schema: '', + schema: undefined, securityLevel: distributedKVStore.SecurityLevel.S2, } try { @@ -564,14 +573,16 @@ try { console.error(`Failed to get KVStore.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting KVStore'); + console.info('Succeeded in getting KVStore'); kvStore = store; - kvManager.deleteKVStore('appId', 'storeId', function (err, data) { + kvStore = null; + store = null; + kvManager.deleteKVStore('appId', 'storeId', function (err) { if (err != undefined) { console.error(`Failed to delete KVStore.code is ${err.code},message is ${err.message}`); return; } - console.log(`Succeeded in deleting KVStore`); + console.info(`Succeeded in deleting KVStore`); }); }); } catch (e) { @@ -619,15 +630,17 @@ const options = { backup: false, autoSync: true, kvStoreType: distributedKVStore.KVStoreType.SINGLE_VERSION, - schema: '', + schema: undefined, securityLevel: distributedKVStore.SecurityLevel.S2, } try { kvManager.getKVStore('storeId', options).then(async (store) => { - console.log('Succeeded in getting KVStore'); + console.info('Succeeded in getting KVStore'); kvStore = store; + kvStore = null; + store = null; kvManager.deleteKVStore('appId', 'storeId').then(() => { - console.log('Succeeded in deleting KVStore'); + console.info('Succeeded in deleting KVStore'); }).catch((err) => { console.error(`Failed to delete KVStore.code is ${err.code},message is ${err.message}`); }); @@ -664,8 +677,8 @@ try { console.error(`Failed to get AllKVStoreId.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting AllKVStoreId'); - console.log(`GetAllKVStoreId size = ${data.length}`); + console.info('Succeeded in getting AllKVStoreId'); + console.info(`GetAllKVStoreId size = ${data.length}`); }); } catch (e) { console.error(`Failed to get AllKVStoreId.code is ${e.code},message is ${e.message}`); @@ -697,10 +710,10 @@ Obtains the IDs of all distributed KV stores that are created by [getKVStore](#g ```js let kvManager; try { - console.log('GetAllKVStoreId'); + console.info('GetAllKVStoreId'); kvManager.getAllKVStoreId('appId').then((data) => { - console.log('Succeeded in getting AllKVStoreId'); - console.log(`GetAllKVStoreId size = ${data.length}`); + console.info('Succeeded in getting AllKVStoreId'); + console.info(`GetAllKVStoreId size = ${data.length}`); }).catch((err) => { console.error(`Failed to get AllKVStoreId.code is ${err.code},message is ${err.message}`); }); @@ -713,7 +726,7 @@ try { on(event: 'distributedDataServiceDie', deathCallback: Callback<void>): void -Subscribes to service status changes. +Subscribes to service status changes. If the service is terminated, you need to register the callbacks for data change notifications and synchronization complete notifications again. In addition, an error will be returned for a synchronization operation. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -729,13 +742,13 @@ Subscribes to service status changes. ```js let kvManager; try { - console.log('KVManagerOn'); + console.info('KVManagerOn'); const deathCallback = function () { - console.log('death callback call'); + console.info('death callback call'); } kvManager.on('distributedDataServiceDie', deathCallback); } catch (e) { - console.log(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); + console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); } ``` @@ -743,7 +756,7 @@ try { off(event: 'distributedDataServiceDie', deathCallback?: Callback<void>): void -Unsubscribes from service status changes. +Unsubscribes from service status changes. The **deathCallback** parameter must be a callback registered for subscribing to service status changes. Otherwise, the unsubscription will fail. **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -752,26 +765,26 @@ Unsubscribes from service status changes. | Name | Type | Mandatory| Description | | ------------- | -------------------- | ---- | ------------------------------------------------------------ | | event | string | Yes | Event to unsubscribe from. The value is **distributedDataServiceDie**, which indicates a service status change event.| -| deathCallback | Callback<void> | No | Callback for the service status change event. | +| deathCallback | Callback<void> | No | Callback for the service status change event. If this parameter is not specified, all subscriptions to the service status change event will be canceled. | **Example** ```js let kvManager; try { - console.log('KVManagerOff'); + console.info('KVManagerOff'); const deathCallback = function () { - console.log('death callback call'); + console.info('death callback call'); } kvManager.off('distributedDataServiceDie', deathCallback); } catch (e) { - console.log(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); + console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); } ``` ## KVStoreResultSet -Provides APIs for obtaining the distributed KV store result sets. +Provides APIs for obtaining the distributed KV store result sets. A maximum of eight result sets can be opened at a time. Before calling any API in **KVStoreResultSet**, you must use **[getKVStore](#getkvstore)** to construct a **SingleKVStore** or **DeviceKVStore** instance. @@ -795,16 +808,17 @@ Obtains the total number of rows in the result set. let kvStore; try { let resultSet; + let count; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + count = resultSet.getCount(); + console.info("getCount succeed:" + count); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const count = resultSet.getCount(); - console.log("getCount succeed:" + count); } catch (e) { - console.log("getCount failed: " + e); + console.error("getCount failed: " + e); } ``` @@ -812,7 +826,7 @@ try { getPosition(): number -Obtains the current data read position (position from which data is read) in the result set. +Obtains the current data read position (position from which data is read) in the result set. The read position changes with the operations, such as [moveToFirst](#movetofirst) and [moveToLast](#movetolast). **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -820,7 +834,7 @@ Obtains the current data read position (position from which data is read) in the | Type | Description | | ------ | ------------------ | -| number | Current data read position obtained.| +| number | Current data read position obtained. The value must be greater than or equal to **-1**. The value **-1** means no data is read; the value **0** indicates the first row.| **Example** @@ -828,16 +842,17 @@ Obtains the current data read position (position from which data is read) in the let kvStore; try { let resultSet; + let position; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeeded.'); + console.info('getResultSet succeeded.'); resultSet = result; + position = resultSet.getPosition(); + console.info("getPosition succeed:" + position); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const position = resultSet.getPosition(); - console.log("getPosition succeed:" + position); } catch (e) { - console.log("getPosition failed: " + e); + console.error("getPosition failed: " + e); } ``` @@ -861,16 +876,17 @@ Moves the data read position to the first row. If the result set is empty, **fal let kvStore; try { let resultSet; + let moved; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + moved = resultSet.moveToFirst(); + console.info("moveToFirst succeed: " + moved); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const moved1 = resultSet.moveToFirst(); - console.log("moveToFirst succeed: " + moved1); } catch (e) { - console.log("moveToFirst failed " + e); + console.error("moveToFirst failed " + e); } ``` @@ -894,16 +910,17 @@ Moves the data read position to the last row. If the result set is empty, **fals let kvStore; try { let resultSet; + let moved; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + moved = resultSet.moveToLast(); + console.info("moveToLast succeed:" + moved); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const moved2 = resultSet.moveToLast(); - console.log("moveToLast succeed:" + moved2); } catch (e) { - console.log("moveToLast failed: " + e); + console.error("moveToLast failed: " + e); } ``` @@ -911,7 +928,7 @@ try { moveToNext(): boolean -Moves the data read position to the next row. If the result set is empty, **false** will be returned. +Moves the data read position to the next row. If the result set is empty, **false** will be returned. This API applies when the whole result set is obtained. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -927,16 +944,20 @@ Moves the data read position to the next row. If the result set is empty, **fals let kvStore; try { let resultSet; + let moved; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + do { + moved = resultSet.moveToNext(); + const entry = resultSet.getEntry(); + console.info("moveToNext succeed: " + moved); + } while (moved) }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const moved3 = resultSet.moveToNext(); - console.log("moveToNext succeed: " + moved3); } catch (e) { - console.log("moveToNext failed: " + e); + console.error("moveToNext failed: " + e); } ``` @@ -944,7 +965,7 @@ try { moveToPrevious(): boolean -Moves the data read position to the previous row. If the result set is empty, **false** will be returned. +Moves the data read position to the previous row. If the result set is empty, **false** will be returned. This API applies when the whole result set is obtained. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -960,16 +981,18 @@ Moves the data read position to the previous row. If the result set is empty, ** let kvStore; try { let resultSet; + let moved; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + moved = resultSet.moveToLast(); + moved = resultSet.moveToPrevious(); + console.info("moveToPrevious succeed:" + moved); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const moved4 = resultSet.moveToPrevious(); - console.log("moveToPrevious succeed:" + moved4); } catch (e) { - console.log("moveToPrevious failed: " + e); + console.error("moveToPrevious failed: " + e); } ``` @@ -977,7 +1000,7 @@ try { move(offset: number): boolean -Moves the data read position with the specified offset from the current position. +Moves the data read position with the specified offset from the current position. That is, moves the number of rows specified by **offset** from the current position. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -999,16 +1022,17 @@ Moves the data read position with the specified offset from the current position let kvStore; try { let resultSet; + let moved; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('Succeeded in getting resultSet'); + console.info('Succeeded in getting resultSet'); resultSet = result; + moved = resultSet.move(2); // If the current position is 0, move the read position forward by two rows, that is, move to row 3. + console.info(`Succeeded in moving.moved = ${moved}`); }).catch((err) => { console.error(`Failed to get resultSet.code is ${err.code},message is ${err.message}`); }); - const moved5 = resultSet.move(1); - console.log(`Succeeded in moving.moved5 = ${moved5}`); } catch (e) { - console.log(`Failed to move.code is ${e.code},message is ${e.message}`); + console.error(`Failed to move.code is ${e.code},message is ${e.message}`); } ``` @@ -1038,14 +1062,15 @@ Moves the data read position from 0 to an absolute position. let kvStore; try { let resultSet; + let moved; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('Succeeded in getting resultSet'); + console.info('Succeeded in getting resultSet'); resultSet = result; + moved = resultSet.moveToPosition(1); + console.info(`Succeeded in moving to position.moved=${moved}`); }).catch((err) => { console.error(`Failed to get resultSet.code is ${err.code},message is ${err.message}`); }); - const moved6 = resultSet.moveToPosition(1); - console.log(`Succeeded in moving to position.moved6=${moved6}`); } catch (e) { console.error(`Failed to move to position.code is ${e.code},message is ${e.message}`); } @@ -1071,16 +1096,17 @@ Checks whether the data read position is the first row. let kvStore; try { let resultSet; + let isfirst; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + isfirst = resultSet.isFirst(); + console.info("Check isFirst succeed:" + isfirst); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const isfirst = resultSet.isFirst(); - console.log("Check isFirst succeed:" + isfirst); } catch (e) { - console.log("Check isFirst failed: " + e); + console.error("Check isFirst failed: " + e); } ``` @@ -1104,16 +1130,17 @@ Checks whether the data read position is the last row. let kvStore; try { let resultSet; + let islast; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + islast = resultSet.isLast(); + console.info("Check isLast succeed: " + islast); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const islast = resultSet.isLast(); - console.log("Check isLast succeed: " + islast); } catch (e) { - console.log("Check isLast failed: " + e); + console.error("Check isLast failed: " + e); } ``` @@ -1138,15 +1165,15 @@ let kvStore; try { let resultSet; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + const isbeforefirst = resultSet.isBeforeFirst(); + console.info("Check isBeforeFirst succeed: " + isbeforefirst); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const isbeforefirst = resultSet.isBeforeFirst(); - console.log("Check isBeforeFirst succeed: " + isbeforefirst); } catch (e) { - console.log("Check isBeforeFirst failed: " + e); + console.error("Check isBeforeFirst failed: " + e); } ``` @@ -1171,13 +1198,13 @@ let kvStore; try { let resultSet; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + const isafterlast = resultSet.isAfterLast(); + console.info("Check isAfterLast succeed:" + isafterlast); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const isafterlast = resultSet.isAfterLast(); - console.log("Check isAfterLast succeed:" + isafterlast); } catch (e) { console.log("Check isAfterLast failed: " + e); } @@ -1204,21 +1231,21 @@ let kvStore; try { let resultSet; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + const entry = resultSet.getEntry(); + console.info("getEntry succeed:" + JSON.stringify(entry)); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const entry = resultSet.getEntry(); - console.log("getEntry succeed:" + JSON.stringify(entry)); } catch (e) { - console.log("getEntry failed: " + e); + console.error("getEntry failed: " + e); } ``` ## Query -Provides methods to create a **Query** object, which defines different data query criteria. +Provides methods to create a **Query** object, which defines different data query criteria. A **Query** object supports a maximum of 256 predicates. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -1250,12 +1277,12 @@ Resets the **Query** object. try { let query = new distributedKVStore.Query(); query.equalTo("key", "value"); - console.log("query is " + query.getSqlLike()); + console.info("query is " + query.getSqlLike()); query.reset(); - console.log("query is " + query.getSqlLike()); + console.info("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("simply calls should be ok :" + e); + console.error("simply calls should be ok :" + e); } ``` @@ -1286,7 +1313,7 @@ Creates a **Query** object to match the specified field whose value is equal to try { let query = new distributedKVStore.Query(); query.equalTo("field", "value"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.ode is ${e.code},message is ${e.message}`); @@ -1320,7 +1347,7 @@ Creates a **Query** object to match the specified field whose value is not equal try { let query = new distributedKVStore.Query(); query.notEqualTo("field", "value"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1353,7 +1380,7 @@ Creates a **Query** object to match the specified field whose value is greater t try { let query = new distributedKVStore.Query(); query.greaterThan("field", "value"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1388,7 +1415,7 @@ Creates a **Query** object to match the specified field whose value is less than try { let query = new distributedKVStore.Query(); query.lessThan("field", "value"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1423,7 +1450,7 @@ Creates a **Query** object to match the specified field whose value is greater t try { let query = new distributedKVStore.Query(); query.greaterThanOrEqualTo("field", "value"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1458,7 +1485,7 @@ Creates a **Query** object to match the specified field whose value is less than try { let query = new distributedKVStore.Query(); query.lessThanOrEqualTo("field", "value"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1491,7 +1518,7 @@ Creates a **Query** object to match the specified field whose value is **null**. try { let query = new distributedKVStore.Query(); query.isNull("field"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1525,7 +1552,7 @@ Creates a **Query** object to match the specified field whose value is within th try { let query = new distributedKVStore.Query(); query.inNumber("field", [0, 1]); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1559,7 +1586,7 @@ Creates a **Query** object to match the specified field whose value is within th try { let query = new distributedKVStore.Query(); query.inString("field", ['test1', 'test2']); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1593,7 +1620,7 @@ Creates a **Query** object to match the specified field whose value is not withi try { let query = new distributedKVStore.Query(); query.notInNumber("field", [0, 1]); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1627,7 +1654,7 @@ Creates a **Query** object to match the specified field whose value is not withi try { let query = new distributedKVStore.Query(); query.notInString("field", ['test1', 'test2']); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1661,7 +1688,7 @@ Creates a **Query** object to match the specified field whose value is similar t try { let query = new distributedKVStore.Query(); query.like("field", "value"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1695,7 +1722,7 @@ Creates a **Query** object to match the specified field whose value is not simil try { let query = new distributedKVStore.Query(); query.unlike("field", "value"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1724,10 +1751,10 @@ try { query.notEqualTo("field", "value1"); query.and(); query.notEqualTo("field", "value2"); - console.log("query is " + query.getSqlLike()); + console.info("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("duplicated calls should be ok :" + e); + console.error("duplicated calls should be ok :" + e); } ``` @@ -1753,10 +1780,10 @@ try { query.notEqualTo("field", "value1"); query.or(); query.notEqualTo("field", "value2"); - console.log("query is " + query.getSqlLike()); + console.info("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("duplicated calls should be ok :" + e); + console.error("duplicated calls should be ok :" + e); } ``` @@ -1787,7 +1814,7 @@ try { let query = new distributedKVStore.Query(); query.notEqualTo("field", "value"); query.orderByAsc("field"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1821,7 +1848,7 @@ try { let query = new distributedKVStore.Query(); query.notEqualTo("field", "value"); query.orderByDesc("field"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1832,7 +1859,7 @@ try { limit(total: number, offset: number): Query -Creates a **Query** object to specify the number of records of the query result and where to start. +Creates a **Query** object to specify the number of records of the query result and where to start. This API must be called after the invocation of the **orderByAsc()**, **orderByDesc()**, and the query APIs of the **Query** object. **System capability**: SystemCapability.DistributedDataManager.KVStore.Core @@ -1858,7 +1885,7 @@ try { let query = new distributedKVStore.Query(); query.notEqualTo("field", "value"); query.limit(total, offset); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1891,7 +1918,7 @@ Creates a **Query** object to match the specified field whose value is not **nul try { let query = new distributedKVStore.Query(); query.isNotNull("field"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1920,10 +1947,10 @@ try { query.beginGroup(); query.isNotNull("field"); query.endGroup(); - console.log("query is " + query.getSqlLike()); + console.info("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("duplicated calls should be ok :" + e); + console.error("duplicated calls should be ok :" + e); } ``` @@ -1949,10 +1976,10 @@ try { query.beginGroup(); query.isNotNull("field"); query.endGroup(); - console.log("query is " + query.getSqlLike()); + console.info("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("duplicated calls should be ok :" + e); + console.error("duplicated calls should be ok :" + e); } ``` @@ -1983,7 +2010,7 @@ try { let query = new distributedKVStore.Query(); query.prefixKey("$.name"); query.prefixKey("0"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -2017,7 +2044,7 @@ try { let query = new distributedKVStore.Query(); query.setSuggestIndex("$.name"); query.setSuggestIndex("0"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -2050,7 +2077,7 @@ Creates a **Query** object with the device ID as the key prefix. try { let query = new distributedKVStore.Query(); query.deviceId("deviceId"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); } @@ -2076,9 +2103,9 @@ Obtains the query statement of the **Query** object. try { let query = new distributedKVStore.Query(); let sql1 = query.getSqlLike(); - console.log(`GetSqlLike sql= ${sql1}`); + console.info(`GetSqlLike sql= ${sql1}`); } catch (e) { - console.log("duplicated calls should be ok : " + e); + console.error("duplicated calls should be ok : " + e); } ``` @@ -2120,12 +2147,12 @@ let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err, data) { + kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err) { if (err != undefined) { console.error(`Failed to put.code is ${err.code},message is ${err.message}`); return; } - console.log("Succeeded in putting"); + console.info("Succeeded in putting"); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -2169,8 +2196,8 @@ let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => { - console.log(`Succeeded in putting.data=${data}`); + kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then(() => { + console.info(`Succeeded in putting data`); }).catch((err) => { console.error(`Failed to put.code is ${err.code},message is ${err.message}`); }); @@ -2191,7 +2218,7 @@ Batch inserts KV pairs to this single KV store. This API uses an asynchronous ca | Name | Type | Mandatory| Description | | -------- | ------------------------ | ---- | ------------------------ | -| entries | [Entry](#entry)[] | Yes | KV pairs to insert in batches.| +| entries | [Entry](#entry)[] | Yes | KV pairs to insert in batches. An **entries** object allows a maximum of 128 entries.| | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | **Error codes** @@ -2220,20 +2247,20 @@ try { } entries.push(entry); } - console.log(`entries: ${entries}`); - kvStore.putBatch(entries, async function (err, data) { + console.info(`entries: ${entries}`); + kvStore.putBatch(entries, async function (err) { if (err != undefined) { console.error(`Failed to put Batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting Batch'); + console.info('Succeeded in putting Batch'); kvStore.getEntries('batch_test_string_key', function (err, entries) { if (err != undefined) { console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); } - console.log('Succeeded in getting Entries'); - console.log(`entries.length: ${entries.length}`); - console.log(`entries[0]: ${entries[0]}`); + console.info('Succeeded in getting Entries'); + console.info(`entries.length: ${entries.length}`); + console.info(`entries[0]: ${entries[0]}`); }); }); } catch (e) { @@ -2253,7 +2280,7 @@ Batch inserts KV pairs to this single KV store. This API uses a promise to retur | Name | Type | Mandatory| Description | | ------- | ----------------- | ---- | ------------------------ | -| entries | [Entry](#entry)[] | Yes | KV pairs to insert in batches.| +| entries | [Entry](#entry)[] | Yes | KV pairs to insert in batches. An **entries** object allows a maximum of 128 entries.| **Return value** @@ -2287,12 +2314,12 @@ try { } entries.push(entry); } - console.log(`entries: ${entries}`); - kvStore.putBatch(entries).then(async (entries) => { - console.log('Succeeded in putting Batch'); + console.info(`entries: ${entries}`); + kvStore.putBatch(entries).then(async () => { + console.info('Succeeded in putting Batch'); kvStore.getEntries('batch_test_string_key').then((entries) => { - console.log('Succeeded in getting Entries'); - console.log(`PutBatch ${entries}`); + console.info('Succeeded in getting Entries'); + console.info(`PutBatch ${entries}`); }).catch((err) => { console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); }); @@ -2344,12 +2371,12 @@ try { v8Arr.push(vb1); v8Arr.push(vb2); v8Arr.push(vb3); - kvStore.putBatch(v8Arr, async function (err, data) { + kvStore.putBatch(v8Arr, async function (err) { if (err != undefined) { console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); }) } catch (e) { console.error(`Failed to put batch.code is ${e.code},message is ${e.message}`); @@ -2401,8 +2428,8 @@ try { v8Arr.push(vb1); v8Arr.push(vb2); v8Arr.push(vb3); - kvStore.putBatch(v8Arr).then(async (data) => { - console.log(`Succeeded in putting patch`); + kvStore.putBatch(v8Arr).then(async () => { + console.info(`Succeeded in putting patch`); }).catch((err) => { console.error(`putBatch fail.code is ${err.code},message is ${err.message}`); }); @@ -2442,18 +2469,18 @@ let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err, data) { + kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err) { if (err != undefined) { console.error(`Failed to put.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting'); - kvStore.delete(KEY_TEST_STRING_ELEMENT, function (err, data) { + console.info('Succeeded in putting'); + kvStore.delete(KEY_TEST_STRING_ELEMENT, function (err) { if (err != undefined) { console.error(`Failed to delete.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in deleting'); + console.info('Succeeded in deleting'); }); }); } catch (e) { @@ -2497,10 +2524,10 @@ let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => { - console.log(`Succeeded in putting: ${data}`); - kvStore.delete(KEY_TEST_STRING_ELEMENT).then((data) => { - console.log('Succeeded in deleting'); + kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then(() => { + console.info(`Succeeded in putting data`); + kvStore.delete(KEY_TEST_STRING_ELEMENT).then(() => { + console.info('Succeeded in deleting'); }).catch((err) => { console.error(`Failed to delete.code is ${err.code},message is ${err.message}`); }); @@ -2545,9 +2572,9 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates'; let kvStore; try { let predicates = new dataSharePredicates.DataSharePredicates(); - kvStore.delete(predicates, function (err, data) { + kvStore.delete(predicates, function (err) { if (err == undefined) { - console.log('Succeeded in deleting'); + console.info('Succeeded in deleting'); } else { console.error(`Failed to delete.code is ${err.code},message is ${err.message}`); } @@ -2598,10 +2625,10 @@ try { let predicates = new dataSharePredicates.DataSharePredicates(); let arr = ["name"]; predicates.inKeys(arr); - kvStore.put("name", "bob").then((data) => { - console.log(`Succeeded in putting: ${data}`); - kvStore.delete(predicates).then((data) => { - console.log('Succeeded in deleting'); + kvStore.put("name", "bob").then(() => { + console.info(`Succeeded in putting data`); + kvStore.delete(predicates).then(() => { + console.info('Succeeded in deleting'); }).catch((err) => { console.error(`Failed to delete.code is ${err.code},message is ${err.message}`); }); @@ -2656,19 +2683,19 @@ try { entries.push(entry); keys.push(key + i); } - console.log(`entries: ${entries}`); - kvStore.putBatch(entries, async function (err, data) { + console.info(`entries: ${entries}`); + kvStore.putBatch(entries, async function (err) { if (err != undefined) { console.error(`Failed to put Batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting Batch'); - kvStore.deleteBatch(keys, async function (err, data) { + console.info('Succeeded in putting Batch'); + kvStore.deleteBatch(keys, async function (err) { if (err != undefined) { console.error(`Failed to delete Batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in deleting Batch'); + console.info('Succeeded in deleting Batch'); }); }); } catch (e) { @@ -2724,11 +2751,11 @@ try { entries.push(entry); keys.push(key + i); } - console.log(`entries: ${entries}`); - kvStore.putBatch(entries).then(async (data) => { - console.log('Succeeded in putting Batch'); - kvStore.deleteBatch(keys).then((err) => { - console.log('Succeeded in deleting Batch'); + console.info(`entries: ${entries}`); + kvStore.putBatch(entries).then(async () => { + console.info('Succeeded in putting Batch'); + kvStore.deleteBatch(keys).then(() => { + console.info('Succeeded in deleting Batch'); }).catch((err) => { console.error(`Failed to delete Batch.code is ${err.code},message is ${err.message}`); }); @@ -2770,16 +2797,16 @@ let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; const VALUE_TEST_STRING_ELEMENT = 'value-string-002'; try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err, data) { - console.log('Succeeded in putting data'); + kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err) { + console.info('Succeeded in putting data'); const deviceid = 'no_exist_device_id'; - kvStore.removeDeviceData(deviceid, async function (err, data) { + kvStore.removeDeviceData(deviceid, async function (err) { if (err == undefined) { - console.log('succeeded in removing device data'); + console.info('succeeded in removing device data'); } else { console.error(`Failed to remove device data.code is ${err.code},message is ${err.message} `); kvStore.get(KEY_TEST_STRING_ELEMENT, async function (err, data) { - console.log('Succeeded in getting data'); + console.info('Succeeded in getting data'); }); } }); @@ -2824,19 +2851,19 @@ let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; const VALUE_TEST_STRING_ELEMENT = 'value-string-001'; try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((err) => { - console.log('Succeeded in putting data'); + kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then(() => { + console.info('Succeeded in putting data'); }).catch((err) => { console.error(`Failed to put data.code is ${err.code},message is ${err.message} `); }); const deviceid = 'no_exist_device_id'; - kvStore.removeDeviceData(deviceid).then((err) => { - console.log('succeeded in removing device data'); + kvStore.removeDeviceData(deviceid).then(() => { + console.info('succeeded in removing device data'); }).catch((err) => { console.error(`Failed to remove device data.code is ${err.code},message is ${err.message} `); }); kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => { - console.log('Succeeded in getting data'); + console.info('Succeeded in getting data'); }).catch((err) => { console.error(`Failed to get data.code is ${err.code},message is ${err.message} `); }); @@ -2877,18 +2904,18 @@ let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err, data) { + kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err) { if (err != undefined) { console.error(`Failed to put.code is ${err.code},message is ${err.message}`); return; } - console.log("Succeeded in putting"); + console.info("Succeeded in putting"); kvStore.get(KEY_TEST_STRING_ELEMENT, function (err, data) { if (err != undefined) { console.error(`Failed to get.code is ${err.code},message is ${err.message}`); return; } - console.log(`Succeeded in getting data.data=${data}`); + console.info(`Succeeded in getting data.data=${data}`); }); }); } catch (e) { @@ -2933,10 +2960,10 @@ let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => { - console.log(`Succeeded in putting data.data=${data}`); + kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then(() => { + console.info(`Succeeded in putting data`); kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => { - console.log(`Succeeded in getting data.data=${data}`); + console.info(`Succeeded in getting data.data=${data}`); }).catch((err) => { console.error(`Failed to get.code is ${err.code},message is ${err.message}`); }); @@ -2989,21 +3016,21 @@ try { } entries.push(entry); } - console.log(`entries: ${entries}`); - kvStore.putBatch(entries, async function (err, data) { + console.info(`entries: ${entries}`); + kvStore.putBatch(entries, async function (err) { if (err != undefined) { console.error(`Failed to put Batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting Batch'); + console.info('Succeeded in putting Batch'); kvStore.getEntries('batch_test_string_key', function (err, entries) { if (err != undefined) { console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting Entries'); - console.log(`entries.length: ${entries.length}`); - console.log(`entries[0]: ${entries[0]}`); + console.info('Succeeded in getting Entries'); + console.info(`entries.length: ${entries.length}`); + console.info(`entries[0]: ${entries[0]}`); }); }); } catch (e) { @@ -3057,12 +3084,12 @@ try { } entries.push(entry); } - console.log(`entries: ${entries}`); - kvStore.putBatch(entries).then(async (entries) => { - console.log('Succeeded in putting Batch'); + console.info(`entries: ${entries}`); + kvStore.putBatch(entries).then(async () => { + console.info('Succeeded in putting Batch'); kvStore.getEntries('batch_test_string_key').then((entries) => { - console.log('Succeeded in getting Entries'); - console.log(`PutBatch ${entries}`); + console.info('Succeeded in getting Entries'); + console.info(`PutBatch ${entries}`); }).catch((err) => { console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); }); @@ -3116,9 +3143,9 @@ try { } entries.push(entry); } - console.log(`entries: {entries}`); - kvStore.putBatch(entries, async function (err, data) { - console.log('Succeeded in putting Batch'); + console.info(`entries: {entries}`); + kvStore.putBatch(entries, async function (err) { + console.info('Succeeded in putting Batch'); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getEntries(query, function (err, entries) { @@ -3126,9 +3153,9 @@ try { console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting Entries'); - console.log(`entries.length: ${entries.length}`); - console.log(`entries[0]: ${entries[0]}`); + console.info('Succeeded in getting Entries'); + console.info(`entries.length: ${entries.length}`); + console.info(`entries[0]: ${entries[0]}`); }); }); } catch (e) { @@ -3183,20 +3210,20 @@ try { } entries.push(entry); } - console.log(`entries: {entries}`); - kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting Batch'); + console.info(`entries: {entries}`); + kvStore.putBatch(entries).then(async () => { + console.info('Succeeded in putting Batch'); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getEntries(query).then((entries) => { - console.log('Succeeded in getting Entries'); + console.info('Succeeded in getting Entries'); }).catch((err) => { console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); }); }).catch((err) => { console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`) }); - console.log('Succeeded in getting Entries'); + console.info('Succeeded in getting Entries'); } catch (e) { console.error(`Failed to get Entries.code is ${e.code},message is ${e.message}`); } @@ -3244,25 +3271,25 @@ try { } entries.push(entry); } - kvStore.putBatch(entries, async function (err, data) { + kvStore.putBatch(entries, async function (err) { if (err != undefined) { console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); kvStore.getResultSet('batch_test_string_key', async function (err, result) { if (err != undefined) { console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; - kvStore.closeResultSet(resultSet, function (err, data) { + kvStore.closeResultSet(resultSet, function (err) { if (err != undefined) { console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); }) }); }); @@ -3318,19 +3345,19 @@ try { } entries.push(entry); } - kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + kvStore.putBatch(entries).then(async () => { + console.info('Succeeded in putting batch'); }).catch((err) => { console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; }).catch((err) => { console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); }); - kvStore.closeResultSet(resultSet).then((err) => { - console.log('Succeeded in closing result set'); + kvStore.closeResultSet(resultSet).then(() => { + console.info('Succeeded in closing result set'); }).catch((err) => { console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); }); @@ -3381,12 +3408,12 @@ try { } entries.push(entry); } - kvStore.putBatch(entries, async function (err, data) { + kvStore.putBatch(entries, async function (err) { if (err != undefined) { console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSet(query, async function (err, result) { @@ -3394,7 +3421,7 @@ try { console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); }); }); } catch (e) { @@ -3449,15 +3476,15 @@ try { } entries.push(entry); } - kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + kvStore.putBatch(entries).then(async () => { + console.info('Succeeded in putting batch'); }).catch((err) => { console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSet(query).then((result) => { - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; }).catch((err) => { console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); @@ -3508,14 +3535,14 @@ try { console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; - kvStore.closeResultSet(resultSet, function (err, data) { + kvStore.closeResultSet(resultSet, function (err) { if (err != undefined) { console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); }) }); } catch (e) { @@ -3565,13 +3592,13 @@ try { let predicates = new dataSharePredicates.DataSharePredicates(); predicates.prefixKey("batch_test_string_key"); kvStore.getResultSet(predicates).then((result) => { - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; }).catch((err) => { console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); }); - kvStore.closeResultSet(resultSet).then((err) => { - console.log('Succeeded in closing result set'); + kvStore.closeResultSet(resultSet).then(() => { + console.info('Succeeded in closing result set'); }).catch((err) => { console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); }); @@ -3601,9 +3628,9 @@ Closes the **KVStoreResultSet** object returned by [SingleKvStore.getResultSet]( let kvStore; try { let resultSet = null; - kvStore.closeResultSet(resultSet, function (err, data) { + kvStore.closeResultSet(resultSet, function (err) { if (err == undefined) { - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); } else { console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); } @@ -3640,7 +3667,7 @@ let kvStore; try { let resultSet = null; kvStore.closeResultSet(resultSet).then(() => { - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); }).catch((err) => { console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); }); @@ -3690,8 +3717,8 @@ try { } entries.push(entry); } - kvStore.putBatch(entries, async function (err, data) { - console.log('Succeeded in putting batch'); + kvStore.putBatch(entries, async function (err) { + console.info('Succeeded in putting batch'); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSize(query, async function (err, resultSize) { @@ -3699,7 +3726,7 @@ try { console.error(`Failed to get result size.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting result set size'); + console.info('Succeeded in getting result set size'); }); }); } catch (e) { @@ -3753,15 +3780,15 @@ try { } entries.push(entry); } - kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + kvStore.putBatch(entries).then(async () => { + console.info('Succeeded in putting batch'); }).catch((err) => { console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSize(query).then((resultSize) => { - console.log('Succeeded in getting result set size'); + console.info('Succeeded in getting result set size'); }).catch((err) => { console.error(`Failed to get result size.code is ${err.code},message is ${err.message}`); }); @@ -3799,11 +3826,11 @@ For details about the error codes, see [Distributed KV Store Error Codes](../err let kvStore; let file = "BK001"; try { - kvStore.backup(file, (err, data) => { + kvStore.backup(file, (err) => { if (err) { console.error(`Failed to backup.code is ${err.code},message is ${err.message} `); } else { - console.info(`Succeeded in backupping data.data=${data}`); + console.info(`Succeeded in backupping data`); } }); } catch (e) { @@ -3845,8 +3872,8 @@ For details about the error codes, see [Distributed KV Store Error Codes](../err let kvStore; let file = "BK001"; try { - kvStore.backup(file).then((data) => { - console.info(`Succeeded in backupping data.data=${data}`); + kvStore.backup(file).then(() => { + console.info(`Succeeded in backupping data`); }).catch((err) => { console.error(`Failed to backup.code is ${err.code},message is ${err.message}`); }); @@ -3884,11 +3911,11 @@ For details about the error codes, see [Distributed KV Store Error Codes](../err let kvStore; let file = "BK001"; try { - kvStore.restore(file, (err, data) => { + kvStore.restore(file, (err) => { if (err) { console.error(`Failed to restore.code is ${err.code},message is ${err.message}`); } else { - console.info(`Succeeded in restoring data.data=${data}`); + console.info(`Succeeded in restoring data`); } }); } catch (e) { @@ -3930,8 +3957,8 @@ For details about the error codes, see [Distributed KV Store Error Codes](../err let kvStore; let file = "BK001"; try { - kvStore.restore(file).then((data) => { - console.info(`Succeeded in restoring data.data=${data}`); + kvStore.restore(file).then(() => { + console.info(`Succeeded in restoring data`); }).catch((err) => { console.error(`Failed to restore.code is ${err.code},message is ${err.message}`); }); @@ -4005,7 +4032,7 @@ try { console.error(`Failed to delete Backup.code is ${err.code},message is ${err.message}`); }) } catch (e) { - console.log(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); + console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); } ``` @@ -4053,23 +4080,23 @@ function putBatchString(len, prefix) { try { var count = 0; kvStore.on('dataChange', 0, function (data) { - console.log(`startTransaction 0 ${data}`); + console.info(`startTransaction 0 ${data}`); count++; }); - kvStore.startTransaction(async function (err, data) { + kvStore.startTransaction(async function (err) { if (err != undefined) { console.error(`Failed to start Transaction.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in starting Transaction'); + console.info('Succeeded in starting Transaction'); let entries = putBatchString(10, 'batch_test_string_key'); - console.log(`entries: ${entries}`); - kvStore.putBatch(entries, async function (err, data) { + console.info(`entries: ${entries}`); + kvStore.putBatch(entries, async function (err) { if (err != undefined) { console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting Batch'); + console.info('Succeeded in putting Batch'); }); }); } catch (e) { @@ -4106,11 +4133,11 @@ let kvStore; try { var count = 0; kvStore.on('dataChange', distributedKVStore.SubscribeType.SUBSCRIBE_TYPE_ALL, function (data) { - console.log(`startTransaction 0 ${data}`); + console.info(`startTransaction 0 ${data}`); count++; }); - kvStore.startTransaction().then(async (err) => { - console.log('Succeeded in starting Transaction'); + kvStore.startTransaction().then(async () => { + console.info('Succeeded in starting Transaction'); }).catch((err) => { console.error(`Failed to start Transaction.code is ${err.code},message is ${err.message}`); }); @@ -4146,9 +4173,9 @@ For details about the error codes, see [Distributed KV Store Error Codes](../err ```js let kvStore; try { - kvStore.commit(function (err, data) { + kvStore.commit(function (err) { if (err == undefined) { - console.log('Succeeded in committing'); + console.info('Succeeded in committing'); } else { console.error(`Failed to commit.code is ${err.code},message is ${err.message}`); } @@ -4185,13 +4212,13 @@ For details about the error codes, see [Distributed KV Store Error Codes](../err ```js let kvStore; try { - kvStore.commit().then(async (err) => { - console.log('Succeeded in committing'); + kvStore.commit().then(async () => { + console.info('Succeeded in committing'); }).catch((err) => { console.error(`Failed to commit.code is ${err.code},message is ${err.message}`); }); } catch (e) { - console.error(`An unexpected error occurred.ode is ${e.code},message is ${e.message}`); + console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); } ``` @@ -4222,9 +4249,9 @@ For details about the error codes, see [Distributed KV Store Error Codes](../err ```js let kvStore; try { - kvStore.rollback(function (err,data) { + kvStore.rollback(function (err) { if (err == undefined) { - console.log('Succeeded in rolling back'); + console.info('Succeeded in rolling back'); } else { console.error(`Failed to rollback.code is ${err.code},message is ${err.message}`); } @@ -4261,8 +4288,8 @@ For details about the error codes, see [Distributed KV Store Error Codes](../err ```js let kvStore; try { - kvStore.rollback().then(async (err) => { - console.log('Succeeded in rolling back'); + kvStore.rollback().then(async () => { + console.info('Succeeded in rolling back'); }).catch((err) => { console.error(`Failed to rollback.code is ${err.code},message is ${err.message}`); }); @@ -4291,9 +4318,9 @@ Sets data synchronization, which can be enabled or disabled. This API uses an as ```js let kvStore; try { - kvStore.enableSync(true, function (err, data) { + kvStore.enableSync(true, function (err) { if (err == undefined) { - console.log('Succeeded in enabling sync'); + console.info('Succeeded in enabling sync'); } else { console.error(`Failed to enable sync.code is ${err.code},message is ${err.message}`); } @@ -4328,8 +4355,8 @@ Sets data synchronization, which can be enabled or disabled. This API uses a pro ```js let kvStore; try { - kvStore.enableSync(true).then((err) => { - console.log('Succeeded in enabling sync'); + kvStore.enableSync(true).then(() => { + console.info('Succeeded in enabling sync'); }).catch((err) => { console.error(`Failed to enable sync.code is ${err.code},message is ${err.message}`); }); @@ -4361,12 +4388,12 @@ let kvStore; try { const localLabels = ['A', 'B']; const remoteSupportLabels = ['C', 'D']; - kvStore.setSyncRange(localLabels, remoteSupportLabels, function (err, data) { + kvStore.setSyncRange(localLabels, remoteSupportLabels, function (err) { if (err != undefined) { console.error(`Failed to set syncRange.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in setting syncRange'); + console.info('Succeeded in setting syncRange'); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -4401,8 +4428,8 @@ let kvStore; try { const localLabels = ['A', 'B']; const remoteSupportLabels = ['C', 'D']; - kvStore.setSyncRange(localLabels, remoteSupportLabels).then((err) => { - console.log('Succeeded in setting syncRange'); + kvStore.setSyncRange(localLabels, remoteSupportLabels).then(() => { + console.info('Succeeded in setting syncRange'); }).catch((err) => { console.error(`Failed to set syncRange.code is ${err.code},message is ${err.message}`); }); @@ -4432,12 +4459,12 @@ Sets the default delay allowed for KV store synchronization. This API uses an as let kvStore; try { const defaultAllowedDelayMs = 500; - kvStore.setSyncParam(defaultAllowedDelayMs, function (err, data) { + kvStore.setSyncParam(defaultAllowedDelayMs, function (err) { if (err != undefined) { console.error(`Failed to set syncParam.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in setting syncParam'); + console.info('Succeeded in setting syncParam'); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -4470,8 +4497,8 @@ Sets the default delay allowed for KV store synchronization. This API uses a pro let kvStore; try { const defaultAllowedDelayMs = 500; - kvStore.setSyncParam(defaultAllowedDelayMs).then((err) => { - console.log('Succeeded in setting syncParam'); + kvStore.setSyncParam(defaultAllowedDelayMs).then(() => { + console.info('Succeeded in setting syncParam'); }).catch((err) => { console.error(`Failed to set syncParam.code is ${err.code},message is ${err.message}`); }); @@ -4499,7 +4526,7 @@ Synchronizes the KV store manually. For details about the synchronization modes | --------- | --------------------- | ---- | ---------------------------------------------- | | deviceIds | string[] | Yes | List of IDs of the devices in the same networking environment to be synchronized.| | mode | [SyncMode](#syncmode) | Yes | Synchronization mode. | -| delayMs | number | No | Allowed synchronization delay time, in ms. | +| delayMs | number | No | Allowed synchronization delay time, in ms. The default value is **0**. | **Error codes** @@ -4532,14 +4559,14 @@ deviceManager.createDeviceManager('bundleName', (err, value) => { } try { kvStore.on('syncComplete', function (data) { - console.log('Sync dataChange'); + console.info('Sync dataChange'); }); - kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err, data) { + kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err) { if (err != undefined) { console.error(`Failed to sync.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting data'); + console.info('Succeeded in putting data'); const mode = distributedKVStore.SyncMode.PULL_ONLY; kvStore.sync(deviceIds, mode, 1000); }); @@ -4570,7 +4597,7 @@ Synchronizes the KV store manually. This API returns the result synchronously. F | deviceIds | string[] | Yes | List of IDs of the devices in the same networking environment to be synchronized.| | mode | [SyncMode](#syncmode) | Yes | Synchronization mode. | | query | [Query](#query) | Yes | **Query** object to match. | -| delayMs | number | No | Allowed synchronization delay time, in ms. | +| delayMs | number | No | Allowed synchronization delay time, in ms. The default value is **0**. | **Error codes** @@ -4603,14 +4630,14 @@ deviceManager.createDeviceManager('bundleName', (err, value) => { } try { kvStore.on('syncComplete', function (data) { - console.log('Sync dataChange'); + console.info('Sync dataChange'); }); - kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err, data) { + kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err) { if (err != undefined) { console.error(`Failed to sync.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting data'); + console.info('Succeeded in putting data'); const mode = distributedKVStore.SyncMode.PULL_ONLY; const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); @@ -4655,7 +4682,7 @@ For details about the error codes, see [Distributed KV Store Error Codes](../err let kvStore; try { kvStore.on('dataChange', distributedKVStore.SubscribeType.SUBSCRIBE_TYPE_LOCAL, function (data) { - console.log(`dataChange callback call data: ${data}`); + console.info(`dataChange callback call data: ${data}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -4685,10 +4712,10 @@ const KEY_TEST_FLOAT_ELEMENT = 'key_test_float'; const VALUE_TEST_FLOAT_ELEMENT = 321.12; try { kvStore.on('syncComplete', function (data) { - console.log(`syncComplete ${data}`); + console.info(`syncComplete ${data}`); }); - kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then((data) => { - console.log('succeeded in putting'); + kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then(() => { + console.info('succeeded in putting'); }).catch((err) => { console.error(`Failed to put.code is ${err.code},message is ${err.message}`); }); @@ -4710,7 +4737,7 @@ Unsubscribes from data changes. | Name | Type | Mandatory| Description | | -------- | --------------------------------------------------------- | ---- | -------------------------------------------------------- | | event | string | Yes | Event to unsubscribe from. The value is **dataChange**, which indicates a data change event.| -| listener | Callback<[ChangeNotification](#changenotification)> | No | Callback for data changes. | +| listener | Callback<[ChangeNotification](#changenotification)> | No | Callback for data changes. If the callback is not specified, all subscriptions to the data change event will be canceled. | **Error codes** @@ -4726,7 +4753,7 @@ For details about the error codes, see [Distributed KV Store Error Codes](../err let kvStore; class KvstoreModel { call(data) { - console.log(`dataChange : ${data}`); + console.info(`dataChange : ${data}`); } subscribeDataChange() { @@ -4764,7 +4791,7 @@ Unsubscribes from synchronization complete events. | Name | Type | Mandatory| Description | | ------------ | --------------------------------------------- | ---- | ---------------------------------------------------------- | | event | string | Yes | Event to unsubscribe from. The value is **syncComplete**, which indicates a synchronization complete event.| -| syncCallback | Callback<Array<[string, number]>> | No | Callback for the synchronization complete event. | +| syncCallback | Callback<Array<[string, number]>> | No | Callback for the synchronization complete event. If the callback is not specified, all subscriptions to the synchronization complete event will be canceled. | **Example** @@ -4772,7 +4799,7 @@ Unsubscribes from synchronization complete events. let kvStore; class KvstoreModel { call(data) { - console.log(`syncComplete : ${data}`); + console.info(`syncComplete : ${data}`); } subscribeDataChange() { @@ -4829,7 +4856,7 @@ try { console.error(`Failed to get SecurityLevel.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting securityLevel'); + console.info('Succeeded in getting securityLevel'); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -4864,7 +4891,7 @@ For details about the error codes, see [Distributed KV Store Error Codes](../err let kvStore; try { kvStore.getSecurityLevel().then((data) => { - console.log('Succeeded in getting securityLevel'); + console.info('Succeeded in getting securityLevel'); }).catch((err) => { console.error(`Failed to get SecurityLevel.code is ${err.code},message is ${err.message}`); }); @@ -4915,18 +4942,18 @@ let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err, data) { + kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err) { if (err != undefined) { console.error(`Failed to put.code is ${err.code},message is ${err.message}`); return; } - console.log("Succeeded in putting"); + console.info("Succeeded in putting"); kvStore.get(KEY_TEST_STRING_ELEMENT, function (err, data) { if (err != undefined) { console.error(`Failed to get.code is ${err.code},message is ${err.message}`); return; } - console.log(`Succeeded in getting data.data=${data}`); + console.info(`Succeeded in getting data.data=${data}`); }); }); } catch (e) { @@ -4971,10 +4998,10 @@ let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => { - console.log(`Succeeded in putting data.data=${data}`); + kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then(() => { + console.info(`Succeeded in putting data`); kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => { - console.log(`Succeeded in getting data.data=${data}`); + console.info(`Succeeded in getting data.data=${data}`); }).catch((err) => { console.error(`Failed to get.code is ${err.code},message is ${err.message}`); }); @@ -5019,18 +5046,18 @@ let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; const VALUE_TEST_STRING_ELEMENT = 'value-string-002'; try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err, data) { + kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err) { if (err != undefined) { console.error(`Failed to put.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting'); + console.info('Succeeded in putting'); kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT, function (err, data) { if (err != undefined) { console.error(`Failed to get.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting'); + console.info('Succeeded in getting'); }); }) } catch (e) { @@ -5076,10 +5103,10 @@ let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; const VALUE_TEST_STRING_ELEMENT = 'value-string-002'; try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then(async (data) => { - console.log('Succeeded in putting'); + kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then(async () => { + console.info('Succeeded in putting'); kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT).then((data) => { - console.log('Succeeded in getting'); + console.info('Succeeded in getting'); }).catch((err) => { console.error(`Failed to get.code is ${err.code},message is ${err.message}`); }); @@ -5132,21 +5159,21 @@ try { } entries.push(entry); } - console.log(`entries: ${entries}`); - kvStore.putBatch(entries, async function (err, data) { + console.info(`entries: ${entries}`); + kvStore.putBatch(entries, async function (err) { if (err != undefined) { console.error(`Failed to put Batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting Batch'); + console.info('Succeeded in putting Batch'); kvStore.getEntries('batch_test_string_key', function (err, entries) { if (err != undefined) { console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting Entries'); - console.log(`entries.length: ${entries.length}`); - console.log(`entries[0]: ${entries[0]}`); + console.info('Succeeded in getting Entries'); + console.info(`entries.length: ${entries.length}`); + console.info(`entries[0]: ${entries[0]}`); }); }); } catch (e) { @@ -5200,12 +5227,12 @@ try { } entries.push(entry); } - console.log(`entries: ${entries}`); - kvStore.putBatch(entries).then(async (entries) => { - console.log('Succeeded in putting Batch'); + console.info(`entries: ${entries}`); + kvStore.putBatch(entries).then(async () => { + console.info('Succeeded in putting Batch'); kvStore.getEntries('batch_test_string_key').then((entries) => { - console.log('Succeeded in getting Entries'); - console.log(`PutBatch ${entries}`); + console.info('Succeeded in getting Entries'); + console.info(`PutBatch ${entries}`); }).catch((err) => { console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); }); @@ -5259,21 +5286,21 @@ try { } entries.push(entry); } - console.log(`entries : ${entries}`); - kvStore.putBatch(entries, async function (err, data) { + console.info(`entries : ${entries}`); + kvStore.putBatch(entries, async function (err) { if (err != undefined) { console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); kvStore.getEntries('localDeviceId', 'batch_test_string_key', function (err, entries) { if (err != undefined) { console.error(`Failed to get entries.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting entries'); - console.log(`entries.length: ${entries.length}`); - console.log(`entries[0]: ${entries[0]}`); + console.info('Succeeded in getting entries'); + console.info(`entries.length: ${entries.length}`); + console.info(`entries[0]: ${entries[0]}`); }); }); } catch (e) { @@ -5328,15 +5355,15 @@ try { } entries.push(entry); } - console.log(`entries: ${entries}`); - kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + console.info(`entries: ${entries}`); + kvStore.putBatch(entries).then(async () => { + console.info('Succeeded in putting batch'); kvStore.getEntries('localDeviceId', 'batch_test_string_key').then((entries) => { - console.log('Succeeded in getting entries'); - console.log(`entries.length: ${entries.length}`); - console.log(`entries[0]: ${entries[0]}`); - console.log(`entries[0].value: ${entries[0].value}`); - console.log(`entries[0].value.value: ${entries[0].value.value}`); + console.info('Succeeded in getting entries'); + console.info(`entries.length: ${entries.length}`); + console.info(`entries[0]: ${entries[0]}`); + console.info(`entries[0].value: ${entries[0].value}`); + console.info(`entries[0].value.value: ${entries[0].value.value}`); }).catch((err) => { console.error(`Failed to get entries.code is ${err.code},message is ${err.message}`); }); @@ -5390,9 +5417,9 @@ try { } entries.push(entry); } - console.log(`entries: {entries}`); - kvStore.putBatch(entries, async function (err, data) { - console.log('Succeeded in putting Batch'); + console.info(`entries: {entries}`); + kvStore.putBatch(entries, async function (err) { + console.info('Succeeded in putting Batch'); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getEntries(query, function (err, entries) { @@ -5400,9 +5427,9 @@ try { console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting Entries'); - console.log(`entries.length: ${entries.length}`); - console.log(`entries[0]: ${entries[0]}`); + console.info('Succeeded in getting Entries'); + console.info(`entries.length: ${entries.length}`); + console.info(`entries[0]: ${entries[0]}`); }); }); } catch (e) { @@ -5457,20 +5484,20 @@ try { } entries.push(entry); } - console.log(`entries: {entries}`); - kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting Batch'); + console.info(`entries: {entries}`); + kvStore.putBatch(entries).then(async () => { + console.info('Succeeded in putting Batch'); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getEntries(query).then((entries) => { - console.log('Succeeded in getting Entries'); + console.info('Succeeded in getting Entries'); }).catch((err) => { console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); }); }).catch((err) => { console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`) }); - console.log('Succeeded in getting Entries'); + console.info('Succeeded in getting Entries'); } catch (e) { console.error(`Failed to get Entries.code is ${e.code},message is ${e.message}`); } @@ -5519,13 +5546,13 @@ try { } entries.push(entry); } - console.log(`entries: ${entries}`); - kvStore.putBatch(entries, async function (err, data) { + console.info(`entries: ${entries}`); + kvStore.putBatch(entries, async function (err) { if (err != undefined) { console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); var query = new distributedKVStore.Query(); query.deviceId('localDeviceId'); query.prefixKey("batch_test"); @@ -5534,12 +5561,12 @@ try { console.error(`Failed to get entries.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting entries'); - console.log(`entries.length: ${entries.length}`); - console.log(`entries[0]: ${entries[0]}`); + console.info('Succeeded in getting entries'); + console.info(`entries.length: ${entries.length}`); + console.info(`entries[0]: ${entries[0]}`); }) }); - console.log('Succeeded in getting entries'); + console.info('Succeeded in getting entries'); } catch (e) { console.error(`Failed to get entries.code is ${e.code},message is ${e.message}`); } @@ -5593,21 +5620,21 @@ try { } entries.push(entry); } - console.log(`entries: ${entries}`); - kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + console.info(`entries: ${entries}`); + kvStore.putBatch(entries).then(async () => { + console.info('Succeeded in putting batch'); var query = new distributedKVStore.Query(); query.deviceId('localDeviceId'); query.prefixKey("batch_test"); kvStore.getEntries('localDeviceId', query).then((entries) => { - console.log('Succeeded in getting entries'); + console.info('Succeeded in getting entries'); }).catch((err) => { console.error(`Failed to get entries.code is ${err.code},message is ${err.message}`); }); }).catch((err) => { console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); - console.log('Succeeded in getting entries'); + console.info('Succeeded in getting entries'); } catch (e) { console.error(`Failed to get entries.code is ${e.code},message is ${e.message}`); } @@ -5655,25 +5682,25 @@ try { } entries.push(entry); } - kvStore.putBatch(entries, async function (err, data) { + kvStore.putBatch(entries, async function (err) { if (err != undefined) { console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); kvStore.getResultSet('batch_test_string_key', async function (err, result) { if (err != undefined) { console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; - kvStore.closeResultSet(resultSet, function (err, data) { + kvStore.closeResultSet(resultSet, function (err) { if (err != undefined) { console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); }) }); }); @@ -5729,19 +5756,19 @@ try { } entries.push(entry); } - kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + kvStore.putBatch(entries).then(async () => { + console.info('Succeeded in putting batch'); }).catch((err) => { console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; }).catch((err) => { console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); }); - kvStore.closeResultSet(resultSet).then((err) => { - console.log('Succeeded in closing result set'); + kvStore.closeResultSet(resultSet).then(() => { + console.info('Succeeded in closing result set'); }).catch((err) => { console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); }); @@ -5786,14 +5813,14 @@ try { console.error(`Failed to get resultSet.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting resultSet'); + console.info('Succeeded in getting resultSet'); resultSet = result; - kvStore.closeResultSet(resultSet, function (err, data) { + kvStore.closeResultSet(resultSet, function (err) { if (err != undefined) { console.error(`Failed to close resultSet.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in closing resultSet'); + console.info('Succeeded in closing resultSet'); }) }); } catch (e) { @@ -5838,13 +5865,13 @@ let kvStore; try { let resultSet; kvStore.getResultSet('localDeviceId', 'batch_test_string_key').then((result) => { - console.log('Succeeded in getting resultSet'); + console.info('Succeeded in getting resultSet'); resultSet = result; }).catch((err) => { console.error(`Failed to get resultSet.code is ${err.code},message is ${err.message}`); }); - kvStore.closeResultSet(resultSet).then((err) => { - console.log('Succeeded in closing resultSet'); + kvStore.closeResultSet(resultSet).then(() => { + console.info('Succeeded in closing resultSet'); }).catch((err) => { console.error(`Failed to close resultSet.code is ${err.code},message is ${err.message}`); }); @@ -5896,12 +5923,12 @@ try { } entries.push(entry); } - kvStore.putBatch(entries, async function (err, data) { + kvStore.putBatch(entries, async function (err) { if (err != undefined) { console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSet('localDeviceId', query, async function (err, result) { @@ -5909,14 +5936,14 @@ try { console.error(`Failed to get resultSet.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting resultSet'); + console.info('Succeeded in getting resultSet'); resultSet = result; - kvStore.closeResultSet(resultSet, function (err, data) { + kvStore.closeResultSet(resultSet, function (err) { if (err != undefined) { console.error(`Failed to close resultSet.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in closing resultSet'); + console.info('Succeeded in closing resultSet'); }) }); }); @@ -5973,23 +6000,23 @@ try { } entries.push(entry); } - kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + kvStore.putBatch(entries).then(async () => { + console.info('Succeeded in putting batch'); }).catch((err) => { console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSet('localDeviceId', query).then((result) => { - console.log('Succeeded in getting resultSet'); + console.info('Succeeded in getting resultSet'); resultSet = result; }).catch((err) => { console.error(`Failed to get resultSet.code is ${err.code},message is ${err.message}`); }); query.deviceId('localDeviceId'); - console.log("GetResultSet " + query.getSqlLike()); - kvStore.closeResultSet(resultSet).then((err) => { - console.log('Succeeded in closing resultSet'); + console.info("GetResultSet " + query.getSqlLike()); + kvStore.closeResultSet(resultSet).then(() => { + console.info('Succeeded in closing resultSet'); }).catch((err) => { console.error(`Failed to close resultSet.code is ${err.code},message is ${err.message}`); }); @@ -6046,18 +6073,18 @@ try { } entries.push(entry); } - kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + kvStore.putBatch(entries).then(async () => { + console.info('Succeeded in putting batch'); }).catch((err) => { console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSet(query).then((result) => { - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; }).catch((err) => { - console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); + console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.code}`); @@ -6066,24 +6093,18 @@ try { ### getResultSet -getResultSet(deviceId: string, query: Query): Promise<KVStoreResultSet> +getResultSet(query: Query, callback:AsyncCallback<KVStoreResultSet>): void Obtains a **KVStoreResultSet** object that matches the specified device ID and **Query** object. This API uses a promise to return the result. -**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore +**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------- | ---- | ---------------------------------- | -| deviceId | string | Yes | ID of the device to which the **KVStoreResultSet** object belongs.| | query | [Query](#query) | Yes | **Query** object to match. | - -**Return value** - -| Type | Description | -| ---------------------------------------------------- | ------------------------------------------------------------ | -| Promise<[KVStoreResultSet](#kvstoreresultset)> | Promise used to return the **KVStoreResultSet** object obtained.| +| callback | AsyncCallback<[KVStoreResultSet](#kvstoreresultset)> | Yes | Callback invoked to return the **KVStoreResultSet** object obtained. | **Error codes** @@ -6112,27 +6133,30 @@ try { } entries.push(entry); } - kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); - }).catch((err) => { - console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); - }); - const query = new distributedKVStore.Query(); - query.prefixKey("batch_test"); - kvStore.getResultSet('localDeviceId', query).then((result) => { - console.log('Succeeded in getting resultSet'); - resultSet = result; - }).catch((err) => { - console.error(`Failed to get resultSet.code is ${err.code},message is ${err.message}`); - }); - query.deviceId('localDeviceId'); - console.log("GetResultSet " + query.getSqlLike()); - kvStore.closeResultSet(resultSet).then((err) => { - console.log('Succeeded in closing resultSet'); - }).catch((err) => { - console.error(`Failed to close resultSet.code is ${err.code},message is ${err.message}`); + kvStore.putBatch(entries, async function (err) { + if (err != undefined) { + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); + return; + } + console.info('Succeeded in putting batch'); + const query = new distributedKVStore.Query(); + query.prefixKey("batch_test"); + kvStore.getResultSet(query, async function (err, result) { + if (err != undefined) { + console.error(`Failed to get resultSet.code is ${err.code},message is ${err.message}`); + return; + } + console.info('Succeeded in getting resultSet'); + resultSet = result; + kvStore.closeResultSet(resultSet, function (err) { + if (err != undefined) { + console.error(`Failed to close resultSet.code is ${err.code},message is ${err.message}`); + return; + } + console.info('Succeeded in closing resultSet'); + }) + }); }); - } catch (e) { console.error(`Failed to get resultSet.code is ${e.code},message is ${e.message}`); } @@ -6179,14 +6203,14 @@ try { console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; - kvStore.closeResultSet(resultSet, function (err, data) { + kvStore.closeResultSet(resultSet, function (err) { if (err != undefined) { console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); }) }); } catch (e) { @@ -6236,13 +6260,13 @@ try { let predicates = new dataSharePredicates.DataSharePredicates(); predicates.prefixKey("batch_test_string_key"); kvStore.getResultSet(predicates).then((result) => { - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; }).catch((err) => { console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); }); - kvStore.closeResultSet(resultSet).then((err) => { - console.log('Succeeded in closing result set'); + kvStore.closeResultSet(resultSet).then(() => { + console.info('Succeeded in closing result set'); }).catch((err) => { console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); }); @@ -6293,14 +6317,14 @@ try { console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; - kvStore.closeResultSet(resultSet, function (err, data) { + kvStore.closeResultSet(resultSet, function (err) { if (err != undefined) { console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); }) }); } catch (e) { @@ -6350,13 +6374,13 @@ try { let predicates = new dataSharePredicates.DataSharePredicates(); predicates.prefixKey("batch_test_string_key"); kvStore.getResultSet('localDeviceId', predicates).then((result) => { - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; }).catch((err) => { console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); }); - kvStore.closeResultSet(resultSet).then((err) => { - console.log('Succeeded in closing result set'); + kvStore.closeResultSet(resultSet).then(() => { + console.info('Succeeded in closing result set'); }).catch((err) => { console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); }); @@ -6406,8 +6430,8 @@ try { } entries.push(entry); } - kvStore.putBatch(entries, async function (err, data) { - console.log('Succeeded in putting batch'); + kvStore.putBatch(entries, async function (err) { + console.info('Succeeded in putting batch'); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSize(query, async function (err, resultSize) { @@ -6415,7 +6439,7 @@ try { console.error(`Failed to get result size.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting result set size'); + console.info('Succeeded in getting result set size'); }); }); } catch (e) { @@ -6469,15 +6493,15 @@ try { } entries.push(entry); } - kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + kvStore.putBatch(entries).then(async () => { + console.info('Succeeded in putting batch'); }).catch((err) => { console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSize(query).then((resultSize) => { - console.log('Succeeded in getting result set size'); + console.info('Succeeded in getting result set size'); }).catch((err) => { console.error(`Failed to get result size.code is ${err.code},message is ${err.message}`); }); @@ -6528,12 +6552,12 @@ try { } entries.push(entry); } - kvStore.putBatch(entries, async function (err, data) { + kvStore.putBatch(entries, async function (err) { if (err != undefined) { console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSize('localDeviceId', query, async function (err, resultSize) { @@ -6541,8 +6565,7 @@ try { console.error(`Failed to get resultSize.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting resultSize'); - ; + console.info('Succeeded in getting resultSize'); }); }); } catch (e) { @@ -6597,16 +6620,15 @@ try { } entries.push(entry); } - kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + kvStore.putBatch(entries).then(async () => { + console.info('Succeeded in putting batch'); }).catch((err) => { console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); var query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSize('localDeviceId', query).then((resultSize) => { - console.log('Succeeded in getting resultSize'); - ; + console.info('Succeeded in getting resultSize'); }).catch((err) => { console.error(`Failed to get resultSize.code is ${err.code},message is ${err.message}`); }); -- GitLab