提交 c1192ac7 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 4df77dcd
...@@ -107,7 +107,7 @@ The following example shows how to implement a distributed data object synchroni ...@@ -107,7 +107,7 @@ The following example shows how to implement a distributed data object synchroni
}); });
} }
} }
// To refresh the page in changeCallback, correctly bind (this) to the changeCallback. // To refresh the page in changeCallback, correctly bind (this) to the changeCallback.
local_object.on("change", this.changeCallback.bind(this)); local_object.on("change", this.changeCallback.bind(this));
``` ```
...@@ -171,7 +171,7 @@ The following example shows how to implement a distributed data object synchroni ...@@ -171,7 +171,7 @@ The following example shows how to implement a distributed data object synchroni
```js ```js
local_object.setSessionId(""); local_object.setSessionId("");
``` ```
## Development Example ## Samples
The following example is provided for you to better understand the development of distributed data objects: The following example is provided for you to better understand the development of distributed data objects:
...@@ -179,4 +179,4 @@ The following example is provided for you to better understand the development o ...@@ -179,4 +179,4 @@ The following example is provided for you to better understand the development o
When an event of the Notepad app occurs on a device, such as a note is added, the tile or content of a note is changed, or the event list is cleared, the change will be synchronized to other devices in the trusted network. When an event of the Notepad app occurs on a device, such as a note is added, the tile or content of a note is changed, or the event list is cleared, the change will be synchronized to other devices in the trusted network.
...@@ -177,5 +177,5 @@ The following uses a single KV store as an example to describe the development p ...@@ -177,5 +177,5 @@ The following uses a single KV store as an example to describe the development p
``` ```
## Samples ## Samples
The following samples are provided to help you better understand the distributed data development: The following samples are provided to help you better understand the distributed data development:
- [`KvStore`: distributed database (eTS) (API8)](https://gitee.com/openharmony/app_samples/tree/master/data/Kvstore) - [`KvStore`: Distributed Data Management (eTS) (API8)](https://gitee.com/openharmony/app_samples/tree/master/data/Kvstore)
- [Distributed Database](https://gitee.com/openharmony/codelabs/tree/master/Data/JsDistributedData) - [Distributed Data Service](https://gitee.com/openharmony/codelabs/tree/master/Data/JsDistributedData)
...@@ -116,8 +116,8 @@ The RDB provides **RdbPredicates** for you to set database operation conditions. ...@@ -116,8 +116,8 @@ The RDB provides **RdbPredicates** for you to set database operation conditions.
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
...@@ -306,3 +306,8 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -306,3 +306,8 @@ You can obtain the distributed table name for a remote device based on the local
let tableName = rdbStore.obtainDistributedTableName(deviceId, "test"); let tableName = rdbStore.obtainDistributedTableName(deviceId, "test");
let resultSet = rdbStore.querySql("SELECT * FROM " + tableName) let resultSet = rdbStore.querySql("SELECT * FROM " + tableName)
``` ```
## Samples
The following samples are provided for you to better understand the RDB development:
- [`Rdb`: eTS RDB (API8)](https://gitee.com/openharmony/app_samples/tree/master/data/Rdb)
- [`DistributedRdb`: eTS Distributed Relational Database (API8)](https://gitee.com/openharmony/app_samples/tree/master/data/DistributedRdb)
- [Relational Database](https://gitee.com/openharmony/codelabs/tree/master/Data/JSRelationshipData)
# DataAbilityPredicates # DataAbilityPredicates
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br/>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -22,6 +22,7 @@ Creates an **RdbPredicates** object based on a **DataAabilityPredicates** object ...@@ -22,6 +22,7 @@ Creates an **RdbPredicates** object based on a **DataAabilityPredicates** object
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| name | string | Yes| Table name in the RDB store.| | name | string | Yes| Table name in the RDB store.|
......
# Distributed Data Object # Distributed Data Object
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br> > **NOTE**<br/>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
import distributedObject from '@ohos.data.distributedDataObject'; import distributedObject from '@ohos.data.distributedDataObject';
``` ```
## distributedDataObject.createDistributedObject ## distributedDataObject.createDistributedObject
createDistributedObject(source: object): DistributedObject createDistributedObject(source: object): DistributedObject
......
...@@ -29,11 +29,12 @@ Obtains a relational database (RDB) store. This API uses an asynchronous callbac ...@@ -29,11 +29,12 @@ Obtains a relational database (RDB) store. This API uses an asynchronous callbac
```js ```js
const STORE_CONFIG = { name: "RdbTest.db"} const STORE_CONFIG = { name: "RdbTest.db"}
const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
data_rdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) { data_rdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) {
rdbStore.executeSql(SQL_CREATE_TABLE, null, function() { if (err) {
console.info('create table done.') console.info("Get RdbStore failed, err: " + err)
}) return
}
console.log("Get RdbStore successfully.")
}) })
``` ```
## data_rdb.getRdbStore ## data_rdb.getRdbStore
...@@ -61,17 +62,11 @@ Obtains an RDB store. This API uses a promise to return the result. You can set ...@@ -61,17 +62,11 @@ Obtains an RDB store. This API uses a promise to return the result. You can set
```js ```js
const STORE_CONFIG = { name: "RdbTest.db" } const STORE_CONFIG = { name: "RdbTest.db" }
const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" let promise = data_rdb.getRdbStore(STORE_CONFIG, 1);
let promisegetRdb = data_rdb.getRdbStore(STORE_CONFIG, 1); promise.then(async (rdbStore) => {
promisegetRdb.then(async (rdbStore) => { console.log("Get RdbStore successfully.")
let promiseExecSql = rdbStore.executeSql(SQL_CREATE_TABLE, null)
promiseExecSql.then(() => {
console.info('executeSql creat done.')
}).catch((err) => {
console.log("executeSql creat err.")
})
}).catch((err) => { }).catch((err) => {
console.log("getRdbStore err.") console.log("Get RdbStore failed, err: " + err)
}) })
``` ```
...@@ -97,11 +92,12 @@ Obtains a relational database (RDB) store. This API uses an asynchronous callbac ...@@ -97,11 +92,12 @@ Obtains a relational database (RDB) store. This API uses an asynchronous callbac
```js ```js
const STORE_CONFIG = { name: "RdbTest.db"} const STORE_CONFIG = { name: "RdbTest.db"}
const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) { data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) {
rdbStore.executeSql(SQL_CREATE_TABLE, null, function() { if (err) {
console.info('create table done.') console.info("Get RdbStore failed, err: " + err)
}) return
}
console.log("Get RdbStore successfully.")
}) })
``` ```
...@@ -131,17 +127,11 @@ Obtains an RDB store. This API uses a promise to return the result. You can set ...@@ -131,17 +127,11 @@ Obtains an RDB store. This API uses a promise to return the result. You can set
```js ```js
const STORE_CONFIG = { name: "RdbTest.db" } const STORE_CONFIG = { name: "RdbTest.db" }
const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" let promise = data_rdb.getRdbStore(this.context, STORE_CONFIG, 1);
let promisegetRdb = data_rdb.getRdbStore(this.context, STORE_CONFIG, 1); promise.then(async (rdbStore) => {
promisegetRdb.then(async (rdbStore) => { console.log("Get RdbStore successfully.")
let promiseExecSql = rdbStore.executeSql(SQL_CREATE_TABLE, null)
promiseExecSql.then(() => {
console.info('executeSql creat done.')
}).catch((err) => {
console.log("executeSql creat err.")
})
}).catch((err) => { }).catch((err) => {
console.log("getRdbStore err.") console.log("Get RdbStore failed, err: " + err)
}) })
``` ```
...@@ -160,11 +150,15 @@ Deletes an RDB store. This API uses a callback to return the result. ...@@ -160,11 +150,15 @@ Deletes an RDB store. This API uses a callback to return the result.
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|
**Example** **Example**
```js ```js
data_rdb.deleteRdbStore("RdbTest.db", function (err, rdbStore) { data_rdb.deleteRdbStore("RdbTest.db", function (err, rdbStore) {
console.info('delete store done.') if (err) {
}) console.info("Delete RdbStore failed, err: " + err)
``` return
}
console.log("Delete RdbStore successfully.")
})
```
## data_rdb.deleteRdbStore ## data_rdb.deleteRdbStore
deleteRdbStore(name: string): Promise&lt;void&gt; deleteRdbStore(name: string): Promise&lt;void&gt;
...@@ -184,14 +178,14 @@ Deletes an RDB store. This API uses a promise to return the result. ...@@ -184,14 +178,14 @@ Deletes an RDB store. This API uses a promise to return the result.
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
let promisedeleteRdb = data_rdb.deleteRdbStore("RdbTest.db") let promise = data_rdb.deleteRdbStore("RdbTest.db")
promisedeleteRdb.then(()=>{ promise.then(()=>{
console.info('delete store done.') console.log("Delete RdbStore successfully.")
}).catch((err) => { }).catch((err) => {
console.log("deleteRdbStore err.") console.info("Delete RdbStore failed, err: " + err)
}) })
``` ```
## data_rdb.deleteRdbStore<sup>8+</sup> ## data_rdb.deleteRdbStore<sup>8+</sup>
...@@ -209,11 +203,15 @@ Deletes an RDB store. This API uses a callback to return the result. ...@@ -209,11 +203,15 @@ Deletes an RDB store. This API uses a callback to return the result.
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|
**Example** **Example**
```js ```js
data_rdb.deleteRdbStore(this.context, "RdbTest.db", function (err, rdbStore) { data_rdb.deleteRdbStore(this.context, "RdbTest.db", function (err, rdbStore) {
console.info('delete store done.') if (err) {
}) console.info("Delete RdbStore failed, err: " + err)
``` return
}
console.log("Delete RdbStore successfully.")
})
```
## data_rdb.deleteRdbStore<sup>8+</sup> ## data_rdb.deleteRdbStore<sup>8+</sup>
...@@ -235,14 +233,14 @@ Deletes an RDB store. This API uses a promise to return the result. ...@@ -235,14 +233,14 @@ Deletes an RDB store. This API uses a promise to return the result.
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
let promisedeleteRdb = data_rdb.deleteRdbStore("RdbTest.db") let promise = data_rdb.deleteRdbStore("RdbTest.db")
promisedeleteRdb.then(()=>{ promise.then(()=>{
console.info('delete store done.') console.log("Delete RdbStore successfully.")
}).catch((err) => { }).catch((err) => {
console.log("deleteRdbStore err.") console.info("Delete RdbStore failed, err: " + err)
}) })
``` ```
## RdbPredicates ## RdbPredicates
...@@ -265,9 +263,9 @@ A constructor used to create an **RdbPredicates** object. ...@@ -265,9 +263,9 @@ A constructor used to create an **RdbPredicates** object.
| name | string | Yes| Database table name.| | name | string | Yes| Database table name.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
``` ```
### inDevices<sup>8+</sup> ### inDevices<sup>8+</sup>
...@@ -289,10 +287,10 @@ Specifies a remote device on the network during distributed database synchroniza ...@@ -289,10 +287,10 @@ Specifies a remote device on the network during distributed database synchroniza
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.inDevices(['12345678abcde']) predicates.inDevices(['12345678abcde'])
``` ```
### inAllDevices<sup>8+</sup> ### inAllDevices<sup>8+</sup>
...@@ -309,10 +307,10 @@ Connects to all remote devices on the network during distributed database synchr ...@@ -309,10 +307,10 @@ Connects to all remote devices on the network during distributed database synchr
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.inAllDevices() predicates.inAllDevices()
``` ```
### equalTo ### equalTo
...@@ -335,10 +333,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v ...@@ -335,10 +333,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "lisi") predicates.equalTo("NAME", "lisi")
``` ```
### notEqualTo ### notEqualTo
...@@ -362,10 +360,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v ...@@ -362,10 +360,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.notEqualTo("NAME", "lisi") predicates.notEqualTo("NAME", "lisi")
``` ```
### beginWrap ### beginWrap
...@@ -383,15 +381,15 @@ Adds a left parenthesis to the **RdbPredicates**. ...@@ -383,15 +381,15 @@ Adds a left parenthesis to the **RdbPredicates**.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a left parenthesis.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a left parenthesis.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "lisi") predicates.equalTo("NAME", "lisi")
.beginWrap() .beginWrap()
.equalTo("AGE", 18) .equalTo("AGE", 18)
.or() .or()
.equalTo("SALARY", 200.5) .equalTo("SALARY", 200.5)
.endWrap() .endWrap()
``` ```
### endWrap ### endWrap
...@@ -409,15 +407,15 @@ Adds a right parenthesis to the **RdbPredicates**. ...@@ -409,15 +407,15 @@ Adds a right parenthesis to the **RdbPredicates**.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a right parenthesis.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a right parenthesis.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "lisi") predicates.equalTo("NAME", "lisi")
.beginWrap() .beginWrap()
.equalTo("AGE", 18) .equalTo("AGE", 18)
.or() .or()
.equalTo("SALARY", 200.5) .equalTo("SALARY", 200.5)
.endWrap() .endWrap()
``` ```
### or ### or
...@@ -435,12 +433,12 @@ Adds the OR condition to the **RdbPredicates**. ...@@ -435,12 +433,12 @@ Adds the OR condition to the **RdbPredicates**.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the OR condition.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the OR condition.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
.or() .or()
.equalTo("NAME", "Rose") .equalTo("NAME", "Rose")
``` ```
### and ### and
...@@ -458,12 +456,12 @@ Adds the AND condition to the **RdbPredicates**. ...@@ -458,12 +456,12 @@ Adds the AND condition to the **RdbPredicates**.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the AND condition.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the AND condition.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
.and() .and()
.equalTo("SALARY", 200.5) .equalTo("SALARY", 200.5)
``` ```
### contains ### contains
...@@ -486,10 +484,10 @@ Sets the **RdbPredicates** to match a string containing the specified value. ...@@ -486,10 +484,10 @@ Sets the **RdbPredicates** to match a string containing the specified value.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.contains("NAME", "os") predicates.contains("NAME", "os")
``` ```
### beginsWith ### beginsWith
...@@ -513,10 +511,10 @@ Sets the **RdbPredicates** to match a string that starts with the specified valu ...@@ -513,10 +511,10 @@ Sets the **RdbPredicates** to match a string that starts with the specified valu
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.beginsWith("NAME", "os") predicates.beginsWith("NAME", "os")
``` ```
### endsWith ### endsWith
...@@ -540,10 +538,10 @@ Sets the **RdbPredicates** to match a string that ends with the specified value. ...@@ -540,10 +538,10 @@ Sets the **RdbPredicates** to match a string that ends with the specified value.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.endsWith("NAME", "se") predicates.endsWith("NAME", "se")
``` ```
### isNull ### isNull
...@@ -566,10 +564,10 @@ Sets the **RdbPredicates** to match the field whose value is null. ...@@ -566,10 +564,10 @@ Sets the **RdbPredicates** to match the field whose value is null.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
- Example - Example
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.isNull("NAME") predicates.isNull("NAME")
``` ```
### isNotNull ### isNotNull
...@@ -592,10 +590,10 @@ Sets the **RdbPredicates** to match the field whose value is not null. ...@@ -592,10 +590,10 @@ Sets the **RdbPredicates** to match the field whose value is not null.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.isNotNull("NAME") predicates.isNotNull("NAME")
``` ```
### like ### like
...@@ -619,10 +617,10 @@ Sets the **RdbPredicates** to match a string that is similar to the specified va ...@@ -619,10 +617,10 @@ Sets the **RdbPredicates** to match a string that is similar to the specified va
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.like("NAME", "%os%") predicates.like("NAME", "%os%")
``` ```
### glob ### glob
...@@ -646,10 +644,10 @@ Sets the **RdbPredicates** to match the specified string. ...@@ -646,10 +644,10 @@ Sets the **RdbPredicates** to match the specified string.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.glob("NAME", "?h*g") predicates.glob("NAME", "?h*g")
``` ```
### between ### between
...@@ -674,10 +672,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v ...@@ -674,10 +672,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.between("AGE", 10, 50) predicates.between("AGE", 10, 50)
``` ```
### notBetween ### notBetween
...@@ -702,10 +700,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v ...@@ -702,10 +700,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.notBetween("AGE", 10, 50) predicates.notBetween("AGE", 10, 50)
``` ```
### greaterThan ### greaterThan
...@@ -728,10 +726,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v ...@@ -728,10 +726,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.greaterThan("AGE", 18) predicates.greaterThan("AGE", 18)
``` ```
### lessThan ### lessThan
...@@ -755,10 +753,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v ...@@ -755,10 +753,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.lessThan("AGE", 20) predicates.lessThan("AGE", 20)
``` ```
### greaterThanOrEqualTo ### greaterThanOrEqualTo
...@@ -783,10 +781,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v ...@@ -783,10 +781,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.greaterThanOrEqualTo("AGE", 18) predicates.greaterThanOrEqualTo("AGE", 18)
``` ```
### lessThanOrEqualTo ### lessThanOrEqualTo
...@@ -811,10 +809,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v ...@@ -811,10 +809,10 @@ Sets the **RdbPredicates** to match the field with data type **ValueType** and v
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.lessThanOrEqualTo("AGE", 20) predicates.lessThanOrEqualTo("AGE", 20)
``` ```
### orderByAsc ### orderByAsc
...@@ -838,10 +836,10 @@ Sets the **RdbPredicates** to match the column with values sorted in ascending o ...@@ -838,10 +836,10 @@ Sets the **RdbPredicates** to match the column with values sorted in ascending o
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.orderByAsc("NAME") predicates.orderByAsc("NAME")
``` ```
### orderByDesc ### orderByDesc
...@@ -865,10 +863,10 @@ Sets the **RdbPredicates** to match the column with values sorted in descending ...@@ -865,10 +863,10 @@ Sets the **RdbPredicates** to match the column with values sorted in descending
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.orderByDesc("AGE") predicates.orderByDesc("AGE")
``` ```
### distinct ### distinct
...@@ -886,17 +884,17 @@ Sets the **RdbPredicates** to filter out duplicate records. ...@@ -886,17 +884,17 @@ Sets the **RdbPredicates** to filter out duplicate records.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that can filter out duplicate records.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that can filter out duplicate records.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose").distinct("NAME") predicates.equalTo("NAME", "Rose").distinct("NAME")
let promisequery = rdbStore.query(predicates, ["NAME"]) let promise = rdbStore.query(predicates, ["NAME"])
promisequery.then((resultSet) => { promise.then((resultSet) => {
console.log("resultSet column names:" + resultSet.columnNames) console.log("resultSet column names:" + resultSet.columnNames)
console.log("resultSet column count:" + resultSet.columnCount) console.log("resultSet column count:" + resultSet.columnCount)
}).catch((err) => { }).catch((err) => {
console.log("query err.") console.log("query err.")
}) })
``` ```
### limitAs ### limitAs
...@@ -919,10 +917,10 @@ Sets the **RdbPredicates** to specify the maximum number of records. ...@@ -919,10 +917,10 @@ Sets the **RdbPredicates** to specify the maximum number of records.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the maximum number of records.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the maximum number of records.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose").limitAs(3) predicates.equalTo("NAME", "Rose").limitAs(3)
``` ```
### offsetAs ### offsetAs
...@@ -945,10 +943,10 @@ Sets the **RdbPredicates** to specify the start position of the returned result. ...@@ -945,10 +943,10 @@ Sets the **RdbPredicates** to specify the start position of the returned result.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the start position of the returned result.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the start position of the returned result.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose").offsetAs(3) predicates.equalTo("NAME", "Rose").offsetAs(3)
``` ```
### groupBy ### groupBy
...@@ -971,10 +969,10 @@ Sets the **RdbPredicates** to group rows that have the same value into summary r ...@@ -971,10 +969,10 @@ Sets the **RdbPredicates** to group rows that have the same value into summary r
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that groups rows with the same value.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that groups rows with the same value.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.groupBy(["AGE", "NAME"]) predicates.groupBy(["AGE", "NAME"])
``` ```
### indexedBy ### indexedBy
...@@ -997,10 +995,10 @@ Sets the **RdbPredicates** object to specify the index column. ...@@ -997,10 +995,10 @@ Sets the **RdbPredicates** object to specify the index column.
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the index column.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the index column.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.indexedBy("SALARY_INDEX") predicates.indexedBy("SALARY_INDEX")
``` ```
### in ### in
...@@ -1025,10 +1023,10 @@ Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueTy ...@@ -1025,10 +1023,10 @@ Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueTy
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.in("AGE", [18, 20]) predicates.in("AGE", [18, 20])
``` ```
### notIn ### notIn
...@@ -1053,10 +1051,10 @@ Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueTy ...@@ -1053,10 +1051,10 @@ Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueTy
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.notIn("NAME", ["Lisa", "Rose"]) predicates.notIn("NAME", ["Lisa", "Rose"])
``` ```
## RdbStore ## RdbStore
...@@ -1080,17 +1078,21 @@ Inserts a row of data into a table. This API uses a callback to return the resul ...@@ -1080,17 +1078,21 @@ Inserts a row of data into a table. This API uses a callback to return the resul
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| | callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
**Example** **Example**
```js ```js
const valueBucket = { const valueBucket = {
"NAME": "Lisa", "NAME": "Lisa",
"AGE": 18, "AGE": 18,
"SALARY": 100.5, "SALARY": 100.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} }
rdbStore.insert("EMPLOYEE", valueBucket, function (err, ret) { rdbStore.insert("EMPLOYEE", valueBucket, function (err, ret) {
console.log("insert first done: " + ret) if (err) {
}) console.info("Insert failed, err: " + err)
``` return
}
console.log("Insert first done: " + ret)
})
```
### insert ### insert
...@@ -1113,20 +1115,20 @@ Inserts a row of data into a table. This API uses a promise to return the result ...@@ -1113,20 +1115,20 @@ Inserts a row of data into a table. This API uses a promise to return the result
| Promise&lt;number&gt; | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| | Promise&lt;number&gt; | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
**Example** **Example**
```js ```js
const valueBucket = { const valueBucket = {
"NAME": "Lisa", "NAME": "Lisa",
"AGE": 18, "AGE": 18,
"SALARY": 100.5, "SALARY": 100.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} }
let promiseinsert = rdbStore.insert("EMPLOYEE", valueBucket) let promise = rdbStore.insert("EMPLOYEE", valueBucket)
promiseinsert.then(async (ret) => { promise.then(async (ret) => {
console.log("insert first done: " + ret) console.log("Insert first done: " + ret)
}).catch((err) => { }).catch((err) => {
console.log("insert err.") console.log("Insert failed, err: " + err)
}) })
``` ```
### update ### update
...@@ -1145,18 +1147,23 @@ Updates data in the database based on the specified RdbPredicates object. This A ...@@ -1145,18 +1147,23 @@ Updates data in the database based on the specified RdbPredicates object. This A
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the number of rows updated.| | callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the number of rows updated.|
**Example** **Example**
```js ```js
const valueBucket = { const valueBucket = {
"NAME": "Rose", "NAME": "Rose",
"AGE": 22, "AGE": 22,
"SALARY": 200.5, "SALARY": 200.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} }
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
rdbStore.update(valueBucket, predicates, function (err, ret) { rdbStore.update(valueBucket, predicates, function (err, ret) {
console.log("updated row count: " + ret)}) if (err) {
``` console.info("Updated failed, err: " + err)
return
}
console.log("Updated row count: " + ret)
})
```
### update ### update
...@@ -1179,22 +1186,22 @@ Updates data in the database based on the specified RdbPredicates object. This A ...@@ -1179,22 +1186,22 @@ Updates data in the database based on the specified RdbPredicates object. This A
| Promise&lt;number&gt; | Promise used to return the number of rows updated.| | Promise&lt;number&gt; | Promise used to return the number of rows updated.|
**Example** **Example**
```js ```js
const valueBucket = { const valueBucket = {
"NAME": "Rose", "NAME": "Rose",
"AGE": 22, "AGE": 22,
"SALARY": 200.5, "SALARY": 200.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} }
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
let promiseupdate = rdbStore.update(valueBucket, predicates) let promise = rdbStore.update(valueBucket, predicates)
promiseupdate.then(async (ret) => { promise.then(async (ret) => {
console.log("updated row count: " + ret) console.log("Updated row count: " + ret)
}).catch((err) => { }).catch((err) => {
console.log("update err.") console.info("Updated failed, err: " + err)
}) })
``` ```
### delete ### delete
...@@ -1213,13 +1220,17 @@ Deletes data from the database based on the specified RdbPredicates object. This ...@@ -1213,13 +1220,17 @@ Deletes data from the database based on the specified RdbPredicates object. This
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of rows updated.| | callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of rows updated.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
rdbStore.delete(predicates, function (err, rows) { rdbStore.delete(predicates, function (err, rows) {
console.log("delete rows: " + rows) if (err) {
}) console.info("Delete failed, err: " + err)
``` return
}
console.log("Delete rows: " + rows)
})
```
### delete ### delete
...@@ -1241,16 +1252,16 @@ Deletes data from the database based on the specified RdbPredicates object. This ...@@ -1241,16 +1252,16 @@ Deletes data from the database based on the specified RdbPredicates object. This
| Promise&lt;number&gt; | Promise used to return the number of rows updated.| | Promise&lt;number&gt; | Promise used to return the number of rows updated.|
**Example** **Example**
```js ```js
let predicatesdelete = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicatesdelete.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
let promisedelete = rdbStore.delete(predicates) let promise = rdbStore.delete(predicates)
promisedelete.then((rows) => { promise.then((rows) => {
console.log("delete rows: " + rows) console.log("Delete rows: " + rows)
}).catch((err) => { }).catch((err) => {
console.log("delete err.") console.info("Delete failed, err: " + err)
}) })
``` ```
### query ### query
...@@ -1269,14 +1280,18 @@ Queries data in the database based on specified conditions. This API uses a call ...@@ -1269,14 +1280,18 @@ Queries data in the database based on specified conditions. This API uses a call
| callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| | callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose") predicates.equalTo("NAME", "Rose")
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) { rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
console.log("resultSet column names:" + resultSet.columnNames) if (err) {
console.log("resultSet column count:" + resultSet.columnCount) console.info("Query failed, err: " + err)
}) return
``` }
console.log("resultSet column names:" + resultSet.columnNames)
console.log("resultSet column count:" + resultSet.columnCount)
})
```
### query ### query
...@@ -1302,12 +1317,12 @@ Queries data in the database based on specified conditions. This API uses a prom ...@@ -1302,12 +1317,12 @@ Queries data in the database based on specified conditions. This API uses a prom
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose") predicates.equalTo("NAME", "Rose")
let promisequery = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
promisequery.then((resultSet) => { promise.then((resultSet) => {
console.log("resultSet column names:" + resultSet.columnNames) console.log("resultSet column names:" + resultSet.columnNames)
console.log("resultSet column count:" + resultSet.columnCount) console.log("resultSet column count:" + resultSet.columnCount)
}).catch((err) => { }).catch((err) => {
console.log("query err.") console.info("Query failed, err: " + err)
}) })
``` ```
...@@ -1328,12 +1343,16 @@ Queries data in the RDB store using the specified SQL statement. This API uses a ...@@ -1328,12 +1343,16 @@ Queries data in the RDB store using the specified SQL statement. This API uses a
| callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| | callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
**Example** **Example**
```js ```js
rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) { rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) {
console.log("resultSet column names:" + resultSet.columnNames) if (err) {
console.log("resultSet column count:" + resultSet.columnCount) console.info("Query failed, err: " + err)
}) return
``` }
console.log("resultSet column names:" + resultSet.columnNames)
console.log("resultSet column count:" + resultSet.columnCount)
})
```
### querySql<sup>8+</sup> ### querySql<sup>8+</sup>
...@@ -1356,15 +1375,15 @@ Queries data in the RDB store using the specified SQL statement. This API uses a ...@@ -1356,15 +1375,15 @@ Queries data in the RDB store using the specified SQL statement. This API uses a
| Promise&lt;[ResultSet](../apis/js-apis-data-resultset.md)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| | Promise&lt;[ResultSet](../apis/js-apis-data-resultset.md)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|
**Example** **Example**
```js ```js
let promisequerySql = rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo']) let promise = rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'])
promisequerySql.then((resultSet) => { promise.then((resultSet) => {
console.log("resultSet column names:" + resultSet.columnNames) console.log("resultSet column names:" + resultSet.columnNames)
console.log("resultSet column count:" + resultSet.columnCount) console.log("resultSet column count:" + resultSet.columnCount)
}).catch((err) => { }).catch((err) => {
console.log("querySql err.") console.info("Query failed, err: " + err)
}) })
``` ```
### executeSql ### executeSql
...@@ -1383,11 +1402,16 @@ Runs the SQL statement that contains the specified parameters but does not retur ...@@ -1383,11 +1402,16 @@ Runs the SQL statement that contains the specified parameters but does not retur
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|
**Example** **Example**
```js ```js
rdbStore.executeSql("DELETE FROM EMPLOYEE", null, function () { const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
console.info('delete done.') rdbStore.executeSql(SQL_CREATE_TABLE, null, function(err) {
}) if (err) {
``` console.info("executeSql failed, err: " + err)
return
}
console.info('create table done.')
})
```
### executeSql ### executeSql
...@@ -1410,14 +1434,15 @@ Runs the SQL statement that contains the specified parameters but does not retur ...@@ -1410,14 +1434,15 @@ Runs the SQL statement that contains the specified parameters but does not retur
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
let promiseexecuteSql = rdbStore.executeSql("DELETE FROM EMPLOYEE") const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
promiseexecuteSql.then(() => { let promise = rdbStore.executeSql(SQL_CREATE_TABLE)
console.info('delete done.') promise.then(() => {
}).catch((err) => { console.info('create table done.')
console.log("executeSql err.") }).catch((err) => {
}) console.info("ExecuteSql failed, err: " + err)
``` })
```
### beginTransaction<sup>8+</sup> ### beginTransaction<sup>8+</sup>
...@@ -1429,17 +1454,21 @@ Starts the transaction before executing an SQL statement. ...@@ -1429,17 +1454,21 @@ Starts the transaction before executing an SQL statement.
**Example** **Example**
```js ```js
rdbStore.beginTransaction() rdbStore.beginTransaction()
const valueBucket = { const valueBucket = {
"name": "lisi", "name": "lisi",
"age": 18, "age": 18,
"salary": 100.5, "salary": 100.5,
"blobType": new Uint8Array([1, 2, 3]), "blobType": new Uint8Array([1, 2, 3]),
} }
rdbStore.insert("test", valueBucket, function (err, ret) { rdbStore.insert("test", valueBucket, function (err, ret) {
console.log("insert done: " + ret) if (err) {
}) console.info("Insert failed, err: " + err)
rdbStore.commit() return
}
console.log("Insert successfully: " + ret)
})
rdbStore.commit()
``` ```
...@@ -1453,18 +1482,22 @@ Commits the executed SQL statements. ...@@ -1453,18 +1482,22 @@ Commits the executed SQL statements.
**Example** **Example**
```js ```js
rdbStore.beginTransaction() rdbStore.beginTransaction()
const valueBucket = { const valueBucket = {
"name": "lisi", "name": "lisi",
"age": 18, "age": 18,
"salary": 100.5, "salary": 100.5,
"blobType": new Uint8Array([1, 2, 3]), "blobType": new Uint8Array([1, 2, 3]),
} }
rdbStore.insert("test", valueBucket, function (err, ret) { rdbStore.insert("test", valueBucket, function (err, ret) {
console.log("insert done: " + ret) if (err) {
}) console.info("Insert failed, err: " + err)
rdbStore.commit() return
}
console.log("Insert successfully: " + ret)
})
rdbStore.commit()
``` ```
...@@ -1478,22 +1511,26 @@ Rolls back the SQL statements that have been executed. ...@@ -1478,22 +1511,26 @@ Rolls back the SQL statements that have been executed.
**Example** **Example**
```js ```js
try { try {
rdbStore.beginTransaction() rdbStore.beginTransaction()
const valueBucket = { const valueBucket = {
"id": 1, "id": 1,
"name": "lisi", "name": "lisi",
"age": 18, "age": 18,
"salary": 100.5, "salary": 100.5,
"blobType": new Uint8Array([1, 2, 3]), "blobType": new Uint8Array([1, 2, 3]),
} }
rdbStore.insert("test", valueBucket, function (err, ret) { rdbStore.insert("test", valueBucket, function (err, ret) {
console.log("insert done: " + ret) if (err) {
}) console.info("Insert failed, err: " + err)
rdbStore.commit() return
} catch (e) { }
rdbStore.rollBack() console.log("Insert successfully: " + ret)
} })
rdbStore.commit()
} catch (e) {
rdbStore.rollBack()
}
``` ```
...@@ -1512,14 +1549,14 @@ Sets a list of distributed tables. This API uses a callback to return the result ...@@ -1512,14 +1549,14 @@ Sets a list of distributed tables. This API uses a callback to return the result
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|
**Example** **Example**
```js ```js
rdbStore.setDistributedTables(["EMPLOYEE"], function (err) { rdbStore.setDistributedTables(["EMPLOYEE"], function (err) {
if (err) { if (err) {
console.info('setDistributedTables failed.') console.info('setDistributedTables failed, err: ' + err)
return return
} }
console.info('setDistributedTables success.') console.info('setDistributedTables successfully.')
}) })
``` ```
...@@ -1542,14 +1579,14 @@ Sets a list of distributed tables. This API uses a promise to return the result. ...@@ -1542,14 +1579,14 @@ Sets a list of distributed tables. This API uses a promise to return the result.
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
let promiseset = rdbStore.setDistributedTables(["EMPLOYEE"]) let promise = rdbStore.setDistributedTables(["EMPLOYEE"])
promiseset.then(() => { promise.then(() => {
console.info("setDistributedTables success.") console.info("setDistributedTables successfully.")
}).catch((err) => { }).catch((err) => {
console.info("setDistributedTables failed.") console.info("setDistributedTables failed, err: " + err)
}) })
``` ```
### obtainDistributedTableName<sup>8+</sup> ### obtainDistributedTableName<sup>8+</sup>
...@@ -1567,15 +1604,15 @@ Obtains the distributed table name for a remote device based on the local table ...@@ -1567,15 +1604,15 @@ Obtains the distributed table name for a remote device based on the local table
| callback | AsyncCallback&lt;string&gt; | Yes| Callback invoked to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| | callback | AsyncCallback&lt;string&gt; | Yes| Callback invoked to return the result. If the operation succeeds, the distributed table name of the remote device is returned.|
**Example** **Example**
```js ```js
rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) { rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) {
if (err) { if (err) {
console.info('obtainDistributedTableName failed.') console.info('obtainDistributedTableName failed, err: ' + err)
return return
} }
console.info('obtainDistributedTableName success, tableName=.' + tableName) console.info('obtainDistributedTableName successfully, tableName=.' + tableName)
}) })
``` ```
### obtainDistributedTableName<sup>8+</sup> ### obtainDistributedTableName<sup>8+</sup>
...@@ -1598,14 +1635,14 @@ Obtains the distributed table name for a remote device based on the local table ...@@ -1598,14 +1635,14 @@ Obtains the distributed table name for a remote device based on the local table
| Promise&lt;string&gt; | Promise used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| | Promise&lt;string&gt; | Promise used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.|
**Example** **Example**
```js ```js
let promiseDistr = rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE") let promise = rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE")
promiseDistr.then((tableName) => { promise.then((tableName) => {
console.info('obtainDistributedTableName success, tableName=' + tableName) console.info('obtainDistributedTableName successfully, tableName=' + tableName)
}).catch((err) => { }).catch((err) => {
console.info('obtainDistributedTableName failed.') console.info('obtainDistributedTableName failed, err: ' + err)
}) })
``` ```
### sync<sup>8+</sup> ### sync<sup>8+</sup>
...@@ -1623,20 +1660,20 @@ Synchronizes data between devices. This API uses a callback to return the result ...@@ -1623,20 +1660,20 @@ Synchronizes data between devices. This API uses a callback to return the result
| callback | AsyncCallback&lt;Array&lt;[string, number]&gt;&gt; | Yes| Callback invoked to send the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. | | callback | AsyncCallback&lt;Array&lt;[string, number]&gt;&gt; | Yes| Callback invoked to send the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
**Example** **Example**
```js ```js
let predicate = new rdb.RdbPredicates('EMPLOYEE') let predicates = new rdb.RdbPredicates('EMPLOYEE')
predicate.inDevices(['12345678abcde']) predicates.inDevices(['12345678abcde'])
rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH, predicate, function (err, result) { rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) {
if (err) { if (err) {
console.log('sync failed') console.log('sync failed, err: ' + err)
return return
} }
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])
} }
}) })
``` ```
### sync<sup>8+</sup> ### sync<sup>8+</sup>
...@@ -1660,19 +1697,19 @@ Synchronizes data between devices. This API uses a promise to return the result. ...@@ -1660,19 +1697,19 @@ Synchronizes data between devices. This API uses a promise to return the result.
| Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise used to return the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. | | Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise used to return the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
**Example** **Example**
```js ```js
let predicatesync = new data_rdb.RdbPredicates('EMPLOYEE') let predicates = new data_rdb.RdbPredicates('EMPLOYEE')
predicatesync.inDevices(['12345678abcde']) predicates.inDevices(['12345678abcde'])
let promisesync = rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicatesync) let promise = rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicates)
promisesync.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])
} }
}).catch((err) => { }).catch((err) => {
console.log('sync failed') console.log('sync failed')
}) })
``` ```
### on('dataChange')<sup>8+</sup> ### on('dataChange')<sup>8+</sup>
...@@ -1691,18 +1728,18 @@ Registers an observer for this RDB store. When the data in the RDB store changes ...@@ -1691,18 +1728,18 @@ Registers an observer for this RDB store. When the data in the RDB store changes
| observer | Callback&lt;Array&lt;string&gt;&gt; | Yes| Observer that listens for the data changes in the RDB store.| | observer | Callback&lt;Array&lt;string&gt;&gt; | Yes| Observer that listens for the data changes in the RDB store.|
**Example** **Example**
```js ```js
function storeObserver(devices) { function storeObserver(devices) {
for (let i = 0; i < devices.length; i++) { for (let i = 0; i < devices.length; i++) {
console.log('device=' + devices[i] + ' data changed') console.log('device=' + devices[i] + ' data changed')
} }
} }
try { try {
rdbStore.on('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) rdbStore.on('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver)
} catch (err) { } catch (err) {
console.log('register observer failed') console.log('register observer failed')
} }
``` ```
### off('dataChange')<sup>8+</sup> ### off('dataChange')<sup>8+</sup>
...@@ -1721,19 +1758,18 @@ Deletes the specified observer of the RDB store. This API uses a callback to ret ...@@ -1721,19 +1758,18 @@ Deletes the specified observer of the RDB store. This API uses a callback to ret
| observer | Callback&lt;Array&lt;string&gt;&gt; | Yes| Data change observer registered.| | observer | Callback&lt;Array&lt;string&gt;&gt; | Yes| Data change observer registered.|
**Example** **Example**
```js
```js function storeObserver(devices) {
function storeObserver(devices) { for (let i = 0; i < devices.length; i++) {
for (let i = 0; i < devices.length; i++) { console.log('device=' + devices[i] + ' data changed')
console.log('device=' + devices[i] + ' data changed') }
} }
} try {
try { rdbStore.off('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver)
rdbStore.off('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) } catch (err) {
} catch (err) { console.log('unregister observer failed')
console.log('unregister observer failed') }
} ```
```
## StoreConfig ## StoreConfig
......
# Result Set # Result Set
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br/>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Lightweight storage provides applications with data processing capability and allows applications to perform lightweight data storage and query. Data is stored in key-value (KV) pairs. Keys are of the string type, and values can be of the number, string, or Boolean type. Lightweight storage provides applications with data processing capability and allows applications to perform lightweight data storage and query. Data is stored in key-value (KV) pairs. Keys are of the string type, and values can be of the number, string, or Boolean type.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br/>
> >
> - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> >
...@@ -30,7 +30,7 @@ import dataStorage from '@ohos.data.storage'; ...@@ -30,7 +30,7 @@ import dataStorage from '@ohos.data.storage';
getStorageSync(path: string): Storage getStorageSync(path: string): Storage
Reads a file and loads the data to the **Storage** instance in synchronous mode. Reads the specified file and load its data to the **Storage** instance for data operations.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -67,7 +67,7 @@ Reads a file and loads the data to the **Storage** instance in synchronous mode. ...@@ -67,7 +67,7 @@ Reads a file and loads the data to the **Storage** instance in synchronous mode.
getStorage(path: string, callback: AsyncCallback&lt;Storage&gt;): void getStorage(path: string, callback: AsyncCallback&lt;Storage&gt;): void
Reads a file and loads the data to the **Storage** instance. This API uses an asynchronous callback to return the execution result. Reads the specified file and loads its data to the **Storage** instance for data operations. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -105,7 +105,7 @@ Reads a file and loads the data to the **Storage** instance. This API uses an as ...@@ -105,7 +105,7 @@ Reads a file and loads the data to the **Storage** instance. This API uses an as
getStorage(path: string): Promise&lt;Storage&gt; getStorage(path: string): Promise&lt;Storage&gt;
Reads a file and loads the data to the **Storage** instance. This API uses a promise to return the execution result. Reads the specified file and loads its data to the **Storage** instance for data operations. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -146,7 +146,7 @@ Reads a file and loads the data to the **Storage** instance. This API uses a pro ...@@ -146,7 +146,7 @@ Reads a file and loads the data to the **Storage** instance. This API uses a pro
deleteStorageSync(path: string): void deleteStorageSync(path: string): void
Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses a synchronous mode. Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -165,7 +165,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete ...@@ -165,7 +165,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
deleteStorage(path: string, callback: AsyncCallback&lt;void&gt;): void deleteStorage(path: string, callback: AsyncCallback&lt;void&gt;): void
Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses an asynchronous callback to return the execution result. Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -191,7 +191,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete ...@@ -191,7 +191,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
deleteStorage(path: string): Promise&lt;void&gt; deleteStorage(path: string): Promise&lt;void&gt;
Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses a promise to return the execution result. Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -222,8 +222,6 @@ removeStorageFromCacheSync(path: string): void ...@@ -222,8 +222,6 @@ removeStorageFromCacheSync(path: string): void
Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur. Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur.
This API uses a synchronous mode.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
...@@ -241,9 +239,7 @@ This API uses a synchronous mode. ...@@ -241,9 +239,7 @@ This API uses a synchronous mode.
removeStorageFromCache(path: string, callback: AsyncCallback&lt;void&gt;): void removeStorageFromCache(path: string, callback: AsyncCallback&lt;void&gt;): void
Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur. Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses an asynchronous callback to return the result.
This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -269,9 +265,7 @@ This API uses an asynchronous callback to return the result. ...@@ -269,9 +265,7 @@ This API uses an asynchronous callback to return the result.
removeStorageFromCache(path: string): Promise&lt;void&gt; removeStorageFromCache(path: string): Promise&lt;void&gt;
Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur. Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses a promise to return the result.
This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -307,8 +301,6 @@ getSync(key: string, defValue: ValueType): ValueType ...@@ -307,8 +301,6 @@ getSync(key: string, defValue: ValueType): ValueType
Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned.
This API uses a synchronous mode.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
...@@ -333,9 +325,7 @@ This API uses a synchronous mode. ...@@ -333,9 +325,7 @@ This API uses a synchronous mode.
get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;): void get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;): void
Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. This API uses an asynchronous callback to return the result.
This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -362,9 +352,7 @@ This API uses an asynchronous callback to return the result. ...@@ -362,9 +352,7 @@ This API uses an asynchronous callback to return the result.
get(key: string, defValue: ValueType): Promise&lt;ValueType&gt; get(key: string, defValue: ValueType): Promise&lt;ValueType&gt;
Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. This API uses a promise to return the result.
This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -397,8 +385,6 @@ putSync(key: string, value: ValueType): void ...@@ -397,8 +385,6 @@ putSync(key: string, value: ValueType): void
Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**. Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**.
This API uses a synchronous mode.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
...@@ -417,9 +403,7 @@ This API uses a synchronous mode. ...@@ -417,9 +403,7 @@ This API uses a synchronous mode.
put(key: string, value: ValueType, callback: AsyncCallback&lt;void&gt;): void put(key: string, value: ValueType, callback: AsyncCallback&lt;void&gt;): void
Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**. Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**. This API uses an asynchronous callback to return the result.
This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -446,9 +430,7 @@ This API uses an asynchronous callback to return the result. ...@@ -446,9 +430,7 @@ This API uses an asynchronous callback to return the result.
put(key: string, value: ValueType): Promise&lt;void&gt; put(key: string, value: ValueType): Promise&lt;void&gt;
Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**. Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**. This API uses a promise to return the result.
This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -480,8 +462,6 @@ hasSync(key: string): boolean ...@@ -480,8 +462,6 @@ hasSync(key: string): boolean
Checks whether the storage object contains data with a given key. Checks whether the storage object contains data with a given key.
This API uses a synchronous mode.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
...@@ -507,9 +487,7 @@ This API uses a synchronous mode. ...@@ -507,9 +487,7 @@ This API uses a synchronous mode.
has(key: string, callback: AsyncCallback&lt;boolean&gt;): boolean has(key: string, callback: AsyncCallback&lt;boolean&gt;): boolean
Checks whether the storage object contains data with a given key. Checks whether the storage object contains data with a given key. This API uses an asynchronous callback to return the result.
This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -542,9 +520,7 @@ This API uses an asynchronous callback to return the result. ...@@ -542,9 +520,7 @@ This API uses an asynchronous callback to return the result.
has(key: string): Promise&lt;boolean&gt; has(key: string): Promise&lt;boolean&gt;
Checks whether the storage object contains data with a given key. Checks whether the storage object contains data with a given key. This API uses a promise to return the result.
This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -577,8 +553,6 @@ deleteSync(key: string): void ...@@ -577,8 +553,6 @@ deleteSync(key: string): void
Deletes data with the specified key from this storage object. Deletes data with the specified key from this storage object.
This API uses a synchronous mode.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
...@@ -592,13 +566,11 @@ This API uses a synchronous mode. ...@@ -592,13 +566,11 @@ This API uses a synchronous mode.
``` ```
### deletej ### delete
delete(key: string, callback: AsyncCallback&lt;void&gt;): void delete(key: string, callback: AsyncCallback&lt;void&gt;): void
Deletes data with the specified key from this storage object. Deletes data with the specified key from this storage object. This API uses an asynchronous callback to return the result.
This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -624,9 +596,7 @@ This API uses an asynchronous callback to return the result. ...@@ -624,9 +596,7 @@ This API uses an asynchronous callback to return the result.
delete(key: string): Promise&lt;void&gt; delete(key: string): Promise&lt;void&gt;
Deletes data with the specified key from this storage object. Deletes data with the specified key from this storage object. This API uses a promise to return the result.
This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -657,8 +627,6 @@ flushSync(): void ...@@ -657,8 +627,6 @@ flushSync(): void
Saves the modification of this object to the **Storage** instance and synchronizes the modification to the file. Saves the modification of this object to the **Storage** instance and synchronizes the modification to the file.
This API uses a synchronous mode.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Example** **Example**
...@@ -671,9 +639,7 @@ This API uses a synchronous mode. ...@@ -671,9 +639,7 @@ This API uses a synchronous mode.
flush(callback: AsyncCallback&lt;void&gt;): void flush(callback: AsyncCallback&lt;void&gt;): void
Saves the modification of this object to the **Storage** instance and synchronizes the modification to the file. Saves the modification of this object to the **Storage** instance and synchronizes the modification to the file. This API uses an asynchronous callback to return the result.
This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -698,9 +664,7 @@ This API uses an asynchronous callback to return the result. ...@@ -698,9 +664,7 @@ This API uses an asynchronous callback to return the result.
flush(): Promise&lt;void&gt; flush(): Promise&lt;void&gt;
Saves the modification of this object to the **Storage** instance and synchronizes the modification to the file. Saves the modification of this object to the **Storage** instance and synchronizes the modification to the file. This API uses a promise to return the result.
This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -726,8 +690,6 @@ clearSync(): void ...@@ -726,8 +690,6 @@ clearSync(): void
Clears this **Storage** object. Clears this **Storage** object.
This API uses a synchronous mode.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Example** **Example**
...@@ -740,9 +702,7 @@ This API uses a synchronous mode. ...@@ -740,9 +702,7 @@ This API uses a synchronous mode.
clear(callback: AsyncCallback&lt;void&gt;): void clear(callback: AsyncCallback&lt;void&gt;): void
Clears this **Storage** object. Clears this **Storage** object. This API uses an asynchronous callback to return the result.
This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -767,9 +727,7 @@ This API uses an asynchronous callback to return the result. ...@@ -767,9 +727,7 @@ This API uses an asynchronous callback to return the result.
clear(): Promise&lt;void&gt; clear(): Promise&lt;void&gt;
Clears this **Storage** object. Clears this **Storage** object. This API uses a promise to return the result.
This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Distributed data management provides collaboration between databases of different devices for applications. The APIs provided by distributed data management can be used to save data to the distributed database and perform operations such as adding, deleting, modifying, and querying data in the distributed database. Distributed data management provides collaboration between databases of different devices for applications. The APIs provided by distributed data management can be used to save data to the distributed database and perform operations such as adding, deleting, modifying, and querying data in the distributed database.
>![](../../public_sys-resources/icon-note.gif) **NOTE**<br/> >**NOTE**<br/>
>The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. >The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -2922,6 +2922,7 @@ These value types can be used only by internal applications. ...@@ -2922,6 +2922,7 @@ These value types can be used only by internal applications.
| BOOLEAN |4 |Boolean. | | BOOLEAN |4 |Boolean. |
| DOUBLE |5 |Double (double-precision floating point). | | DOUBLE |5 |Double (double-precision floating point). |
## SingleKVStore ## SingleKVStore
Provides methods to query and synchronize data in a single KV store. This class inherits from **KVStore**. Before calling any method in **SingleKVStore**, you must use [getKVStore](#getkvstore) to obtain a **SingleKVStore** object. Provides methods to query and synchronize data in a single KV store. This class inherits from **KVStore**. Before calling any method in **SingleKVStore**, you must use [getKVStore](#getkvstore) to obtain a **SingleKVStore** object.
...@@ -3447,7 +3448,7 @@ Closes the **KvStoreResultSet** object obtained by **getResultSet**. This API us ...@@ -3447,7 +3448,7 @@ Closes the **KvStoreResultSet** object obtained by **getResultSet**. This API us
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| resultSet |[KvStoreResultSet](#kvstoreresultset8) | Yes |**KvStoreResultSet** object to close. | | resultSet |[KvStoreResultSet](#kvstoreresultset8) | Yes |**KvStoreResultSet** object to close. |
| callback |AsyncCallback&lt;void&gt; | Yes |Callback used to return the execution result. | | callback |AsyncCallback&lt;void&gt; | Yes |Callback used to return the result. |
**Example** **Example**
......
# Data Storage # Data Storage
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br/>
> >
> - The APIs of this module are no longer maintained since API Version 6, and you are advised to use [`@ohos.data.storage`](js-apis-data-storage.md). From API Version 9, you are advised to use [`@ohos.data.preferences`](js-apis-data-preferences.md). > - The APIs of this module are no longer maintained since API Version 6, and you are advised to use [`@ohos.data.storage`](js-apis-data-storage.md). From API Version 9, you are advised to use [`@ohos.data.preferences`](js-apis-data-preferences.md).
> >
...@@ -67,7 +67,7 @@ Sets the value in the cache based on the specified key. ...@@ -67,7 +67,7 @@ Sets the value in the cache based on the specified key.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the value to set.| | key | string | Yes| Key of the data to set.|
| value | string | Yes| New value to set. The maximum length is 128 bytes.| | value | string | Yes| New value to set. The maximum length is 128 bytes.|
| success | Function | No| Called when **storage.set()** is successful.| | success | Function | No| Called when **storage.set()** is successful.|
| fail | Function | No| Called when **storage.set()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.| | fail | Function | No| Called when **storage.set()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册