>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.
## Modules to Import<a name="s56d19203690d4782bfc74069abb6bd71"></a>
Obtains a relational database \(RDB\) store. You can set parameters for the RDB store based on service requirements, call APIs to perform data operations, and use a callback to return the result.
Obtains a relational database (RDB) store. You can set parameters for the RDB store based on service requirements, call APIs to perform data operations, and use a callback to return the result.
<td class="cellrowborder" valign="top" width="49.614822038030226%" headers="mcps1.1.5.1.4 "><p id="p9351151163112"><a name="p9351151163112"></a><a name="p9351151163112"></a>Callback invoked to return the RDB store.</p>
</td>
</tr>
</tbody>
</table>
- Example
- Example
```
```
import dataRdb from '@ohos.data.rdb'
import Ability from '@ohos.application.Ability'
import data_rdb from '@ohos.data.rdb'
export default class MainAbility extends Ability {
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)"
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)"
dataRdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) {
data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) {
Obtains an RDB store. You can set parameters for the RDB store based on service requirements, call APIs to perform data operations, and use a promise to return the result.
Obtains an RDB store. You can set parameters for the RDB store based on service requirements, call APIs to perform data operations, and use a promise to return the result.
- Parameters
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| context | Context | Yes| Context of the app or functionality.|
| config | [StoreConfig](#storeconfig) | Yes| Configuration of the RDB store.|
<td class="cellrowborder" valign="top" width="69.56%" headers="mcps1.1.3.1.2 "><p id="p9368840152411"><a name="p9368840152411"></a><a name="p9368840152411"></a>Promise used to return the RDB store.</p>
</td>
</tr>
</tbody>
</table>
- Example
- Example
```
```
import dataRdb from '@ohos.data.rdb'
import Ability from '@ohos.application.Ability'
import data_rdb from '@ohos.data.rdb'
export default class MainAbility extends Ability {
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)"
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 = dataRdb.getRdbStore(STORE_CONFIG, 1);
let promise = data_rdb.getRdbStore(this.context, STORE_CONFIG, 1);
| callback | AsyncCallback<void> | Yes| Callback invoked to return the result. If the RDB store is deleted, **true** will be returned. Otherwise, **false** will be returned.|
<td class="cellrowborder" valign="top" width="60.360799609946355%" headers="mcps1.1.5.1.4 "><p id="p7722105418272"><a name="p7722105418272"></a><a name="p7722105418272"></a>Name of the RDB store to delete.</p>
<td class="cellrowborder" valign="top" width="60.360799609946355%" headers="mcps1.1.5.1.4 "><p id="p3473123212716"><a name="p3473123212716"></a><a name="p3473123212716"></a>Callback invoked to return the result. If the RDB store is deleted, <strong id="b1271976267"><a name="b1271976267"></a><a name="b1271976267"></a>true</strong> will be returned. Otherwise, <strong id="b1729162013266"><a name="b1729162013266"></a><a name="b1729162013266"></a>false</strong> will be returned.</p>
</td>
</tr>
</tbody>
</table>
- Example
- Example
```
```
import dataRdb from '@ohos.data.rdb'
import Ability from '@ohos.application.Ability'
dataRdb.deleteRdbStore("RdbTest.db", function (err, rdbStore) {
import data_rdb from '@ohos.data.rdb'
export default class MainAbility extends Ability {
data_rdb.deleteRdbStore(this.context, "RdbTest.db", function (err, rdbStore) {
| Promise<void> | Promise used to return the result. If the RDB store is deleted, **true** will be returned. Otherwise, **false** will be returned.|
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p157012058162714"><a name="p157012058162714"></a><a name="p157012058162714"></a>Name of the RDB store to delete.</p>
<td class="cellrowborder" valign="top" width="69.56%" headers="mcps1.1.3.1.2 "><p id="p11918175962910"><a name="p11918175962910"></a><a name="p11918175962910"></a>Promise used to return the result. If the RDB store is deleted, <strong id="b139941828205711"><a name="b139941828205711"></a><a name="b139941828205711"></a>true</strong> will be returned. Otherwise, <strong id="b13782985717"><a name="b13782985717"></a><a name="b13782985717"></a>false</strong> will be returned.</p>
</td>
</tr>
</tbody>
</table>
- Example
- Example
```
```
import dataRdb from '@ohos.data.rdb'
import Ability from '@ohos.application.Ability'
let promise = dataRdb.deleteRdbStore("RdbTest.db")
import data_rdb from '@ohos.data.rdb'
export default class MainAbility extends Ability {
let promise = data_rdb.deleteRdbStore(this.context, "RdbTest.db")
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p13948172810562"><a name="p13948172810562"></a><a name="p13948172810562"></a>Column name in the database table.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p16532133810511"><a name="p16532133810511"></a><a name="p16532133810511"></a>Column name in the database table.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p1595612471811"><a name="p1595612471811"></a><a name="p1595612471811"></a>Column name in the database table.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p35911455102217"><a name="p35911455102217"></a><a name="p35911455102217"></a>Column name in the database table.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p17593942142517"><a name="p17593942142517"></a><a name="p17593942142517"></a>Column name in the database table.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p1996411246271"><a name="p1996411246271"></a><a name="p1996411246271"></a>Column name in the database table.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p1529081319307"><a name="p1529081319307"></a><a name="p1529081319307"></a>Column name in the database table.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p201222193217"><a name="p201222193217"></a><a name="p201222193217"></a>Column name in the database table.</p>
Sets the **RdbPredicates** to match the specified string.
Sets the **RdbPredicates** to match the specified string.
- Parameters
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| value | string | Yes| Value to match the **RdbPredicates**. <br>Wildcards are supported. ***** indicates zero, one, or multiple digits or characters. **?** indicates a single digit or character.|
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p12823846193519"><a name="p12823846193519"></a><a name="p12823846193519"></a>Column name in the database table.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p11585122912376"><a name="p11585122912376"></a><a name="p11585122912376"></a>Column name in the database table.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p65868296372"><a name="p65868296372"></a><a name="p65868296372"></a>Minimum value to match the <strong id="b14859186102319"><a name="b14859186102319"></a><a name="b14859186102319"></a>RdbPredicates</strong>.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p2022844615374"><a name="p2022844615374"></a><a name="p2022844615374"></a>Maximum value to match the <strong id="b49418293236"><a name="b49418293236"></a><a name="b49418293236"></a>RdbPredicates</strong>.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p1981444134313"><a name="p1981444134313"></a><a name="p1981444134313"></a>Column name in the database table.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p1381844194316"><a name="p1381844194316"></a><a name="p1381844194316"></a>Minimum value to match the <strong id="b14792430192610"><a name="b14792430192610"></a><a name="b14792430192610"></a>RdbPredicates</strong>.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p88354494313"><a name="p88354494313"></a><a name="p88354494313"></a>Maximum value to match the <strong id="b1097254010269"><a name="b1097254010269"></a><a name="b1097254010269"></a>RdbPredicates</strong>.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p1691124318464"><a name="p1691124318464"></a><a name="p1691124318464"></a>Column name in the database table.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p113631950154917"><a name="p113631950154917"></a><a name="p113631950154917"></a>Column name in the database table.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p514164619518"><a name="p514164619518"></a><a name="p514164619518"></a>Column name in the database table.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p17334204215534"><a name="p17334204215534"></a><a name="p17334204215534"></a>Column name in the database table.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p68841111195510"><a name="p68841111195510"></a><a name="p68841111195510"></a>Column name in the database table.</p>
<td class="cellrowborder" valign="top" width="69.56%" headers="mcps1.1.3.1.2 "><p id="p77969322566"><a name="p77969322566"></a><a name="p77969322566"></a><strong id="b5671449111214"><a name="b5671449111214"></a><a name="b5671449111214"></a>RdbPredicates</strong> object that matches the column with values sorted in the specified order.</p>
</td>
</tr>
</tbody>
</table>
- Example
- Example
```
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p1387316305811"><a name="p1387316305811"></a><a name="p1387316305811"></a>Column name in the database table.</p>
<td class="cellrowborder" valign="top" width="69.56%" headers="mcps1.1.3.1.2 "><p id="p1987416318588"><a name="p1987416318588"></a><a name="p1987416318588"></a><strong id="b196751495120"><a name="b196751495120"></a><a name="b196751495120"></a>RdbPredicates</strong> object that matches the column with values sorted in the specified order.</p>
</td>
</tr>
</tbody>
</table>
- Example
- Example
```
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.orderByDesc("AGE")
predicates.orderByDesc("AGE")
```
```
### distinct<a name="section45891667519"></a>
### distinct
distinct(): RdbPredicates
distinct\(\): RdbPredicates
Sets the **RdbPredicates** to filter out duplicate records.
Sets the **RdbPredicates** to filter out duplicate records.
<td class="cellrowborder" valign="top" width="69.56%" headers="mcps1.1.3.1.2 "><p id="p1556711111755"><a name="p1556711111755"></a><a name="p1556711111755"></a><strong id="b8722115093117"><a name="b8722115093117"></a><a name="b8722115093117"></a>RdbPredicates</strong> object that specifies the maximum number of records.</p>
</td>
</tr>
</tbody>
</table>
- Example
- Example
```
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose").limitAs(3)
predicates.equalTo("NAME", "Rose").limitAs(3)
```
```
### offsetAs<a name="section73879413300"></a>
### offsetAs
offsetAs(rowOffset: number): RdbPredicates
offsetAs\(rowOffset: number\): RdbPredicates
Sets the **RdbPredicates** to specify the start position of the returned result.
Sets the **RdbPredicates** to specify the start position of the returned result.
- Parameters
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| rowOffset | number | Yes| Number of rows to offset from the beginning. The value is a positive integer.|
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p643616810715"><a name="p643616810715"></a><a name="p643616810715"></a>Number of rows to offset from the beginning. The value is a positive integer.</p>
<td class="cellrowborder" valign="top" width="69.56%" headers="mcps1.1.3.1.2 "><p id="p1259123415819"><a name="p1259123415819"></a><a name="p1259123415819"></a><strong id="b1293220983814"><a name="b1293220983814"></a><a name="b1293220983814"></a>RdbPredicates</strong> object that specifies the start position of the returned result.</p>
</td>
</tr>
</tbody>
</table>
- Example
- Example
```
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
<td class="cellrowborder" valign="top" width="69.56%" headers="mcps1.1.3.1.2 "><p id="p158461234133315"><a name="p158461234133315"></a><a name="p158461234133315"></a><strong id="b16445510428"><a name="b16445510428"></a><a name="b16445510428"></a>RdbPredicates</strong> object that groups rows with the same value.</p>
</td>
</tr>
</tbody>
</table>
- Example
- Example
```
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.groupBy(["AGE", "NAME"])
predicates.groupBy(["AGE", "NAME"])
```
```
### indexedBy<a name="section1874631393616"></a>
### indexedBy
indexedBy(indexName: string): RdbPredicates
indexedBy\(indexName: string\): RdbPredicates
Sets the **RdbPredicates** object to specify the index column.
Sets the **RdbPredicates** object to specify the index column.
- Parameters
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| indexName | string | Yes| Name of the index column.|
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p654944414119"><a name="p654944414119"></a><a name="p654944414119"></a>Name of the index column.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p163145220191"><a name="p163145220191"></a><a name="p163145220191"></a>Column name in the database table.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p4140741183519"><a name="p4140741183519"></a><a name="p4140741183519"></a>Column name in the database table.</p>
| 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.|
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p124921153185019"><a name="p124921153185019"></a><a name="p124921153185019"></a>Row of data to insert.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p742233425213"><a name="p742233425213"></a><a name="p742233425213"></a>Callback invoked to return the result. If the operation is successful, the row ID will be returned. If the operation fails, <strong id="b122361652125110"><a name="b122361652125110"></a><a name="b122361652125110"></a>-1</strong> will be returned.</p>
</td>
</tr>
</tbody>
</table>
- Example
- Example
```
```
const valueBucket = {
const valueBucket = {
"NAME": "Lisa",
"NAME": "Lisa",
...
@@ -1979,66 +940,24 @@ Inserts a row of data into a table. This method uses a callback to return the re
...
@@ -1979,66 +940,24 @@ Inserts a row of data into a table. This method uses a callback to return the re
| Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p673516184593"><a name="p673516184593"></a><a name="p673516184593"></a>Row of data to insert.</p>
<td class="cellrowborder" valign="top" width="69.56%" headers="mcps1.1.3.1.2 "><p id="p966518169235"><a name="p966518169235"></a><a name="p966518169235"></a>Promise used to return the result. If the operation is successful, the row ID will be returned. If the operation fails, <strong id="b3817192716336"><a name="b3817192716336"></a><a name="b3817192716336"></a>-1</strong> will be returned.</p>
</td>
</tr>
</tbody>
</table>
- Example
- Example
```
```
const valueBucket = {
const valueBucket = {
"NAME": "Lisa",
"NAME": "Lisa",
...
@@ -2053,57 +972,20 @@ Inserts a row of data into a table. This method uses a promise to return the res
...
@@ -2053,57 +972,20 @@ Inserts a row of data into a table. This method uses a promise to return the res
| 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.|
</th>
| rdbPredicates | [RdbPredicates](#rdbpredicates) | Yes| Row of data to insert.|
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p115701665813"><a name="p115701665813"></a><a name="p115701665813"></a>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.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p142261739615"><a name="p142261739615"></a><a name="p142261739615"></a>Row of data to insert.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p4162947172417"><a name="p4162947172417"></a><a name="p4162947172417"></a>Callback used to return the number of rows updated.</p>
</td>
</tr>
</tbody>
</table>
- Example
- Example
```
```
const valueBucket = {
const valueBucket = {
"NAME": "Rose",
"NAME": "Rose",
...
@@ -2111,73 +993,31 @@ Updates data in the database based on the specified **RdbPredicates** object.
...
@@ -2111,73 +993,31 @@ Updates data in the database based on the specified **RdbPredicates** object.
"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 dataRdb.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) {
Updates data in the database based on the specified **RdbPredicates** object. This method uses a promise to return the result.
Updates data in the database based on the specified RdbPredicates object. This method uses a promise to return the result.
- Parameters
- Parameters
| 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.|
| rdbPredicates | [RdbPredicates](#rdbpredicates) | Yes| Row of data to insert.|
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p1690919394126"><a name="p1690919394126"></a><a name="p1690919394126"></a>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.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p12910739101212"><a name="p12910739101212"></a><a name="p12910739101212"></a>Row of data to insert.</p>
<td class="cellrowborder" valign="top" width="69.56%" headers="mcps1.1.3.1.2 "><p id="p1752322401217"><a name="p1752322401217"></a><a name="p1752322401217"></a>Promise used to return the number of rows updated.</p>
</td>
</tr>
</tbody>
</table>
- Example
- Example
```
```
const valueBucket = {
const valueBucket = {
"NAME": "Rose",
"NAME": "Rose",
...
@@ -2185,7 +1025,7 @@ Updates data in the database based on the specified **RdbPredicates** object.
...
@@ -2185,7 +1025,7 @@ Updates data in the database based on the specified **RdbPredicates** object.
"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 dataRdb.RdbPredicates("EMPLOYEE")
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa")
predicates.equalTo("NAME", "Lisa")
let promise = rdbStore.update(valueBucket, predicates)
let promise = rdbStore.update(valueBucket, predicates)
promise.then(async (ret) => {
promise.then(async (ret) => {
...
@@ -2194,108 +1034,48 @@ Updates data in the database based on the specified **RdbPredicates** object.
...
@@ -2194,108 +1034,48 @@ Updates data in the database based on the specified **RdbPredicates** object.
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p5850183112010"><a name="p5850183112010"></a><a name="p5850183112010"></a>Callback invoked to return the number of rows deleted.</p>
<td class="cellrowborder" valign="top" width="69.56%" headers="mcps1.1.3.1.2 "><p id="p141862692016"><a name="p141862692016"></a><a name="p141862692016"></a>Promise used to return the number of rows deleted.</p>
</td>
</tr>
</tbody>
</table>
- Example
- Example
```
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa")
predicates.equalTo("NAME", "Lisa")
let promise = rdbStore.delete(predicates)
let promise = rdbStore.delete(predicates)
promise.then((rows) => {
promise.then((rows) => {
...
@@ -2304,59 +1084,22 @@ Deletes data from the database based on the specified **RdbPredicates** object
...
@@ -2304,59 +1084,22 @@ Deletes data from the database based on the specified **RdbPredicates** object
| 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.|
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p1140502514190"><a name="p1140502514190"></a><a name="p1140502514190"></a>Columns to query. If this parameter is not specified, the query applies to all columns.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p97851358184916"><a name="p97851358184916"></a><a name="p97851358184916"></a>Callback invoked to return the result. If the operation is successful, a <strong id="b987410446454"><a name="b987410446454"></a><a name="b987410446454"></a>ResultSet</strong> object will be returned.</p>
</td>
</tr>
</tbody>
</table>
- Example
- Example
```
```
let predicates = new dataRdb.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) {
| 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.|
<td class="cellrowborder" valign="top" width="59.76596782057533%" headers="mcps1.1.5.1.4 "><p id="p129372299204"><a name="p129372299204"></a><a name="p129372299204"></a>Columns to query. If this parameter is not specified, the query applies to all columns.</p>
<td class="cellrowborder" valign="top" width="82.99%" headers="mcps1.1.3.1.2 "><p id="p13207156165218"><a name="p13207156165218"></a><a name="p13207156165218"></a>Promise used to return the result. If the operation is successful, a <strong id="b58428584715"><a name="b58428584715"></a><a name="b58428584715"></a>ResultSet</strong> object will be returned.</p>
</td>
</tr>
</tbody>
</table>
- Example
- Example
```
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose")
predicates.equalTo("NAME", "Rose")
let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
promise.then((resultSet) => {
promise.then((resultSet) => {
...
@@ -2433,211 +1135,357 @@ Queries data in the database based on specified conditions. This method uses a p
...
@@ -2433,211 +1135,357 @@ Queries data in the database based on specified conditions. This method uses a p
Runs the SQL statement that contains the specified parameters but does not return a value. This method uses a callback to return the execution result.
Queries data in the RDB store using the specified SQL statement. This method uses a callback to return the result.
- Parameters
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.|
| bindArgs | Array<[ValueType](#valuetype)> | Yes| Values of the parameters 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.|
- Example
```
rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) {
<td class="cellrowborder" valign="top" width="59.76596782057533%" headers="mcps1.1.5.1.4 "><p id="p1890095820554"><a name="p1890095820554"></a><a name="p1890095820554"></a>Values of the parameters in the SQL statement.</p>
<td class="cellrowborder" valign="top" width="59.76596782057533%" headers="mcps1.1.5.1.4 "><p id="p26551149115616"><a name="p26551149115616"></a><a name="p26551149115616"></a>Callback invoked to return the result.</p>
</td>
</tr>
</tbody>
</table>
Queries data in the RDB store using the specified SQL statement. This method uses a promise to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.|
| bindArgs | Array<[ValueType](#valuetype)> | No| Values of the parameters in the SQL statement.|
- Return value
| 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.|
- Example
- Example
```
let promise = rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'])
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p15628721142612"><a name="p15628721142612"></a><a name="p15628721142612"></a>Values of the parameters in the SQL statement.</p>
<td class="cellrowborder" valign="top" width="82.99%" headers="mcps1.1.3.1.2 "><p id="p3871251119"><a name="p3871251119"></a><a name="p3871251119"></a>Promise used to return the result.</p>
</td>
</tr>
</tbody>
</table>
- Example
- Example
```
```
let promise = rdbStore.executeSql("DELETE FROM EMPLOYEE")
let promise = rdbStore.executeSql("DELETE FROM EMPLOYEE")
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 method uses a callback to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| device | string | Yes| Remote device.|
| table | string | Yes| Local table name.|
| 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
```
rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) {
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 method uses a promise to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| device | string | Yes| Remote device.|
| table | string | Yes| Local table name.|
## StoreConfig<a name="section957124521217"></a>
- Return value
| Type| Description|
| -------- | -------- |
| Promise<string> | Promise used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.|
- Example
```
let promise = rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE")
Synchronizes data between devices. This method uses a callback to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| mode | SyncMode | Yes| Data synchronization mode, which can be **push** or **pull**.|
| predicates | 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. |
- Example
```
let predicate = new rdb.RdbPredicates('EMPLOYEE')
predicate.inDevices(['12345678abcde'])
rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH, predicate, function (err, result) {
Synchronizes data between devices. This method uses a promise to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| mode | SyncMode | Yes| Data synchronization mode, which can be **push** or **pull**.|
| predicates | RdbPredicates | Yes| **RdbPredicates** object that specifies the data and devices to synchronize.|
- Return value
| 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. |
- Example
```
let predicate = new rdb.RdbPredicates('EMPLOYEE')
predicate.inDevices(['12345678abcde'])
let promise = rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH, predicate)