From c1192ac72fe1e8e13f672090b84359bc805cfc1e Mon Sep 17 00:00:00 2001 From: Annie_wang Date: Tue, 24 May 2022 11:34:31 +0800 Subject: [PATCH] update docs Signed-off-by: Annie_wang --- .../database-distributedobject-guidelines.md | 6 +- .../database/database-mdds-guidelines.md | 4 +- .../database-relational-guidelines.md | 9 +- .../reference/apis/js-apis-data-ability.md | 3 +- .../apis/js-apis-data-distributedobject.md | 4 +- .../reference/apis/js-apis-data-rdb.md | 898 +++++++++--------- .../reference/apis/js-apis-data-resultset.md | 2 +- .../reference/apis/js-apis-data-storage.md | 86 +- .../apis/js-apis-distributed-data.md | 5 +- .../reference/apis/js-apis-system-storage.md | 4 +- 10 files changed, 510 insertions(+), 511 deletions(-) diff --git a/en/application-dev/database/database-distributedobject-guidelines.md b/en/application-dev/database/database-distributedobject-guidelines.md index 4ff96ed5e1..a3f5d13676 100644 --- a/en/application-dev/database/database-distributedobject-guidelines.md +++ b/en/application-dev/database/database-distributedobject-guidelines.md @@ -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. local_object.on("change", this.changeCallback.bind(this)); ``` @@ -171,7 +171,7 @@ The following example shows how to implement a distributed data object synchroni ```js local_object.setSessionId(""); ``` -## Development Example +## Samples 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 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. - + diff --git a/en/application-dev/database/database-mdds-guidelines.md b/en/application-dev/database/database-mdds-guidelines.md index d59fd3904a..ce4f1ad79d 100644 --- a/en/application-dev/database/database-mdds-guidelines.md +++ b/en/application-dev/database/database-mdds-guidelines.md @@ -177,5 +177,5 @@ The following uses a single KV store as an example to describe the development p ``` ## Samples 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) -- [Distributed Database](https://gitee.com/openharmony/codelabs/tree/master/Data/JsDistributedData) +- [`KvStore`: Distributed Data Management (eTS) (API8)](https://gitee.com/openharmony/app_samples/tree/master/data/Kvstore) +- [Distributed Data Service](https://gitee.com/openharmony/codelabs/tree/master/Data/JsDistributedData) diff --git a/en/application-dev/database/database-relational-guidelines.md b/en/application-dev/database/database-relational-guidelines.md index d23f0c0c57..d43b11ff62 100644 --- a/en/application-dev/database/database-relational-guidelines.md +++ b/en/application-dev/database/database-relational-guidelines.md @@ -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**. -> ![icon-notice.gif](../public_sys-resources/icon-notice.gif) **NOTICE**
-> After a result set is used, you must call the **close()** method to close it explicitly.** +> ![icon-notice.gif](public_sys-resources/icon-notice.gif) **NOTICE**
+> After a result set is used, you must call the **close()** method to close it explicitly. **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 let tableName = rdbStore.obtainDistributedTableName(deviceId, "test"); 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) diff --git a/en/application-dev/reference/apis/js-apis-data-ability.md b/en/application-dev/reference/apis/js-apis-data-ability.md index 14fba24573..7149bdeeaa 100644 --- a/en/application-dev/reference/apis/js-apis-data-ability.md +++ b/en/application-dev/reference/apis/js-apis-data-ability.md @@ -1,6 +1,6 @@ # DataAbilityPredicates -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
+> **NOTE**
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -22,6 +22,7 @@ Creates an **RdbPredicates** object based on a **DataAabilityPredicates** object **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | name | string | Yes| Table name in the RDB store.| diff --git a/en/application-dev/reference/apis/js-apis-data-distributedobject.md b/en/application-dev/reference/apis/js-apis-data-distributedobject.md index 5ac7b6707c..36761408ca 100644 --- a/en/application-dev/reference/apis/js-apis-data-distributedobject.md +++ b/en/application-dev/reference/apis/js-apis-data-distributedobject.md @@ -1,6 +1,6 @@ # Distributed Data Object -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
+> **NOTE**
> 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 @@ import distributedObject from '@ohos.data.distributedDataObject'; ``` - - ## distributedDataObject.createDistributedObject createDistributedObject(source: object): DistributedObject diff --git a/en/application-dev/reference/apis/js-apis-data-rdb.md b/en/application-dev/reference/apis/js-apis-data-rdb.md index 73a87a94f2..77af49f308 100644 --- a/en/application-dev/reference/apis/js-apis-data-rdb.md +++ b/en/application-dev/reference/apis/js-apis-data-rdb.md @@ -29,11 +29,12 @@ Obtains a relational database (RDB) store. This API uses an asynchronous callbac ```js const STORE_CONFIG = { name: "RdbTest.db"} -const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" data_rdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) { - rdbStore.executeSql(SQL_CREATE_TABLE, null, function() { - console.info('create table done.') - }) + if (err) { + console.info("Get RdbStore failed, err: " + err) + return + } + console.log("Get RdbStore successfully.") }) ``` ## data_rdb.getRdbStore @@ -61,17 +62,11 @@ Obtains an RDB store. This API uses a promise to return the result. You can set ```js const STORE_CONFIG = { name: "RdbTest.db" } -const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" -let promisegetRdb = data_rdb.getRdbStore(STORE_CONFIG, 1); -promisegetRdb.then(async (rdbStore) => { - let promiseExecSql = rdbStore.executeSql(SQL_CREATE_TABLE, null) - promiseExecSql.then(() => { - console.info('executeSql creat done.') - }).catch((err) => { - console.log("executeSql creat err.") - }) +let promise = data_rdb.getRdbStore(STORE_CONFIG, 1); +promise.then(async (rdbStore) => { + console.log("Get RdbStore successfully.") }).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 ```js const STORE_CONFIG = { name: "RdbTest.db"} -const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) { - rdbStore.executeSql(SQL_CREATE_TABLE, null, function() { - console.info('create table done.') - }) + if (err) { + 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 ```js const STORE_CONFIG = { name: "RdbTest.db" } -const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" -let promisegetRdb = data_rdb.getRdbStore(this.context, STORE_CONFIG, 1); -promisegetRdb.then(async (rdbStore) => { - let promiseExecSql = rdbStore.executeSql(SQL_CREATE_TABLE, null) - promiseExecSql.then(() => { - console.info('executeSql creat done.') - }).catch((err) => { - console.log("executeSql creat err.") - }) +let promise = data_rdb.getRdbStore(this.context, STORE_CONFIG, 1); +promise.then(async (rdbStore) => { + console.log("Get RdbStore successfully.") }).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. | callback | AsyncCallback<void> | Yes| Callback invoked to return the result.| **Example** - ```js - data_rdb.deleteRdbStore("RdbTest.db", function (err, rdbStore) { - console.info('delete store done.') - }) - ``` +```js +data_rdb.deleteRdbStore("RdbTest.db", function (err, rdbStore) { + if (err) { + console.info("Delete RdbStore failed, err: " + err) + return + } + console.log("Delete RdbStore successfully.") +}) +``` ## data_rdb.deleteRdbStore deleteRdbStore(name: string): Promise<void> @@ -184,14 +178,14 @@ Deletes an RDB store. This API uses a promise to return the result. | Promise<void> | Promise used to return the result.| **Example** - ```js - let promisedeleteRdb = data_rdb.deleteRdbStore("RdbTest.db") - promisedeleteRdb.then(()=>{ - console.info('delete store done.') - }).catch((err) => { - console.log("deleteRdbStore err.") - }) - ``` +```js +let promise = data_rdb.deleteRdbStore("RdbTest.db") +promise.then(()=>{ + console.log("Delete RdbStore successfully.") +}).catch((err) => { + console.info("Delete RdbStore failed, err: " + err) +}) +``` ## data_rdb.deleteRdbStore8+ @@ -209,11 +203,15 @@ Deletes an RDB store. This API uses a callback to return the result. | callback | AsyncCallback<void> | Yes| Callback invoked to return the result.| **Example** - ```js - data_rdb.deleteRdbStore(this.context, "RdbTest.db", function (err, rdbStore) { - console.info('delete store done.') - }) - ``` +```js +data_rdb.deleteRdbStore(this.context, "RdbTest.db", function (err, rdbStore) { + if (err) { + console.info("Delete RdbStore failed, err: " + err) + return + } + console.log("Delete RdbStore successfully.") +}) +``` ## data_rdb.deleteRdbStore8+ @@ -235,14 +233,14 @@ Deletes an RDB store. This API uses a promise to return the result. | Promise<void> | Promise used to return the result.| **Example** - ```js - let promisedeleteRdb = data_rdb.deleteRdbStore("RdbTest.db") - promisedeleteRdb.then(()=>{ - console.info('delete store done.') - }).catch((err) => { - console.log("deleteRdbStore err.") - }) - ``` +```js +let promise = data_rdb.deleteRdbStore("RdbTest.db") +promise.then(()=>{ + console.log("Delete RdbStore successfully.") +}).catch((err) => { + console.info("Delete RdbStore failed, err: " + err) +}) +``` ## RdbPredicates @@ -265,9 +263,9 @@ A constructor used to create an **RdbPredicates** object. | name | string | Yes| Database table name.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +``` ### inDevices8+ @@ -289,10 +287,10 @@ Specifies a remote device on the network during distributed database synchroniza | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.inDevices(['12345678abcde']) - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.inDevices(['12345678abcde']) +``` ### inAllDevices8+ @@ -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.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.inAllDevices() - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.inAllDevices() +``` ### equalTo @@ -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.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "lisi") - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.equalTo("NAME", "lisi") +``` ### notEqualTo @@ -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.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.notEqualTo("NAME", "lisi") - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.notEqualTo("NAME", "lisi") +``` ### beginWrap @@ -383,15 +381,15 @@ Adds a left parenthesis to the **RdbPredicates**. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a left parenthesis.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "lisi") - .beginWrap() - .equalTo("AGE", 18) - .or() - .equalTo("SALARY", 200.5) - .endWrap() - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.equalTo("NAME", "lisi") + .beginWrap() + .equalTo("AGE", 18) + .or() + .equalTo("SALARY", 200.5) + .endWrap() +``` ### endWrap @@ -409,15 +407,15 @@ Adds a right parenthesis to the **RdbPredicates**. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a right parenthesis.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "lisi") - .beginWrap() - .equalTo("AGE", 18) - .or() - .equalTo("SALARY", 200.5) - .endWrap() - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.equalTo("NAME", "lisi") + .beginWrap() + .equalTo("AGE", 18) + .or() + .equalTo("SALARY", 200.5) + .endWrap() +``` ### or @@ -435,12 +433,12 @@ Adds the OR condition to the **RdbPredicates**. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the OR condition.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Lisa") - .or() - .equalTo("NAME", "Rose") - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.equalTo("NAME", "Lisa") + .or() + .equalTo("NAME", "Rose") +``` ### and @@ -458,12 +456,12 @@ Adds the AND condition to the **RdbPredicates**. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the AND condition.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Lisa") - .and() - .equalTo("SALARY", 200.5) - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.equalTo("NAME", "Lisa") + .and() + .equalTo("SALARY", 200.5) +``` ### contains @@ -486,10 +484,10 @@ Sets the **RdbPredicates** to match a string containing the specified value. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.contains("NAME", "os") - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.contains("NAME", "os") +``` ### beginsWith @@ -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.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.beginsWith("NAME", "os") - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.beginsWith("NAME", "os") +``` ### endsWith @@ -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.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.endsWith("NAME", "se") - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.endsWith("NAME", "se") +``` ### isNull @@ -566,10 +564,10 @@ Sets the **RdbPredicates** to match the field whose value is null. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| - Example - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.isNull("NAME") - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.isNull("NAME") +``` ### isNotNull @@ -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.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.isNotNull("NAME") - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.isNotNull("NAME") +``` ### like @@ -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.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.like("NAME", "%os%") - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.like("NAME", "%os%") +``` ### glob @@ -646,10 +644,10 @@ Sets the **RdbPredicates** to match the specified string. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.glob("NAME", "?h*g") - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.glob("NAME", "?h*g") +``` ### between @@ -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.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.between("AGE", 10, 50) - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.between("AGE", 10, 50) +``` ### notBetween @@ -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.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.notBetween("AGE", 10, 50) - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.notBetween("AGE", 10, 50) +``` ### greaterThan @@ -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.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.greaterThan("AGE", 18) - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.greaterThan("AGE", 18) +``` ### lessThan @@ -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.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.lessThan("AGE", 20) - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.lessThan("AGE", 20) +``` ### greaterThanOrEqualTo @@ -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.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.greaterThanOrEqualTo("AGE", 18) - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.greaterThanOrEqualTo("AGE", 18) +``` ### lessThanOrEqualTo @@ -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.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.lessThanOrEqualTo("AGE", 20) - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.lessThanOrEqualTo("AGE", 20) +``` ### orderByAsc @@ -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.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.orderByAsc("NAME") - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.orderByAsc("NAME") +``` ### orderByDesc @@ -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.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.orderByDesc("AGE") - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.orderByDesc("AGE") +``` ### distinct @@ -886,17 +884,17 @@ Sets the **RdbPredicates** to filter out duplicate records. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that can filter out duplicate records.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Rose").distinct("NAME") - let promisequery = rdbStore.query(predicates, ["NAME"]) - promisequery.then((resultSet) => { - console.log("resultSet column names:" + resultSet.columnNames) - console.log("resultSet column count:" + resultSet.columnCount) - }).catch((err) => { - console.log("query err.") - }) - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.equalTo("NAME", "Rose").distinct("NAME") +let promise = rdbStore.query(predicates, ["NAME"]) +promise.then((resultSet) => { + console.log("resultSet column names:" + resultSet.columnNames) + console.log("resultSet column count:" + resultSet.columnCount) +}).catch((err) => { + console.log("query err.") +}) +``` ### limitAs @@ -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.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Rose").limitAs(3) - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.equalTo("NAME", "Rose").limitAs(3) +``` ### offsetAs @@ -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.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Rose").offsetAs(3) - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.equalTo("NAME", "Rose").offsetAs(3) +``` ### groupBy @@ -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.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.groupBy(["AGE", "NAME"]) - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.groupBy(["AGE", "NAME"]) +``` ### indexedBy @@ -997,10 +995,10 @@ Sets the **RdbPredicates** object to specify the index column. | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the index column.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.indexedBy("SALARY_INDEX") - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.indexedBy("SALARY_INDEX") +``` ### in @@ -1025,10 +1023,10 @@ Sets the **RdbPredicates** to match the field with data type **Array<ValueTy | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.in("AGE", [18, 20]) - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.in("AGE", [18, 20]) +``` ### notIn @@ -1053,10 +1051,10 @@ Sets the **RdbPredicates** to match the field with data type **Array<ValueTy | [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.notIn("NAME", ["Lisa", "Rose"]) - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.notIn("NAME", ["Lisa", "Rose"]) +``` ## RdbStore @@ -1080,17 +1078,21 @@ Inserts a row of data into a table. This API uses a callback to return the resul | callback | AsyncCallback<number> | Yes| Callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| **Example** - ```js - const valueBucket = { - "NAME": "Lisa", - "AGE": 18, - "SALARY": 100.5, - "CODES": new Uint8Array([1, 2, 3, 4, 5]), - } - rdbStore.insert("EMPLOYEE", valueBucket, function (err, ret) { - console.log("insert first done: " + ret) - }) - ``` +```js +const valueBucket = { + "NAME": "Lisa", + "AGE": 18, + "SALARY": 100.5, + "CODES": new Uint8Array([1, 2, 3, 4, 5]), +} +rdbStore.insert("EMPLOYEE", valueBucket, function (err, ret) { + if (err) { + console.info("Insert failed, err: " + err) + return + } + console.log("Insert first done: " + ret) +}) +``` ### insert @@ -1113,20 +1115,20 @@ Inserts a row of data into a table. This API uses a promise to return the result | Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| **Example** - ```js - const valueBucket = { - "NAME": "Lisa", - "AGE": 18, - "SALARY": 100.5, - "CODES": new Uint8Array([1, 2, 3, 4, 5]), - } - let promiseinsert = rdbStore.insert("EMPLOYEE", valueBucket) - promiseinsert.then(async (ret) => { - console.log("insert first done: " + ret) - }).catch((err) => { - console.log("insert err.") - }) - ``` +```js +const valueBucket = { + "NAME": "Lisa", + "AGE": 18, + "SALARY": 100.5, + "CODES": new Uint8Array([1, 2, 3, 4, 5]), +} +let promise = rdbStore.insert("EMPLOYEE", valueBucket) +promise.then(async (ret) => { + console.log("Insert first done: " + ret) +}).catch((err) => { + console.log("Insert failed, err: " + err) +}) +``` ### update @@ -1145,18 +1147,23 @@ Updates data in the database based on the specified RdbPredicates object. This A | callback | AsyncCallback<number> | Yes| Callback used to return the number of rows updated.| **Example** - ```js - const valueBucket = { - "NAME": "Rose", - "AGE": 22, - "SALARY": 200.5, - "CODES": new Uint8Array([1, 2, 3, 4, 5]), - } - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Lisa") - rdbStore.update(valueBucket, predicates, function (err, ret) { - console.log("updated row count: " + ret)}) - ``` +```js +const valueBucket = { + "NAME": "Rose", + "AGE": 22, + "SALARY": 200.5, + "CODES": new Uint8Array([1, 2, 3, 4, 5]), +} +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.equalTo("NAME", "Lisa") +rdbStore.update(valueBucket, predicates, function (err, ret) { + if (err) { + console.info("Updated failed, err: " + err) + return + } + console.log("Updated row count: " + ret) +}) +``` ### update @@ -1179,22 +1186,22 @@ Updates data in the database based on the specified RdbPredicates object. This A | Promise<number> | Promise used to return the number of rows updated.| **Example** - ```js - const valueBucket = { - "NAME": "Rose", - "AGE": 22, - "SALARY": 200.5, - "CODES": new Uint8Array([1, 2, 3, 4, 5]), - } - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Lisa") - let promiseupdate = rdbStore.update(valueBucket, predicates) - promiseupdate.then(async (ret) => { - console.log("updated row count: " + ret) - }).catch((err) => { - console.log("update err.") - }) - ``` +```js +const valueBucket = { + "NAME": "Rose", + "AGE": 22, + "SALARY": 200.5, + "CODES": new Uint8Array([1, 2, 3, 4, 5]), +} +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.equalTo("NAME", "Lisa") +let promise = rdbStore.update(valueBucket, predicates) +promise.then(async (ret) => { + console.log("Updated row count: " + ret) +}).catch((err) => { + console.info("Updated failed, err: " + err) +}) +``` ### delete @@ -1213,13 +1220,17 @@ Deletes data from the database based on the specified RdbPredicates object. This | callback | AsyncCallback<number> | Yes| Callback invoked to return the number of rows updated.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Lisa") - rdbStore.delete(predicates, function (err, rows) { - console.log("delete rows: " + rows) - }) - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.equalTo("NAME", "Lisa") +rdbStore.delete(predicates, function (err, rows) { + if (err) { + console.info("Delete failed, err: " + err) + return + } + console.log("Delete rows: " + rows) +}) +``` ### delete @@ -1241,16 +1252,16 @@ Deletes data from the database based on the specified RdbPredicates object. This | Promise<number> | Promise used to return the number of rows updated.| **Example** - ```js - let predicatesdelete = new data_rdb.RdbPredicates("EMPLOYEE") - predicatesdelete.equalTo("NAME", "Lisa") - let promisedelete = rdbStore.delete(predicates) - promisedelete.then((rows) => { - console.log("delete rows: " + rows) - }).catch((err) => { - console.log("delete err.") - }) - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.equalTo("NAME", "Lisa") +let promise = rdbStore.delete(predicates) +promise.then((rows) => { + console.log("Delete rows: " + rows) +}).catch((err) => { + console.info("Delete failed, err: " + err) +}) +``` ### query @@ -1269,14 +1280,18 @@ Queries data in the database based on specified conditions. This API uses a call | callback | AsyncCallback<[ResultSet](js-apis-data-resultset.md)> | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| **Example** - ```js - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Rose") - rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) { - console.log("resultSet column names:" + resultSet.columnNames) - console.log("resultSet column count:" + resultSet.columnCount) - }) - ``` +```js +let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +predicates.equalTo("NAME", "Rose") +rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) { + if (err) { + console.info("Query failed, err: " + err) + return + } + console.log("resultSet column names:" + resultSet.columnNames) + console.log("resultSet column count:" + resultSet.columnCount) +}) +``` ### query @@ -1302,12 +1317,12 @@ Queries data in the database based on specified conditions. This API uses a prom ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.equalTo("NAME", "Rose") - let promisequery = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) - promisequery.then((resultSet) => { + let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) + promise.then((resultSet) => { console.log("resultSet column names:" + resultSet.columnNames) console.log("resultSet column count:" + resultSet.columnCount) }).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 | callback | AsyncCallback<[ResultSet](js-apis-data-resultset.md)> | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| **Example** - ```js - rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) { - console.log("resultSet column names:" + resultSet.columnNames) - console.log("resultSet column count:" + resultSet.columnCount) - }) - ``` +```js +rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) { + if (err) { + console.info("Query failed, err: " + err) + return + } + console.log("resultSet column names:" + resultSet.columnNames) + console.log("resultSet column count:" + resultSet.columnCount) +}) +``` ### querySql8+ @@ -1356,15 +1375,15 @@ Queries data in the RDB store using the specified SQL statement. This API uses a | Promise<[ResultSet](../apis/js-apis-data-resultset.md)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| **Example** - ```js - let promisequerySql = rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo']) - promisequerySql.then((resultSet) => { - console.log("resultSet column names:" + resultSet.columnNames) - console.log("resultSet column count:" + resultSet.columnCount) - }).catch((err) => { - console.log("querySql err.") - }) - ``` +```js +let promise = rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo']) +promise.then((resultSet) => { + console.log("resultSet column names:" + resultSet.columnNames) + console.log("resultSet column count:" + resultSet.columnCount) +}).catch((err) => { + console.info("Query failed, err: " + err) +}) +``` ### executeSql @@ -1383,11 +1402,16 @@ Runs the SQL statement that contains the specified parameters but does not retur | callback | AsyncCallback<void> | Yes| Callback invoked to return the result.| **Example** - ```js - rdbStore.executeSql("DELETE FROM EMPLOYEE", null, function () { - console.info('delete done.') - }) - ``` +```js +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)" +rdbStore.executeSql(SQL_CREATE_TABLE, null, function(err) { + if (err) { + console.info("executeSql failed, err: " + err) + return + } + console.info('create table done.') +}) +``` ### executeSql @@ -1410,14 +1434,15 @@ Runs the SQL statement that contains the specified parameters but does not retur | Promise<void> | Promise used to return the result.| **Example** - ```js - let promiseexecuteSql = rdbStore.executeSql("DELETE FROM EMPLOYEE") - promiseexecuteSql.then(() => { - console.info('delete done.') - }).catch((err) => { - console.log("executeSql err.") - }) - ``` +```js +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 = rdbStore.executeSql(SQL_CREATE_TABLE) +promise.then(() => { + console.info('create table done.') +}).catch((err) => { + console.info("ExecuteSql failed, err: " + err) +}) +``` ### beginTransaction8+ @@ -1429,17 +1454,21 @@ Starts the transaction before executing an SQL statement. **Example** ```js - rdbStore.beginTransaction() - const valueBucket = { - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": new Uint8Array([1, 2, 3]), - } - rdbStore.insert("test", valueBucket, function (err, ret) { - console.log("insert done: " + ret) - }) - rdbStore.commit() +rdbStore.beginTransaction() +const valueBucket = { + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": new Uint8Array([1, 2, 3]), +} +rdbStore.insert("test", valueBucket, function (err, ret) { + if (err) { + console.info("Insert failed, err: " + err) + return + } + console.log("Insert successfully: " + ret) +}) +rdbStore.commit() ``` @@ -1453,18 +1482,22 @@ Commits the executed SQL statements. **Example** ```js - rdbStore.beginTransaction() - const valueBucket = { - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": new Uint8Array([1, 2, 3]), - } - - rdbStore.insert("test", valueBucket, function (err, ret) { - console.log("insert done: " + ret) - }) - rdbStore.commit() +rdbStore.beginTransaction() +const valueBucket = { + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": new Uint8Array([1, 2, 3]), +} + +rdbStore.insert("test", valueBucket, function (err, ret) { + if (err) { + console.info("Insert failed, err: " + err) + return + } + console.log("Insert successfully: " + ret) +}) +rdbStore.commit() ``` @@ -1478,22 +1511,26 @@ Rolls back the SQL statements that have been executed. **Example** ```js - try { - rdbStore.beginTransaction() - const valueBucket = { - "id": 1, - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": new Uint8Array([1, 2, 3]), - } - rdbStore.insert("test", valueBucket, function (err, ret) { - console.log("insert done: " + ret) - }) - rdbStore.commit() - } catch (e) { - rdbStore.rollBack() - } +try { + rdbStore.beginTransaction() + const valueBucket = { + "id": 1, + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": new Uint8Array([1, 2, 3]), + } + rdbStore.insert("test", valueBucket, function (err, ret) { + if (err) { + console.info("Insert failed, err: " + err) + return + } + 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 | callback | AsyncCallback<void> | Yes| Callback invoked to return the result.| **Example** - ```js - rdbStore.setDistributedTables(["EMPLOYEE"], function (err) { - if (err) { - console.info('setDistributedTables failed.') - return - } - console.info('setDistributedTables success.') - }) +```js +rdbStore.setDistributedTables(["EMPLOYEE"], function (err) { + if (err) { + console.info('setDistributedTables failed, err: ' + err) + return + } + console.info('setDistributedTables successfully.') +}) ``` @@ -1542,14 +1579,14 @@ Sets a list of distributed tables. This API uses a promise to return the result. | Promise<void> | Promise used to return the result.| **Example** - ```js - let promiseset = rdbStore.setDistributedTables(["EMPLOYEE"]) - promiseset.then(() => { - console.info("setDistributedTables success.") - }).catch((err) => { - console.info("setDistributedTables failed.") - }) - ``` +```js +let promise = rdbStore.setDistributedTables(["EMPLOYEE"]) +promise.then(() => { + console.info("setDistributedTables successfully.") +}).catch((err) => { + console.info("setDistributedTables failed, err: " + err) +}) +``` ### obtainDistributedTableName8+ @@ -1567,15 +1604,15 @@ Obtains the distributed table name for a remote device based on the local table | callback | AsyncCallback<string> | Yes| Callback invoked to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| **Example** - ```js - rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) { - if (err) { - console.info('obtainDistributedTableName failed.') - return - } - console.info('obtainDistributedTableName success, tableName=.' + tableName) - }) - ``` +```js +rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) { + if (err) { + console.info('obtainDistributedTableName failed, err: ' + err) + return + } + console.info('obtainDistributedTableName successfully, tableName=.' + tableName) +}) +``` ### obtainDistributedTableName8+ @@ -1598,14 +1635,14 @@ Obtains the distributed table name for a remote device based on the local table | Promise<string> | Promise used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| **Example** - ```js - let promiseDistr = rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE") - promiseDistr.then((tableName) => { - console.info('obtainDistributedTableName success, tableName=' + tableName) - }).catch((err) => { - console.info('obtainDistributedTableName failed.') - }) - ``` +```js +let promise = rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE") +promise.then((tableName) => { + console.info('obtainDistributedTableName successfully, tableName=' + tableName) +}).catch((err) => { + console.info('obtainDistributedTableName failed, err: ' + err) +}) +``` ### sync8+ @@ -1623,20 +1660,20 @@ Synchronizes data between devices. This API uses a callback to return the result | callback | AsyncCallback<Array<[string, number]>> | Yes| Callback invoked to send the synchronization result to the caller.
**string** indicates the device ID.
**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. | **Example** - ```js - let predicate = new rdb.RdbPredicates('EMPLOYEE') - predicate.inDevices(['12345678abcde']) - rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH, predicate, function (err, result) { - if (err) { - console.log('sync failed') - return - } - console.log('sync done.') - for (let i = 0; i < result.length; i++) { - console.log('device=' + result[i][0] + ' status=' + result[i][1]) - } - }) - ``` +```js +let predicates = new rdb.RdbPredicates('EMPLOYEE') +predicates.inDevices(['12345678abcde']) +rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) { + if (err) { + console.log('sync failed, err: ' + err) + return + } + console.log('sync done.') + for (let i = 0; i < result.length; i++) { + console.log('device=' + result[i][0] + ' status=' + result[i][1]) + } +}) +``` ### sync8+ @@ -1660,19 +1697,19 @@ Synchronizes data between devices. This API uses a promise to return the result. | Promise<Array<[string, number]>> | Promise used to return the synchronization result to the caller.
**string** indicates the device ID.
**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. | **Example** - ```js - let predicatesync = new data_rdb.RdbPredicates('EMPLOYEE') - predicatesync.inDevices(['12345678abcde']) - let promisesync = rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicatesync) - promisesync.then((result) =>{ - console.log('sync done.') - for (let i = 0; i < result.length; i++) { - console.log('device=' + result[i][0] + ' status=' + result[i][1]) - } - }).catch((err) => { - console.log('sync failed') - }) - ``` +```js +let predicates = new data_rdb.RdbPredicates('EMPLOYEE') +predicates.inDevices(['12345678abcde']) +let promise = rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicates) +promise.then((result) =>{ + console.log('sync done.') + for (let i = 0; i < result.length; i++) { + console.log('device=' + result[i][0] + ' status=' + result[i][1]) + } +}).catch((err) => { + console.log('sync failed') +}) +``` ### on('dataChange')8+ @@ -1691,18 +1728,18 @@ Registers an observer for this RDB store. When the data in the RDB store changes | observer | Callback<Array<string>> | Yes| Observer that listens for the data changes in the RDB store.| **Example** - ```js - function storeObserver(devices) { - for (let i = 0; i < devices.length; i++) { - console.log('device=' + devices[i] + ' data changed') - } - } - try { - rdbStore.on('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) - } catch (err) { - console.log('register observer failed') - } - ``` +```js +function storeObserver(devices) { + for (let i = 0; i < devices.length; i++) { + console.log('device=' + devices[i] + ' data changed') + } +} +try { + rdbStore.on('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) +} catch (err) { + console.log('register observer failed') +} +``` ### off('dataChange')8+ @@ -1721,19 +1758,18 @@ Deletes the specified observer of the RDB store. This API uses a callback to ret | observer | Callback<Array<string>> | Yes| Data change observer registered.| **Example** - - ```js - function storeObserver(devices) { - for (let i = 0; i < devices.length; i++) { - console.log('device=' + devices[i] + ' data changed') - } - } - try { - rdbStore.off('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) - } catch (err) { - console.log('unregister observer failed') - } - ``` +```js +function storeObserver(devices) { + for (let i = 0; i < devices.length; i++) { + console.log('device=' + devices[i] + ' data changed') + } +} +try { + rdbStore.off('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) +} catch (err) { + console.log('unregister observer failed') +} +``` ## StoreConfig diff --git a/en/application-dev/reference/apis/js-apis-data-resultset.md b/en/application-dev/reference/apis/js-apis-data-resultset.md index 3dca6cfcb0..613e793255 100644 --- a/en/application-dev/reference/apis/js-apis-data-resultset.md +++ b/en/application-dev/reference/apis/js-apis-data-resultset.md @@ -1,6 +1,6 @@ # Result Set -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
+> **NOTE**
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. diff --git a/en/application-dev/reference/apis/js-apis-data-storage.md b/en/application-dev/reference/apis/js-apis-data-storage.md index 844b24576a..63ae9d95bc 100644 --- a/en/application-dev/reference/apis/js-apis-data-storage.md +++ b/en/application-dev/reference/apis/js-apis-data-storage.md @@ -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. -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
+> **NOTE**
> > - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > @@ -30,7 +30,7 @@ import dataStorage from '@ohos.data.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 @@ -67,7 +67,7 @@ Reads a file and loads the data to the **Storage** instance in synchronous mode. getStorage(path: string, callback: AsyncCallback<Storage>): void -Reads a file and loads the data to the **Storage** instance. This 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 @@ -105,7 +105,7 @@ Reads a file and loads the data to the **Storage** instance. This API uses an as getStorage(path: string): Promise<Storage> -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 @@ -146,7 +146,7 @@ Reads a file and loads the data to the **Storage** instance. This API uses a pro 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 @@ -165,7 +165,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete deleteStorage(path: string, callback: AsyncCallback<void>): void -Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This 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 @@ -191,7 +191,7 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete deleteStorage(path: string): Promise<void> -Deletes the singleton **Storage** instance of a file from the memory, and deletes the specified file, its backup file, and damaged files. After the specified files are deleted, the **Storage** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This 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 @@ -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. -This API uses a synchronous mode. - **System capability**: SystemCapability.DistributedDataManager.Preferences.Core **Parameters** @@ -241,9 +239,7 @@ This API uses a synchronous mode. removeStorageFromCache(path: string, callback: AsyncCallback<void>): void -Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur. - -This API uses an asynchronous callback to return the result. +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. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core @@ -269,9 +265,7 @@ This API uses an asynchronous callback to return the result. removeStorageFromCache(path: string): Promise<void> -Removes the singleton **Storage** instance of a file from the cache. The removed instance cannot be used for data operations. Otherwise, data inconsistency will occur. - -This API uses a promise to return the result. +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. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core @@ -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. -This API uses a synchronous mode. - **System capability**: SystemCapability.DistributedDataManager.Preferences.Core **Parameters** @@ -333,9 +325,7 @@ This API uses a synchronous mode. get(key: string, defValue: ValueType, callback: AsyncCallback<ValueType>): 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. - -This API uses an asynchronous callback to return the result. +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. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core @@ -362,9 +352,7 @@ This API uses an asynchronous callback to return the result. get(key: string, defValue: ValueType): Promise<ValueType> -Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. - -This API uses a promise to return the result. +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. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core @@ -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()**. -This API uses a synchronous mode. - **System capability**: SystemCapability.DistributedDataManager.Preferences.Core **Parameters** @@ -417,9 +403,7 @@ This API uses a synchronous mode. put(key: string, value: ValueType, callback: AsyncCallback<void>): void -Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**. - -This API uses an asynchronous callback to return the result. +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. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core @@ -446,9 +430,7 @@ This API uses an asynchronous callback to return the result. put(key: string, value: ValueType): Promise<void> -Obtains the **Storage** instance corresponding to the specified file, writes data to the **Storage** instance using a **Storage** API, and saves the modification using **flush()** or **flushSync()**. - -This API uses a promise to return the result. +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. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core @@ -480,8 +462,6 @@ hasSync(key: string): boolean Checks whether the storage object contains data with a given key. -This API uses a synchronous mode. - **System capability**: SystemCapability.DistributedDataManager.Preferences.Core **Parameters** @@ -507,9 +487,7 @@ This API uses a synchronous mode. has(key: string, callback: AsyncCallback<boolean>): boolean -Checks whether the storage object contains data with a given key. - -This API uses an asynchronous callback to return the result. +Checks whether the storage object contains data with a given key. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core @@ -542,9 +520,7 @@ This API uses an asynchronous callback to return the result. has(key: string): Promise<boolean> -Checks whether the storage object contains data with a given key. - -This API uses a promise to return the result. +Checks whether the storage object contains data with a given key. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core @@ -577,8 +553,6 @@ deleteSync(key: string): void Deletes data with the specified key from this storage object. -This API uses a synchronous mode. - **System capability**: SystemCapability.DistributedDataManager.Preferences.Core **Parameters** @@ -592,13 +566,11 @@ This API uses a synchronous mode. ``` -### deletej +### delete delete(key: string, callback: AsyncCallback<void>): void -Deletes data with the specified key from this storage object. - -This API uses an asynchronous callback to return the result. +Deletes data with the specified key from this storage object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core @@ -624,9 +596,7 @@ This API uses an asynchronous callback to return the result. delete(key: string): Promise<void> -Deletes data with the specified key from this storage object. - -This API uses a promise to return the result. +Deletes data with the specified key from this storage object. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core @@ -657,8 +627,6 @@ flushSync(): void 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 **Example** @@ -671,9 +639,7 @@ This API uses a synchronous mode. flush(callback: AsyncCallback<void>): void -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. +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. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core @@ -698,9 +664,7 @@ This API uses an asynchronous callback to return the result. flush(): Promise<void> -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. +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. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core @@ -726,8 +690,6 @@ clearSync(): void Clears this **Storage** object. -This API uses a synchronous mode. - **System capability**: SystemCapability.DistributedDataManager.Preferences.Core **Example** @@ -740,9 +702,7 @@ This API uses a synchronous mode. clear(callback: AsyncCallback<void>): void -Clears this **Storage** object. - -This API uses an asynchronous callback to return the result. +Clears this **Storage** object. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core @@ -767,9 +727,7 @@ This API uses an asynchronous callback to return the result. clear(): Promise<void> -Clears this **Storage** object. - -This API uses a promise to return the result. +Clears this **Storage** object. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core diff --git a/en/application-dev/reference/apis/js-apis-distributed-data.md b/en/application-dev/reference/apis/js-apis-distributed-data.md index 8f5b800d57..6bbe4a0111 100644 --- a/en/application-dev/reference/apis/js-apis-distributed-data.md +++ b/en/application-dev/reference/apis/js-apis-distributed-data.md @@ -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. ->![](../../public_sys-resources/icon-note.gif) **NOTE**
+>**NOTE**
>The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -2922,6 +2922,7 @@ These value types can be used only by internal applications. | BOOLEAN |4 |Boolean. | | DOUBLE |5 |Double (double-precision floating point). | + ## 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. @@ -3447,7 +3448,7 @@ Closes the **KvStoreResultSet** object obtained by **getResultSet**. This API us | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | resultSet |[KvStoreResultSet](#kvstoreresultset8) | Yes |**KvStoreResultSet** object to close. | -| callback |AsyncCallback<void> | Yes |Callback used to return the execution result. | +| callback |AsyncCallback<void> | Yes |Callback used to return the result. | **Example** diff --git a/en/application-dev/reference/apis/js-apis-system-storage.md b/en/application-dev/reference/apis/js-apis-system-storage.md index d80bf1ea12..37e8dc5de7 100644 --- a/en/application-dev/reference/apis/js-apis-system-storage.md +++ b/en/application-dev/reference/apis/js-apis-system-storage.md @@ -1,6 +1,6 @@ # Data Storage -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
+> **NOTE**
> > - 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. | 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.| | 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.| -- GitLab