提交 10bcb75a 编写于 作者: A annie_wangli

update docs

Signed-off-by: Nannie_wangli <annie.wangli@huawei.com>
上级 fcbcccd5
...@@ -15,7 +15,7 @@ Call **createDistributedObject()** to create a distributed data object instance. ...@@ -15,7 +15,7 @@ Call **createDistributedObject()** to create a distributed data object instance.
**Table 1** API for creating a distributed data object instance **Table 1** API for creating a distributed data object instance
| Package| API| Description| | Package| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| ohos.data.distributedDataObject| createDistributedObject(source: object): DistributedObject | Creates a distributed data object instance for data operations.| | ohos.data.distributedDataObject| createDistributedObject(source: object): DistributedObject | Creates a distributed data object instance for data operations.<br>- &nbsp;**source**: attributes of the **distributedObject** set.<br>- &nbsp;**DistributedObject**: returns the distributed object created.|
### Generating a Session ID ### Generating a Session ID
...@@ -43,7 +43,7 @@ Call **on()** to subscribe to data changes of a distributed data object. When th ...@@ -43,7 +43,7 @@ Call **on()** to subscribe to data changes of a distributed data object. When th
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| DistributedDataObject| on(type: 'change', callback: Callback<{ sessionId: string, fields: Array&lt;string&gt; }>): void | Subscribes to data changes.| | DistributedDataObject| on(type: 'change', callback: Callback<{ sessionId: string, fields: Array&lt;string&gt; }>): void | Subscribes to data changes.|
| DistributedDataObject| off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array&lt;string&gt; }>): void | Unsubscribes from data changes.| | DistributedDataObject| off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array&lt;string&gt; }>): void | Unsubscribes from data changes. Callback used to return changes of the distributed object. If this parameter is not specified, all callbacks related to data changes will be unregistered.|
### Observing Online or Offline Status ### Observing Online or Offline Status
...@@ -82,13 +82,13 @@ The following example shows how to implement a distributed data object synchroni ...@@ -82,13 +82,13 @@ The following example shows how to implement a distributed data object synchroni
```js ```js
// Local object // Local object
var local_object = distributedObject.createDistributedObject({name:"jack", age:18, isVis:true, var local_object = distributedObject.createDistributedObject({name:"jack", age:18, isVis:true,
parent:{mother:"jack mom",father:"jack Dad"},[{mother:"jack mom"}, {father:"jack Dad"}]}; parent:{mother:"jack mom",father:"jack Dad"},list:[{mother:"jack mom"}, {father:"jack Dad"}]});
local_object.setsessionId(sessionId); local_object.setSessionId(sessionId);
// Remote object // Remote object
var remote_object = distributedObject.createDistributedObject({name:undefined, age:undefined, isVis:true, var remote_object = distributedObject.createDistributedObject({name:undefined, age:undefined, isVis:true,
parent:undefined, list:undefined}); parent:undefined, list:undefined});
remote_object.setsessionId(sessionId); remote_object.setSessionId(sessionId);
// After obtaining that the device status goes online, the remote object synchronizes data. That is, name changes to jack and age to 18. // After obtaining that the device status goes online, the remote object synchronizes data. That is, name changes to jack and age to 18.
``` ```
...@@ -97,7 +97,7 @@ The following example shows how to implement a distributed data object synchroni ...@@ -97,7 +97,7 @@ The following example shows how to implement a distributed data object synchroni
The sample code is as follows: The sample code is as follows:
```js ```js
changeCallback : function (sessionId, changeData) { function changeCallback(sessionId, changeData) {
console.info("change" + sessionId); console.info("change" + sessionId);
if (changeData != null && changeData != undefined) { if (changeData != null && changeData != undefined) {
...@@ -147,7 +147,7 @@ The following example shows how to implement a distributed data object synchroni ...@@ -147,7 +147,7 @@ The following example shows how to implement a distributed data object synchroni
8. Subscribe to the status (online/offline) changes of the distributed data object. A callback will be invoked to report the status change when the target distributed data object goes online or offline. 8. Subscribe to the status (online/offline) changes of the distributed data object. A callback will be invoked to report the status change when the target distributed data object goes online or offline.
The sample code is as follows: The sample code is as follows:
```js ```js
statusCallback : function (sessionId, networkid, status) { function statusCallback(sessionId, networkid, status) {
this.response += "status changed " + sessionId + " " + status + " " + networkId; this.response += "status changed " + sessionId + " " + status + " " + networkId;
} }
...@@ -162,7 +162,7 @@ The following example shows how to implement a distributed data object synchroni ...@@ -162,7 +162,7 @@ The following example shows how to implement a distributed data object synchroni
// unsubscribe from all status change callbacks. // unsubscribe from all status change callbacks.
local_object.off("status"); local_object.off("status");
``` ```
10. Remove the distributed data object from the synchronization network. After the distributed data object is removed from the network, the data changes on the local end will not be synchronized to the remote end. 10. Remove a distributed data object from the synchronization network. After the distributed data object is removed from the network, the data changes on the local end will not be synchronized to the remote end.
The sample code is as follows: The sample code is as follows:
```js ```js
......
...@@ -7,7 +7,7 @@ On the basis of the SQLite database, the relational database (RDB) allows you to ...@@ -7,7 +7,7 @@ On the basis of the SQLite database, the relational database (RDB) allows you to
## Available APIs ## Available APIs
**Creating and Deleting an RDB Store** ### Creating or Deleting an RDB Store
The following table describes the APIs available for creating and deleting an RDB store. The following table describes the APIs available for creating and deleting an RDB store.
...@@ -17,51 +17,55 @@ The following table describes the APIs available for creating and deleting an RD ...@@ -17,51 +17,55 @@ The following table describes the APIs available for creating and deleting an RD
| -------- | -------- | | -------- | -------- |
|getRdbStore(config:&nbsp;StoreConfig,&nbsp;version:&nbsp;number,&nbsp;callback:&nbsp;AsyncCallback&lt;RdbStore&gt;):&nbsp;void | Obtains an RDB store. This method uses a callback to return the result. You can set parameters for the RDB store based on service requirements, and then call APIs to perform data operations.<br>-&nbsp;**config**: configuration of the RDB store.<br>-&nbsp;**version**: RDB version.<br>-&nbsp;**callback**: callback invoked to return the RDB store obtained.| |getRdbStore(config:&nbsp;StoreConfig,&nbsp;version:&nbsp;number,&nbsp;callback:&nbsp;AsyncCallback&lt;RdbStore&gt;):&nbsp;void | Obtains an RDB store. This method uses a callback to return the result. You can set parameters for the RDB store based on service requirements, and then call APIs to perform data operations.<br>-&nbsp;**config**: configuration of the RDB store.<br>-&nbsp;**version**: RDB version.<br>-&nbsp;**callback**: callback invoked to return the RDB store obtained.|
|getRdbStore(config:&nbsp;StoreConfig,&nbsp;version:&nbsp;number):&nbsp;Promise&lt;RdbStore&gt; | Obtains an RDB store. This method uses a promise to return the result. You can set parameters for the RDB store based on service requirements, and then call APIs to perform data operations.<br>-&nbsp;**config**: configuration of the RDB store.<br>-&nbsp;**version**: RDB version.| |getRdbStore(config:&nbsp;StoreConfig,&nbsp;version:&nbsp;number):&nbsp;Promise&lt;RdbStore&gt; | Obtains an RDB store. This method uses a promise to return the result. You can set parameters for the RDB store based on service requirements, and then call APIs to perform data operations.<br>-&nbsp;**config**: configuration of the RDB store.<br>-&nbsp;**version**: RDB version.|
|deleteRdbStore(name:&nbsp;string,&nbsp;callback:&nbsp;AsyncCallback&lt;void&gt;):&nbsp;void | Deletes an RDB store. This method uses a callback to return the result. <br>-&nbsp;**name**: RDB store to delete.<br>-&nbsp;**callback**: callback invoked to return the result. If the RDB store is deleted, **true** will be returned. Otherwise, **false** will be returned.| |deleteRdbStore(name:&nbsp;string,&nbsp;callback:&nbsp;AsyncCallback&lt;void&gt;):&nbsp;void | Deletes an RDB store. This method uses a callback to return the result. <br>-&nbsp;**name**: RDB store to delete.<br>-&nbsp;**callback**: callback invoked to return the result.|
| deleteRdbStore(name:&nbsp;string):&nbsp;Promise&lt;void&gt; | Deletes an RDB store. This method uses a promise to return the result.<br>-&nbsp;**name**: RDB store to delete.| | deleteRdbStore(name:&nbsp;string):&nbsp;Promise&lt;void&gt; | Deletes an RDB store. This method uses a promise to return the result.<br>-&nbsp;**name**: RDB store to delete.|
**Managing Data in an RDB Store** ### Managing Data in an RDB Store
The RDB provides APIs for inserting, deleting, updating, and querying data in the local RDB store. The RDB provides APIs for inserting, deleting, updating, and querying data in the local RDB store.
- **Inserting data**<br/> - **Inserting data**
The RDB provides APIs for inserting data through a **ValuesBucket** in a data table. If the data is inserted, the row ID of the data inserted will be returned; otherwise, **-1** will be returned. The RDB provides APIs for inserting data through a **ValuesBucket** in a data table. If the data is inserted, the row ID of the data inserted will be returned; otherwise, **-1** will be returned.
**Table 2** APIs for inserting data **Table 2** APIs for inserting data
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | insert(name:&nbsp;string,&nbsp;values:&nbsp;ValuesBucket,&nbsp;callback:&nbsp;AsyncCallback&lt;number&gt;):void | Inserts a row of data into a table. This method uses a callback to return the result.<br>-&nbsp;**name**: name of the target table.<br>-&nbsp;**values**: data to be inserted into the table.<br>-&nbsp;**callback**: callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| | RdbStore | insert(name:&nbsp;string,&nbsp;values:&nbsp;ValuesBucket,&nbsp;callback:&nbsp;AsyncCallback&lt;number&gt;):void | Inserts a row of data into a table. This method uses a callback to return the result.<br>-&nbsp;**name**: name of the target table.<br>-&nbsp;**values**: data to be inserted into the table.<br>-&nbsp;**callback**: callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
| RdbStore | insert(name:&nbsp;string,&nbsp;values:&nbsp;ValuesBucket):&nbsp;Promise&lt;number&gt; | Inserts a row of data into a table. This method uses a promise to return the result.<br>-&nbsp;**name**: name of the target table.<br>-&nbsp;**values**: data to be inserted into the table.| | RdbStore | insert(name:&nbsp;string,&nbsp;values:&nbsp;ValuesBucket):&nbsp;Promise&lt;number&gt; | Inserts a row of data into a table. This method uses a promise to return the result.<br>-&nbsp;**name**: name of the target table.<br>-&nbsp;**values**: data to be inserted into the table.|
- **Updating data**<br/> - **Updating data**
Call the **update()** method to pass new data and specify the update conditions by using **RdbPredicates**. If the data is updated, the number of rows of the updated data will be returned; otherwise, **0** will be returned. Call the **update()** method to pass new data and specify the update conditions by using **RdbPredicates**. If the data is updated, the number of rows of the updated data will be returned; otherwise, **0** will be returned.
**Table 3** APIs for updating data **Table 3** APIs for updating data
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | update(values:&nbsp;ValuesBucket,&nbsp;rdbPredicates:&nbsp;RdbPredicates,&nbsp;callback:&nbsp;AsyncCallback&lt;number&gt;):void | Updates data in the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.<br>-&nbsp;**values**: data to update, which is stored in a **ValuesBucket**.<br>-&nbsp;**rdbPredicates**: conditions for updating data.<br>-&nbsp;**callback**: callback invoked to return the number of rows updated.| | RdbStore | update(values:&nbsp;ValuesBucket,&nbsp;rdbPredicates:&nbsp;RdbPredicates,&nbsp;callback:&nbsp;AsyncCallback&lt;number&gt;):void | Updates data in the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.<br>-&nbsp;**values**: data to update, which is stored in a **ValuesBucket**.<br>-&nbsp;**rdbPredicates**: conditions for updating data.<br>-&nbsp;**callback**: callback invoked to return the number of rows updated.|
| RdbStore | update(values:&nbsp;ValuesBucket,&nbsp;rdbPredicates:&nbsp;RdbPredicates):&nbsp;Promise | Updates data in the RDB store based on the specified **RdbPredicates** object. This method uses a promise to return the result.<br>-&nbsp;**values**: data to update, which is stored in a **ValuesBucket**.<br>-&nbsp;**rdbPredicates**: conditions for updating data.| | RdbStore | update(values:&nbsp;ValuesBucket,&nbsp;rdbPredicates:&nbsp;RdbPredicates):&nbsp;Promise | Updates data in the RDB store based on the specified **RdbPredicates** object. This method uses a promise to return the result.<br>-&nbsp;**values**: data to update, which is stored in a **ValuesBucket**.<br>-&nbsp;**rdbPredicates**: conditions for updating data.|
- **Deleting data**<br/> - **Deleting data**
Call the **delete()** method to delete data meeting the conditions specified by **RdbPredicates**. If the data is deleted, the number of rows of the deleted data will be returned; otherwise, **0** will be returned. Call the **delete()** method to delete data meeting the conditions specified by **RdbPredicates**. If the data is deleted, the number of rows of the deleted data will be returned; otherwise, **0** will be returned.
**Table 4** APIs for deleting data **Table 4** APIs for deleting data
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | delete(rdbPredicates:&nbsp;RdbPredicates,&nbsp;callback:&nbsp;AsyncCallback&lt;number&gt;):void | Deletes data from the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.<br>-&nbsp;**rdbPredicates**: conditions for deleting data.<br>-&nbsp;**callback**: callback invoked to return the number of rows deleted.| | RdbStore | delete(rdbPredicates:&nbsp;RdbPredicates,&nbsp;callback:&nbsp;AsyncCallback&lt;number&gt;):void | Deletes data from the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.<br>-&nbsp;**rdbPredicates**: conditions for deleting data.<br>-&nbsp;**callback**: callback invoked to return the number of rows deleted.|
| RdbStore | delete(rdbPredicates:&nbsp;RdbPredicates):&nbsp;Promise | Deletes data from the RDB store based on the specified **RdbPredicates** object. This method uses a promise to return the result.<br>-&nbsp;**rdbPredicates**: conditions for deleting data.| | RdbStore | delete(rdbPredicates:&nbsp;RdbPredicates):&nbsp;Promise | Deletes data from the RDB store based on the specified **RdbPredicates** object. This method uses a promise to return the result.<br>-&nbsp;**rdbPredicates**: conditions for deleting data.|
- **Querying data**
- **Querying data**<br/>
You can query data in an RDB store in either of the following ways: You can query data in an RDB store in either of the following ways:
- Call the **query()** method to query data based on the predicates, without passing any SQL statement. - Call the **query()** method to query data based on the predicates, without passing any SQL statement.
- Run the native SQL statement. - Run the native SQL statement.
**Table 5** APIs for querying data **Table 5** APIs for querying data
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | query(rdbPredicates:&nbsp;RdbPredicates,&nbsp;columns:&nbsp;Array,&nbsp;callback:&nbsp;AsyncCallback&lt;ResultSet&gt;):&nbsp;void | Queries data in the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.<br>-&nbsp;**rdbPredicates**: conditions for querying data.<br>-&nbsp;**columns**: columns to query. If this parameter is not specified, the query applies to all columns.<br>-&nbsp;**callback**: callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| | RdbStore | query(rdbPredicates:&nbsp;RdbPredicates,&nbsp;columns:&nbsp;Array,&nbsp;callback:&nbsp;AsyncCallback&lt;ResultSet&gt;):&nbsp;void | Queries data in the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.<br>-&nbsp;**rdbPredicates**: conditions for querying data.<br>-&nbsp;**columns**: columns to query. If this parameter is not specified, the query applies to all columns.<br>-&nbsp;**callback**: callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
...@@ -69,7 +73,7 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th ...@@ -69,7 +73,7 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th
| RdbStore | querySql(sql:&nbsp;string,&nbsp;bindArgs:&nbsp;Array&lt;ValueType&gt;,&nbsp;callback:&nbsp;AsyncCallback&lt;ResultSet&gt;):void | Queries data in the RDB store using the specified SQL statement. This method uses a callback to return the result.<br>-&nbsp;**sql**: SQL statement.<br>-&nbsp;**bindArgs**: arguments in the SQL statement.<br>-&nbsp;**callback**: callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| | RdbStore | querySql(sql:&nbsp;string,&nbsp;bindArgs:&nbsp;Array&lt;ValueType&gt;,&nbsp;callback:&nbsp;AsyncCallback&lt;ResultSet&gt;):void | Queries data in the RDB store using the specified SQL statement. This method uses a callback to return the result.<br>-&nbsp;**sql**: SQL statement.<br>-&nbsp;**bindArgs**: arguments in the SQL statement.<br>-&nbsp;**callback**: callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
| RdbStore | querySql(sql:&nbsp;string,&nbsp;bindArgs?:&nbsp;Array&lt;ValueType&gt;):Promise&lt;ResultSet&gt; | Queries data in the RDB store using the specified SQL statement. This method uses a promise to return the result.<br>-&nbsp;**sql**: SQL statement.<br>-&nbsp;**bindArgs**: arguments in the SQL statement.| | RdbStore | querySql(sql:&nbsp;string,&nbsp;bindArgs?:&nbsp;Array&lt;ValueType&gt;):Promise&lt;ResultSet&gt; | Queries data in the RDB store using the specified SQL statement. This method uses a promise to return the result.<br>-&nbsp;**sql**: SQL statement.<br>-&nbsp;**bindArgs**: arguments in the SQL statement.|
**Using Predicates** ### Using Predicates
The RDB provides **RdbPredicates** for you to set database operation conditions. The RDB provides **RdbPredicates** for you to set database operation conditions.
...@@ -108,12 +112,12 @@ The RDB provides **RdbPredicates** for you to set database operation conditions. ...@@ -108,12 +112,12 @@ The RDB provides **RdbPredicates** for you to set database operation conditions.
| RdbPredicates | in(field:&nbsp;string,&nbsp;value:&nbsp;Array&lt;ValueType&gt;):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value within the specified range.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: array of **ValueType** to match.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | in(field:&nbsp;string,&nbsp;value:&nbsp;Array&lt;ValueType&gt;):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value within the specified range.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: array of **ValueType** to match.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | notIn(field:&nbsp;string,&nbsp;value:&nbsp;Array&lt;ValueType&gt;):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value out of the specified range.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: array of **ValueType** to match.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | notIn(field:&nbsp;string,&nbsp;value:&nbsp;Array&lt;ValueType&gt;):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value out of the specified range.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: array of **ValueType** to match.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
**Using the Result Set** ### Using the Result Set
A result set can be regarded as a row of data in the queried results. It allows you to traverse and access the data you have queried. The following table describes the external APIs of **ResultSet**. A result set can be regarded as a row of data in the queried results. It allows you to traverse and access the data you have queried. The following table describes the external APIs of **ResultSet**.
> ![icon-notice.gif](../public_sys-resources/icon-notice.gif) **NOTICE**<br/> > ![icon-notice.gif](public_sys-resources/icon-notice.gif) **NOTICE**<br/>
> After a result set is used, you must call the **close()** method to close it explicitly. > After a result set is used, you must call the **close()** method to close it explicitly.**
**Table 7** APIs for using the result set **Table 7** APIs for using the result set
...@@ -133,26 +137,13 @@ A result set can be regarded as a row of data in the queried results. It allows ...@@ -133,26 +137,13 @@ A result set can be regarded as a row of data in the queried results. It allows
| ResultSet | isColumnNull(columnIndex:&nbsp;number):&nbsp;boolean | Checks whether the value in the specified column of the current row is null.| | ResultSet | isColumnNull(columnIndex:&nbsp;number):&nbsp;boolean | Checks whether the value in the specified column of the current row is null.|
| ResultSet | close():&nbsp;void | Closes the result set.| | ResultSet | close():&nbsp;void | Closes the result set.|
**Changing the Encryption Key for an RDB Store**
You can encrypt an RDB store.
When creating an RDB store, you can add a key for security purposes. After that, the RDB store can be accessed only with the correct key. You can change the key but cannot delete it.
Once an RDB store is created without a key, you can no longer add a key for it.
**Table 8** APIs for changing the encryption key ### Setting Distributed Tables
| Class| API| Description|
| -------- | -------- | -------- |
| RdbStore | changeEncryptKey(newEncryptKey:Uint8Array,&nbsp;callback:&nbsp;AsyncCallback&lt;number&gt;):void; | Changes the encryption key for this RDB store. This method uses a callback to return the result. If the operation is successful, **0** will be returned. Otherwise, a non-zero value will be returned.|
| RdbStore | changeEncryptKey(newEncryptKey:Uint8Array):&nbsp;Promise&lt;number&gt;; | Changes the encryption key for this RDB store. This method uses a promise to return the result. If the operation is successful, **0** will be returned. Otherwise, a non-zero value will be returned.|
**Setting Distributed Tables** **Setting Distributed Tables**
You can set a list of distributed tables for data operations across devices. **Table 8** APIs for setting distributed tables
**Table 9** APIs for setting distributed tables
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
...@@ -163,7 +154,7 @@ You can set a list of distributed tables for data operations across devices. ...@@ -163,7 +154,7 @@ You can set a list of distributed tables for data operations across devices.
You can obtain the distributed table name for a remote device based on the local table name. The distributed table name can be used to query the RDB store of the remote device. You can obtain the distributed table name for a remote device based on the local table name. The distributed table name can be used to query the RDB store of the remote device.
**Table 10** API for obtaining the distributed table name of a remote device **Table 9** API for obtaining the distributed table name of a remote device
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
...@@ -172,17 +163,16 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -172,17 +163,16 @@ You can obtain the distributed table name for a remote device based on the local
**Synchronizing Data Between Devices** **Synchronizing Data Between Devices**
**Table 11** APIs for synchronizing data between devices **Table 10** APIs for synchronizing data between devices
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback<Array<[string, number]>>): void;| Synchronizes data between devices. This method uses a callback to return the result.<br>-&nbsp;**mode**: data synchronization mode. **SYNC\_MODE\_PUSH** means to push data from the local device to a remote device. **SYNC\_MODE\_PULL** means to pull data from a remote device to the local device.<br>-&nbsp;**predicates**: data and devices to be synchronized.<br>-&nbsp;**callback**: callback invoked to return the result. In the result, **string** indicates the device ID, and **number** indicates the synchronization status of each device. The value **0** indicates a success, and other values indicate a failure.| | RdbStore | sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback<Array<[string, number]>>): void;| Synchronizes data between devices. This method uses a callback to return the result.<br>-&nbsp;**mode**: data synchronization mode. **SYNC\_MODE\_PUSH** means to push data from the local device to a remote device. **SYNC\_MODE\_PULL** means to pull data from a remote device to the local device.<br>-&nbsp;**predicates**: data and devices to be synchronized.<br>-&nbsp;**callback**: callback invoked to return the result. In the result, **string** indicates the device ID, and **number** indicates the synchronization status of each device. The value **0** indicates a success, and other values indicate a failure.|
| RdbStore | sync(mode: SyncMode, predicates: RdbPredicates): Promise<Array<[string, number]>>;| Synchronizes data between devices. This method uses a promise to return the result.<br>-&nbsp;**mode**: data synchronization mode. **SYNC\_MODE\_PUSH** means to push data from the local device to a remote device. **SYNC\_MODE\_PULL** means to pull data from a remote device to the local device.<br>-&nbsp;**predicates**: data and devices to be synchronized. | | RdbStore | sync(mode: SyncMode, predicates: RdbPredicates): Promise<Array<[string, number]>>;| Synchronizes data between devices. This method uses a promise to return the result.<br>-&nbsp;**mode**: data synchronization mode. **SYNC\_MODE\_PUSH** means to push data from the local device to a remote device. **SYNC\_MODE\_PULL** means to pull data from a remote device to the local device.<br>-&nbsp;**predicates**: data and devices to be synchronized. |
**Registering an RDB Store Observer** **Registering an RDB Store Observer**
**Table 12** API for registering an observer **Table 11** API for registering an observer
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
...@@ -190,7 +180,7 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -190,7 +180,7 @@ You can obtain the distributed table name for a remote device based on the local
**Unregistering an RDB Store Observer** **Unregistering an RDB Store Observer**
**Table 13** API for unregistering an observer **Table 12** API for unregistering an observer
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
...@@ -211,9 +201,10 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -211,9 +201,10 @@ You can obtain the distributed table name for a remote device based on the local
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
const STORE_CONFIG = {name: "rdbstore.db",} const STORE_CONFIG = {name: "rdbstore.db",}
data_rdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) {
let rdbStore = await data_rdb.getRdbStore(STORE_CONFIG, 1); rdbStore.executeSql(SQL_CREATE_TABLE)
await rdbStore.executeSql(CREATE_TABLE_TEST); console.info('create table done.')
})
``` ```
2. Insert data. 2. Insert data.
...@@ -238,16 +229,16 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -238,16 +229,16 @@ You can obtain the distributed table name for a remote device based on the local
``` ```
let predicates = new data_rdb.RdbPredicates("test"); let predicates = new data_rdb.RdbPredicates("test");
predicates.equalTo("name", "Tom") predicates.equalTo("name", "Tom")
let resultSet = await rdbStore.query(predicates) let promisequery = rdbStore.query(predicates)
promisequery.then((resultSet) => {
resultSet.goToFirstRow() resultSet.goToFirstRow()
const id = await resultSet.getLong(resultSet.getColumnIndex("id")) const id = resultSet.getLong(resultSet.getColumnIndex("id"))
const name = await resultSet.getString(resultSet.getColumnIndex("name")) const name = resultSet.getString(resultSet.getColumnIndex("name"))
const age = await resultSet.getLong(resultSet.getColumnIndex("age")) const age = resultSet.getLong(resultSet.getColumnIndex("age"))
const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary")) const salary = resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType")) const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType"))
resultSet.close()
resultSet.close() })
``` ```
4. Set the distributed tables to be synchronized. 4. Set the distributed tables to be synchronized.
...@@ -261,7 +252,7 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -261,7 +252,7 @@ You can obtain the distributed table name for a remote device based on the local
promise.then(() => { promise.then(() => {
console.info("setDistributedTables success.") console.info("setDistributedTables success.")
}).catch((err) => { }).catch((err) => {
console.info("setDistributedTables failed."") console.info("setDistributedTables failed.")
}) })
``` ```
...@@ -276,7 +267,7 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -276,7 +267,7 @@ You can obtain the distributed table name for a remote device based on the local
let predicate = new data_rdb.RdbPredicates('test') let predicate = new data_rdb.RdbPredicates('test')
predicate.inDevices(['12345678abcde']) predicate.inDevices(['12345678abcde'])
let promise = rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH, predicate) let promise = rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH, predicate)
promise.then(result) { promise.then((result) => {
console.log('sync done.') console.log('sync done.')
for (let i = 0; i < result.length; i++) { for (let i = 0; i < result.length; i++) {
console.log('device=' + result[i][0] + ' status=' + result[i][1]) console.log('device=' + result[i][0] + ' status=' + result[i][1])
......
...@@ -26,29 +26,29 @@ Creates a **KVManager** object to manage key-value (KV) stores. This method uses ...@@ -26,29 +26,29 @@ Creates a **KVManager** object to manage key-value (KV) stores. This method uses
| config | [KVManagerConfig](#kvmanagerconfig) | Yes | Configuration of the **KVManager** object, including the bundle name and user information of the caller.| | config | [KVManagerConfig](#kvmanagerconfig) | Yes | Configuration of the **KVManager** object, including the bundle name and user information of the caller.|
| callback | AsyncCallback&lt;[KVManager](#kvmanager)&gt; | Yes | Callback invoked to return the **KVManager** object created.| | callback | AsyncCallback&lt;[KVManager](#kvmanager)&gt; | Yes | Callback invoked to return the **KVManager** object created.|
**Example** **Example**
```
let kvManager; let kvManager;
try { try {
const kvManagerConfig = { const kvManagerConfig = {
bundleName : 'com.example.datamanagertest', bundleName : 'com.example.datamanagertest',
userInfo : { userInfo : {
userId : '0', userId : '0',
userType : distributedData.UserType.SAME_USER_ID userType : distributedData.UserType.SAME_USER_ID
}
} }
distributedData.createKVManager(kvManagerConfig, function (err, manager) {
if (err) {
console.log("createKVManager err: " + JSON.stringify(err));
return;
}
console.log("createKVManager success");
kvManager = manager;
});
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
} }
distributedData.createKVManager(kvManagerConfig, function (err, manager) {
if (err) {
console.log("createKVManager err: " + JSON.stringify(err));
return;
}
console.log("createKVManager success");
kvManager = manager;
});
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
## distributedData.createKVManager ## distributedData.createKVManager
...@@ -72,25 +72,26 @@ Creates a **KVManager** object to manage KV stores. This method uses a promise t ...@@ -72,25 +72,26 @@ Creates a **KVManager** object to manage KV stores. This method uses a promise t
**Example** **Example**
let kvManager; ```
try { let kvManager;
const kvManagerConfig = { try {
bundleName : 'com.example.datamanagertest', const kvManagerConfig = {
userInfo : { bundleName : 'com.example.datamanagertest',
userId : '0', userInfo : {
userType : distributedData.UserType.SAME_USER_ID userId : '0',
} userType : distributedData.UserType.SAME_USER_ID
} }
distributedData.createKVManager(kvManagerConfig).then((manager) => {
console.log("createKVManager success");
kvManager = manager;
}).catch((err) => {
console.log("createKVManager err: " + JSON.stringify(err));
});
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
} }
distributedData.createKVManager(kvManagerConfig).then((manager) => {
console.log("createKVManager success");
kvManager = manager;
}).catch((err) => {
console.log("createKVManager err: " + JSON.stringify(err));
});
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
## KVManagerConfig ## KVManagerConfig
...@@ -103,8 +104,6 @@ Provides configuration of the **KVManager** object, including the bundle name an ...@@ -103,8 +104,6 @@ Provides configuration of the **KVManager** object, including the bundle name an
| userInfo | [UserInfo](#userinfo) | Yes | User information.| | userInfo | [UserInfo](#userinfo) | Yes | User information.|
| bundleName | string | Yes | Bundle name.| | bundleName | string | Yes | Bundle name.|
## UserInfo ## UserInfo
Defines user information. Defines user information.
...@@ -132,8 +131,6 @@ Defines the user type. ...@@ -132,8 +131,6 @@ Defines the user type.
Creates a **KVManager** object to obtain KV store information. Before calling any method in **KVManager**, you must use **createKVManager** to create a **KVManager** object. Creates a **KVManager** object to obtain KV store information. Before calling any method in **KVManager**, you must use **createKVManager** to create a **KVManager** object.
### getKVStore ### getKVStore
getKVStore&lt;T extends KVStore&gt;(storeId: string, options: Options, callback: AsyncCallback&lt;T&gt;): void getKVStore&lt;T extends KVStore&gt;(storeId: string, options: Options, callback: AsyncCallback&lt;T&gt;): void
...@@ -152,30 +149,30 @@ Creates and obtains a KV store. This method uses an asynchronous callback to ret ...@@ -152,30 +149,30 @@ Creates and obtains a KV store. This method uses an asynchronous callback to ret
**Example** **Example**
``` ```
let kvStore; let kvStore;
let kvManager; let kvManager;
try { try {
const options = { const options = {
createIfMissing : true, createIfMissing : true,
encrypt : false, encrypt : false,
backup : false, backup : false,
autoSync : true, autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION, kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
securityLevel : distributedData.SecurityLevel.S2, securityLevel : distributedData.SecurityLevel.S2,
}; };
kvManager.getKVStore('storeId', options, function (err, store) { kvManager.getKVStore('storeId', options, function (err, store) {
if (err) { if (err) {
console.log("getKVStore err: " + JSON.stringify(err)); console.log("getKVStore err: " + JSON.stringify(err));
return; return;
} }
console.log("getKVStore success"); console.log("getKVStore success");
kvStore = store; kvStore = store;
}); });
} catch (e) { } catch (e) {
console.log("An unexpected error occurred. Error:" + e); console.log("An unexpected error occurred. Error:" + e);
} }
``` ```
### getKVStore ### getKVStore
...@@ -200,31 +197,30 @@ Creates and obtains a KV store. This method uses a promise to return the result. ...@@ -200,31 +197,30 @@ Creates and obtains a KV store. This method uses a promise to return the result.
| -------------------------------------- | ------------------------ | | -------------------------------------- | ------------------------ |
| Promise&lt;T&gt; &lt;T extends KVStore&gt; | Promise used to return the KV store created.| | Promise&lt;T&gt; &lt;T extends KVStore&gt; | Promise used to return the KV store created.|
**Example** **Example**
``` ```
let kvStore; let kvStore;
let kvManager; let kvManager;
try { try {
const options = { const options = {
createIfMissing : true, createIfMissing : true,
encrypt : false, encrypt : false,
backup : false, backup : false,
autoSync : true, autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION, kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
securityLevel : distributedData.SecurityLevel.S2, securityLevel : distributedData.SecurityLevel.S2,
}; };
kvManager.getKVStore('storeId', options).then((store) => { kvManager.getKVStore('storeId', options).then((store) => {
console.log("getKVStore success"); console.log("getKVStore success");
kvStore = store; kvStore = store;
}).catch((err) => { }).catch((err) => {
console.log("getKVStore err: " + JSON.stringify(err)); console.log("getKVStore err: " + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
console.log("An unexpected error occurred. Error:" + e); console.log("An unexpected error occurred. Error:" + e);
} }
``` ```
### closeKVStore<sup>8+</sup> ### ### closeKVStore<sup>8+</sup> ###
...@@ -244,33 +240,33 @@ Closes a KV store. This method uses an asynchronous callback to return the resul ...@@ -244,33 +240,33 @@ Closes a KV store. This method uses an asynchronous callback to return the resul
| kvStore | [KVStore](#kvstore) | Yes | KV store to close. | | kvStore | [KVStore](#kvstore) | Yes | KV store to close. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the KV store is closed, **true** will be returned. Otherwise, **false** will be returned. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the KV store is closed, **true** will be returned. Otherwise, **false** will be returned. |
**Example** **Example**
``` ```
let kvStore; let kvStore;
let kvManager; let kvManager;
const options = { const options = {
createIfMissing : true, createIfMissing : true,
encrypt : false, encrypt : false,
backup : false, backup : false,
autoSync : true, autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION, kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
schema : '', schema : '',
securityLevel : distributedData.SecurityLevel.S2, securityLevel : distributedData.SecurityLevel.S2,
} }
try { try {
kvManager.getKVStore('storeId', options, async function (err, store) { kvManager.getKVStore('storeId', options, async function (err, store) {
console.log('getKVStore success'); console.log('getKVStore success');
kvStore = store; kvStore = store;
await kvManager.closeKVStore('appId', 'storeId', kvStore, function (err, data) { await kvManager.closeKVStore('appId', 'storeId', kvStore, function (err, data) {
console.log('closeKVStore success'); console.log('closeKVStore success');
}); });
}); });
} catch (e) { } catch (e) {
console.log('closeKVStore e ' + e); console.log('closeKVStore e ' + e);
} }
``` ```
### closeKVStore<sup>8+</sup> ### ### closeKVStore<sup>8+</sup> ###
...@@ -296,34 +292,34 @@ Closes a KV store. This method uses a promise to return the result. ...@@ -296,34 +292,34 @@ Closes a KV store. This method uses a promise to return the result.
**Example** **Example**
``` ```
let kvManager; let kvManager;
let kvStore; let kvStore;
const options = { const options = {
createIfMissing : true, createIfMissing : true,
encrypt : false, encrypt : false,
backup : false, backup : false,
autoSync : true, autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION, kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
schema : '', schema : '',
securityLevel : distributedData.SecurityLevel.S2, securityLevel : distributedData.SecurityLevel.S2,
} }
try { try {
kvManager.getKVStore('storeId', options).then(async (store) => { kvManager.getKVStore('storeId', options).then(async (store) => {
console.log('getKVStore success'); console.log('getKVStore success');
kvStore = store; kvStore = store;
await kvManager.closeKVStore('appId', 'storeId', kvStore).then(() => { await kvManager.closeKVStore('appId', 'storeId', kvStore).then(() => {
console.log('closeKVStore success'); console.log('closeKVStore success');
}).catch((err) => { }).catch((err) => {
console.log('closeKVStore err ' + JSON.stringify(err)); console.log('closeKVStore err ' + JSON.stringify(err));
}); });
}).catch((err) => { }).catch((err) => {
console.log('CloseKVStore getKVStore err ' + JSON.stringify(err)); console.log('CloseKVStore getKVStore err ' + JSON.stringify(err));
}); });
} catch (e) { } catch (e) {
console.log('closeKVStore e ' + e); console.log('closeKVStore e ' + e);
} }
``` ```
### deleteKVStore<sup>8+</sup> ### ### deleteKVStore<sup>8+</sup> ###
...@@ -342,33 +338,32 @@ Deletes a KV store. This method uses an asynchronous callback to return the resu ...@@ -342,33 +338,32 @@ Deletes a KV store. This method uses an asynchronous callback to return the resu
| storeId | string | Yes | Unique identifier of the KV store to delete. The length cannot exceed the value of [MAX_STORE_ID_LENGTH](#constants).| | storeId | string | Yes | Unique identifier of the KV store to delete. The length cannot exceed the value of [MAX_STORE_ID_LENGTH](#constants).|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the KV store is deleted, **true** will be returned. Otherwise, **false** will be returned. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the KV store is deleted, **true** will be returned. Otherwise, **false** will be returned. |
**Example** **Example**
``` ```
let kvManager; let kvManager;
let kvStore; let kvStore;
const options = { const options = {
createIfMissing : true, createIfMissing : true,
encrypt : false, encrypt : false,
backup : false, backup : false,
autoSync : true, autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION, kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
schema : '', schema : '',
securityLevel : distributedData.SecurityLevel.S2, securityLevel : distributedData.SecurityLevel.S2,
} }
try { try {
kvManager.getKVStore('store', options, async function (err, store) { kvManager.getKVStore('store', options, async function (err, store) {
console.log('getKVStore success'); console.log('getKVStore success');
kvStore = store; kvStore = store;
await kvManager.deleteKVStore('appId', 'storeId', function (err, data) { await kvManager.deleteKVStore('appId', 'storeId', function (err, data) {
console.log('deleteKVStore success'); console.log('deleteKVStore success');
});
}); });
} catch (e) { });
console.log('DeleteKVStore e ' + e); } catch (e) {
} console.log('DeleteKVStore e ' + e);
``` }
```
### deleteKVStore<sup>8+</sup> ### ### deleteKVStore<sup>8+</sup> ###
...@@ -394,34 +389,34 @@ Deletes a KV store. This method uses a promise to return the result. ...@@ -394,34 +389,34 @@ Deletes a KV store. This method uses a promise to return the result.
**Example** **Example**
``` ```
let kvManager; let kvManager;
let kvStore; let kvStore;
const options = { const options = {
createIfMissing : true, createIfMissing : true,
encrypt : false, encrypt : false,
backup : false, backup : false,
autoSync : true, autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION, kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
schema : '', schema : '',
securityLevel : distributedData.SecurityLevel.S2, securityLevel : distributedData.SecurityLevel.S2,
} }
try { try {
kvManager.getKVStore('storId', options).then(async (store) => { kvManager.getKVStore('storId', options).then(async (store) => {
console.log('getKVStore success'); console.log('getKVStore success');
kvStore = store; kvStore = store;
await kvManager.deleteKVStore('appId', 'storeId').then(() => { await kvManager.deleteKVStore('appId', 'storeId').then(() => {
console.log('deleteKVStore success'); console.log('deleteKVStore success');
}).catch((err) => {
console.log('deleteKVStore err ' + JSON.stringify(err));
});
}).catch((err) => { }).catch((err) => {
console.log('getKVStore err ' + JSON.stringify(err)); console.log('deleteKVStore err ' + JSON.stringify(err));
}); });
} catch (e) { }).catch((err) => {
console.log('deleteKVStore e ' + e); console.log('getKVStore err ' + JSON.stringify(err));
} });
``` } catch (e) {
console.log('deleteKVStore e ' + e);
}
```
### getAllKVStoreId<sup>8+</sup> ### ### getAllKVStoreId<sup>8+</sup> ###
...@@ -441,17 +436,17 @@ Obtains the IDs of all the KV stores that are created using **getKvStore** and h ...@@ -441,17 +436,17 @@ Obtains the IDs of all the KV stores that are created using **getKvStore** and h
**Example** **Example**
``` ```
let kvManager; let kvManager;
try { try {
kvManager.getAllKVStoreId('appId', function (err, data) { kvManager.getAllKVStoreId('appId', function (err, data) {
console.log('GetAllKVStoreId success'); console.log('GetAllKVStoreId success');
console.log('GetAllKVStoreId size = ' + data.length); console.log('GetAllKVStoreId size = ' + data.length);
}); });
} catch (e) { } catch (e) {
console.log('GetAllKVStoreId e ' + e); console.log('GetAllKVStoreId e ' + e);
} }
``` ```
### getAllKVStoreId<sup>8+</sup> ### ### getAllKVStoreId<sup>8+</sup> ###
...@@ -477,20 +472,20 @@ Obtains the IDs of all the KV stores that are created using **getKvStore** and h ...@@ -477,20 +472,20 @@ Obtains the IDs of all the KV stores that are created using **getKvStore** and h
**Example** **Example**
``` ```
let kvManager; let kvManager;
try { try {
console.log('GetAllKVStoreId'); console.log('GetAllKVStoreId');
kvManager.getAllKVStoreId('apppId').then((data) => { kvManager.getAllKVStoreId('apppId').then((data) => {
console.log('getAllKVStoreId success'); console.log('getAllKVStoreId success');
console.log('size = ' + data.length); console.log('size = ' + data.length);
}).catch((err) => { }).catch((err) => {
console.log('getAllKVStoreId err ' + JSON.stringify(err)); console.log('getAllKVStoreId err ' + JSON.stringify(err));
}); });
} catch(e) { } catch(e) {
console.log('getAllKVStoreId e ' + e); console.log('getAllKVStoreId e ' + e);
} }
``` ```
### on<sup>8+</sup> ### ### on<sup>8+</sup> ###
...@@ -508,23 +503,21 @@ Subscribes to the **distributedDataServiceDie** events. This method uses a synch ...@@ -508,23 +503,21 @@ Subscribes to the **distributedDataServiceDie** events. This method uses a synch
| event | 'distributedDataServiceDie' | Yes | Type of events to subscribe to. | | event | 'distributedDataServiceDie' | Yes | Type of events to subscribe to. |
| deathCallback | Callback&lt;void&gt; | Yes | Callback invoked when the distributed data service is dead. | | deathCallback | Callback&lt;void&gt; | Yes | Callback invoked when the distributed data service is dead. |
**Example** **Example**
``` ```
let kvManager; let kvManager;
try { try {
console.log('KVManagerOn'); console.log('KVManagerOn');
const deathCallback = function () { const deathCallback = function () {
console.log('death callback call'); console.log('death callback call');
}
kvManager.on('distributedDataServiceDie', deathCallback);
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
} }
``` kvManager.on('distributedDataServiceDie', deathCallback);
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
### off<sup>8+</sup> ### ### off<sup>8+</sup> ###
...@@ -545,19 +538,19 @@ Unsubscribes from the **distributedDataServiceDie** events. This method uses a s ...@@ -545,19 +538,19 @@ Unsubscribes from the **distributedDataServiceDie** events. This method uses a s
**Example** **Example**
``` ```
let kvManager; let kvManager;
try { try {
console.log('KVManagerOff'); console.log('KVManagerOff');
const deathCallback = function () { const deathCallback = function () {
console.log('death callback call'); console.log('death callback call');
}
kvManager.off('distributedDataServiceDie', deathCallback);
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
} }
kvManager.off('distributedDataServiceDie', deathCallback);
} catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
``` ```
## Options ## Options
...@@ -573,7 +566,7 @@ Provides KV store configuration. ...@@ -573,7 +566,7 @@ Provides KV store configuration.
| autoSync | boolean | No|Whether to automatically synchronize database files. By default, database files are not automatically synchronized. | | autoSync | boolean | No|Whether to automatically synchronize database files. By default, database files are not automatically synchronized. |
| kvStoreType | [KVStoreType](#kvstoretype) | No|Type of the KV store to create. By default, a device KV store is created. The device KV store stores data for multiple devices that collaborate with each other.| | kvStoreType | [KVStoreType](#kvstoretype) | No|Type of the KV store to create. By default, a device KV store is created. The device KV store stores data for multiple devices that collaborate with each other.|
| securityLevel | [SecurityLevel](#securitylevel) | No|Security level of the KV store. By default, the security level is not set. | | securityLevel | [SecurityLevel](#securitylevel) | No|Security level of the KV store. By default, the security level is not set. |
| schema | [schema](#Schema<sup>8+</sup>) | No| Schema used to define the values stored in a KV store.| | schema<sup>8+</sup> | [Schema](#schema8) | No| Schema used to define the values stored in a KV store.|
## KVStoreType ## KVStoreType
...@@ -589,7 +582,6 @@ Defines the KV store types. ...@@ -589,7 +582,6 @@ Defines the KV store types.
| MULTI_VERSION | 2 | Multi-version KV store. This type is not supported currently. | | MULTI_VERSION | 2 | Multi-version KV store. This type is not supported currently. |
## SecurityLevel ## SecurityLevel
Defines the KV store security levels. Defines the KV store security levels.
...@@ -629,8 +621,8 @@ Defines a database schema. When creating or opening a KV store, you can create a ...@@ -629,8 +621,8 @@ Defines a database schema. When creating or opening a KV store, you can create a
| Name | Type| Description | | Name | Type| Description |
| --- | ---- | ----------------------- | | --- | ---- | ----------------------- |
| root<sup>8+</sup> | [FieldNode](#FieldNode) | JSON root object. | | root<sup>8+</sup> | [FieldNode](#fieldnode8) | JSON root object. |
| indexes<sup>8+</sup> | Array<string> | String array in JSON format. | | indexes<sup>8+</sup> | Array\<string> | String array in JSON format. |
| mode<sup>8+</sup> | number | Schema mode. | | mode<sup>8+</sup> | number | Schema mode. |
| skip<sup>8+</sup> | number | Size of a skip of the schema. | | skip<sup>8+</sup> | number | Size of a skip of the schema. |
...@@ -664,9 +656,9 @@ A constructor used to create a **FieldNode** instance with a string field. ...@@ -664,9 +656,9 @@ A constructor used to create a **FieldNode** instance with a string field.
**Parameters** **Parameters**
| Name | Type| Mandatory | Description | | Name| Type| Mandatory| Description |
| ----- | ------ | ---- | ----------------------- | | ------ | -------- | ---- | --------------- |
| name | string | Yes | Value of **FieldNode**. | name | string | Yes | Value of **FieldNode**.|
### appendChild<sup>8+</sup> ### ### appendChild<sup>8+</sup> ###
...@@ -680,7 +672,7 @@ Appends a child node to this **FieldNode**. ...@@ -680,7 +672,7 @@ Appends a child node to this **FieldNode**.
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| child | [FieldNode](#FieldNode) | Yes | Child node to append. | | child | [FieldNode](#fieldnode8) | Yes | Child node to append. |
**Return value** **Return value**
...@@ -691,27 +683,25 @@ Appends a child node to this **FieldNode**. ...@@ -691,27 +683,25 @@ Appends a child node to this **FieldNode**.
**Example** **Example**
``` ```
import ddm from '@ohos.data.distributedData'; import ddm from '@ohos.data.distributedData';
try { try {
let node = new ddm.FieldNode("root"); let node = new ddm.FieldNode("root");
let child1 = new ddm.FieldNode("child1"); let child1 = new ddm.FieldNode("child1");
let child2 = new ddm.FieldNode("child2"); let child2 = new ddm.FieldNode("child2");
let child3 = new ddm.FieldNode("child3"); let child3 = new ddm.FieldNode("child3");
node.appendChild(child1); node.appendChild(child1);
node.appendChild(child2); node.appendChild(child2);
node.appendChild(child3); node.appendChild(child3);
console.log("appendNode " + node.toJson()); console.log("appendNode " + node.toJson());
child1 = null; child1 = null;
child2 = null; child2 = null;
child3 = null; child3 = null;
node = null; node = null;
} catch (e) { } catch (e) {
console.log("AppendChild " + e); console.log("AppendChild " + e);
} }
``` ```
## KvStoreResultSet<sup>8+</sup> ## ## KvStoreResultSet<sup>8+</sup> ##
...@@ -735,23 +725,22 @@ Obtains the number of rows in the result set. ...@@ -735,23 +725,22 @@ Obtains the number of rows in the result set.
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet success');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet fail ' + err);
}); });
const count = resultSet.getCount(); const count = resultSet.getCount();
console.log("GetCount " + count); console.log("GetCount " + count);
} catch (e) { } catch (e) {
console.log("GetCount fail " + e); console.log("GetCount fail " + e);
} }
``` ```
### getPosition<sup>8+</sup> ### ### getPosition<sup>8+</sup> ###
...@@ -769,22 +758,22 @@ Obtains the current data read position (position from which data is read) in the ...@@ -769,22 +758,22 @@ Obtains the current data read position (position from which data is read) in the
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet success');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet fail ' + err);
}); });
const positon = resultSet.getPosition(); const position = resultSet.getPosition();
console.log("getPosition " + positon); console.log("getPosition " + position);
} catch (e) { } catch (e) {
console.log("GetPosition fail " + e); console.log("GetPosition fail " + e);
} }
``` ```
### moveToFirst<sup>8+</sup> ### ### moveToFirst<sup>8+</sup> ###
...@@ -803,22 +792,22 @@ Moves the data read position to the first row. ...@@ -803,22 +792,22 @@ Moves the data read position to the first row.
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet success');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet fail ' + err);
}); });
const moved = resultSet.moveToFirst(); const moved = resultSet.moveToFirst();
console.log("moveToFirst " + moved); console.log("moveToFirst " + moved);
} catch (e) { } catch (e) {
console.log("MoveToFirst fail " + e); console.log("MoveToFirst fail " + e);
} }
``` ```
### moveToLast<sup>8+</sup> ### ### moveToLast<sup>8+</sup> ###
...@@ -837,22 +826,22 @@ Moves the data read position to the last row. ...@@ -837,22 +826,22 @@ Moves the data read position to the last row.
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet success');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet fail ' + err);
}); });
const moved = resultSet.moveToLast(); const moved = resultSet.moveToLast();
console.log("moveToLast " + moved); console.log("moveToLast " + moved);
} catch (e) { } catch (e) {
console.log("moveToLast fail " + e); console.log("moveToLast fail " + e);
} }
``` ```
### moveToNext<sup>8+</sup> ### ### moveToNext<sup>8+</sup> ###
...@@ -871,22 +860,22 @@ Moves the data read position to the next row. ...@@ -871,22 +860,22 @@ Moves the data read position to the next row.
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet success');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet fail ' + err);
}); });
const moved = resultSet.moveToNext(); const moved = resultSet.moveToNext();
console.log("moveToNext " + moved); console.log("moveToNext " + moved);
} catch (e) { } catch (e) {
console.log("moveToNext fail " + e); console.log("moveToNext fail " + e);
} }
``` ```
### moveToPrevious<sup>8+</sup> ### ### moveToPrevious<sup>8+</sup> ###
...@@ -905,22 +894,22 @@ Moves the data read position to the previous row. ...@@ -905,22 +894,22 @@ Moves the data read position to the previous row.
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet success');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet fail ' + err);
}); });
const moved = resultSet.moveToPrevious(); const moved = resultSet.moveToPrevious();
console.log("moveToPrevious " + moved); console.log("moveToPrevious " + moved);
} catch (e) { } catch (e) {
console.log("moveToPrevious fail " + e); console.log("moveToPrevious fail " + e);
} }
``` ```
### move<sup>8+</sup> ### ### move<sup>8+</sup> ###
...@@ -945,22 +934,22 @@ Moves the data read position with the specified offset from the current position ...@@ -945,22 +934,22 @@ Moves the data read position with the specified offset from the current position
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet success');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet fail ' + err);
}); });
const moved = resultSet.move(); const moved = resultSet.move();
console.log("move " + moved); console.log("move " + moved);
} catch (e) { } catch (e) {
console.log("move fail " + e); console.log("move fail " + e);
} }
``` ```
### moveToPosition<sup>8+</sup> ### ### moveToPosition<sup>8+</sup> ###
...@@ -985,22 +974,22 @@ Moves the data read position from 0 to an absolute position. ...@@ -985,22 +974,22 @@ Moves the data read position from 0 to an absolute position.
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet success');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet fail ' + err);
}); });
const moved = resultSet.moveToPosition(); const moved = resultSet.moveToPosition();
console.log("moveToPosition " + moved); console.log("moveToPosition " + moved);
} catch (e) { } catch (e) {
console.log("moveToPosition fail " + e); console.log("moveToPosition fail " + e);
} }
``` ```
### isFirst<sup>8+</sup> ### ### isFirst<sup>8+</sup> ###
...@@ -1019,22 +1008,22 @@ Checks whether the data read position is the first row. ...@@ -1019,22 +1008,22 @@ Checks whether the data read position is the first row.
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet success');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet fail ' + err);
}); });
const moved = resultSet.isFirst(); const moved = resultSet.isFirst();
console.log("isFirst " + moved); console.log("isFirst " + moved);
} catch (e) { } catch (e) {
console.log("isFirst fail " + e); console.log("isFirst fail " + e);
} }
``` ```
### isLast<sup>8+</sup> ### ### isLast<sup>8+</sup> ###
...@@ -1053,23 +1042,22 @@ Checks whether the data read position is the last row. ...@@ -1053,23 +1042,22 @@ Checks whether the data read position is the last row.
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet success');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet fail ' + err);
}); });
const moved = resultSet.isLast(); const moved = resultSet.isLast();
console.log("isLast " + moved); console.log("isLast " + moved);
} catch (e) { } catch (e) {
console.log("isLast fail " + e); console.log("isLast fail " + e);
} }
``` ```
### isBeforeFirst<sup>8+</sup> ### ### isBeforeFirst<sup>8+</sup> ###
...@@ -1087,22 +1075,22 @@ Checks whether the data read position is before the first row. ...@@ -1087,22 +1075,22 @@ Checks whether the data read position is before the first row.
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet success');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet fail ' + err);
}); });
const moved = resultSet.isBeforeFirst(); const moved = resultSet.isBeforeFirst();
console.log("isBeforeFirst " + moved); console.log("isBeforeFirst " + moved);
} catch (e) { } catch (e) {
console.log("isBeforeFirst fail " + e); console.log("isBeforeFirst fail " + e);
} }
``` ```
### isAfterLast<sup>8+</sup> ### ### isAfterLast<sup>8+</sup> ###
...@@ -1121,22 +1109,22 @@ Checks whether the data read position is after the last row. ...@@ -1121,22 +1109,22 @@ Checks whether the data read position is after the last row.
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet success');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet fail ' + err);
}); });
const moved = resultSet.isAfterLast(); const moved = resultSet.isAfterLast();
console.log("isAfterLast " + moved); console.log("isAfterLast " + moved);
} catch (e) { } catch (e) {
console.log("isAfterLast fail " + e); console.log("isAfterLast fail " + e);
} }
``` ```
### getEntry<sup>8+</sup> ### ### getEntry<sup>8+</sup> ###
...@@ -1155,23 +1143,23 @@ Obtains a KV pair. ...@@ -1155,23 +1143,23 @@ Obtains a KV pair.
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet success');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet fail ' + err);
}); });
const moved = resultSet.moveToNext(); const moved = resultSet.moveToNext();
const entry = resultSet.getEntry(); const entry = resultSet.getEntry();
console.log("getEntry " + JSON.stringify(entry)); console.log("getEntry " + JSON.stringify(entry));
} catch (e) { } catch (e) {
console.log("getEntry fail " + e); console.log("getEntry fail " + e);
} }
``` ```
## Query<sup>8+</sup> ## ## Query<sup>8+</sup> ##
...@@ -1206,18 +1194,18 @@ Resets the **Query** object that contains common query options. ...@@ -1206,18 +1194,18 @@ Resets the **Query** object that contains common query options.
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.equalTo("key", "value"); query.equalTo("key", "value");
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query.reset(); query.reset();
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("simply calls should be ok :" + e); console.log("simply calls should be ok :" + e);
} }
``` ```
### equalTo<sup>8+</sup> ### ### equalTo<sup>8+</sup> ###
...@@ -1243,16 +1231,16 @@ Creates a **Query** object to match the specified field whose value is equal to ...@@ -1243,16 +1231,16 @@ Creates a **Query** object to match the specified field whose value is equal to
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.equalTo("field", "value"); query.equalTo("field", "value");
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### notEqualTo<sup>8+</sup> ### ### notEqualTo<sup>8+</sup> ###
...@@ -1278,16 +1266,16 @@ Creates a **Query** object to match the specified field whose value is not equal ...@@ -1278,16 +1266,16 @@ Creates a **Query** object to match the specified field whose value is not equal
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.notEqualTo("field", "value"); query.notEqualTo("field", "value");
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### greaterThan<sup>8+</sup> ### ### greaterThan<sup>8+</sup> ###
...@@ -1303,7 +1291,7 @@ Creates a **Query** object to match the specified field whose value is greater t ...@@ -1303,7 +1291,7 @@ Creates a **Query** object to match the specified field whose value is greater t
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. |
| value | number/string/boolean | Yes | Value specified.| | value | number\|string\|boolean | Yes | Value specified.|
**Return value** **Return value**
...@@ -1313,16 +1301,16 @@ Creates a **Query** object to match the specified field whose value is greater t ...@@ -1313,16 +1301,16 @@ Creates a **Query** object to match the specified field whose value is greater t
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.greaterThan("field", "value"); query.greaterThan("field", "value");
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### lessThan<sup>8+</sup> ### ### lessThan<sup>8+</sup> ###
...@@ -1338,7 +1326,7 @@ Creates a **Query** object to match the specified field whose value is less than ...@@ -1338,7 +1326,7 @@ Creates a **Query** object to match the specified field whose value is less than
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. |
| value | number/string/boolean | Yes | Value specified.| | value | number\|string\|boolean | Yes | Value specified.|
**Return value** **Return value**
...@@ -1348,16 +1336,16 @@ Creates a **Query** object to match the specified field whose value is less than ...@@ -1348,16 +1336,16 @@ Creates a **Query** object to match the specified field whose value is less than
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.lessThan("field", "value"); query.lessThan("field", "value");
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### greaterThanOrEqualTo<sup>8+</sup> ### ### greaterThanOrEqualTo<sup>8+</sup> ###
...@@ -1373,7 +1361,7 @@ Creates a **Query** object to match the specified field whose value is greater t ...@@ -1373,7 +1361,7 @@ Creates a **Query** object to match the specified field whose value is greater t
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. |
| value | number/string/boolean | Yes | Value specified.| | value | number\|string\|boolean | Yes | Value specified.|
**Return value** **Return value**
...@@ -1383,16 +1371,16 @@ Creates a **Query** object to match the specified field whose value is greater t ...@@ -1383,16 +1371,16 @@ Creates a **Query** object to match the specified field whose value is greater t
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.greaterThanOrEqualTo("field", "value"); query.greaterThanOrEqualTo("field", "value");
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### lessThanOrEqualTo<sup>8+</sup> ### ### lessThanOrEqualTo<sup>8+</sup> ###
...@@ -1408,7 +1396,7 @@ Creates a **Query** object to match the specified field whose value is less than ...@@ -1408,7 +1396,7 @@ Creates a **Query** object to match the specified field whose value is less than
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. |
| value | number/string/boolean | Yes | Value specified.| | value | number\|string\|boolean | Yes | Value specified.|
**Return value** **Return value**
...@@ -1418,16 +1406,16 @@ Creates a **Query** object to match the specified field whose value is less than ...@@ -1418,16 +1406,16 @@ Creates a **Query** object to match the specified field whose value is less than
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.lessThanOrEqualTo("field", "value"); query.lessThanOrEqualTo("field", "value");
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### isNull<sup>8+</sup> ### ### isNull<sup>8+</sup> ###
...@@ -1453,16 +1441,16 @@ Creates a **Query** object to match the specified field whose value is **null**. ...@@ -1453,16 +1441,16 @@ Creates a **Query** object to match the specified field whose value is **null**.
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.isNull("field"); query.isNull("field");
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### inNumber<sup>8+</sup> ### ### inNumber<sup>8+</sup> ###
...@@ -1487,19 +1475,18 @@ Creates a **Query** object to match the specified field whose value is within th ...@@ -1487,19 +1475,18 @@ Creates a **Query** object to match the specified field whose value is within th
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object Created.|
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.inNumber("field", [0, 1]); query.inNumber("field", [0, 1]);
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### inString<sup>8+</sup> ### ### inString<sup>8+</sup> ###
...@@ -1525,16 +1512,16 @@ Creates a **Query** object to match the specified field whose value is within th ...@@ -1525,16 +1512,16 @@ Creates a **Query** object to match the specified field whose value is within th
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.inString("field", ['test1', 'test2']); query.inString("field", ['test1', 'test2']);
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### notInNumber<sup>8+</sup> ### ### notInNumber<sup>8+</sup> ###
...@@ -1560,16 +1547,16 @@ Creates a **Query** object to match the specified field whose value is not withi ...@@ -1560,16 +1547,16 @@ Creates a **Query** object to match the specified field whose value is not withi
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.notInNumber("field", [0, 1]); query.notInNumber("field", [0, 1]);
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### notInString<sup>8+</sup> ### ### notInString<sup>8+</sup> ###
...@@ -1595,16 +1582,16 @@ Creates a **Query** object to match the specified field whose value is not withi ...@@ -1595,16 +1582,16 @@ Creates a **Query** object to match the specified field whose value is not withi
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.notInString("field", ['test1', 'test2']); query.notInString("field", ['test1', 'test2']);
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### like<sup>8+</sup> ### ### like<sup>8+</sup> ###
...@@ -1630,16 +1617,16 @@ Creates a **Query** object to match the specified field whose value is similar t ...@@ -1630,16 +1617,16 @@ Creates a **Query** object to match the specified field whose value is similar t
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.like("field", "value"); query.like("field", "value");
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### unlike<sup>8+</sup> ### ### unlike<sup>8+</sup> ###
...@@ -1665,16 +1652,16 @@ Creates a **Query** object to match the specified field whose value is not simil ...@@ -1665,16 +1652,16 @@ Creates a **Query** object to match the specified field whose value is not simil
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.unlike("field", "value"); query.unlike("field", "value");
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### and<sup>8+</sup> ### ### and<sup>8+</sup> ###
...@@ -1693,18 +1680,18 @@ Creates a **Query** object with the AND condition. ...@@ -1693,18 +1680,18 @@ Creates a **Query** object with the AND condition.
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
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.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### or<sup>8+</sup> ### ### or<sup>8+</sup> ###
...@@ -1723,18 +1710,18 @@ Creates a **Query** object with the OR condition. ...@@ -1723,18 +1710,18 @@ Creates a **Query** object with the OR condition.
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
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.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### orderByAsc<sup>8+</sup> ### ### orderByAsc<sup>8+</sup> ###
...@@ -1759,17 +1746,17 @@ Creates a **Query** object to sort the query results in ascending order. ...@@ -1759,17 +1746,17 @@ Creates a **Query** object to sort the query results in ascending order.
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.notEqualTo("field", "value"); query.notEqualTo("field", "value");
query.orderByAsc("field"); query.orderByAsc("field");
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### orderByDesc<sup>8+</sup> ### ### orderByDesc<sup>8+</sup> ###
...@@ -1792,20 +1779,19 @@ Creates a **Query** object to sort the query results in descending order. ...@@ -1792,20 +1779,19 @@ Creates a **Query** object to sort the query results in descending order.
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | [Query](#query8) |**Query** object Created.|
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.notEqualTo("field", "value"); query.notEqualTo("field", "value");
query.orderByDesc("field"); query.orderByDesc("field");
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### limit<sup>8+</sup> ### ### limit<sup>8+</sup> ###
...@@ -1831,17 +1817,17 @@ Creates a **Query** object to specify the number of results and where to start. ...@@ -1831,17 +1817,17 @@ Creates a **Query** object to specify the number of results and where to start.
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.notEqualTo("field", "value"); query.notEqualTo("field", "value");
query.limit("total", "offset"); query.limit("total", "offset");
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### isNotNull<sup>8+</sup> ### ### isNotNull<sup>8+</sup> ###
...@@ -1866,16 +1852,16 @@ Creates a **Query** object with a specified field that is not null. ...@@ -1866,16 +1852,16 @@ Creates a **Query** object with a specified field that is not null.
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.isNotNull("field"); query.isNotNull("field");
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### beginGroup<sup>8+</sup> ### ### beginGroup<sup>8+</sup> ###
...@@ -1894,18 +1880,18 @@ Creates a **Query** object for a query condition group with a left parenthesis. ...@@ -1894,18 +1880,18 @@ Creates a **Query** object for a query condition group with a left parenthesis.
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.beginGroup(); query.beginGroup();
query.isNotNull("field"); query.isNotNull("field");
query.endGroup(); query.endGroup();
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### endGroup<sup>8+</sup> ### ### endGroup<sup>8+</sup> ###
...@@ -1924,18 +1910,18 @@ Creates a **Query** object for a query condition group with a right parenthesis. ...@@ -1924,18 +1910,18 @@ Creates a **Query** object for a query condition group with a right parenthesis.
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.beginGroup(); query.beginGroup();
query.isNotNull("field"); query.isNotNull("field");
query.endGroup(); query.endGroup();
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### prefixKey<sup>8+</sup> ### ### prefixKey<sup>8+</sup> ###
...@@ -1960,17 +1946,17 @@ Creates a **Query** object with a specified key prefix. ...@@ -1960,17 +1946,17 @@ Creates a **Query** object with a specified key prefix.
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.prefixKey("$.name"); query.prefixKey("$.name");
query.prefixKey("0"); query.prefixKey("0");
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### setSuggestIndex<sup>8+</sup> ### ### setSuggestIndex<sup>8+</sup> ###
...@@ -1995,17 +1981,17 @@ Creates a **Query** object with an index preferentially used for query. ...@@ -1995,17 +1981,17 @@ Creates a **Query** object with an index preferentially used for query.
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.setSuggestIndex("$.name"); query.setSuggestIndex("$.name");
query.setSuggestIndex("0"); query.setSuggestIndex("0");
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
query = null; query = null;
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok :" + e); console.log("dumplicated calls should be ok :" + e);
} }
``` ```
### deviceId<sup>8+</sup> ### ### deviceId<sup>8+</sup> ###
...@@ -2031,15 +2017,15 @@ Creates a **Query** object with the device ID as the key prefix. ...@@ -2031,15 +2017,15 @@ Creates a **Query** object with the device ID as the key prefix.
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
query.deviceId("deviceId"); query.deviceId("deviceId");
console.log("query is " + query.getSqlLike()); console.log("query is " + query.getSqlLike());
} catch (e) { } catch (e) {
console.log("should be ok on Method Chaining : " + e); console.log("should be ok on Method Chaining : " + e);
} }
``` ```
### getSqlLike<sup>8+</sup> ### ### getSqlLike<sup>8+</sup> ###
...@@ -2058,15 +2044,15 @@ Obtains the query statement of this **Query** object. ...@@ -2058,15 +2044,15 @@ Obtains the query statement of this **Query** object.
**Example** **Example**
``` ```
try { try {
let query = new distributedData.Query(); let query = new distributedData.Query();
let sql1 = query.getSqlLike(); let sql1 = query.getSqlLike();
console.log("GetSqlLike sql=" + sql1); console.log("GetSqlLike sql=" + sql1);
} catch (e) { } catch (e) {
console.log("dumplicated calls should be ok : " + e); console.log("dumplicated calls should be ok : " + e);
} }
``` ```
## KVStore ## KVStore
...@@ -2089,26 +2075,26 @@ Adds a KV pair of the specified type to this KV store. This method uses an async ...@@ -2089,26 +2075,26 @@ Adds a KV pair of the specified type to this KV store. This method uses an async
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| key | string | Yes |Key of the KV pair to add. It cannot be empty, and the length cannot exceed [MAX_KEY_LENGTH](#constants). | | key | string | Yes |Key of the KV pair to add. It cannot be empty, and the length cannot exceed [MAX_KEY_LENGTH](#constants). |
| value | Uint8Array \| string \| number \| boolean | Yes |Value of the KV pair to add. The value type can be Uint8Array, number, string, or boolean. A value of the Uint8Array or string type cannot exceed [MAX_VALUE_LENGTH](#constants). | | value | Uint8Array \| string \| number \| boolean | Yes |Value of the KV pair to add. The value type can be Uint8Array, number, string, or boolean. A value of the Uint8Array or string type cannot exceed [MAX_VALUE_LENGTH](#constants). |
| callback | AsyncCallback&lt;void> | Yes |Callback invoked to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes |Callback invoked to return the result. |
**Example** **Example**
``` ```
let kvStore; let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try { 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,data) {
if (err != undefined) { if (err != undefined) {
console.log("put err: " + JSON.stringify(err)); console.log("put err: " + JSON.stringify(err));
return; return;
} }
console.log("put success"); console.log("put success");
}); });
}catch (e) { }catch (e) {
console.log("An unexpected error occurred. Error:" + e); console.log("An unexpected error occurred. Error:" + e);
} }
``` ```
### put ### put
...@@ -2132,23 +2118,22 @@ Adds a KV pair of the specified type to this KV store. This method uses a promis ...@@ -2132,23 +2118,22 @@ Adds a KV pair of the specified type to this KV store. This method uses a promis
| ------ | ------- | | ------ | ------- |
| Promise&lt;void&gt; |Promise used to return the result.| | Promise&lt;void&gt; |Promise used to return the result.|
**Example** **Example**
``` ```
let kvStore; let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try { try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => {
console.log("put success: " + JSON.stringify(data)); console.log("put success: " + JSON.stringify(data));
}).catch((err) => { }).catch((err) => {
console.log("put err: " + JSON.stringify(err)); console.log("put err: " + JSON.stringify(err));
}); });
}catch (e) { }catch (e) {
console.log("An unexpected error occurred. Error:" + e); console.log("An unexpected error occurred. Error:" + e);
} }
``` ```
### delete ### delete
...@@ -2168,29 +2153,29 @@ Deletes a KV pair from this KV store. This method uses an asynchronous callback ...@@ -2168,29 +2153,29 @@ Deletes a KV pair from this KV store. This method uses an asynchronous callback
**Example** **Example**
``` ```
let kvStore; let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try { 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,data) {
if (err != undefined) {
console.log("put err: " + JSON.stringify(err));
return;
}
console.log("put success");
kvStore.delete(KEY_TEST_STRING_ELEMENT, function (err,data) {
if (err != undefined) { if (err != undefined) {
console.log("put err: " + JSON.stringify(err)); console.log("delete err: " + JSON.stringify(err));
return; return;
} }
console.log("put success"); console.log("delete success");
kvStore.delete(KEY_TEST_STRING_ELEMENT, function (err,data) {
if (err != undefined) {
console.log("delete err: " + JSON.stringify(err));
return;
}
console.log("delete success");
});
}); });
}catch (e) { });
console.log("An unexpected error occurred. Error:" + e); }catch (e) {
} console.log("An unexpected error occurred. Error:" + e);
``` }
```
### delete ### delete
...@@ -2215,25 +2200,25 @@ Deletes a KV pair from this KV store. This method uses a promise to return the r ...@@ -2215,25 +2200,25 @@ Deletes a KV pair from this KV store. This method uses a promise to return the r
**Example** **Example**
``` ```
let kvStore; let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try { try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => {
console.log("put success: " + JSON.stringify(data)); console.log("put success: " + JSON.stringify(data));
kvStore.delete(KEY_TEST_STRING_ELEMENT).then((data) => { kvStore.delete(KEY_TEST_STRING_ELEMENT).then((data) => {
console.log("delete success"); console.log("delete success");
}).catch((err) => {
console.log("delete err: " + JSON.stringify(err));
});
}).catch((err) => { }).catch((err) => {
console.log("put err: " + JSON.stringify(err)); console.log("delete err: " + JSON.stringify(err));
}); });
}catch (e) { }).catch((err) => {
console.log("An unexpected error occurred. Error:" + e); console.log("put err: " + JSON.stringify(err));
} });
``` }catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
### on ### on
...@@ -2248,19 +2233,18 @@ Subscribes to data changes of the specified type. This method uses a synchronous ...@@ -2248,19 +2233,18 @@ Subscribes to data changes of the specified type. This method uses a synchronous
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event |'dataChange' | Yes |Type of the events. | | event |'dataChange' | Yes |Type of the events. |
| type |[SubscribeType](#subscribetype) | Yes |Type of data changes. | | type |[SubscribeType](#subscribetype) | Yes |Type of data changes. |
| observer |Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes |Callback invoked to return the result.| | observer |Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes |Callback invoked to return the result.|
**Example** **Example**
``` ```
let kvStore; let kvStore;
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, function (data) { kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, function (data) {
console.log("dataChange callback call data: " + JSON.stringify(data)); console.log("dataChange callback call data: " + JSON.stringify(data));
}); });
``` ```
### on ### on
...@@ -2275,18 +2259,17 @@ Subscribes to data synchronization completion events. This method uses a synchro ...@@ -2275,18 +2259,17 @@ Subscribes to data synchronization completion events. This method uses a synchro
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event |'syncComplete' | Yes |Type of the events. | | event |'syncComplete' | Yes |Type of the events. |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | Yes |Callback invoked to return the result. | | syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | Yes |Callback invoked to return the result. |
**Example** **Example**
``` ```
let kvStore; let kvStore;
kvStore.on('syncComplete', function (data) { kvStore.on('syncComplete', function (data) {
console.log("syncComplete callback call data: " + data); console.log("syncComplete callback call data: " + data);
}); });
``` ```
### off<sup>8+</sup> ### off<sup>8+</sup>
...@@ -2305,15 +2288,15 @@ Unsubscribes from data change events. This method uses a synchronous callback to ...@@ -2305,15 +2288,15 @@ Unsubscribes from data change events. This method uses a synchronous callback to
**Example** **Example**
``` ```
let kvStore; let kvStore;
kvStore.on('dataChange', function (data) { kvStore.on('dataChange', function (data) {
console.log("syncComplete callback call data: " + data); console.log("syncComplete callback call data: " + data);
}); });
kvStore.off('dataChange', function (data) { kvStore.off('dataChange', function (data) {
console.log("syncComplete callback call data: " + data); console.log("syncComplete callback call data: " + data);
}); });
``` ```
### putBatch<sup>8+</sup> ### putBatch<sup>8+</sup>
...@@ -2333,35 +2316,34 @@ Inserts KV pairs in batches to this KV store. This method uses an asynchronous c ...@@ -2333,35 +2316,34 @@ Inserts KV pairs in batches to this KV store. This method uses an asynchronous c
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
console.log('entries: ' + JSON.stringify(entries)); entries.push(entry);
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
await kvStore.getEntries('batch_test_string_key', function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
}catch(e) {
console.log('PutBatch e ' + e);
} }
console.log('entries: ' + JSON.stringify(entries));
``` kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
await kvStore.getEntries('batch_test_string_key', function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
}catch(e) {
console.log('PutBatch e ' + e);
}
```
### putBatch<sup>8+</sup> ### putBatch<sup>8+</sup>
...@@ -2386,37 +2368,37 @@ Inserts KV pairs in batches to this KV store. This method uses a promise to retu ...@@ -2386,37 +2368,37 @@ Inserts KV pairs in batches to this KV store. This method uses a promise to retu
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
console.log('entries: ' + JSON.stringify(entries)); entries.push(entry);
kvStore.putBatch(entries).then(async (err) => { }
console.log('putBatch success'); console.log('entries: ' + JSON.stringify(entries));
await kvStore.getEntries('batch_test_string_key').then((entrys) => { kvStore.putBatch(entries).then(async (err) => {
console.log('getEntries success'); console.log('putBatch success');
console.log('PutBatch ' + JSON.stringify(entries)); await kvStore.getEntries('batch_test_string_key').then((entrys) => {
}).catch((err) => { console.log('getEntries success');
console.log('getEntries fail ' + JSON.stringify(err)); console.log('PutBatch ' + JSON.stringify(entries));
});
}).catch((err) => { }).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err)); console.log('getEntries fail ' + JSON.stringify(err));
}); });
}catch(e) { }).catch((err) => {
console.log('PutBatch e ' + e); console.log('putBatch fail ' + JSON.stringify(err));
} });
``` }catch(e) {
console.log('PutBatch e ' + e);
}
```
### deleteBatch<sup>8+</sup> ### deleteBatch<sup>8+</sup>
...@@ -2436,34 +2418,34 @@ Deletes KV pairs in batches from this KV store. This method uses an asynchronous ...@@ -2436,34 +2418,34 @@ Deletes KV pairs in batches from this KV store. This method uses an asynchronous
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let entries = []; let entries = [];
let keys = []; let keys = [];
for (var i = 0; i < 5; i++) { for (var i = 0; i < 5; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
keys.push(key + i);
} }
console.log('entries: ' + JSON.stringify(entries)); entries.push(entry);
kvStore.putBatch(entries, async function (err,data) { keys.push(key + i);
console.log('putBatch success');
await kvStore.deleteBatch(keys, async function (err,data) {
console.log('deleteBatch success');
});
});
}catch(e) {
console.log('DeleteBatch e ' + e);
} }
``` console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
await kvStore.deleteBatch(keys, async function (err,data) {
console.log('deleteBatch success');
});
});
}catch(e) {
console.log('DeleteBatch e ' + e);
}
```
### deleteBatch<sup>8+</sup> ### ### deleteBatch<sup>8+</sup> ###
...@@ -2488,38 +2470,38 @@ Deletes KV pairs in batches from this KV store. This method uses a promise to re ...@@ -2488,38 +2470,38 @@ Deletes KV pairs in batches from this KV store. This method uses a promise to re
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let entries = []; let entries = [];
let keys = []; let keys = [];
for (var i = 0; i < 5; i++) { for (var i = 0; i < 5; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
keys.push(key + i);
} }
console.log('entries: ' + JSON.stringify(entries)); entries.push(entry);
kvStore.putBatch(entries).then(async (err) => { keys.push(key + i);
console.log('putBatch success'); }
await kvStore.deleteBatch(keys).then((err) => { console.log('entries: ' + JSON.stringify(entries));
console.log('deleteBatch success'); kvStore.putBatch(entries).then(async (err) => {
}).catch((err) => { console.log('putBatch success');
console.log('deleteBatch fail ' + JSON.stringify(err)); await kvStore.deleteBatch(keys).then((err) => {
}); console.log('deleteBatch success');
}).catch((err) => { }).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err)); console.log('deleteBatch fail ' + JSON.stringify(err));
}); });
}catch(e) { }).catch((err) => {
console.log('DeleteBatch e ' + e); console.log('putBatch fail ' + JSON.stringify(err));
} });
``` }catch(e) {
console.log('DeleteBatch e ' + e);
}
```
### startTransaction<sup>8+</sup> ### ### startTransaction<sup>8+</sup> ###
...@@ -2538,40 +2520,40 @@ Starts the transaction in this KV store. This method uses an asynchronous callba ...@@ -2538,40 +2520,40 @@ Starts the transaction in this KV store. This method uses an asynchronous callba
**Example** **Example**
``` ```
let kvStore; let kvStore;
function putBatchString(len, prefix) { function putBatchString(len, prefix) {
let entries = []; let entries = [];
for (var i = 0; i < len; i++) { for (var i = 0; i < len; i++) {
var entry = { var entry = {
key : prefix + i, key : prefix + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
return entries; entries.push(entry);
} }
try { return entries;
var count = 0; }
kvStore.on('dataChange', 0, function (data) { try {
console.log('startTransaction 0' + data) var count = 0;
count++; kvStore.on('dataChange', 0, function (data) {
}); console.log('startTransaction 0' + data)
kvStore.startTransaction(async function (err,data) { count++;
console.log('startTransaction success'); });
let entries = putBatchString(10, 'batch_test_string_key'); kvStore.startTransaction(async function (err,data) {
console.log('entries: ' + JSON.stringify(entries)); console.log('startTransaction success');
await kvStore.putBatch(entries, async function (err,data) { let entries = putBatchString(10, 'batch_test_string_key');
console.log('putBatch success'); console.log('entries: ' + JSON.stringify(entries));
}); await kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
}); });
}catch(e) { });
console.log('startTransaction e ' + e); }catch(e) {
} console.log('startTransaction e ' + e);
``` }
```
### startTransaction<sup>8+</sup> ### ### startTransaction<sup>8+</sup> ###
...@@ -2590,23 +2572,23 @@ Starts the transaction in this KV store. This method uses a promise to return th ...@@ -2590,23 +2572,23 @@ Starts the transaction in this KV store. This method uses a promise to return th
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
var count = 0; var count = 0;
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_ALL, function (data) { kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_ALL, function (data) {
console.log('startTransaction ' + JSON.stringify(data)); console.log('startTransaction ' + JSON.stringify(data));
count++; count++;
}); });
kvStore.startTransaction().then(async (err) => { kvStore.startTransaction().then(async (err) => {
console.log('startTransaction success'); console.log('startTransaction success');
}).catch((err) => { }).catch((err) => {
console.log('startTransaction fail ' + JSON.stringify(err)); console.log('startTransaction fail ' + JSON.stringify(err));
}); });
}catch(e) { }catch(e) {
console.log('startTransaction e ' + e); console.log('startTransaction e ' + e);
} }
``` ```
### commit<sup>8+</sup> ### ### commit<sup>8+</sup> ###
...@@ -2625,20 +2607,20 @@ Commits the transaction in this KV store. This method uses an asynchronous callb ...@@ -2625,20 +2607,20 @@ Commits the transaction in this KV store. This method uses an asynchronous callb
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
kvStore.commit(function (err,data) { kvStore.commit(function (err,data) {
if (err == undefined) { if (err == undefined) {
console.log('commit success'); console.log('commit success');
} else { } else {
console.log('commit fail'); console.log('commit fail');
} }
}); });
}catch(e) { }catch(e) {
console.log('Commit e ' + e); console.log('Commit e ' + e);
} }
``` ```
### commit<sup>8+</sup> ### ### commit<sup>8+</sup> ###
...@@ -2657,18 +2639,18 @@ Commits the transaction in this KV store. This method uses a promise to return t ...@@ -2657,18 +2639,18 @@ Commits the transaction in this KV store. This method uses a promise to return t
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
kvStore.commit().then(async (err) => { kvStore.commit().then(async (err) => {
console.log('commit success'); console.log('commit success');
}).catch((err) => { }).catch((err) => {
console.log('commit fail ' + JSON.stringify(err)); console.log('commit fail ' + JSON.stringify(err));
}); });
}catch(e) { }catch(e) {
console.log('Commit e ' + e); console.log('Commit e ' + e);
} }
``` ```
### rollback<sup>8+</sup> ### ### rollback<sup>8+</sup> ###
...@@ -2687,20 +2669,20 @@ Rolls back the transaction in this KV store. This method uses an asynchronous ca ...@@ -2687,20 +2669,20 @@ Rolls back the transaction in this KV store. This method uses an asynchronous ca
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
kvStore.rollback(function (err,data) { kvStore.rollback(function (err,data) {
if (err == undefined) { if (err == undefined) {
console.log('commit success'); console.log('commit success');
} else { } else {
console.log('commit fail'); console.log('commit fail');
} }
}); });
}catch(e) { }catch(e) {
console.log('Rollback e ' + e); console.log('Rollback e ' + e);
} }
``` ```
### rollback<sup>8+</sup> ### ### rollback<sup>8+</sup> ###
...@@ -2719,18 +2701,18 @@ Rolls back the transaction in this KV store. This method uses a promise to retur ...@@ -2719,18 +2701,18 @@ Rolls back the transaction in this KV store. This method uses a promise to retur
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
kvStore.rollback().then(async (err) => { kvStore.rollback().then(async (err) => {
console.log('rollback success'); console.log('rollback success');
}).catch((err) => { }).catch((err) => {
console.log('rollback fail ' + JSON.stringify(err)); console.log('rollback fail ' + JSON.stringify(err));
}); });
}catch(e) { }catch(e) {
console.log('Rollback e ' + e); console.log('Rollback e ' + e);
} }
``` ```
### enableSync<sup>8+</sup> ### ### enableSync<sup>8+</sup> ###
...@@ -2750,20 +2732,20 @@ Sets data synchronization, which can be enabled or disable. This method uses an ...@@ -2750,20 +2732,20 @@ Sets data synchronization, which can be enabled or disable. This method uses an
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
kvStore.enableSync(true, function (err,data) { kvStore.enableSync(true, function (err,data) {
if (err == undefined) { if (err == undefined) {
console.log('enableSync success'); console.log('enableSync success');
} else { } else {
console.log('enableSync fail'); console.log('enableSync fail');
} }
}); });
}catch(e) { }catch(e) {
console.log('EnableSync e ' + e); console.log('EnableSync e ' + e);
} }
``` ```
### enableSync<sup>8+</sup> ### ### enableSync<sup>8+</sup> ###
...@@ -2788,18 +2770,18 @@ Enables or disables data synchronization. This method uses a promise to return t ...@@ -2788,18 +2770,18 @@ Enables or disables data synchronization. This method uses a promise to return t
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
kvStore.enableSync(true).then((err) => { kvStore.enableSync(true).then((err) => {
console.log('enableSync success'); console.log('enableSync success');
}).catch((err) => { }).catch((err) => {
console.log('enableSync fail ' + JSON.stringify(err)); console.log('enableSync fail ' + JSON.stringify(err));
}); });
}catch(e) { }catch(e) {
console.log('EnableSync e ' + e); console.log('EnableSync e ' + e);
} }
``` ```
### setSyncRange<sup>8+</sup> ### ### setSyncRange<sup>8+</sup> ###
...@@ -2820,18 +2802,18 @@ Sets the data synchronization range. This method uses an asynchronous callback t ...@@ -2820,18 +2802,18 @@ Sets the data synchronization range. This method uses an asynchronous callback t
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
const localLabels = ['A', 'B']; const localLabels = ['A', 'B'];
const remoteSupportLabels = ['C', 'D']; const remoteSupportLabels = ['C', 'D'];
kvStore.setSyncRange(localLabels, remoteSupportLabels, function (err,data) { kvStore.setSyncRange(localLabels, remoteSupportLabels, function (err,data) {
console.log('SetSyncRange put success'); console.log('SetSyncRange put success');
}); });
}catch(e) { }catch(e) {
console.log('SetSyncRange e ' + e); console.log('SetSyncRange e ' + e);
} }
``` ```
### setSyncRange<sup>8+</sup> ### ### setSyncRange<sup>8+</sup> ###
...@@ -2858,20 +2840,20 @@ Sets the data synchronization range. This method uses a promise to return the re ...@@ -2858,20 +2840,20 @@ Sets the data synchronization range. This method uses a promise to return the re
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
const localLabels = ['A', 'B']; const localLabels = ['A', 'B'];
const remoteSupportLabels = ['C', 'D']; const remoteSupportLabels = ['C', 'D'];
kvStore.setSyncRange(localLabels, remoteSupportLabels).then((err) => { kvStore.setSyncRange(localLabels, remoteSupportLabels).then((err) => {
console.log('setSyncRange success'); console.log('setSyncRange success');
}).catch((err) => { }).catch((err) => {
console.log('delete fail ' + err); console.log('delete fail ' + err);
}); });
}catch(e) { }catch(e) {
console.log('SetSyncRange e ' + e); console.log('SetSyncRange e ' + e);
} }
``` ```
## SubscribeType ## SubscribeType
...@@ -2958,34 +2940,34 @@ Obtains the value of a specified key. This method uses an asynchronous callback ...@@ -2958,34 +2940,34 @@ Obtains the value of a specified key. This method uses an asynchronous callback
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| key |string | Yes |Key of the value to obtain. It cannot be empty, and the length cannot exceed [MAX_KEY_LENGTH](#constants). | | key |string | Yes |Key of the value to obtain. It cannot be empty, and the length cannot exceed [MAX_KEY_LENGTH](#constants). |
| callback |AsyncCallback&lt;Uint8Array / string / boolean / number&gt;) | Yes |Callback used to return the value obtained. | | callback |AsyncCallback&lt;Uint8Array \| string \| boolean \| number&gt;) | Yes |Callback used to return the value obtained. |
**Example** **Example**
``` ```
let kvStore; let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try { 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,data) {
if (err != undefined) { if (err != undefined) {
console.log("put err: " + JSON.stringify(err)); console.log("put err: " + JSON.stringify(err));
return; return;
} }
console.log("put success"); console.log("put success");
kvStore.get(KEY_TEST_STRING_ELEMENT, function (err,data) { kvStore.get(KEY_TEST_STRING_ELEMENT, function (err,data) {
console.log("get success data: " + data); console.log("get success data: " + data);
});
}); });
}catch (e) { });
console.log("An unexpected error occurred. Error:" + e); }catch (e) {
} console.log("An unexpected error occurred. Error:" + e);
``` }
```
### get ### get
get(key: string): Promise&lt;Uint8Array | string | boolean | number&gt get(key: string): Promise&lt;Uint8Array | string | boolean | number&gt;
Obtains the value of a specified key. This method uses a promise to return the result. Obtains the value of a specified key. This method uses a promise to return the result.
...@@ -3002,30 +2984,29 @@ Obtains the value of a specified key. This method uses a promise to return the r ...@@ -3002,30 +2984,29 @@ Obtains the value of a specified key. This method uses a promise to return the r
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
|Promise&lt;Uint8Array / string / boolean / number&gt; |Promise used to return the value obtained.| |Promise&lt;Uint8Array \| string \| boolean \| number&gt; |Promise used to return the value obtained.|
**Example** **Example**
``` ```
let kvStore; let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string';
try { try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => {
console.log("put success: " + JSON.stringify(data)); console.log("put success: " + JSON.stringify(data));
kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => { kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => {
console.log("get success data: " + data); console.log("get success data: " + data);
}).catch((err) => {
console.log("get err: " + JSON.stringify(err));
});
}).catch((err) => { }).catch((err) => {
console.log("put err: " + JSON.stringify(err)); console.log("get err: " + JSON.stringify(err));
}); });
}catch (e) { }).catch((err) => {
console.log("An unexpected error occurred. Error:" + e); console.log("put err: " + JSON.stringify(err));
} });
``` }catch (e) {
console.log("An unexpected error occurred. Error:" + e);
}
```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup> ###
...@@ -3040,37 +3021,37 @@ Obtains the KV pairs that match the specified key prefix. This method uses an as ...@@ -3040,37 +3021,37 @@ Obtains the KV pairs that match the specified key prefix. This method uses an as
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| keyPrefix |string | Yes |Key prefix to match. | | keyPrefix |string | Yes |Key prefix to match. |
| callback |AsyncCallback&lt;Entry[]&gt; | Yes |Callback used to return the KV pairs obtained. | | callback |AsyncCallback&lt;[Entry](#entry)[]&gt; | Yes |Callback used to return the KV pairs obtained. |
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_number_key'; var key = 'batch_test_number_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.INTEGER, type : distributedData.ValueType.INTEGER,
value : 222 value : 222
}
} }
entries.push(entry);
} }
kvStore.putBatch(entries, async function (err,data) { entries.push(entry);
console.log('putBatch success');
await kvStore.getEntries('batch_test_number_key', function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
}catch(e) {
console.log('PutBatch e ' + e);
} }
``` kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
await kvStore.getEntries('batch_test_number_key', function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
}catch(e) {
console.log('PutBatch e ' + e);
}
```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup> ###
...@@ -3095,40 +3076,40 @@ Obtains the KV pairs that match the specified key prefix. This method uses a pro ...@@ -3095,40 +3076,40 @@ Obtains the KV pairs that match the specified key prefix. This method uses a pro
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
console.log('entries: ' + entries); entries.push(entry);
kvStore.putBatch(entries).then(async (err) => { }
console.log('putBatch success'); console.log('entries: ' + entries);
await kvStore.getEntries('batch_test_string_key').then((entrys) => { kvStore.putBatch(entries).then(async (err) => {
console.log('getEntries success'); console.log('putBatch success');
console.log('entrys.length: ' + entrys.length); await kvStore.getEntries('batch_test_string_key').then((entrys) => {
console.log('entrys[0]: ' + JSON.stringify(entrys[0])); console.log('getEntries success');
console.log('entrys[0].value: ' + JSON.stringify(entrys[0].value)); console.log('entrys.length: ' + entrys.length);
console.log('entrys[0].value.value: ' + entrys[0].value.value); console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
}).catch((err) => { console.log('entrys[0].value: ' + JSON.stringify(entrys[0].value));
console.log('getEntries fail ' + JSON.stringify(err)); console.log('entrys[0].value.value: ' + entrys[0].value.value);
});
}).catch((err) => { }).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err)); console.log('getEntries fail ' + JSON.stringify(err));
}); });
}catch(e) { }).catch((err) => {
console.log('PutBatch e ' + e); console.log('putBatch fail ' + JSON.stringify(err));
} });
``` }catch(e) {
console.log('PutBatch e ' + e);
}
```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup> ###
...@@ -3144,42 +3125,42 @@ Obtains the KV pairs that match the specified **Query** object. This method uses ...@@ -3144,42 +3125,42 @@ Obtains the KV pairs that match the specified **Query** object. This method uses
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| query |[Query](#query8) | Yes |**Query** object to match. | | query |[Query](#query8) | Yes |**Query** object to match. |
| callback |AsyncCallback&lt;Entry[]&gt; | Yes |Callback used to return the KV pairs obtained. | | callback |AsyncCallback&lt;[Entry](#entry)[]&gt; | Yes |Callback used to return the KV pairs obtained. |
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
var arr = new Uint8Array([21,31]); var arr = new Uint8Array([21,31]);
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_bool_key'; var key = 'batch_test_bool_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.BYTE_ARRAY, type : distributedData.ValueType.BYTE_ARRAY,
value : arr value : arr
}
} }
entries.push(entry);
} }
console.log('entries: ' + JSON.stringify(entries)); entries.push(entry);
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getEntries(query, function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
console.log('GetEntries success');
}catch(e) {
console.log('GetEntries e ' + e);
} }
``` console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getEntries(query, function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
console.log('GetEntries success');
}catch(e) {
console.log('GetEntries e ' + e);
}
```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup> ###
...@@ -3204,39 +3185,39 @@ Obtains the KV pairs that match the specified **Query** object. This method uses ...@@ -3204,39 +3185,39 @@ Obtains the KV pairs that match the specified **Query** object. This method uses
**Example** **Example**
``` ```
try { try {
var arr = new Uint8Array([21,31]); var arr = new Uint8Array([21,31]);
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_bool_key'; var key = 'batch_test_bool_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.BYTE_ARRAY, type : distributedData.ValueType.BYTE_ARRAY,
value : arr value : arr
}
} }
entries.push(entry);
} }
console.log('entries: ' + JSON.stringify(entries)); entries.push(entry);
kvStore.putBatch(entries).then(async (err) => { }
console.log('putBatch success'); console.log('entries: ' + JSON.stringify(entries));
const query = new distributedData.Query(); kvStore.putBatch(entries).then(async (err) => {
query.prefixKey("batch_test"); console.log('putBatch success');
await kvStore.getEntries(query).then((entrys) => { const query = new distributedData.Query();
console.log('getEntries success'); query.prefixKey("batch_test");
}).catch((err) => { await kvStore.getEntries(query).then((entrys) => {
console.log('getEntries fail ' + JSON.stringify(err)); console.log('getEntries success');
});
}).catch((err) => { }).catch((err) => {
console.log('GetEntries putBatch fail ' + JSON.stringify(err)) console.log('getEntries fail ' + JSON.stringify(err));
}); });
console.log('GetEntries success'); }).catch((err) => {
}catch(e) { console.log('GetEntries putBatch fail ' + JSON.stringify(err))
console.log('GetEntries e ' + e); });
} console.log('GetEntries success');
``` }catch(e) {
console.log('GetEntries e ' + e);
}
```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup> ###
...@@ -3256,36 +3237,36 @@ Obtains the result set with the specified key prefix from this single KV store. ...@@ -3256,36 +3237,36 @@ Obtains the result set with the specified key prefix from this single KV store.
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
kvStore.putBatch(entries, async function (err, data) { entries.push(entry);
console.log('GetResultSet putBatch success');
await kvStore.getResultSet('batch_test_string_key', async function (err, result) {
console.log('GetResultSet getResultSet success');
resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) {
console.log('GetResultSet closeResultSet success');
})
});
});
}catch(e) {
console.log('GetResultSet e ' + e);
} }
``` kvStore.putBatch(entries, async function (err, data) {
console.log('GetResultSet putBatch success');
await kvStore.getResultSet('batch_test_string_key', async function (err, result) {
console.log('GetResultSet getResultSet success');
resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) {
console.log('GetResultSet closeResultSet success');
})
});
});
}catch(e) {
console.log('GetResultSet e ' + e);
}
```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup> ###
...@@ -3310,42 +3291,42 @@ Obtains the result set with the specified key prefix from this single KV store. ...@@ -3310,42 +3291,42 @@ Obtains the result set with the specified key prefix from this single KV store.
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
kvStore.putBatch(entries).then(async (err) => { entries.push(entry);
console.log('putBatch success');
}).catch((err) => {
console.log('PutBatch putBatch fail ' + JSON.stringify(err));
});
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('GetResult getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('GetResult closeResultSet success');
}).catch((err) => {
console.log('closeResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResult e ' + e);
} }
``` kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
}).catch((err) => {
console.log('PutBatch putBatch fail ' + JSON.stringify(err));
});
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('GetResult getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('GetResult closeResultSet success');
}).catch((err) => {
console.log('closeResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResult e ' + e);
}
```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup> ###
...@@ -3365,35 +3346,35 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj ...@@ -3365,35 +3346,35 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
kvStore.putBatch(entries, async function (err, data) { entries.push(entry);
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSet(query, async function (err, result) {
console.log('getResultSet success');
resultSet = result;
});
});
} catch(e) {
console.log('GetResultSet e ' + e);
} }
``` kvStore.putBatch(entries, async function (err, data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSet(query, async function (err, result) {
console.log('getResultSet success');
resultSet = result;
});
});
} catch(e) {
console.log('GetResultSet e ' + e);
}
```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup> ###
...@@ -3418,40 +3399,39 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj ...@@ -3418,40 +3399,39 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
kvStore.putBatch(entries).then(async (err) => { entries.push(entry);
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
const query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSet(query).then((result) => {
console.log(' getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSet e ' + e);
} }
``` kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
const query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSet(query).then((result) => {
console.log(' getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSet e ' + e);
}
```
### closeResultSet<sup>8+</sup> ### ### closeResultSet<sup>8+</sup> ###
...@@ -3470,21 +3450,21 @@ Closes the **KvStoreResultSet** object obtained by **getResultSet**. This method ...@@ -3470,21 +3450,21 @@ Closes the **KvStoreResultSet** object obtained by **getResultSet**. This method
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet = null; let resultSet = null;
kvStore.closeResultSet(resultSet, function (err, data) { kvStore.closeResultSet(resultSet, function (err, data) {
if (err == undefined) { if (err == undefined) {
console.log('closeResultSet success'); console.log('closeResultSet success');
} else { } else {
console.log('closeResultSet fail'); console.log('closeResultSet fail');
} }
}); });
}catch(e) { }catch(e) {
console.log('CloseResultSet e ' + e); console.log('CloseResultSet e ' + e);
} }
``` ```
### closeResultSet<sup>8+</sup> ### ### closeResultSet<sup>8+</sup> ###
...@@ -3509,19 +3489,19 @@ Closes the **KvStoreResultSet** object obtained by **getResultSet**. This method ...@@ -3509,19 +3489,19 @@ Closes the **KvStoreResultSet** object obtained by **getResultSet**. This method
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet = null; let resultSet = null;
kvStore.closeResultSet(resultSet).then(() => { kvStore.closeResultSet(resultSet).then(() => {
console.log('closeResultSet success'); console.log('closeResultSet success');
}).catch((err) => { }).catch((err) => {
console.log('closeResultSet fail ' + JSON.stringify(err)); console.log('closeResultSet fail ' + JSON.stringify(err));
}); });
}catch(e) { }catch(e) {
console.log('CloseResultSet e ' + e); console.log('CloseResultSet e ' + e);
} }
``` ```
### getResultSize<sup>8+</sup> ### ### getResultSize<sup>8+</sup> ###
...@@ -3541,33 +3521,33 @@ Obtains the number of results that matches the specified **Query** object. This ...@@ -3541,33 +3521,33 @@ Obtains the number of results that matches the specified **Query** object. This
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
kvStore.putBatch(entries, async function (err, data) { entries.push(entry);
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSize(query, async function (err, resultSize) {
console.log('getResultSet success');
});
});
} catch(e) {
console.log('GetResultSize e ' + e);
} }
``` kvStore.putBatch(entries, async function (err, data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSize(query, async function (err, resultSize) {
console.log('getResultSet success');
});
});
} catch(e) {
console.log('GetResultSize e ' + e);
}
```
### getResultSize<sup>8+</sup> ### ### getResultSize<sup>8+</sup> ###
...@@ -3592,37 +3572,37 @@ Obtains the number of results that matches the specified **Query** object. This ...@@ -3592,37 +3572,37 @@ Obtains the number of results that matches the specified **Query** object. This
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
kvStore.putBatch(entries).then(async (err) => { entries.push(entry);
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
const query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSize(query).then((resultSize) => {
console.log('getResultSet success');
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSize e ' + e);
} }
``` kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
const query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSize(query).then((resultSize) => {
console.log('getResultSet success');
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSize e ' + e);
}
```
### removeDeviceData<sup>8+</sup> ### ### removeDeviceData<sup>8+</sup> ###
...@@ -3642,29 +3622,29 @@ Deletes data of a device. This method uses an asynchronous callback to return th ...@@ -3642,29 +3622,29 @@ Deletes data of a device. This method uses an asynchronous callback to return th
**Example** **Example**
``` ```
let kvStore; let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; const KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
const VALUE_TEST_STRING_ELEMENT = 'value-string-002'; const VALUE_TEST_STRING_ELEMENT = 'value-string-002';
try { try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) {
console.log('put success'); console.log('put success');
const deviceid = 'no_exist_device_id'; const deviceid = 'no_exist_device_id';
await kvStore.removeDeviceData(deviceid, async function (err,data) { await kvStore.removeDeviceData(deviceid, async function (err,data) {
if (err == undefined) { if (err == undefined) {
console.log('removeDeviceData success'); console.log('removeDeviceData success');
} else { } else {
console.log('removeDeviceData fail'); console.log('removeDeviceData fail');
await kvStore.get(KEY_TEST_STRING_ELEMENT, async function (err,data) { await kvStore.get(KEY_TEST_STRING_ELEMENT, async function (err,data) {
console.log('RemoveDeviceData get success'); console.log('RemoveDeviceData get success');
}); });
} }
});
}); });
}catch(e) { });
console.log('RemoveDeviceData e ' + e); }catch(e) {
} console.log('RemoveDeviceData e ' + e);
``` }
```
### removeDeviceData<sup>8+</sup> ### ### removeDeviceData<sup>8+</sup> ###
...@@ -3689,31 +3669,31 @@ Deletes data of a device. This method uses a promise to return the result. ...@@ -3689,31 +3669,31 @@ Deletes data of a device. This method uses a promise to return the result.
**Example** **Example**
``` ```
let kvStore; let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; const KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
const VALUE_TEST_STRING_ELEMENT = 'value-string-001'; const VALUE_TEST_STRING_ELEMENT = 'value-string-001';
try { try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((err) => { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((err) => {
console.log('removeDeviceData put success'); console.log('removeDeviceData put success');
}).catch((err) => { }).catch((err) => {
console.log('put fail ' + JSON.stringify(err)); console.log('put fail ' + JSON.stringify(err));
}); });
const deviceid = 'no_exist_device_id'; const deviceid = 'no_exist_device_id';
kvStore.removeDeviceData(deviceid).then((err) => { kvStore.removeDeviceData(deviceid).then((err) => {
console.log('removeDeviceData success'); console.log('removeDeviceData success');
}).catch((err) => { }).catch((err) => {
console.log('removeDeviceData fail ' + JSON.stringify(err)); console.log('removeDeviceData fail ' + JSON.stringify(err));
}); });
kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => { kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => {
console.log('get success data:' + data); console.log('get success data:' + data);
}).catch((err) => { }).catch((err) => {
console.log('RemoveDeviceData get fail ' + JSON.stringify(err)); console.log('RemoveDeviceData get fail ' + JSON.stringify(err));
}); });
}catch(e) { }catch(e) {
console.log('RemoveDeviceData e ' + e); console.log('RemoveDeviceData e ' + e);
} }
``` ```
### on<sup>8+</sup> ### ### on<sup>8+</sup> ###
...@@ -3733,30 +3713,30 @@ Subscribes to the synchronization completion events. This method uses a synchron ...@@ -3733,30 +3713,30 @@ Subscribes to the synchronization completion events. This method uses a synchron
**Example** **Example**
``` ```
let kvStore; let kvStore;
const KEY_TEST_FLOAT_ELEMENT = 'key_test_float'; const KEY_TEST_FLOAT_ELEMENT = 'key_test_float';
const VALUE_TEST_FLOAT_ELEMENT = 321.12; const VALUE_TEST_FLOAT_ELEMENT = 321.12;
try { try {
kvStore.on('syncComplete', function (data) { kvStore.on('syncComplete', function (data) {
console.log('syncComplete ' + data) console.log('syncComplete ' + data)
}); });
kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then((data) => { kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then((data) => {
console.log('syncComplete put success'); console.log('syncComplete put success');
}).catch((error) => { }).catch((error) => {
console.log('syncComplete put fail ' + error); console.log('syncComplete put fail ' + error);
}); });
}catch(e) { }catch(e) {
console.log('syncComplete put e ' + e); console.log('syncComplete put e ' + e);
} }
``` ```
### off<sup>8+</sup> ### ### off<sup>8+</sup> ###
off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
Unsubscribes from the synchronization completion events. This method uses a synchronization callback to return the result. Unsubscribes from the synchronization completion events. This method uses a synchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -3767,21 +3747,20 @@ Unsubscribes from the synchronization completion events. This method uses a sync ...@@ -3767,21 +3747,20 @@ Unsubscribes from the synchronization completion events. This method uses a sync
| event |'syncComplete' | Yes |Event triggered when the synchronization is complete. | | event |'syncComplete' | Yes |Event triggered when the synchronization is complete. |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | No |Callback used to return the synchronization result. | | syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | No |Callback used to return the synchronization result. |
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
const func = function (data) { const func = function (data) {
console.log('syncComplete ' + data) console.log('syncComplete ' + data)
}; };
kvStore.on('syncComplete', func); kvStore.on('syncComplete', func);
kvStore.off('syncComplete', func); kvStore.off('syncComplete', func);
}catch(e) { }catch(e) {
console.log('syncComplete e ' + e); console.log('syncComplete e ' + e);
} }
``` ```
### sync ### sync
...@@ -3789,6 +3768,7 @@ Unsubscribes from the synchronization completion events. This method uses a sync ...@@ -3789,6 +3768,7 @@ Unsubscribes from the synchronization completion events. This method uses a sync
sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void
Manually triggers KV store synchronization synchronously. Manually triggers KV store synchronization synchronously.
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -3802,10 +3782,10 @@ Manually triggers KV store synchronization synchronously. ...@@ -3802,10 +3782,10 @@ Manually triggers KV store synchronization synchronously.
**Example** **Example**
``` ```
let kvStore; let kvStore;
kvStore.sync('deviceIds', distributedData.SyncMode.PULL_ONLY, 1000); kvStore.sync('deviceIds', distributedData.SyncMode.PULL_ONLY, 1000);
``` ```
### setSyncParam<sup>8+</sup> ### ### setSyncParam<sup>8+</sup> ###
...@@ -3822,20 +3802,19 @@ Sets the default delay of database synchronization. This method uses an asynchro ...@@ -3822,20 +3802,19 @@ Sets the default delay of database synchronization. This method uses an asynchro
| defaultAllowedDelayMs |number | Yes |Default delay allowed for database synchronization, in ms. | | defaultAllowedDelayMs |number | Yes |Default delay allowed for database synchronization, in ms. |
| callback |AsyncCallback&lt;void&gt; | Yes |Callback used to return the result. | | callback |AsyncCallback&lt;void&gt; | Yes |Callback used to return the result. |
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
const defaultAllowedDelayMs = 500; const defaultAllowedDelayMs = 500;
kvStore.setSyncParam(defaultAllowedDelayMs, function (err,data) { kvStore.setSyncParam(defaultAllowedDelayMs, function (err,data) {
console.log('SetSyncParam put success'); console.log('SetSyncParam put success');
}); });
}catch(e) { }catch(e) {
console.log('testSingleKvStoreSetSyncParam e ' + e); console.log('testSingleKvStoreSetSyncParam e ' + e);
} }
``` ```
### setSyncParam<sup>8+</sup> ### ### setSyncParam<sup>8+</sup> ###
...@@ -3861,19 +3840,19 @@ Sets the default delay of database synchronization. This method uses a promise t ...@@ -3861,19 +3840,19 @@ Sets the default delay of database synchronization. This method uses a promise t
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
const defaultAllowedDelayMs = 500; const defaultAllowedDelayMs = 500;
kvStore.setSyncParam(defaultAllowedDelayMs).then((err) => { kvStore.setSyncParam(defaultAllowedDelayMs).then((err) => {
console.log('SetSyncParam put success'); console.log('SetSyncParam put success');
}).catch((err) => { }).catch((err) => {
console.log('SetSyncParam put fail ' + JSON.stringify(err)); console.log('SetSyncParam put fail ' + JSON.stringify(err));
}); });
}catch(e) { }catch(e) {
console.log('SetSyncParam e ' + e); console.log('SetSyncParam e ' + e);
} }
``` ```
### getSecurityLevel<sup>8+</sup> ### ### getSecurityLevel<sup>8+</sup> ###
...@@ -3892,16 +3871,16 @@ Obtains the security level of this KV store. This method uses an asynchronous ca ...@@ -3892,16 +3871,16 @@ Obtains the security level of this KV store. This method uses an asynchronous ca
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
kvStore.getSecurityLevel(function (err,data) { kvStore.getSecurityLevel(function (err,data) {
console.log('getSecurityLevel success'); console.log('getSecurityLevel success');
}); });
}catch(e) { }catch(e) {
console.log('GetSecurityLeve e ' + e); console.log('GetSecurityLeve e ' + e);
} }
``` ```
### getSecurityLevel<sup>8+</sup> ### ### getSecurityLevel<sup>8+</sup> ###
...@@ -3918,21 +3897,20 @@ Obtains the security level of this KV store. This method uses a promise to retur ...@@ -3918,21 +3897,20 @@ Obtains the security level of this KV store. This method uses a promise to retur
| ------ | ------- | | ------ | ------- |
|Promise&lt;[SecurityLevel](#securitylevel)&gt; |Promise used to return the security level obtained.| |Promise&lt;[SecurityLevel](#securitylevel)&gt; |Promise used to return the security level obtained.|
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
kvStore.getSecurityLevel().then((data) => { kvStore.getSecurityLevel().then((data) => {
console.log(' getSecurityLevel success'); console.log(' getSecurityLevel success');
}).catch((err) => { }).catch((err) => {
console.log('getSecurityLevel fail ' + JSON.stringify(err)); console.log('getSecurityLevel fail ' + JSON.stringify(err));
}); });
}catch(e) { }catch(e) {
console.log('GetSecurityLeve e ' + e); console.log('GetSecurityLeve e ' + e);
} }
``` ```
## DeviceKVStore<sup>8+</sup> ## ## DeviceKVStore<sup>8+</sup> ##
...@@ -3947,7 +3925,7 @@ get(deviceId: string, key: string, callback: AsyncCallback&lt;boolean|string|num ...@@ -3947,7 +3925,7 @@ get(deviceId: string, key: string, callback: AsyncCallback&lt;boolean|string|num
Obtains the string value that matches the specified key for a device. This method uses an asynchronous callback to return the result. Obtains the string value that matches the specified key for a device. This method uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
**Parameters** **Parameters**
...@@ -3955,26 +3933,25 @@ Obtains the string value that matches the specified key for a device. This metho ...@@ -3955,26 +3933,25 @@ Obtains the string value that matches the specified key for a device. This metho
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| deviceId |string | Yes |ID of the target device. | | deviceId |string | Yes |ID of the target device. |
| key |string | Yes |Key to match. | | key |string | Yes |Key to match. |
| callback |AsyncCallback&lt;boolean/string/number/Uint8Array&gt; | Yes |Callback used to return the value obtained. | | callback |AsyncCallback&lt;boolean\|string\|number\|Uint8Array&gt; | Yes |Callback used to return the value obtained. |
**Example** **Example**
``` ```
let kvStore; let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; const KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
const VALUE_TEST_STRING_ELEMENT = 'value-string-002'; const VALUE_TEST_STRING_ELEMENT = 'value-string-002';
try{ try{
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) {
console.log('put success'); console.log('put success');
kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT, function (err,data) { kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT, function (err,data) {
console.log('get success'); console.log('get success');
}); });
}) })
}catch(e) { }catch(e) {
console.log('get e' + e); console.log('get e' + e);
} }
``` ```
### get<sup>8+</sup> ### ### get<sup>8+</sup> ###
...@@ -4000,25 +3977,25 @@ Obtains the string value that matches the specified key for a device. This metho ...@@ -4000,25 +3977,25 @@ Obtains the string value that matches the specified key for a device. This metho
**Example** **Example**
``` ```
let kvStore; let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; const KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
const VALUE_TEST_STRING_ELEMENT = 'value-string-002'; const VALUE_TEST_STRING_ELEMENT = 'value-string-002';
try { try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then(async (data) => { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then(async (data) => {
console.log(' put success'); console.log(' put success');
kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT).then((data) => { kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT).then((data) => {
console.log('get success'); console.log('get success');
}).catch((err) => { }).catch((err) => {
console.log('get fail ' + JSON.stringify(err)); console.log('get fail ' + JSON.stringify(err));
});
}).catch((error) => {
console.log('put error' + error);
}); });
} catch (e) { }).catch((error) => {
console.log('Get e ' + e); console.log('put error' + error);
} });
``` } catch (e) {
console.log('Get e ' + e);
}
```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup> ###
...@@ -4039,34 +4016,34 @@ Obtains the KV pairs that match the specified key prefix for a device. This meth ...@@ -4039,34 +4016,34 @@ Obtains the KV pairs that match the specified key prefix for a device. This meth
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
console.log('entries: ' + entries); entries.push(entry);
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
await kvStore.getEntries('localDeviceId', 'batch_test_string_key', function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
}catch(e) {
console.log('PutBatch e ' + e);
} }
``` console.log('entries: ' + entries);
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
await kvStore.getEntries('localDeviceId', 'batch_test_string_key', function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
}catch(e) {
console.log('PutBatch e ' + e);
}
```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup> ###
...@@ -4092,40 +4069,40 @@ Obtains the KV pairs that match the specified key prefix for a device. This meth ...@@ -4092,40 +4069,40 @@ Obtains the KV pairs that match the specified key prefix for a device. This meth
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
console.log('entries: ' + entries); entries.push(entry);
kvStore.putBatch(entries).then(async (err) => { }
console.log('putBatch success'); console.log('entries: ' + entries);
await kvStore.getEntries('localDeviceId', 'batch_test_string_key').then((entrys) => { kvStore.putBatch(entries).then(async (err) => {
console.log('getEntries success'); console.log('putBatch success');
console.log('entrys.length: ' + entrys.length); await kvStore.getEntries('localDeviceId', 'batch_test_string_key').then((entrys) => {
console.log('entrys[0]: ' + JSON.stringify(entrys[0])); console.log('getEntries success');
console.log('entrys[0].value: ' + JSON.stringify(entrys[0].value)); console.log('entrys.length: ' + entrys.length);
console.log('entrys[0].value.value: ' + entrys[0].value.value); console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
}).catch((err) => { console.log('entrys[0].value: ' + JSON.stringify(entrys[0].value));
console.log('getEntries fail ' + JSON.stringify(err)); console.log('entrys[0].value.value: ' + entrys[0].value.value);
});
}).catch((err) => { }).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err)); console.log('getEntries fail ' + JSON.stringify(err));
}); });
}catch(e) { }).catch((err) => {
console.log('PutBatch e ' + e); console.log('putBatch fail ' + JSON.stringify(err));
} });
``` }catch(e) {
console.log('PutBatch e ' + e);
}
```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup> ###
...@@ -4145,40 +4122,40 @@ Obtains the KV pairs that match the specified **Query** object. This method uses ...@@ -4145,40 +4122,40 @@ Obtains the KV pairs that match the specified **Query** object. This method uses
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
var arr = new Uint8Array([21,31]); var arr = new Uint8Array([21,31]);
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_bool_key'; var key = 'batch_test_bool_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.BYTE_ARRAY, type : distributedData.ValueType.BYTE_ARRAY,
value : arr value : arr
}
} }
entries.push(entry);
} }
console.log('entries: ' + JSON.stringify(entries)); entries.push(entry);
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
expect(err == undefined).assertTrue();
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
await kvStore.getEntries(query, function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
console.log('GetEntries success');
}catch(e) {
console.log('GetEntries e ' + e);
} }
``` console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
expect(err == undefined).assertTrue();
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
await kvStore.getEntries(query, function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
});
});
console.log('GetEntries success');
}catch(e) {
console.log('GetEntries e ' + e);
}
```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup> ###
...@@ -4203,40 +4180,40 @@ Obtains the KV pairs that match the specified **Query** object. This method uses ...@@ -4203,40 +4180,40 @@ Obtains the KV pairs that match the specified **Query** object. This method uses
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
var arr = new Uint8Array([21,31]); var arr = new Uint8Array([21,31]);
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_bool_key'; var key = 'batch_test_bool_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.BYTE_ARRAY, type : distributedData.ValueType.BYTE_ARRAY,
value : arr value : arr
}
} }
entries.push(entry);
} }
console.log('entries: ' + JSON.stringify(entries)); entries.push(entry);
kvStore.putBatch(entries).then(async (err) => { }
console.log('putBatch success'); console.log('entries: ' + JSON.stringify(entries));
const query = new distributedData.Query(); kvStore.putBatch(entries).then(async (err) => {
query.prefixKey("batch_test"); console.log('putBatch success');
await kvStore.getEntries(query).then((entrys) => { const query = new distributedData.Query();
console.log('getEntries success'); query.prefixKey("batch_test");
}).catch((err) => { await kvStore.getEntries(query).then((entrys) => {
console.log('getEntries fail ' + JSON.stringify(err)); console.log('getEntries success');
});
}).catch((err) => { }).catch((err) => {
console.log('GetEntries putBatch fail ' + JSON.stringify(err)) console.log('getEntries fail ' + JSON.stringify(err));
}); });
console.log('GetEntries success'); }).catch((err) => {
}catch(e) { console.log('GetEntries putBatch fail ' + JSON.stringify(err))
console.log('GetEntries e ' + e); });
} console.log('GetEntries success');
``` }catch(e) {
console.log('GetEntries e ' + e);
}
```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup> ###
...@@ -4257,40 +4234,40 @@ Obtains the KV pairs that match the specified **Query** object for a device. Thi ...@@ -4257,40 +4234,40 @@ Obtains the KV pairs that match the specified **Query** object for a device. Thi
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
var arr = new Uint8Array([21,31]); var arr = new Uint8Array([21,31]);
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_bool_key'; var key = 'batch_test_bool_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.BYTE_ARRAY, type : distributedData.ValueType.BYTE_ARRAY,
value : arr value : arr
}
} }
entries.push(entry);
} }
console.log('entries: ' + JSON.stringify(entries)); entries.push(entry);
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
expect(err == undefined).assertTrue();
var query = new distributedData.Query();
query.deviceId('localDeviceId');
query.prefixKey("batch_test");
await kvStore.getEntries('localDeviceId', query, function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
})
});
console.log('GetEntries success');
}catch(e) {
console.log('GetEntries e ' + e);
} }
``` console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
expect(err == undefined).assertTrue();
var query = new distributedData.Query();
query.deviceId('localDeviceId');
query.prefixKey("batch_test");
await kvStore.getEntries('localDeviceId', query, function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
})
});
console.log('GetEntries success');
}catch(e) {
console.log('GetEntries e ' + e);
}
```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup> ###
...@@ -4316,41 +4293,41 @@ Obtains the KV pairs that match the specified **Query** object for a device. Thi ...@@ -4316,41 +4293,41 @@ Obtains the KV pairs that match the specified **Query** object for a device. Thi
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
var arr = new Uint8Array([21,31]); var arr = new Uint8Array([21,31]);
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_bool_key'; var key = 'batch_test_bool_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.BYTE_ARRAY, type : distributedData.ValueType.BYTE_ARRAY,
value : arr value : arr
}
} }
entries.push(entry);
} }
console.log('entries: ' + JSON.stringify(entries)); entries.push(entry);
kvStore.putBatch(entries).then(async (err) => { }
console.log('putBatch success'); console.log('entries: ' + JSON.stringify(entries));
var query = new distributedData.Query(); kvStore.putBatch(entries).then(async (err) => {
query.deviceId('localDeviceId'); console.log('putBatch success');
query.prefixKey("batch_test"); var query = new distributedData.Query();
await kvStore.getEntries('localDeviceId', query).then((entrys) => { query.deviceId('localDeviceId');
console.log('getEntries success'); query.prefixKey("batch_test");
}).catch((err) => { await kvStore.getEntries('localDeviceId', query).then((entrys) => {
console.log('getEntries fail ' + JSON.stringify(err)); console.log('getEntries success');
});
}).catch((err) => { }).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err)); console.log('getEntries fail ' + JSON.stringify(err));
}); });
console.log('GetEntries success'); }).catch((err) => {
}catch(e) { console.log('putBatch fail ' + JSON.stringify(err));
console.log('GetEntries e ' + e); });
} console.log('GetEntries success');
``` }catch(e) {
console.log('GetEntries e ' + e);
}
```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup> ###
...@@ -4371,21 +4348,21 @@ Obtains the **KvStoreResultSet** object that matches the specified key prefix fo ...@@ -4371,21 +4348,21 @@ Obtains the **KvStoreResultSet** object that matches the specified key prefix fo
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('localDeviceId', 'batch_test_string_key', async function (err, result) { kvStore.getResultSet('localDeviceId', 'batch_test_string_key', async function (err, result) {
console.log('getResultSet success'); console.log('getResultSet success');
resultSet = result; resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) { await kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success'); console.log('closeResultSet success');
}) })
}); });
}catch(e) { }catch(e) {
console.log('GetResultSet e ' + e); console.log('GetResultSet e ' + e);
} }
``` ```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup> ###
...@@ -4411,25 +4388,25 @@ Obtains the **KvStoreResultSet** object that matches the specified key prefix fo ...@@ -4411,25 +4388,25 @@ Obtains the **KvStoreResultSet** object that matches the specified key prefix fo
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('localDeviceId', 'batch_test_string_key').then((result) => { kvStore.getResultSet('localDeviceId', 'batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet success');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err)); console.log('getResultSet fail ' + JSON.stringify(err));
}); });
kvStore.closeResultSet(resultSet).then((err) => { kvStore.closeResultSet(resultSet).then((err) => {
console.log('closeResultSet success'); console.log('closeResultSet success');
}).catch((err) => { }).catch((err) => {
console.log('closeResultSet fail ' + JSON.stringify(err)); console.log('closeResultSet fail ' + JSON.stringify(err));
}); });
}catch(e) { }catch(e) {
console.log('GetResultSet e ' + e); console.log('GetResultSet e ' + e);
} }
``` ```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup> ###
...@@ -4449,39 +4426,39 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj ...@@ -4449,39 +4426,39 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
kvStore.putBatch(entries, async function (err, data) { entries.push(entry);
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
await kvStore.getResultSet(query, async function (err, result) {
console.log('getResultSet success');
resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success');
})
});
});
} catch(e) {
console.log('GetResultSet e ' + e);
} }
``` kvStore.putBatch(entries, async function (err, data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
await kvStore.getResultSet(query, async function (err, result) {
console.log('getResultSet success');
resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success');
})
});
});
} catch(e) {
console.log('GetResultSet e ' + e);
}
```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup> ###
...@@ -4506,46 +4483,46 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj ...@@ -4506,46 +4483,46 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
kvStore.putBatch(entries).then(async (err) => { entries.push(entry);
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + err);
});
const query = new distributedData.Query();
query.deviceId('localDeviceId');
query.prefixKey("batch_test");
console.log("GetResultSet " + query.getSqlLike());
kvStore.getResultSet(query).then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('closeResultSet success');
}).catch((err) => {
console.log('closeResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSet e ' + e);
} }
``` kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + err);
});
const query = new distributedData.Query();
query.deviceId('localDeviceId');
query.prefixKey("batch_test");
console.log("GetResultSet " + query.getSqlLike());
kvStore.getResultSet(query).then((result) => {
console.log('getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('closeResultSet success');
}).catch((err) => {
console.log('closeResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSet e ' + e);
}
```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup> ###
...@@ -4566,38 +4543,38 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj ...@@ -4566,38 +4543,38 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
kvStore.putBatch(entries, async function (err, data) { entries.push(entry);
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSet('localDeviceId', query, async function (err, result) {
console.log('getResultSet success');
resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success');
})
});
});
} catch(e) {
console.log('GetResultSet e ' + e);
} }
``` kvStore.putBatch(entries, async function (err, data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSet('localDeviceId', query, async function (err, result) {
console.log('getResultSet success');
resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success');
})
});
});
} catch(e) {
console.log('GetResultSet e ' + e);
}
```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup> ###
...@@ -4623,47 +4600,47 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj ...@@ -4623,47 +4600,47 @@ Obtains the **KvStoreResultSet** object that matches the specified **Query** obj
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let resultSet; let resultSet;
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
kvStore.putBatch(entries).then(async (err) => { entries.push(entry);
console.log('GetResultSet putBatch success');
}).catch((err) => {
console.log('PutBatch putBatch fail ' + JSON.stringify(err));
});
const query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSet('localDeviceId', query).then((result) => {
console.log('GetResultSet getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('GetResultSet getResultSet fail ' + JSON.stringify(err));
});
query.deviceId('localDeviceId');
console.log("GetResultSet " + query.getSqlLike());
kvStore.closeResultSet(resultSet).then((err) => {
console.log('GetResultSet closeResultSet success');
}).catch((err) => {
console.log('GetResultSet closeResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSet e ' + e);
} }
``` kvStore.putBatch(entries).then(async (err) => {
console.log('GetResultSet putBatch success');
}).catch((err) => {
console.log('PutBatch putBatch fail ' + JSON.stringify(err));
});
const query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSet('localDeviceId', query).then((result) => {
console.log('GetResultSet getResultSet success');
resultSet = result;
}).catch((err) => {
console.log('GetResultSet getResultSet fail ' + JSON.stringify(err));
});
query.deviceId('localDeviceId');
console.log("GetResultSet " + query.getSqlLike());
kvStore.closeResultSet(resultSet).then((err) => {
console.log('GetResultSet closeResultSet success');
}).catch((err) => {
console.log('GetResultSet closeResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSet e ' + e);
}
```
### closeResultSet<sup>8+</sup> ### ### closeResultSet<sup>8+</sup> ###
...@@ -4683,22 +4660,22 @@ Closes the **KvStoreResultSet** object obtained by **getResultSet**. This method ...@@ -4683,22 +4660,22 @@ Closes the **KvStoreResultSet** object obtained by **getResultSet**. This method
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
console.log('CloseResultSet success'); console.log('CloseResultSet success');
let resultSet = null; let resultSet = null;
kvStore.closeResultSet(resultSet, function (err, data) { kvStore.closeResultSet(resultSet, function (err, data) {
if (err == undefined) { if (err == undefined) {
console.log('closeResultSet success'); console.log('closeResultSet success');
} else { } else {
console.log('closeResultSet fail'); console.log('closeResultSet fail');
} }
}); });
}catch(e) { }catch(e) {
console.log('CloseResultSet e ' + e); console.log('CloseResultSet e ' + e);
} }
``` ```
### closeResultSet<sup>8+</sup> ### ### closeResultSet<sup>8+</sup> ###
...@@ -4723,20 +4700,20 @@ Closes the **KvStoreResultSet** object obtained by **getResultSet**. This method ...@@ -4723,20 +4700,20 @@ Closes the **KvStoreResultSet** object obtained by **getResultSet**. This method
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
console.log('CloseResultSet success'); console.log('CloseResultSet success');
let resultSet = null; let resultSet = null;
kvStore.closeResultSet(resultSet).then(() => { kvStore.closeResultSet(resultSet).then(() => {
console.log('closeResultSet success'); console.log('closeResultSet success');
}).catch((err) => { }).catch((err) => {
console.log('closeResultSet fail ' + JSON.stringify(err)); console.log('closeResultSet fail ' + JSON.stringify(err));
}); });
}catch(e) { }catch(e) {
console.log('CloseResultSet e ' + e); console.log('CloseResultSet e ' + e);
} }
``` ```
### getResultSize<sup>8+</sup> ### ### getResultSize<sup>8+</sup> ###
...@@ -4756,34 +4733,34 @@ Obtains the number of results that matches the specified **Query** object. This ...@@ -4756,34 +4733,34 @@ Obtains the number of results that matches the specified **Query** object. This
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
kvStore.putBatch(entries, async function (err, data) { entries.push(entry);
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
await kvStore.getResultSize(query, async function (err, resultSize) {
console.log('getResultSet success');
});
});
} catch(e) {
console.log('GetResultSize e ' + e);
} }
``` kvStore.putBatch(entries, async function (err, data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
await kvStore.getResultSize(query, async function (err, resultSize) {
console.log('getResultSet success');
});
});
} catch(e) {
console.log('GetResultSize e ' + e);
}
```
### getResultSize<sup>8+</sup> ### ### getResultSize<sup>8+</sup> ###
...@@ -4808,38 +4785,38 @@ Obtains the number of results that matches the specified **Query** object. This ...@@ -4808,38 +4785,38 @@ Obtains the number of results that matches the specified **Query** object. This
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
kvStore.putBatch(entries).then(async (err) => { entries.push(entry);
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
kvStore.getResultSize(query).then((resultSize) => {
console.log('getResultSet success');
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSize e ' + e);
} }
``` kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
kvStore.getResultSize(query).then((resultSize) => {
console.log('getResultSet success');
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSize e ' + e);
}
```
### getResultSize<sup>8+</sup> ### ### getResultSize<sup>8+</sup> ###
...@@ -4860,33 +4837,33 @@ Obtains the number of results that matches the specified **Query** object for a ...@@ -4860,33 +4837,33 @@ Obtains the number of results that matches the specified **Query** object for a
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
kvStore.putBatch(entries, async function (err, data) { entries.push(entry);
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSize('localDeviceId', query, async function (err, resultSize) {
console.log('getResultSet success');
});
});
} catch(e) {
console.log('GetResultSize e ' + e);
} }
``` kvStore.putBatch(entries, async function (err, data) {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSize('localDeviceId', query, async function (err, resultSize) {
console.log('getResultSet success');
});
});
} catch(e) {
console.log('GetResultSize e ' + e);
}
```
### getResultSize<sup>8+</sup> ### ### getResultSize<sup>8+</sup> ###
...@@ -4912,37 +4889,37 @@ Obtains the number of results that matches the specified **Query** object for a ...@@ -4912,37 +4889,37 @@ Obtains the number of results that matches the specified **Query** object for a
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
let entries = []; let entries = [];
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var key = 'batch_test_string_key'; var key = 'batch_test_string_key';
var entry = { var entry = {
key : key + i, key : key + i,
value : { value : {
type : distributedData.ValueType.STRING, type : distributedData.ValueType.STRING,
value : 'batch_test_string_value' value : 'batch_test_string_value'
}
} }
entries.push(entry);
} }
kvStore.putBatch(entries).then(async (err) => { entries.push(entry);
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
var query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSize('localDeviceId', query).then((resultSize) => {
console.log('getResultSet success');
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSize e ' + e);
} }
``` kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
}).catch((err) => {
console.log('putBatch fail ' + JSON.stringify(err));
});
var query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSize('localDeviceId', query).then((resultSize) => {
console.log('getResultSet success');
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSize e ' + e);
}
```
### removeDeviceData<sup>8+</sup> ### ### removeDeviceData<sup>8+</sup> ###
...@@ -4962,29 +4939,29 @@ Removes data of a device from this KV store. This method uses an asynchronous ca ...@@ -4962,29 +4939,29 @@ Removes data of a device from this KV store. This method uses an asynchronous ca
**Example** **Example**
``` ```
let kvStore; let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-string-001'; const VALUE_TEST_STRING_ELEMENT = 'value-string-001';
try { try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) {
console.log('RemoveDeviceData put success'); console.log('RemoveDeviceData put success');
const deviceid = 'no_exist_device_id'; const deviceid = 'no_exist_device_id';
await kvStore.removeDeviceData(deviceid, async function (err,data) { await kvStore.removeDeviceData(deviceid, async function (err,data) {
if (err == undefined) { if (err == undefined) {
console.log('removeDeviceData success'); console.log('removeDeviceData success');
} else { } else {
console.log('removeDeviceData fail'); console.log('removeDeviceData fail');
await kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT, async function (err,data) { await kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT, async function (err,data) {
console.log('RemoveDeviceData get success'); console.log('RemoveDeviceData get success');
}); });
} }
});
}); });
}catch(e) { });
console.log('RemoveDeviceData e ' + e); }catch(e) {
} console.log('RemoveDeviceData e ' + e);
``` }
```
### removeDeviceData<sup>8+</sup> ### ### removeDeviceData<sup>8+</sup> ###
...@@ -5009,31 +4986,31 @@ Removes data of a device from this KV store. This method uses a promise to retur ...@@ -5009,31 +4986,31 @@ Removes data of a device from this KV store. This method uses a promise to retur
**Example** **Example**
``` ```
let kvStore; let kvStore;
const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const VALUE_TEST_STRING_ELEMENT = 'value-string-001'; const VALUE_TEST_STRING_ELEMENT = 'value-string-001';
try { try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((err) => { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((err) => {
console.log('RemoveDeviceData put success'); console.log('RemoveDeviceData put success');
}).catch((err) => { }).catch((err) => {
console.log('RemoveDeviceData put fail ' + JSON.stringify(err)); console.log('RemoveDeviceData put fail ' + JSON.stringify(err));
}); });
const deviceid = 'no_exist_device_id'; const deviceid = 'no_exist_device_id';
kvStore.removeDeviceData(deviceid).then((err) => { kvStore.removeDeviceData(deviceid).then((err) => {
console.log('removeDeviceData success'); console.log('removeDeviceData success');
}).catch((err) => { }).catch((err) => {
console.log('removeDeviceData fail ' + JSON.stringify(err)); console.log('removeDeviceData fail ' + JSON.stringify(err));
}); });
kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT).then((data) => { kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT).then((data) => {
console.log('RemoveDeviceData get success data:' + data); console.log('RemoveDeviceData get success data:' + data);
}).catch((err) => { }).catch((err) => {
console.log('RemoveDeviceData get fail ' + JSON.stringify(err)); console.log('RemoveDeviceData get fail ' + JSON.stringify(err));
}); });
}catch(e) { }catch(e) {
console.log('RemoveDeviceData e ' + e); console.log('RemoveDeviceData e ' + e);
} }
``` ```
### sync<sup>8+</sup> ### ### sync<sup>8+</sup> ###
...@@ -5041,6 +5018,7 @@ Removes data of a device from this KV store. This method uses a promise to retur ...@@ -5041,6 +5018,7 @@ Removes data of a device from this KV store. This method uses a promise to retur
sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void
Manually triggers KV store synchronization synchronously. Manually triggers KV store synchronization synchronously.
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -5052,31 +5030,30 @@ Manually triggers KV store synchronization synchronously. ...@@ -5052,31 +5030,30 @@ Manually triggers KV store synchronization synchronously.
| mode |[SyncMode](#syncmode) | Yes |Data synchronization mode, which can be **PUSH**, **PULL**, or **PUSH_PULL**. | | mode |[SyncMode](#syncmode) | Yes |Data synchronization mode, which can be **PUSH**, **PULL**, or **PUSH_PULL**. |
| allowedDelayMs |number | No |Allowed synchronization delay time, in ms. | | allowedDelayMs |number | No |Allowed synchronization delay time, in ms. |
**Example** **Example**
``` ```
let kvStore; let kvStore;
const KEY_TEST_SYNC_ELEMENT = 'key_test_sync'; const KEY_TEST_SYNC_ELEMENT = 'key_test_sync';
const VALUE_TEST_SYNC_ELEMENT = 'value-string-001'; const VALUE_TEST_SYNC_ELEMENT = 'value-string-001';
try { try {
kvStore.on('syncComplete', function (data) { kvStore.on('syncComplete', function (data) {
console.log('Sync dataChange'); console.log('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,data) {
console.log('Sync put success'); console.log('Sync put success');
const devices = ['deviceList']; const devices = ['deviceList'];
const mode = distributedData.SyncMode.PULL_ONLY; const mode = distributedData.SyncMode.PULL_ONLY;
kvStore.sync(devices, mode); kvStore.sync(devices, mode);
}); });
}catch(e) { }catch(e) {
console.log('Sync e' + e); console.log('Sync e' + e);
} }
``` ```
### on<sup>8+</sup> ### ### on<sup>8+</sup> ###
on(event: 'syncComplete', syncCallback: Callback&lt;Arrary&lt;[string, number]&gt;&gt;): void on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
Subscribes to the synchronization completion events. This method uses a synchronous callback to return the result. Subscribes to the synchronization completion events. This method uses a synchronous callback to return the result.
...@@ -5087,25 +5064,26 @@ Subscribes to the synchronization completion events. This method uses a synchron ...@@ -5087,25 +5064,26 @@ Subscribes to the synchronization completion events. This method uses a synchron
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event |'syncComplete' | Yes |Event triggered when the synchronization is complete.| | event |'syncComplete' | Yes |Event triggered when the synchronization is complete.|
| syncCallback |Callback<Arrary&lt;<[string, number]&gt; | Yes |Callback used to return the synchronization result. | | syncCallback |Callback<Array&lt;<[string, number]&gt; | Yes |Callback used to return the synchronization result. |
**Example** **Example**
```
const KEY_TEST_FLOAT_ELEMENT = 'key_test_float'; ```
const VALUE_TEST_FLOAT_ELEMENT = 321.12; const KEY_TEST_FLOAT_ELEMENT = 'key_test_float';
try { const VALUE_TEST_FLOAT_ELEMENT = 321.12;
kvStore.on('syncComplete', function (data) { try {
console.log('syncComplete ' + data) kvStore.on('syncComplete', function (data) {
}); console.log('syncComplete ' + data)
kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then((data) => { });
console.log('syncComplete put success'); kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then((data) => {
}).catch((error) => { console.log('syncComplete put success');
console.log('syncComplete put fail ' + error); }).catch((error) => {
}); console.log('syncComplete put fail ' + error);
}catch(e) { });
console.log('syncComplete put e ' + e); }catch(e) {
} console.log('syncComplete put e ' + e);
``` }
```
### off<sup>8+</sup> ### ### off<sup>8+</sup> ###
...@@ -5121,23 +5099,22 @@ Unsubscribes from the synchronization completion events. This method uses a sync ...@@ -5121,23 +5099,22 @@ Unsubscribes from the synchronization completion events. This method uses a sync
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event |'syncComplete' | Yes |Event triggered when the synchronization is complete.| | event |'syncComplete' | Yes |Event triggered when the synchronization is complete.|
| syncCallback |Callback<Arrary&lt;[string, number]&gt;&gt; | No |Callback used to return the synchronization result. | | syncCallback |Callback<Array&lt;[string, number]&gt;&gt; | No |Callback used to return the synchronization result. |
**Example** **Example**
``` ```
let kvStore; let kvStore;
try { try {
const func = function (data) { const func = function (data) {
console.log('syncComplete ' + data) console.log('syncComplete ' + data)
}; };
kvStore.on('syncComplete', func); kvStore.on('syncComplete', func);
kvStore.off('syncComplete', func); kvStore.off('syncComplete', func);
}catch(e) { }catch(e) {
console.log('syncComplete e ' + e); console.log('syncComplete e ' + e);
} }
``` ```
## SyncMode ## SyncMode
......
...@@ -91,21 +91,21 @@ Enumerates error codes. ...@@ -91,21 +91,21 @@ Enumerates error codes.
## HuksKeyPurpose ## HuksKeyPurpose
Represents the purpose (usage) of a key or key pair. Represents the purpose (usage) of a key.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
| Name | Value | Description | | Name | Value | Description |
| ------------------------ | ---- | ------------------------------------------ | | ------------------------ | ---- | -------------------------------- |
| HUKS_KEY_PURPOSE_ENCRYPT | 1 | The key (key pair) is used to encrypt the plaintext.| | HUKS_KEY_PURPOSE_ENCRYPT | 1 | The key is used to encrypt plain text.|
| HUKS_KEY_PURPOSE_DECRYPT | 2 | The key (key pair) is used to decrypt the ciphertext.| | HUKS_KEY_PURPOSE_DECRYPT | 2 | The key is used to decrypt the cipher text.|
| HUKS_KEY_PURPOSE_SIGN | 4 | The key pair is used to sign data. | | HUKS_KEY_PURPOSE_SIGN | 4 | The key is used to sign data. |
| HUKS_KEY_PURPOSE_VERIFY | 8 | The key pair is used to verify signed data. | | HUKS_KEY_PURPOSE_VERIFY | 8 | The key is used to verify the signed data. |
| HUKS_KEY_PURPOSE_DERIVE | 16 | The key is used to derive a key. | | HUKS_KEY_PURPOSE_DERIVE | 16 | The key is used to derive a key. |
| HUKS_KEY_PURPOSE_WRAP | 32 | The key is used for encrypted import. | | HUKS_KEY_PURPOSE_WRAP | 32 | The key is used for encrypted import. |
| HUKS_KEY_PURPOSE_UNWRAP | 64 | The key is exported in encrypted mode. | | HUKS_KEY_PURPOSE_UNWRAP | 64 | The key is exported in encrypted mode. |
| HUKS_KEY_PURPOSE_MAC | 128 | The key is used to generate a message authentication code (MAC). | | HUKS_KEY_PURPOSE_MAC | 128 | The key is used to generate a message authentication code (MAC). |
| HUKS_KEY_PURPOSE_AGREE | 256 | The key pair is used for key agreement. | | HUKS_KEY_PURPOSE_AGREE | 256 | The key is used for key agreement. |
## HuksKeyDigest ## HuksKeyDigest
...@@ -155,30 +155,30 @@ Enumerates the cipher modes. ...@@ -155,30 +155,30 @@ Enumerates the cipher modes.
## HuksKeySize ## HuksKeySize
Enumerates the key (key pair) sizes. Represents the key length.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
| Name | Value | Description | | Name | Value | Description |
| ---------------------------- | ---- | -------------------------------------------- | | ---------------------------- | ---- | ------------------------------------------ |
| HUKS_RSA_KEY_SIZE_512 | 512 | Rivest-Shamir-Adleman (RSA) key pair of 512 bits. | | HUKS_RSA_KEY_SIZE_512 | 512 | Rivest-Shamir-Adleman (RSA) key of 512 bits. |
| HUKS_RSA_KEY_SIZE_768 | 768 | RSA key pair of 768 bits. | | HUKS_RSA_KEY_SIZE_768 | 768 | RSA key of 768 bits. |
| HUKS_RSA_KEY_SIZE_1024 | 1024 | RSA key pair of 1024 bits. | | HUKS_RSA_KEY_SIZE_1024 | 1024 | RSA key of 1024 bits. |
| HUKS_RSA_KEY_SIZE_2048 | 2048 | RSA key pair of 2048 bits. | | HUKS_RSA_KEY_SIZE_2048 | 2048 | RSA key of 2048 bits. |
| HUKS_RSA_KEY_SIZE_3072 | 3072 | RSA key pair of 3072 bits. | | HUKS_RSA_KEY_SIZE_3072 | 3072 | RSA key of 3072 bits. |
| HUKS_RSA_KEY_SIZE_4096 | 4096 | RSA key pair of 4096 bits. | | HUKS_RSA_KEY_SIZE_4096 | 4096 | RSA key of 4096 bits. |
| HUKS_ECC_KEY_SIZE_224 | 224 | ECC key pair of 224 bits. | | HUKS_ECC_KEY_SIZE_224 | 224 | ECC key of 224 bits. |
| HUKS_ECC_KEY_SIZE_256 | 256 | ECC key pair of 256 bits. | | HUKS_ECC_KEY_SIZE_256 | 256 | ECC key of 256 bits. |
| HUKS_ECC_KEY_SIZE_384 | 384 | ECC key pair of 384 bits. | | HUKS_ECC_KEY_SIZE_384 | 384 | ECC key of 384 bits. |
| HUKS_ECC_KEY_SIZE_521 | 521 | ECC key pair of 521 bits. | | HUKS_ECC_KEY_SIZE_521 | 521 | ECC key of 521 bits. |
| HUKS_AES_KEY_SIZE_128 | 128 | AES key of 128 bits. | | HUKS_AES_KEY_SIZE_128 | 128 | AES key of 128 bits. |
| HUKS_AES_KEY_SIZE_192 | 196 | AES key of 196 bits. | | HUKS_AES_KEY_SIZE_192 | 196 | AES key of 196 bits. |
| HUKS_AES_KEY_SIZE_256 | 256 | AES key of 256 bits. | | HUKS_AES_KEY_SIZE_256 | 256 | AES key of 256 bits. |
| HUKS_AES_KEY_SIZE_512 | 512 | AES key of 512 bits. | | HUKS_AES_KEY_SIZE_512 | 512 | AES key of 512 bits. |
| HUKS_CURVE25519_KEY_SIZE_256 | 256 | Curve25519 key pair of 256 bits.| | HUKS_CURVE25519_KEY_SIZE_256 | 256 | Curve25519 key of 256 bits.|
| HUKS_DH_KEY_SIZE_2048 | 2048 | DH key pair of 2048 bits. | | HUKS_DH_KEY_SIZE_2048 | 2048 | DH key of 2048 bits. |
| HUKS_DH_KEY_SIZE_3072 | 3072 | DH key pair of 3072 bits. | | HUKS_DH_KEY_SIZE_3072 | 3072 | DH key of 3072 bits. |
| HUKS_DH_KEY_SIZE_4096 | 4096 | The DH key pair is 4096 bits. | | HUKS_DH_KEY_SIZE_4096 | 4096 | DH key of 4096 bits. |
## HuksKeyAlg ## HuksKeyAlg
...@@ -254,14 +254,14 @@ Enumerates the tag data types. ...@@ -254,14 +254,14 @@ Enumerates the tag data types.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
| Name | Value | Description | | Name | Value | Description |
| --------------------- | ------- | --------------------------------- | | --------------------- | ------- | --------------------------------------- |
| HUKS_TAG_TYPE_INVALID | 0 << 28 | Invalid tag type. | | HUKS_TAG_TYPE_INVALID | 0 << 28 | Invalid tag type. |
| HUKS_TAG_TYPE_INT | 1 << 28 | int. | | HUKS_TAG_TYPE_INT | 1 << 28 | Number of the int type. |
| HUKS_TAG_TYPE_UINT | 2 << 28 | uint. | | HUKS_TAG_TYPE_UINT | 2 << 28 | Number of the uint type.|
| HUKS_TAG_TYPE_ULONG | 3 << 28 | bigint. | | HUKS_TAG_TYPE_ULONG | 3 << 28 | bigint. |
| HUKS_TAG_TYPE_BOOL | 4 << 28 | Boolean. | | HUKS_TAG_TYPE_BOOL | 4 << 28 | Boolean. |
| HUKS_TAG_TYPE_BYTES | 5 << 28 | Uint8Array.| | HUKS_TAG_TYPE_BYTES | 5 << 28 | Uint8Array. |
## HuksTag ## HuksTag
...@@ -273,15 +273,15 @@ Enumerates the tags used to invoke parameters. ...@@ -273,15 +273,15 @@ Enumerates the tags used to invoke parameters.
| -------------------------------------- | ---------------------------------------- | -------------------------------------- | | -------------------------------------- | ---------------------------------------- | -------------------------------------- |
| HUKS_TAG_INVALID | HuksTagType.HUKS_TAG_TYPE_INVALID \| 0 | Invalid tag. | | HUKS_TAG_INVALID | HuksTagType.HUKS_TAG_TYPE_INVALID \| 0 | Invalid tag. |
| HUKS_TAG_ALGORITHM | HUKS_TAG_TYPE_UINT \| 1 | Indicates the algorithm. | | HUKS_TAG_ALGORITHM | HUKS_TAG_TYPE_UINT \| 1 | Indicates the algorithm. |
| HUKS_TAG_PURPOSE | HuksTagType.HUKS_TAG_TYPE_UINT \| 2 | Indicates the purpose (usage) of a key or key pair. | | HUKS_TAG_PURPOSE | HuksTagType.HUKS_TAG_TYPE_UINT \| 2 | Indicates the purpose of a key. |
| HUKS_TAG_KEY_SIZE | HuksTagType.HUKS_TAG_TYPE_UINT \| 3 | Indicates the key (key pair) length. | | HUKS_TAG_KEY_SIZE | HuksTagType.HUKS_TAG_TYPE_UINT \| 3 | Indicates the key length. |
| HUKS_TAG_DIGEST | HuksTagType.HUKS_TAG_TYPE_UINT \| 4 | Indicates the digest algorithm. | | HUKS_TAG_DIGEST | HuksTagType.HUKS_TAG_TYPE_UINT \| 4 | Indicates the digest algorithm. |
| HUKS_TAG_PADDING | HuksTagType.HUKS_TAG_TYPE_UINT \| 5 | Indicates the padding algorithm. | | HUKS_TAG_PADDING | HuksTagType.HUKS_TAG_TYPE_UINT \| 5 | Indicates the padding algorithm. |
| HUKS_TAG_BLOCK_MODE | HuksTagType.HUKS_TAG_TYPE_UINT \| 6 | Indicates the cipher mode. | | HUKS_TAG_BLOCK_MODE | HuksTagType.HUKS_TAG_TYPE_UINT \| 6 | Indicates the cipher mode. |
| HUKS_TAG_KEY_TYPE | HuksTagType.HUKS_TAG_TYPE_UINT \| 7 | Indicates the key type. | | HUKS_TAG_KEY_TYPE | HuksTagType.HUKS_TAG_TYPE_UINT \| 7 | Indicates the key type. |
| HUKS_TAG_ASSOCIATED_DATA | HuksTagType.HUKS_TAG_TYPE_BYTES \| 8 | Indicates the associated authentication data. | | HUKS_TAG_ASSOCIATED_DATA | HuksTagType.HUKS_TAG_TYPE_BYTES \| 8 | Indicates the associated authentication data. |
| HUKS_TAG_NONCE | HuksTagType.HUKS_TAG_TYPE_BYTES \| 9 | Indicates the nonce. | | HUKS_TAG_NONCE | HuksTagType.HUKS_TAG_TYPE_BYTES \| 9 | Indicates the field for key encryption and decryption. |
| HUKS_TAG_IV | HuksTagType.HUKS_TAG_TYPE_BYTES \| 10 | Indicates the IV. | | HUKS_TAG_IV | HuksTagType.HUKS_TAG_TYPE_BYTES \| 10 | Indicates the IV. |
| HUKS_TAG_INFO | HuksTagType.HUKS_TAG_TYPE_BYTES \| 11 | Indicates the information generated during key derivation. | | HUKS_TAG_INFO | HuksTagType.HUKS_TAG_TYPE_BYTES \| 11 | Indicates the information generated during key derivation. |
| HUKS_TAG_SALT | HuksTagType.HUKS_TAG_TYPE_BYTES \| 12 | Indicates the salt value used for key derivation. | | HUKS_TAG_SALT | HuksTagType.HUKS_TAG_TYPE_BYTES \| 12 | Indicates the salt value used for key derivation. |
| HUKS_TAG_PWD | HuksTagType.HUKS_TAG_TYPE_BYTES \| 13 | Indicates the password used for key derivation. | | HUKS_TAG_PWD | HuksTagType.HUKS_TAG_TYPE_BYTES \| 13 | Indicates the password used for key derivation. |
...@@ -352,7 +352,7 @@ Enumerates the tags used to invoke parameters. ...@@ -352,7 +352,7 @@ Enumerates the tags used to invoke parameters.
generateKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void generateKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
Generates a key (key pair). This method uses an asynchronous callback to return the result. Generates a key. This method uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -362,7 +362,7 @@ Generates a key (key pair). This method uses an asynchronous callback to return ...@@ -362,7 +362,7 @@ Generates a key (key pair). This method uses an asynchronous callback to return
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| keyAlias | string | Yes | Alias of the key. | | keyAlias | string | Yes | Alias of the key. |
| options | [HuksOptions](#huksoptions) | Yes | Tags required for generating the key. | | options | [HuksOptions](#huksoptions) | Yes | Tags required for generating the key. |
| callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes | Callback used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**. | | callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes | Callback used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**.|
**Example** **Example**
...@@ -403,7 +403,7 @@ huks.generateKey(alias, options, function (err, data){}); ...@@ -403,7 +403,7 @@ huks.generateKey(alias, options, function (err, data){});
generateKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult> generateKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult>
Generates a key (key pair). This method uses a promise to return the result. Generates a key. This method uses a promise to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -418,7 +418,7 @@ Generates a key (key pair). This method uses a promise to return the result. ...@@ -418,7 +418,7 @@ Generates a key (key pair). This method uses a promise to return the result.
| Type | Description | | Type | Description |
| ----------------------------------- | -------------------------------------------------- | | ----------------------------------- | -------------------------------------------------- |
| Promise\<[HuksResult](#huksresult)> | Promise used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**. | | Promise\<[HuksResult](#huksresult)> | Promise used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**.|
**Example** **Example**
...@@ -469,7 +469,7 @@ Deletes a key. This method uses an asynchronous callback to return the result. ...@@ -469,7 +469,7 @@ Deletes a key. This method uses an asynchronous callback to return the result.
| -------- | ----------------------------------------- | ---- | -------------------------------------------------- | | -------- | ----------------------------------------- | ---- | -------------------------------------------------- |
| keyAlias | string | Yes | Key alias passed in when the key was generated. | | keyAlias | string | Yes | Key alias passed in when the key was generated. |
| options | [HuksOptions](#huksoptions) | Yes | Empty object (leave this parameter empty). | | options | [HuksOptions](#huksoptions) | Yes | Empty object (leave this parameter empty). |
| callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes | Callback used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**. | | callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes | Callback used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**.|
**Example** **Example**
...@@ -500,7 +500,7 @@ Deletes a key. This method uses a promise to return the result. ...@@ -500,7 +500,7 @@ Deletes a key. This method uses a promise to return the result.
| Type | Description | | Type | Description |
| ----------------------------------- | -------------------------------------------------- | | ----------------------------------- | -------------------------------------------------- |
| Promise\<[HuksResult](#huksresult)> | Promise used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**. | | Promise\<[HuksResult](#huksresult)> | Promise used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**.|
**Example** **Example**
...@@ -528,9 +528,9 @@ Obtains the SDK version of the current system. ...@@ -528,9 +528,9 @@ Obtains the SDK version of the current system.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | ------------------------------------------------------------ | | ------ | ------------- |
| string | SDK version obtained. | | string | SDK version obtained.|
**Example** **Example**
...@@ -545,7 +545,7 @@ var result = huks.getSdkVersion(emptyOptions); ...@@ -545,7 +545,7 @@ var result = huks.getSdkVersion(emptyOptions);
importKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void importKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
Imports a key pair. This method uses an asynchronous callback to return the result. Imports a key. This method uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -555,7 +555,7 @@ Imports a key pair. This method uses an asynchronous callback to return the resu ...@@ -555,7 +555,7 @@ Imports a key pair. This method uses an asynchronous callback to return the resu
| -------- | ------------------------ | ---- | ------------------------------------------------- | | -------- | ------------------------ | ---- | ------------------------------------------------- |
| keyAlias | string | Yes | Key alias, which is used to hold the key pair.| | keyAlias | string | Yes | Key alias, which is used to hold the key pair.|
| options | [HuksOptions](#huksoptions) | Yes | Tags required for the import and key pair to import.| | options | [HuksOptions](#huksoptions) | Yes | Tags required for the import and key pair to import.|
| callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes | Callback used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**. | | callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes | Callback used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**.|
**Example** **Example**
...@@ -593,7 +593,7 @@ huks.importKey(keyAlias, options, function (err, data){}); ...@@ -593,7 +593,7 @@ huks.importKey(keyAlias, options, function (err, data){});
importKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult> importKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult>
Imports a key pair. This method uses a promise to return the result. Imports a key. This method uses a promise to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -608,7 +608,7 @@ Imports a key pair. This method uses a promise to return the result. ...@@ -608,7 +608,7 @@ Imports a key pair. This method uses a promise to return the result.
| Type | Description | | Type | Description |
| ----------------------------------- | -------------------------------------------------- | | ----------------------------------- | -------------------------------------------------- |
| Promise\<[HuksResult](#huksresult)> | Promise used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**. | | Promise\<[HuksResult](#huksresult)> | Promise used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**.|
**Example** **Example**
...@@ -646,7 +646,7 @@ var result = huks.importKey(keyAlias, options); ...@@ -646,7 +646,7 @@ var result = huks.importKey(keyAlias, options);
exportKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void exportKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
Exports a key pair. This method uses an asynchronous callback to return the result. Exports a key. This method uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -656,7 +656,7 @@ Exports a key pair. This method uses an asynchronous callback to return the resu ...@@ -656,7 +656,7 @@ Exports a key pair. This method uses an asynchronous callback to return the resu
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| keyAlias | string | Yes | Key alias, which must be the same as the alias used when the key was generated. | | keyAlias | string | Yes | Key alias, which must be the same as the alias used when the key was generated. |
| options | [HuksOptions](#huksoptions) | Yes | Empty object (leave this parameter empty). | | options | [HuksOptions](#huksoptions) | Yes | Empty object (leave this parameter empty). |
| callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes | Callback used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**. **outData** contains the public key exported. | | callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes | Callback used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**.**outData** contains the public key exported.|
**Example** **Example**
...@@ -672,7 +672,7 @@ huks.exportKey(keyAlias, emptyOptions, function (err, data){}); ...@@ -672,7 +672,7 @@ huks.exportKey(keyAlias, emptyOptions, function (err, data){});
exportKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult> exportKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult>
Exports a key pair. This method uses a promise to return the result. Exports a key. This method uses a promise to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -687,7 +687,7 @@ Exports a key pair. This method uses a promise to return the result. ...@@ -687,7 +687,7 @@ Exports a key pair. This method uses a promise to return the result.
| Type | Description | | Type | Description |
| ----------------------------------- | ------------------------------------------------------------ | | ----------------------------------- | ------------------------------------------------------------ |
| Promise\<[HuksResult](#huksresult)> | Promise used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**.<br/> **outData** contains the public key exported. | | Promise\<[HuksResult](#huksresult)> | Promise used to return the result. If the operation is successful, **HUKS_SUCCESS** will be returned. If the operation fails, an error code will be returned. For details about the error codes, see **HuksResult**.**outData** contains the public key exported.|
**Example** **Example**
...@@ -713,7 +713,7 @@ Obtains key properties. This method uses an asynchronous callback to return the ...@@ -713,7 +713,7 @@ Obtains key properties. This method uses an asynchronous callback to return the
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| keyAlias | string | Yes | Key alias, which must be the same as the alias used when the key was generated. | | keyAlias | string | Yes | Key alias, which must be the same as the alias used when the key was generated. |
| options | [HuksOptions](#huksoptions) | Yes | Empty object (leave this parameter empty). | | options | [HuksOptions](#huksoptions) | Yes | Empty object (leave this parameter empty). |
| callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes | Callback used to return the result. In **errorCode**, **HUKS_SUCCESS** will be returned if the operation is successful; an error code will be returned otherwise. | | callback | AsyncCallback\<[HuksResult](#huksresult)> | Yes | Callback used to return the result. In **errorCode**, **HUKS_SUCCESS** will be returned if the operation is successful; an error code will be returned otherwise. For details about the error codes, see **HuksResult**.|
**Example** **Example**
...@@ -737,14 +737,14 @@ Obtains key properties. This method uses a promise to return the result. ...@@ -737,14 +737,14 @@ Obtains key properties. This method uses a promise to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------- | ---- | ------------------------------------------------------------ | | -------- | ----------- | ---- | ------------------------------------------------------------ |
| keyAlias | string | Yes | Key alias, which must be the same as the alias used when the key was generated. | | keyAlias | string | Yes | Key alias, which must be the same as the alias used when the key was generated.|
| options | [HuksOptions](#huksoptions) | Yes | Empty object (leave this parameter empty). | | options | [HuksOptions](#huksoptions) | Yes | Empty object (leave this parameter empty).|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------ | ------------------------------------------------------------ | | ------------------ | ------------------------------------------------------------ |
| Promise\<[HuksResult](#huksoptions)> | Promise used to return the result. In **errorCode**, **HUKS_SUCCESS** will be returned if the operation is successful; an error code will be returned otherwise. For details about the error codes, see **HuksResult**. | | Promise\<[HuksResult](#huksoptions)> | Promise used to return the result. In **errorCode**, **HUKS_SUCCESS** will be returned if the operation is successful; an error code will be returned otherwise. For details about the error codes, see **HuksResult**.|
**Example** **Example**
...@@ -991,7 +991,7 @@ var result = huks.update(handle, options) ...@@ -991,7 +991,7 @@ var result = huks.update(handle, options)
finish(handle: number, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void finish(handle: number, options: HuksOptions, callback: AsyncCallback\<HuksResult>) : void
Completes the operation and then releases resources. This method uses an asynchronous callback to return the result. Completes the key operation and releases resources. This method uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
...@@ -1029,7 +1029,7 @@ huks.finish(handle, options, function (err, data){}); ...@@ -1029,7 +1029,7 @@ huks.finish(handle, options, function (err, data){});
finish(handle: number, options: HuksOptions) : Promise\<HuksResult> finish(handle: number, options: HuksOptions) : Promise\<HuksResult>
Completes the operation and then releases resources. This method uses a promise to return the result. Completes the key operation and releases resources. This method uses a promise to return the result.
**System capability**: SystemCapability.Security.Huks **System capability**: SystemCapability.Security.Huks
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册