@@ -6,9 +6,8 @@ The APIs provided by **DataSharePredicates** correspond to the filter criteria
...
@@ -6,9 +6,8 @@ The APIs provided by **DataSharePredicates** correspond to the filter criteria
> **NOTE**
> **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.
>
>- The APIs provided by this module are system APIs.
> The APIs provided by this module are system APIs.
## Modules to Import
## Modules to Import
...
@@ -18,7 +17,7 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
...
@@ -18,7 +17,7 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
```
```
## 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.
@@ -23,10 +23,10 @@ Creates a distributed data object.
...
@@ -23,10 +23,10 @@ Creates a distributed data object.
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| context | Context | Yes| Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).|
| context | Context | Yes| Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>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.|
| source | object | Yes| Attributes of the distributed data object.|
**Return value**
**Return value**
...
@@ -75,9 +75,9 @@ Creates a random session ID.
...
@@ -75,9 +75,9 @@ Creates a random session ID.
**Return value**
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| -------- | -------- |
| string | Session ID created.|
| string | Session ID created.|
**Example**
**Example**
...
@@ -124,18 +124,18 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
...
@@ -124,18 +124,18 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| sessionId | string | Yes| ID of a distributed data object on a trusted network.|
| 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.|
| callback | AsyncCallback<void> | Yes| Asynchronous callback invoked when the session ID is successfully set.|
**Error codes**
**Error codes**
For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md).
For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md).
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 15400001 | Failed to create the in-memory database.|
| 15400001 | Create table failed.|
**Example**
**Example**
...
@@ -158,17 +158,17 @@ Exits all joined sessions.
...
@@ -158,17 +158,17 @@ Exits all joined sessions.
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<void> | Yes| Asynchronous callback invoked when the distributed data object exits all joined sessions.|
| callback | AsyncCallback<void> | Yes| Asynchronous callback invoked when the distributed data object exits all joined sessions.|
**Error codes**
**Error codes**
For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md).
For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md).
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 15400001 | Failed to create the in-memory database.|
| 15400001 | Create table failed.|
**Example**
**Example**
...
@@ -195,9 +195,9 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
...
@@ -195,9 +195,9 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| 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.|
| 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**
**Return value**
...
@@ -209,9 +209,9 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
...
@@ -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).
For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md).
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 15400001 | Failed to create the in-memory database.|
| 15400001 | Create table failed.|
**Example**
**Example**
...
@@ -240,10 +240,10 @@ Subscribes to data changes of this distributed data object.
...
@@ -240,10 +240,10 @@ Subscribes to data changes of this distributed data object.
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to subscribe to. The value is **change**, which indicates data changes.|
| 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.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.|
| callback | Callback<{sessionId:string,fields:Array<string>}> | Yes| Callback invoked to return the changes of the distributed data object.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.|
**Example**
**Example**
...
@@ -269,10 +269,10 @@ Unsubscribes from the data changes of this distributed data object.
...
@@ -269,10 +269,10 @@ Unsubscribes from the data changes of this distributed data object.
**Parameters**
**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.|
| 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.<br>**sessionId** indicates the session ID of the distributed data object.<br>**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.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.|
**Example**
**Example**
...
@@ -294,10 +294,10 @@ Subscribes to status changes of this distributed data object.
...
@@ -294,10 +294,10 @@ Subscribes to status changes of this distributed data object.
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| 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.|
| 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.<br>**sessionId** indicates the session ID of the distributed data object.<br>**networkId** indicates the object device ID, that is, **deviceId**.<br>**status** indicates the object status, which can be online or offline.|
| callback | Callback<{sessionId:string,networkId:string,status:'online'\|'offline'}> | Yes| Callback invoked to return the status change.<br>**sessionId** indicates the session ID of the distributed data object.<br>**networkId** indicates the object device ID, that is, **deviceId**.<br>**status** indicates the object status, which can be online or offline.|
**Example**
**Example**
...
@@ -318,10 +318,10 @@ Unsubscribes from the status change of this distributed data object.
...
@@ -318,10 +318,10 @@ Unsubscribes from the status change of this distributed data object.
**Parameters**
**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.|
| 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.<br>**sessionId** indicates the session ID of the distributed data object.<br>**deviceId** indicates the device ID of the distributed data object.<br>**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.<br>**sessionId** indicates the session ID of the distributed data object.<br>**deviceId** indicates the device ID of the distributed data object.<br>**status** indicates the object status, which can be online or offline.|
**Example**
**Example**
...
@@ -354,10 +354,10 @@ The saved data will be released in the following cases:
...
@@ -354,10 +354,10 @@ The saved data will be released in the following cases:
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| deviceId | string | Yes| ID of the device where data is stored. The value **local** indicates the local device.|
| 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.|
| callback | AsyncCallback<[SaveSuccessResponse](#savesuccessresponse9)> | Yes| Callback invoked to return **SaveSuccessResponse**, which contains information such as session ID, version, and device ID.|
**Example**
**Example**
...
@@ -394,15 +394,15 @@ The saved data will be released in the following cases:
...
@@ -394,15 +394,15 @@ The saved data will be released in the following cases:
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| 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. |
| deviceId | string | Yes| ID of the device where the data is saved. The default value is **local**, which indicates the local device. |
**Return value**
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| -------- | -------- |
| Promise<[SaveSuccessResponse](#savesuccessresponse9)> | Promise used to return **SaveSuccessResponse**, which contains information such as session ID, version, and device ID.|
| Promise<[SaveSuccessResponse](#savesuccessresponse9)> | Promise used to return **SaveSuccessResponse**, which contains information such as session ID, version, and device ID.|
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 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.
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
...
@@ -477,9 +477,9 @@ If the object is stored on another device, the data on the local device will be
**Return value**
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| -------- | -------- |
| Promise<[RevokeSaveSuccessResponse](#revokesavesuccessresponse9)> | Promise used to return **RevokeSaveSuccessResponse**, which contains the session ID.|
| Promise<[RevokeSaveSuccessResponse](#revokesavesuccessresponse9)> | Promise used to return **RevokeSaveSuccessResponse**, which contains the session ID.|
**Example**
**Example**
...
@@ -520,9 +520,9 @@ Creates a distributed data object.
...
@@ -520,9 +520,9 @@ Creates a distributed data object.
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| source | object | Yes| Attributes of the distributed data object.|
| source | object | Yes| Attributes of the distributed data object.|
**Return value**
**Return value**
...
@@ -558,15 +558,15 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
...
@@ -558,15 +558,15 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| 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.|
| 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**
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| -------- | -------- |
| boolean | Returns **true** if the session ID is set successfully;<br>returns **false** otherwise. |
| boolean | Returns **true** if the session ID is set successfully;<br>returns **false** otherwise. |
**Example**
**Example**
...
@@ -593,10 +593,10 @@ Subscribes to data changes of this distributed data object.
...
@@ -593,10 +593,10 @@ Subscribes to data changes of this distributed data object.
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to subscribe to. The value is **change**, which indicates data changes.|
| 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.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.|
| callback | Callback<{sessionId:string,fields:Array<string>}> | Yes| Callback invoked to return the changes of the distributed data object.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.|
**Example**
**Example**
...
@@ -628,10 +628,10 @@ Unsubscribes from the data changes of this distributed data object.
...
@@ -628,10 +628,10 @@ Unsubscribes from the data changes of this distributed data object.
**Parameters**
**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.|
| 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.<br>**sessionId** indicates the session ID of the distributed data object.<br>**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.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.|
**Example**
**Example**
...
@@ -659,10 +659,10 @@ Subscribes to status changes of this distributed data object.
...
@@ -659,10 +659,10 @@ Subscribes to status changes of this distributed data object.
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| 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.|
| 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.<br>**sessionId** indicates the session ID of the distributed data object.<br>**networkId** indicates the object device ID, that is, **deviceId**.<br>**status** indicates the object status, which can be online or offline.|
| callback | Callback<{sessionId:string,networkId:string,status:'online'\|'offline'}> | Yes| Callback invoked to return the status change.<br>**sessionId** indicates the session ID of the distributed data object.<br>**networkId** indicates the object device ID, that is, **deviceId**.<br>**status** indicates the object status, which can be online or offline.|
**Example**
**Example**
...
@@ -689,8 +689,8 @@ Unsubscribes from the status change of this distributed data object.
...
@@ -689,8 +689,8 @@ Unsubscribes from the status change of this distributed data object.
**Parameters**
**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.|
| 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.<br>**sessionId** indicates the session ID of the distributed data object.<br>**deviceId** indicates the device ID of the distributed data object.<br>**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 unregistered.<br>**sessionId** indicates the session ID of the distributed data object.<br>**deviceId** indicates the device ID of the distributed data object.<br>**status** indicates the object status, which can be online or offline.|
@@ -9,9 +9,8 @@ This module provides the following RDB-related functions:
...
@@ -9,9 +9,8 @@ This module provides the following RDB-related functions:
> **NOTE**
> **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 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 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).
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.
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**<br/>
> **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.
> 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
...
@@ -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.
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**<br/>
> **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.
> 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
...
@@ -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.|
| event | string | Yes| The value is'dataChange', which indicates a data change event.|
| type | [SubscribeType](#subscribetype8) | Yes| Subscription type to register.|
| 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<string>** indicates the IDs of the peer devices whose data in the database is changed.|
**Example**
**Example**
...
@@ -2076,7 +2075,7 @@ Unregisters the observer of the specified type from the RDB store. This API uses
...
@@ -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.|
| event | string | Yes| The value is'dataChange', which indicates a data change event.|
| type | [SubscribeType](#subscribetype8) | Yes| Subscription type to unregister.|
| 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<string>** indicates the IDs of the peer devices whose data in the database is changed.|
| securityLevel | [SecurityLevel](#securitylevel) | Yes | Security level of the RDB store. |
| securityLevel | [SecurityLevel](#securitylevel) | Yes | Security level of the RDB store. |
| encrypt | boolean | No | Whether to encrypt the RDB store.<br> The value **true** means to encrypt the RDB store;<br> the value **false** means the opposite.|
| encrypt | boolean | No | Whether to encrypt the RDB store.<br> The value **true** means to encrypt the RDB store;<br> the value **false**(default) means the opposite.|
## SecurityLevel
## SecurityLevel
...
@@ -319,7 +323,7 @@ Enumerates the RDB store security levels.
...
@@ -319,7 +323,7 @@ Enumerates the RDB store security levels.
> **NOTE**
> **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).
@@ -344,7 +348,7 @@ Defines the data types allowed.
...
@@ -344,7 +348,7 @@ Defines the data types allowed.
## ValuesBucket
## 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.
@@ -377,7 +381,7 @@ Defines the subscription type.
...
@@ -377,7 +381,7 @@ Defines the subscription type.
## RdbPredicates
## 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.
| Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
| 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).
@@ -1306,7 +1318,7 @@ let promise = store.insert("EMPLOYEE", valueBucket);
...
@@ -1306,7 +1318,7 @@ let promise = store.insert("EMPLOYEE", valueBucket);
promise.then((rowId)=>{
promise.then((rowId)=>{
console.info(`Insert is successful, rowId = ${rowId}`);
console.info(`Insert is successful, rowId = ${rowId}`);
}).catch((err)=>{
}).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
...
@@ -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. |
| 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.|
| 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).
| 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.|
| 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).
@@ -1701,7 +1802,7 @@ let promise = store.delete("EMPLOYEE", predicates);
...
@@ -1701,7 +1802,7 @@ let promise = store.delete("EMPLOYEE", predicates);
promise.then((rows)=>{
promise.then((rows)=>{
console.info(`Delete rows: ${rows}`);
console.info(`Delete rows: ${rows}`);
}).catch((err)=>{
}).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
...
@@ -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. |
| 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.|
| 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).
| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|
| 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).
**Model restriction**: This API can be used only in the stage model.
**System API**: This is a system API.
**System API**: This is a system API.
**Parameters**
**Parameters**
...
@@ -1790,6 +1909,14 @@ Queries data from the RDB store based on specified conditions. This API uses an
...
@@ -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. |
| 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.|
| 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).
| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|
| 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).
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
...
@@ -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. |
| 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.|
| 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).
| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|
| 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).
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
...
@@ -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.|
| 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. |
| 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).
| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|
| 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).
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
...
@@ -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.|
| 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. |
| 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).
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
...
@@ -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. |
| 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.|
| 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).
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
...
@@ -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. |
| 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. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
| callback | AsyncCallback<Array<[string, number]>> | Yes | Callback invoked to send the synchronization result to the caller. <br>**string** indicates the device ID. <br>**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).
| Promise<Array<[string, number]>> | Promise used to send the synchronization result. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
| Promise<Array<[string, number]>> | Promise used to send the synchronization result. <br>**string** indicates the device ID. <br>**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).
| event | string | Yes | Event to observe. The value is **dataChange**, which indicates a data change event. |
| event | string | Yes | Event to observe. The value is **dataChange**, which indicates a data change event. |
| type | [SubscribeType](#subscribetype) | Yes | Subscription type to register.|
| 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<string>** indicates the IDs of the peer devices whose data in the database is changed.|
**Example**
**Example**
...
@@ -2596,7 +2869,7 @@ function storeObserver(devices) {
...
@@ -2596,7 +2869,7 @@ function storeObserver(devices) {
| event | string | Yes | Event to observe. The value is **dataChange**, which indicates a data change event. |
| event | string | Yes | Event to observe. The value is **dataChange**, which indicates a data change event. |
| type | [SubscribeType](#subscribetype) | Yes | Subscription type to unregister. |
| 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<string>** indicates the IDs of the peer devices whose data in the database is changed.|
**Example**
**Example**
...
@@ -2627,7 +2900,7 @@ function storeObserver(devices) {
...
@@ -2627,7 +2900,7 @@ function storeObserver(devices) {
The **ValueBucket** module holds data in key-value (KV) pairs. You can use it to insert data into a database.
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
...
@@ -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 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
## Modules to Import
...
@@ -30,7 +29,7 @@ Enumerates the value types allowed by the database.
...
@@ -30,7 +29,7 @@ Enumerates the value types allowed by the database.
## ValuesBucket
## 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.
@@ -575,13 +575,13 @@ Provides KV store configuration.
...
@@ -575,13 +575,13 @@ Provides KV store configuration.
| Name | Type| Mandatory | Description |
| Name | Type| Mandatory | Description |
| ----- | ------ | ------ | -------------------|
| ----- | ------ | ------ | -------------------|
| createIfMissing | boolean | No| Whether to create a KV store if no database file exists. By default, a KV store is created.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core |
| createIfMissing | boolean | No| Whether to create a KV store if no database file exists. The default value is **true**, which means to create a KV store.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core |
| encrypt | boolean | No|Whether to encrypt database files. By default, database files are not encrypted.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core |
| encrypt | boolean | No|Whether to encrypt the KV store. The default value is **false**, which means the KV store is not encrypted.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core |
| backup | boolean | No|Whether to back up database files. By default, database files are backed up. <br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core |
| backup | boolean | No|Whether to back up the KV store. The default value is **true**, which means to back up the KV store.<br>**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.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core<br>**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC |
| 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.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core<br>**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC |
| kvStoreType | [KVStoreType](#kvstoretype) | No|Type of the KV store to create. By default, a device KV store is created. The device KV store stores data for multiple devices that collaborate with each other.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core|
| kvStoreType | [KVStoreType](#kvstoretype) | No|Type of the KV store to create. The default value is **DEVICE_COLLABORATION**, which indicates a device KV store.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core|
| securityLevel | [SecurityLevel](#securitylevel) | No|Security level of the KV store. By default, the security level is not set.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core |
| securityLevel | [SecurityLevel](#securitylevel) | Yes|Security level (S1-S4) of the KV store.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core |
| schema<sup>8+</sup> | [Schema](#schema8) | No| Schema used to define the values stored in a KV store.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore|
| schema<sup>8+</sup> | [Schema](#schema8) | No| Schema used to define the values stored in the KV store. The default value is **undefined**, which means the schema is not set.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore|
## KVStoreType
## KVStoreType
...
@@ -602,8 +602,8 @@ Enumerates the KV store security levels.
...
@@ -602,8 +602,8 @@ Enumerates the KV store security levels.
| Name | Value| Description |
| Name | Value| Description |
| --- | ---- | ----------------------- |
| --- | ---- | ----------------------- |
| NO_LEVEL | 0 | No security level is set for the KV store.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore |
| NO_LEVEL | 0 | No security level is set for the KV store (deprecated).<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore |
| S0 | 1 | The KV store security level is public.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core |
| S0 | 1 | The KV store security level is public (deprecated).<br>**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.<br>**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.<br>**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.<br>**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.<br>**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.<br>**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.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core |
...
@@ -2292,7 +2292,7 @@ Unsubscribes from data changes.
...
@@ -2292,7 +2292,7 @@ Unsubscribes from data changes.
| event | string | Yes | Event to unsubscribe from. The value is **dataChange**, which indicates a data change event.|
| 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.
...
@@ -2330,7 +2330,7 @@ Unsubscribes from synchronization complete events.
| event | string | Yes | Event to unsubscribe from. The value is **syncComplete**, which indicates a synchronization complete event.|
| 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**
**Example**
...
@@ -3769,7 +3769,7 @@ Synchronizes the KV store manually.
...
@@ -3769,7 +3769,7 @@ Synchronizes the KV store manually.
| event | string | Yes | Event to unsubscribe from. The value is **dataChange**, which indicates a data change event.|
| 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**
**Example**
...
@@ -3920,7 +3920,7 @@ Unsubscribes from synchronization complete events.
...
@@ -3920,7 +3920,7 @@ Unsubscribes from synchronization complete events.
| event | string | Yes | Event to unsubscribe from. The value is **syncComplete**, which indicates a synchronization complete event.|
| 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**
**Example**
...
@@ -5191,7 +5191,7 @@ Synchronizes the KV store manually.
...
@@ -5191,7 +5191,7 @@ Synchronizes the KV store manually.
| event | string | Yes | Event to unsubscribe from. The value is **dataChange**, which indicates a data change event.|
| 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**
**Example**
...
@@ -5342,7 +5342,7 @@ Unsubscribes from synchronization complete events.
...
@@ -5342,7 +5342,7 @@ Unsubscribes from synchronization complete events.
| event | string | Yes | Event to unsubscribe from. The value is **syncComplete**, which indicates a synchronization complete event.|
| 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. |
@@ -12,7 +12,8 @@ The **distributedKVStore** module provides the following functions:
...
@@ -12,7 +12,8 @@ The **distributedKVStore** module provides the following functions:
> **NOTE**
> **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
## Modules to Import
...
@@ -148,13 +149,13 @@ Provides KV store configuration.
...
@@ -148,13 +149,13 @@ Provides KV store configuration.
| createIfMissing | boolean | No | Whether to create a KV store if no database file exists. By default, a KV store is created.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core|
| 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.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core|
| encrypt | boolean | No | Whether to encrypt database files. By default, database files are not encrypted.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core|
| encrypt | boolean | No | Whether to encrypt the KV store. The default value is **false**, which means the KV store is not encrypted.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core|
| backup | boolean | No | Whether to back up database files. By default, database files are backed up. <br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core|
| backup | boolean | No | Whether to back up the KV store. The default value is **true**, which means to back up the KV store.<br>**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.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core<br>**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC|
| autoSync | boolean | No | Whether to automatically synchronize database files. The default value is **false**, which means the database files are manually synchronized.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core<br>**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC|
| kvStoreType | [KVStoreType](#kvstoretype) | No | Type of the KV store to create. By default, a device KV store is created. The device KV store stores data for multiple devices that collaborate with each other.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core|
| kvStoreType | [KVStoreType](#kvstoretype) | No | Type of the KV store to create. The default value is **DEVICE_COLLABORATION**, which indicates a device KV store.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core|
| securityLevel | [SecurityLevel](#securitylevel) | Yes |Security level of the KV store.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core|
| securityLevel | [SecurityLevel](#securitylevel) | Yes |Security level of the KV store.<br>**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.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore|
| 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.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore|
## Schema
## Schema
...
@@ -226,23 +227,23 @@ Appends a child node to this **FieldNode**.
...
@@ -226,23 +227,23 @@ Appends a child node to this **FieldNode**.
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.
Unsubscribes from service status changes. The **deathCallback** parameter must be a callback registered for subscribing to service status changes. Otherwise, the unsubscription will fail.
| event | string | Yes | Event to unsubscribe from. The value is **distributedDataServiceDie**, which indicates a service status change event.|
| 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. |
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
## 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.
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.
...
@@ -795,16 +808,17 @@ Obtains the total number of rows in the result set.
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).
@@ -820,7 +834,7 @@ Obtains the current data read position (position from which data is read) in the
...
@@ -820,7 +834,7 @@ Obtains the current data read position (position from which data is read) in the
| Type | Description |
| 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**
**Example**
...
@@ -828,16 +842,17 @@ Obtains the current data read position (position from which data is read) in the
...
@@ -828,16 +842,17 @@ Obtains the current data read position (position from which data is read) in the
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.
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.
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.
@@ -1250,12 +1277,12 @@ Resets the **Query** object.
...
@@ -1250,12 +1277,12 @@ Resets the **Query** object.
try{
try{
letquery=newdistributedKVStore.Query();
letquery=newdistributedKVStore.Query();
query.equalTo("key","value");
query.equalTo("key","value");
console.log("query is "+query.getSqlLike());
console.info("query is "+query.getSqlLike());
query.reset();
query.reset();
console.log("query is "+query.getSqlLike());
console.info("query is "+query.getSqlLike());
query=null;
query=null;
}catch(e){
}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
...
@@ -1286,7 +1313,7 @@ Creates a **Query** object to match the specified field whose value is equal to
try{
try{
letquery=newdistributedKVStore.Query();
letquery=newdistributedKVStore.Query();
query.equalTo("field","value");
query.equalTo("field","value");
console.log(`query is ${query.getSqlLike()}`);
console.info(`query is ${query.getSqlLike()}`);
query=null;
query=null;
}catch(e){
}catch(e){
console.error(`duplicated calls should be ok.ode is ${e.code},message is ${e.message}`);
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
...
@@ -1320,7 +1347,7 @@ Creates a **Query** object to match the specified field whose value is not equal
try{
try{
letquery=newdistributedKVStore.Query();
letquery=newdistributedKVStore.Query();
query.notEqualTo("field","value");
query.notEqualTo("field","value");
console.log(`query is ${query.getSqlLike()}`);
console.info(`query is ${query.getSqlLike()}`);
query=null;
query=null;
}catch(e){
}catch(e){
console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`);
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
...
@@ -1353,7 +1380,7 @@ Creates a **Query** object to match the specified field whose value is greater t
try{
try{
letquery=newdistributedKVStore.Query();
letquery=newdistributedKVStore.Query();
query.greaterThan("field","value");
query.greaterThan("field","value");
console.log(`query is ${query.getSqlLike()}`);
console.info(`query is ${query.getSqlLike()}`);
query=null;
query=null;
}catch(e){
}catch(e){
console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`);
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
...
@@ -1388,7 +1415,7 @@ Creates a **Query** object to match the specified field whose value is less than
try{
try{
letquery=newdistributedKVStore.Query();
letquery=newdistributedKVStore.Query();
query.lessThan("field","value");
query.lessThan("field","value");
console.log(`query is ${query.getSqlLike()}`);
console.info(`query is ${query.getSqlLike()}`);
query=null;
query=null;
}catch(e){
}catch(e){
console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`);
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
...
@@ -1423,7 +1450,7 @@ Creates a **Query** object to match the specified field whose value is greater t
try{
try{
letquery=newdistributedKVStore.Query();
letquery=newdistributedKVStore.Query();
query.greaterThanOrEqualTo("field","value");
query.greaterThanOrEqualTo("field","value");
console.log(`query is ${query.getSqlLike()}`);
console.info(`query is ${query.getSqlLike()}`);
query=null;
query=null;
}catch(e){
}catch(e){
console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`);
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
...
@@ -1458,7 +1485,7 @@ Creates a **Query** object to match the specified field whose value is less than
try{
try{
letquery=newdistributedKVStore.Query();
letquery=newdistributedKVStore.Query();
query.lessThanOrEqualTo("field","value");
query.lessThanOrEqualTo("field","value");
console.log(`query is ${query.getSqlLike()}`);
console.info(`query is ${query.getSqlLike()}`);
query=null;
query=null;
}catch(e){
}catch(e){
console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`);
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**.
...
@@ -1491,7 +1518,7 @@ Creates a **Query** object to match the specified field whose value is **null**.
try{
try{
letquery=newdistributedKVStore.Query();
letquery=newdistributedKVStore.Query();
query.isNull("field");
query.isNull("field");
console.log(`query is ${query.getSqlLike()}`);
console.info(`query is ${query.getSqlLike()}`);
query=null;
query=null;
}catch(e){
}catch(e){
console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`);
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
...
@@ -1525,7 +1552,7 @@ Creates a **Query** object to match the specified field whose value is within th
try{
try{
letquery=newdistributedKVStore.Query();
letquery=newdistributedKVStore.Query();
query.inNumber("field",[0,1]);
query.inNumber("field",[0,1]);
console.log(`query is ${query.getSqlLike()}`);
console.info(`query is ${query.getSqlLike()}`);
query=null;
query=null;
}catch(e){
}catch(e){
console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`);
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
...
@@ -1559,7 +1586,7 @@ Creates a **Query** object to match the specified field whose value is within th
try{
try{
letquery=newdistributedKVStore.Query();
letquery=newdistributedKVStore.Query();
query.inString("field",['test1','test2']);
query.inString("field",['test1','test2']);
console.log(`query is ${query.getSqlLike()}`);
console.info(`query is ${query.getSqlLike()}`);
query=null;
query=null;
}catch(e){
}catch(e){
console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`);
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
...
@@ -1593,7 +1620,7 @@ Creates a **Query** object to match the specified field whose value is not withi
try{
try{
letquery=newdistributedKVStore.Query();
letquery=newdistributedKVStore.Query();
query.notInNumber("field",[0,1]);
query.notInNumber("field",[0,1]);
console.log(`query is ${query.getSqlLike()}`);
console.info(`query is ${query.getSqlLike()}`);
query=null;
query=null;
}catch(e){
}catch(e){
console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`);
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
...
@@ -1627,7 +1654,7 @@ Creates a **Query** object to match the specified field whose value is not withi
try{
try{
letquery=newdistributedKVStore.Query();
letquery=newdistributedKVStore.Query();
query.notInString("field",['test1','test2']);
query.notInString("field",['test1','test2']);
console.log(`query is ${query.getSqlLike()}`);
console.info(`query is ${query.getSqlLike()}`);
query=null;
query=null;
}catch(e){
}catch(e){
console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`);
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
...
@@ -1661,7 +1688,7 @@ Creates a **Query** object to match the specified field whose value is similar t
try{
try{
letquery=newdistributedKVStore.Query();
letquery=newdistributedKVStore.Query();
query.like("field","value");
query.like("field","value");
console.log(`query is ${query.getSqlLike()}`);
console.info(`query is ${query.getSqlLike()}`);
query=null;
query=null;
}catch(e){
}catch(e){
console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`);
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
...
@@ -1695,7 +1722,7 @@ Creates a **Query** object to match the specified field whose value is not simil
try{
try{
letquery=newdistributedKVStore.Query();
letquery=newdistributedKVStore.Query();
query.unlike("field","value");
query.unlike("field","value");
console.log(`query is ${query.getSqlLike()}`);
console.info(`query is ${query.getSqlLike()}`);
query=null;
query=null;
}catch(e){
}catch(e){
console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`);
console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`);
...
@@ -1724,10 +1751,10 @@ try {
...
@@ -1724,10 +1751,10 @@ try {
query.notEqualTo("field","value1");
query.notEqualTo("field","value1");
query.and();
query.and();
query.notEqualTo("field","value2");
query.notEqualTo("field","value2");
console.log("query is "+query.getSqlLike());
console.info("query is "+query.getSqlLike());
query=null;
query=null;
}catch(e){
}catch(e){
console.log("duplicated calls should be ok :"+e);
console.error("duplicated calls should be ok :"+e);
}
}
```
```
...
@@ -1753,10 +1780,10 @@ try {
...
@@ -1753,10 +1780,10 @@ try {
query.notEqualTo("field","value1");
query.notEqualTo("field","value1");
query.or();
query.or();
query.notEqualTo("field","value2");
query.notEqualTo("field","value2");
console.log("query is "+query.getSqlLike());
console.info("query is "+query.getSqlLike());
query=null;
query=null;
}catch(e){
}catch(e){
console.log("duplicated calls should be ok :"+e);
console.error("duplicated calls should be ok :"+e);
}
}
```
```
...
@@ -1787,7 +1814,7 @@ try {
...
@@ -1787,7 +1814,7 @@ try {
letquery=newdistributedKVStore.Query();
letquery=newdistributedKVStore.Query();
query.notEqualTo("field","value");
query.notEqualTo("field","value");
query.orderByAsc("field");
query.orderByAsc("field");
console.log(`query is ${query.getSqlLike()}`);
console.info(`query is ${query.getSqlLike()}`);
query=null;
query=null;
}catch(e){
}catch(e){
console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`);
console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`);
...
@@ -1821,7 +1848,7 @@ try {
...
@@ -1821,7 +1848,7 @@ try {
letquery=newdistributedKVStore.Query();
letquery=newdistributedKVStore.Query();
query.notEqualTo("field","value");
query.notEqualTo("field","value");
query.orderByDesc("field");
query.orderByDesc("field");
console.log(`query is ${query.getSqlLike()}`);
console.info(`query is ${query.getSqlLike()}`);
query=null;
query=null;
}catch(e){
}catch(e){
console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`);
console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`);
...
@@ -1832,7 +1859,7 @@ try {
...
@@ -1832,7 +1859,7 @@ try {
limit(total: number, offset: number): Query
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.
| event | string | Yes | Event to unsubscribe from. The value is **dataChange**, which indicates a data change event.|
| 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**
**Error codes**
...
@@ -4726,7 +4753,7 @@ For details about the error codes, see [Distributed KV Store Error Codes](../err
...
@@ -4726,7 +4753,7 @@ For details about the error codes, see [Distributed KV Store Error Codes](../err
letkvStore;
letkvStore;
classKvstoreModel{
classKvstoreModel{
call(data){
call(data){
console.log(`dataChange : ${data}`);
console.info(`dataChange : ${data}`);
}
}
subscribeDataChange(){
subscribeDataChange(){
...
@@ -4764,7 +4791,7 @@ Unsubscribes from synchronization complete events.
...
@@ -4764,7 +4791,7 @@ Unsubscribes from synchronization complete events.
| event | string | Yes | Event to unsubscribe from. The value is **syncComplete**, which indicates a synchronization complete event.|
| 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**
**Example**
...
@@ -4772,7 +4799,7 @@ Unsubscribes from synchronization complete events.
...
@@ -4772,7 +4799,7 @@ Unsubscribes from synchronization complete events.
letkvStore;
letkvStore;
classKvstoreModel{
classKvstoreModel{
call(data){
call(data){
console.log(`syncComplete : ${data}`);
console.info(`syncComplete : ${data}`);
}
}
subscribeDataChange(){
subscribeDataChange(){
...
@@ -4829,7 +4856,7 @@ try {
...
@@ -4829,7 +4856,7 @@ try {
console.error(`Failed to get SecurityLevel.code is ${err.code},message is ${err.message}`);
console.error(`Failed to get SecurityLevel.code is ${err.code},message is ${err.message}`);
return;
return;
}
}
console.log('Succeeded in getting securityLevel');
console.info('Succeeded in getting securityLevel');
});
});
}catch(e){
}catch(e){
console.error(`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}`);
...
@@ -4864,7 +4891,7 @@ For details about the error codes, see [Distributed KV Store Error Codes](../err
...
@@ -4864,7 +4891,7 @@ For details about the error codes, see [Distributed KV Store Error Codes](../err
letkvStore;
letkvStore;
try{
try{
kvStore.getSecurityLevel().then((data)=>{
kvStore.getSecurityLevel().then((data)=>{
console.log('Succeeded in getting securityLevel');
console.info('Succeeded in getting securityLevel');
}).catch((err)=>{
}).catch((err)=>{
console.error(`Failed to get SecurityLevel.code is ${err.code},message is ${err.message}`);
console.error(`Failed to get SecurityLevel.code is ${err.code},message is ${err.message}`);