@@ -4,10 +4,10 @@ The relational database (RDB) manages data based on relational models. With the
...
@@ -4,10 +4,10 @@ The relational database (RDB) manages data based on relational models. With the
This module provides the following RDB-related functions:
This module provides the following RDB-related functions:
-[RdbPredicates](#rdbpredicates): predicates indicating the nature, feature, or relationship of a data entity in an RDB store. It is used to define the operation conditions for an RDB store.
-[RdbPredicates](#rdbpredicates): provides predicates indicating the nature, feature, or relationship of a data entity in an RDB store. It is used to define the operation conditions for an RDB store.
-[RdbStore](#rdbstore): provides APIs for managing an RDB store.
-[RdbStore](#rdbstore): provides APIs for managing an RDB store.
> **NOTE**
> **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.
Obtains an RDB store. This API uses a promise to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations.
Obtains an RDB store. This API uses a promise to return the result. You can set parameters for the RDB store based on service requirements, and then call APIs to perform data operations.
Before using the following APIs, use [executeSql](#executesql) to initialize the database table structure and related data. For details, see [RDB Development](../../database/database-relational-guidelines.md).
### insert
### insert
...
@@ -984,7 +986,7 @@ rdbStore.insert("EMPLOYEE", valueBucket, function (err, ret) {
...
@@ -984,7 +986,7 @@ rdbStore.insert("EMPLOYEE", valueBucket, function (err, ret) {
@@ -1037,7 +1039,7 @@ Updates data in the database based on the specified RdbPredicates object. This A
...
@@ -1037,7 +1039,7 @@ Updates data in the database based on the specified RdbPredicates object. This A
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| values | [ValuesBucket](#valuesbucket) | Yes| Data to update. The value specifies the row of data to be updated in the database. The key-value pair is associated with the column name in the target table.|
| values | [ValuesBucket](#valuesbucket) | Yes| Data to update. The value specifies the row of data to be updated in the database. The key-value pair is associated with the column name in the target table.|
| rdbPredicates | [RdbPredicates](#rdbpredicates) | Yes| Row of data to insert.|
| rdbPredicates | [RdbPredicates](#rdbpredicates) | Yes| Update conditions specified by the **RdbPredicates** object.|
| callback | AsyncCallback<number> | Yes| Callback invoked to return the number of rows updated.|
| callback | AsyncCallback<number> | Yes| Callback invoked to return the number of rows updated.|
**Example**
**Example**
...
@@ -1064,7 +1066,7 @@ rdbStore.update(valueBucket, predicates, function (err, ret) {
...
@@ -1064,7 +1066,7 @@ rdbStore.update(valueBucket, predicates, function (err, ret) {
@@ -1072,7 +1074,7 @@ Updates data in the database based on the specified RdbPredicates object. This A
...
@@ -1072,7 +1074,7 @@ Updates data in the database based on the specified RdbPredicates object. This A
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| values | [ValuesBucket](#valuesbucket) | Yes| Data to update. The value specifies the row of data to be updated in the database. The key-value pair is associated with the column name in the target table.|
| values | [ValuesBucket](#valuesbucket) | Yes| Data to update. The value specifies the row of data to be updated in the database. The key-value pair is associated with the column name in the target table.|
| rdbPredicates | [RdbPredicates](#rdbpredicates) | Yes| Row of data to insert.|
| rdbPredicates | [RdbPredicates](#rdbpredicates) | Yes| Update conditions specified by the **RdbPredicates** object.|
@@ -1205,7 +1207,7 @@ Queries data in the database based on specified conditions. This API uses a prom
...
@@ -1205,7 +1207,7 @@ Queries data in the database based on specified conditions. This API uses a prom
**Return value**
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| -------- | -------- |
| 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.|
| Promise<[ResultSet](js-apis-data-resultset.md)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|
**Example**
**Example**
```js
```js
...
@@ -1233,7 +1235,7 @@ Queries data in the RDB store using the specified SQL statement. This API uses a
...
@@ -1233,7 +1235,7 @@ Queries data in the RDB store using the specified SQL statement. This API uses a
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.|
| sql | string | Yes| SQL statement to run.|
| bindArgs | Array<[ValueType](#valuetype)> | Yes| Values of the parameters in the SQL statement.|
| bindArgs | Array<[ValueType](#valuetype)> | Yes| Arguments in the SQL statement.|
| 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.|
| 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**
**Example**
...
@@ -1261,12 +1263,12 @@ Queries data in the RDB store using the specified SQL statement. This API uses a
...
@@ -1261,12 +1263,12 @@ Queries data in the RDB store using the specified SQL statement. This API uses a
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.|
| sql | string | Yes| SQL statement to run.|
| bindArgs | Array<[ValueType](#valuetype)> | No| Values of the parameters in the SQL statement.|
| bindArgs | Array<[ValueType](#valuetype)> | No| Arguments in the SQL statement.|
**Return value**
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| -------- | -------- |
| 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.|
| Promise<[ResultSet](js-apis-data-resultset.md)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|
**Example**
**Example**
```js
```js
...
@@ -1292,7 +1294,7 @@ Runs the SQL statement that contains the specified parameters but does not retur
...
@@ -1292,7 +1294,7 @@ Runs the SQL statement that contains the specified parameters but does not retur
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.|
| sql | string | Yes| SQL statement to run.|
| bindArgs | Array<[ValueType](#valuetype)> | Yes| Values of the parameters in the SQL statement.|
| bindArgs | Array<[ValueType](#valuetype)> | Yes| Arguments in the SQL statement.|
| callback | AsyncCallback<void> | Yes| Callback invoked to return the result.|
| callback | AsyncCallback<void> | Yes| Callback invoked to return the result.|
@@ -1320,7 +1322,7 @@ Runs the SQL statement that contains the specified parameters but does not retur
...
@@ -1320,7 +1322,7 @@ Runs the SQL statement that contains the specified parameters but does not retur
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.|
| sql | string | Yes| SQL statement to run.|
| bindArgs | Array<[ValueType](#valuetype)> | No| Values of the parameters in the SQL statement.|
| bindArgs | Array<[ValueType](#valuetype)> | No| Arguments in the SQL statement.|
**Return value**
**Return value**
| Type| Description|
| Type| Description|
...
@@ -1332,7 +1334,7 @@ Runs the SQL statement that contains the specified parameters but does not retur
...
@@ -1332,7 +1334,7 @@ Runs the SQL statement that contains the specified parameters but does not retur
constSQL_CREATE_TABLE="CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
constSQL_CREATE_TABLE="CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
letpromise=rdbStore.executeSql(SQL_CREATE_TABLE)
letpromise=rdbStore.executeSql(SQL_CREATE_TABLE)
promise.then(()=>{
promise.then(()=>{
console.info('create table done.')
console.info('Created table successfully.')
}).catch((err)=>{
}).catch((err)=>{
console.info("Failed to execute SQL, err: "+err)
console.info("Failed to execute SQL, err: "+err)
})
})
...
@@ -1449,7 +1451,7 @@ rdbStore.setDistributedTables(["EMPLOYEE"], function (err) {
...
@@ -1449,7 +1451,7 @@ rdbStore.setDistributedTables(["EMPLOYEE"], function (err) {
console.info('Failed to set distributed tables, err: '+err)
console.info('Failed to set distributed tables, err: '+err)
Obtains the distributed table name for a remote device based on the local table name. The distributed table name is required when the database of a remote device is queried. This API uses an asynchronous callback to return the result.
Obtains the distributed table name for a remote device based on the local table name. This API uses an asynchronous callback to return the result. The distributed table name is required when the database of a remote device is queried.
Obtains the distributed table name for a remote device based on the local table name. The distributed table name is required when the database of a remote device is queried. This API uses a promise to return the result.
Obtains the distributed table name for a remote device based on the local table name. This API uses a promise to return the result. The distributed table name is used to query the RDB store of the remote device.
console.info('Failed to obtain DistributedTableName, err: '+err)
console.info('Failed to obtain DistributedTableName, err: '+err)
})
})
...
@@ -1551,7 +1553,7 @@ Synchronizes data between devices. This API uses an asynchronous callback to ret
...
@@ -1551,7 +1553,7 @@ Synchronizes data between devices. This API uses an asynchronous callback to ret
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| mode | [SyncMode](#syncmode8) | Yes| Data synchronization mode. The value can be **push** or **pull**.|
| mode | [SyncMode](#syncmode8) | Yes| Data synchronization mode. The value can be **push** or **pull**.|
| predicates | [RdbPredicates](#rdbpredicates) | Yes| **RdbPredicates** object that specifies the data and devices to synchronize.|
| predicates | [RdbPredicates](#rdbpredicates) | Yes| **RdbPredicates** object that specifies the data and devices to synchronize.|
| callback | AsyncCallback<Array<[string, number]>> | Yes| Callback invoked to send the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
| callback | AsyncCallback<Array<[string, number]>> | Yes| Callback invoked to send the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
**Example**
**Example**
```js
```js
...
@@ -1588,7 +1590,7 @@ Synchronizes data between devices. This API uses a promise to return the result.
...
@@ -1588,7 +1590,7 @@ Synchronizes data between devices. This API uses a promise to return the result.
| Type| Description|
| Type| Description|
| -------- | -------- |
| -------- | -------- |
| Promise<Array<[string, number]>> | 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<Array<[string, number]>> | Promise used to return the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |