js-apis-data-rdb.md 55.2 KB
Newer Older
1
# Relational Database
Z
zengyawen 已提交
2

A
Annie_wang 已提交
3
> **NOTE**<br/>
A
annie_wangli 已提交
4
> 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.
Z
zengyawen 已提交
5

A
annie_wangli 已提交
6
## Modules to Import
Z
zengyawen 已提交
7

A
Annie_wang 已提交
8 9
```js
import data_rdb from '@ohos.data.rdb';
Z
zengyawen 已提交
10
```
A
annie_wangli 已提交
11 12 13

## data_rdb.getRdbStore

A
Annie_wang 已提交
14
getRdbStore(config: StoreConfig, version: number, callback: AsyncCallback&lt;RdbStore&gt;): void
A
annie_wangli 已提交
15

A
Annie_wang 已提交
16
Obtains a relational database (RDB) store. This API uses an asynchronous callback to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations.
A
annie_wangli 已提交
17

A
annie_wangli 已提交
18
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
19

A
annie_wangli 已提交
20
**Parameters**
A
Annie_wang 已提交
21

A
annie_wangli 已提交
22 23 24 25 26 27 28 29
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| config | [StoreConfig](#storeconfig) | Yes| Configuration of the RDB store.|
| version | number | Yes| RDB store version.|
| callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | Yes| Callback invoked to return the RDB store obtained.|

**Example**

A
Annie_wang 已提交
30
```js
A
annie_wangli 已提交
31 32 33
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) {
A
Annie_wang 已提交
34
    rdbStore.executeSql(SQL_CREATE_TABLE, null, function() {
A
annie_wangli 已提交
35
        console.info('create table done.')
A
Annie_wang 已提交
36 37
        })
})
A
annie_wangli 已提交
38
```
A
annie_wangli 已提交
39 40
## data_rdb.getRdbStore

A
Annie_wang 已提交
41
getRdbStore(config: StoreConfig, version: number): Promise&lt;RdbStore&gt;
Z
zengyawen 已提交
42

A
Annie_wang 已提交
43
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.
Z
zengyawen 已提交
44

A
annie_wangli 已提交
45
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
46

A
annie_wangli 已提交
47
**Parameters**
A
annie_wangli 已提交
48

A
annie_wangli 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| config | [StoreConfig](#storeconfig) | Yes| Configuration of the RDB store.|
| version | number | Yes| RDB store version.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise&lt;[RdbStore](#rdbstore)&gt; | Promise used to return the RDB store obtained.|

**Example**

A
Annie_wang 已提交
62
```js
A
annie_wangli 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
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.")
    })
}).catch((err) => {
    console.log("getRdbStore err.")
})
```


A
Annie_wang 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
## data_rdb.getRdbStore<sup>8+</sup>

getRdbStore(context: Context, config: StoreConfig, version: number, callback: AsyncCallback&lt;RdbStore&gt;): void

Obtains a relational database (RDB) store. This API uses an asynchronous callback to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| context<sup>8+</sup> | Context | Yes| Context of the app or functionality.<br>For the definition of **Context** of API version 8, see [Context](js-apis-Context.md).<br>For the definition of **Context** of API version 9, see [Context](js-apis-ability-context.md).|
| config | [StoreConfig](#storeconfig) | Yes| Configuration of the RDB store.|
| version | number | Yes| RDB store version.|
| callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | Yes| Callback invoked to return the RDB store obtained.|

**Example**

```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.')
        })    
})
A
annie_wangli 已提交
106
```
A
Annie_wang 已提交
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139

## data_rdb.getRdbStore<sup>8+</sup>

getRdbStore(context: Context, config: StoreConfig, version: number): Promise&lt;RdbStore&gt;

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.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| context<sup>8+</sup> | Context | Yes| Context of the app or functionality.<br>For the definition of **Context** of API version 8, see [Context](js-apis-Context.md).<br>For the definition of **Context** of API version 9, see [Context](js-apis-ability-context.md).|
| config | [StoreConfig](#storeconfig) | Yes| Configuration of the RDB store.|
| version | number | Yes| RDB store version.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise&lt;[RdbStore](#rdbstore)&gt; | Promise used to return the RDB store obtained.|

**Example**

```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.')
A
annie_wangli 已提交
140
    }).catch((err) => {
A
Annie_wang 已提交
141
        console.log("executeSql creat err.")
A
annie_wangli 已提交
142
    })
A
Annie_wang 已提交
143 144 145
}).catch((err) => {
    console.log("getRdbStore err.")
})
A
annie_wangli 已提交
146
```
A
annie_wangli 已提交
147 148 149

## data_rdb.deleteRdbStore

A
Annie_wang 已提交
150
deleteRdbStore(name: string, callback: AsyncCallback&lt;void&gt;): void
Z
zengyawen 已提交
151

A
Annie_wang 已提交
152
Deletes an RDB store. This API uses a callback to return the result. 
Z
zengyawen 已提交
153

A
annie_wangli 已提交
154
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
155

A
annie_wangli 已提交
156 157 158 159 160 161 162
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the RDB store to delete.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|

**Example**
A
Annie_wang 已提交
163
  ```js
A
annie_wangli 已提交
164 165 166
  data_rdb.deleteRdbStore("RdbTest.db", function (err, rdbStore) {
      console.info('delete store done.')
  })
A
annie_wangli 已提交
167
  ```
A
Annie_wang 已提交
168
  ## data_rdb.deleteRdbStore
A
annie_wangli 已提交
169

A
Annie_wang 已提交
170
deleteRdbStore(name: string): Promise&lt;void&gt;
A
annie_wangli 已提交
171

A
Annie_wang 已提交
172
Deletes an RDB store. This API uses a promise to return the result.
A
annie_wangli 已提交
173

A
Annie_wang 已提交
174 175 176 177 178 179 180 181 182 183
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the RDB store to delete.|

**Return value**
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
184
| Promise&lt;void&gt; | Promise used to return the result.|
A
Annie_wang 已提交
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218

**Example**
  ```js
  let promisedeleteRdb = data_rdb.deleteRdbStore("RdbTest.db")
  promisedeleteRdb.then(()=>{
      console.info('delete store done.')
  }).catch((err) => {
      console.log("deleteRdbStore err.")
  })
  ```

## data_rdb.deleteRdbStore<sup>8+</sup>

deleteRdbStore(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void

Deletes an RDB store. This API uses a callback to return the result. 

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| context<sup>8+</sup> | Context | Yes| Context of the app or functionality.<br>For the definition of **Context** of API version 8, see [Context](js-apis-Context.md).<br>For the definition of **Context** of API version 9, see [Context](js-apis-ability-context.md).|
| name | string | Yes| Name of the RDB store to delete.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|

**Example**
  ```js
  data_rdb.deleteRdbStore(this.context, "RdbTest.db", function (err, rdbStore) {
      console.info('delete store done.')
  })
  ```

## data_rdb.deleteRdbStore<sup>8+</sup>
A
annie_wangli 已提交
219 220

deleteRdbStore(context: Context, name: string): Promise&lt;void&gt;
Z
zengyawen 已提交
221

A
Annie_wang 已提交
222
Deletes an RDB store. This API uses a promise to return the result.
Z
zengyawen 已提交
223

A
annie_wangli 已提交
224
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
225

A
annie_wangli 已提交
226 227 228
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
229
| context<sup>8+</sup> | Context | Yes| Context of the app or functionality.<br>For the definition of **Context** of API version 8, see [Context](js-apis-Context.md).<br>For the definition of **Context** of API version 9, see [Context](js-apis-ability-context.md).|
A
annie_wangli 已提交
230
| name | string | Yes| Name of the RDB store to delete.|
A
annie_wangli 已提交
231

A
annie_wangli 已提交
232 233 234
**Return value**
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
235
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
236 237

**Example**
A
Annie_wang 已提交
238
  ```js
A
annie_wangli 已提交
239 240 241 242 243 244
  let promisedeleteRdb = data_rdb.deleteRdbStore("RdbTest.db")
  promisedeleteRdb.then(()=>{
      console.info('delete store done.')
  }).catch((err) => {
      console.log("deleteRdbStore err.")
  })
A
annie_wangli 已提交
245 246
  ```

A
annie_wangli 已提交
247

A
annie_wangli 已提交
248
## RdbPredicates
Z
zengyawen 已提交
249 250 251

Defines predicates for an RDB store. This class determines whether the conditional expression for the RDB store is true or false.

A
annie_wangli 已提交
252 253 254 255 256 257 258 259

### constructor

constructor(name: string)


A constructor used to create an **RdbPredicates** object.

A
annie_wangli 已提交
260
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
261

A
annie_wangli 已提交
262 263 264 265
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Database table name.|
A
annie_wangli 已提交
266

A
annie_wangli 已提交
267
**Example**
A
Annie_wang 已提交
268
  ```js
A
annie_wangli 已提交
269 270 271
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  ```

A
annie_wangli 已提交
272
### inDevices<sup>8+</sup>
A
annie_wangli 已提交
273

A
annie_wangli 已提交
274
inDevices(devices: Array&lt;string&gt;): RdbPredicates
A
annie_wangli 已提交
275 276 277 278


Specifies a remote device on the network during distributed database synchronization.

A
annie_wangli 已提交
279
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
280

A
annie_wangli 已提交
281 282 283 284
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| devices | Array&lt;string&gt; | Yes| ID of the remote device to specify.|
A
annie_wangli 已提交
285

A
annie_wangli 已提交
286 287 288 289
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
290

A
annie_wangli 已提交
291
**Example**
A
Annie_wang 已提交
292
  ```js
A
annie_wangli 已提交
293
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
A
Annie_wang 已提交
294
  predicates.inDevices(['12345678abcde'])
A
annie_wangli 已提交
295 296
  ```

A
annie_wangli 已提交
297
### inAllDevices<sup>8+</sup>
A
annie_wangli 已提交
298

A
annie_wangli 已提交
299
inAllDevices(): RdbPredicates
A
annie_wangli 已提交
300 301 302 303


Connects to all remote devices on the network during distributed database synchronization.

A
annie_wangli 已提交
304
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
305

A
annie_wangli 已提交
306 307 308 309
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
310

A
annie_wangli 已提交
311
**Example**
A
Annie_wang 已提交
312
  ```js
A
annie_wangli 已提交
313 314 315 316 317 318 319 320 321 322 323
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.inAllDevices()
  ```

### equalTo

equalTo(field: string, value: ValueType): RdbPredicates


Sets the **RdbPredicates** to match the field with data type **ValueType** and value equal to the specified value.

A
annie_wangli 已提交
324
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
325

A
annie_wangli 已提交
326 327 328 329 330
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**.|
A
annie_wangli 已提交
331

A
annie_wangli 已提交
332 333 334 335
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
336

A
annie_wangli 已提交
337
**Example**
A
Annie_wang 已提交
338
  ```js
A
annie_wangli 已提交
339 340 341 342 343 344 345 346 347 348 349 350
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.equalTo("NAME", "lisi")
  ```


### notEqualTo

notEqualTo(field: string, value: ValueType): RdbPredicates


Sets the **RdbPredicates** to match the field with data type **ValueType** and value not equal to the specified value.

A
annie_wangli 已提交
351
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
352

A
annie_wangli 已提交
353 354 355 356 357
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**.|
A
annie_wangli 已提交
358

A
annie_wangli 已提交
359 360 361 362
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
363

A
annie_wangli 已提交
364
**Example**
A
Annie_wang 已提交
365
  ```js
A
annie_wangli 已提交
366 367 368 369 370 371 372 373 374 375 376 377
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.notEqualTo("NAME", "lisi")
  ```


### beginWrap

beginWrap(): RdbPredicates


Adds a left parenthesis to the **RdbPredicates**.

A
annie_wangli 已提交
378
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
379

A
annie_wangli 已提交
380 381 382 383
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a left parenthesis.|
A
annie_wangli 已提交
384

A
annie_wangli 已提交
385
**Example**
A
Annie_wang 已提交
386
  ```js
A
annie_wangli 已提交
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.equalTo("NAME", "lisi")
      .beginWrap()
      .equalTo("AGE", 18)
      .or()
      .equalTo("SALARY", 200.5)
      .endWrap()
  ```


### endWrap

endWrap(): RdbPredicates


Adds a right parenthesis to the **RdbPredicates**.

A
annie_wangli 已提交
404
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
405

A
annie_wangli 已提交
406 407 408 409
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a right parenthesis.|
A
annie_wangli 已提交
410

A
annie_wangli 已提交
411
**Example**
A
Annie_wang 已提交
412
  ```js
A
annie_wangli 已提交
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.equalTo("NAME", "lisi")
      .beginWrap()
      .equalTo("AGE", 18)
      .or()
      .equalTo("SALARY", 200.5)
      .endWrap()
  ```


### or

or(): RdbPredicates


Adds the OR condition to the **RdbPredicates**.

A
annie_wangli 已提交
430
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
431

A
annie_wangli 已提交
432 433 434 435
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the OR condition.|
A
annie_wangli 已提交
436

A
annie_wangli 已提交
437
**Example**
A
Annie_wang 已提交
438
  ```js
A
annie_wangli 已提交
439 440 441 442 443 444 445 446 447 448 449 450 451 452
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.equalTo("NAME", "Lisa")
      .or()
      .equalTo("NAME", "Rose")
  ```


### and

and(): RdbPredicates


Adds the AND condition to the **RdbPredicates**.

A
annie_wangli 已提交
453
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
454

A
annie_wangli 已提交
455 456 457 458
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the AND condition.|
A
annie_wangli 已提交
459

A
annie_wangli 已提交
460
**Example**
A
Annie_wang 已提交
461
  ```js
A
annie_wangli 已提交
462 463 464 465 466 467 468 469 470
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.equalTo("NAME", "Lisa")
      .and()
      .equalTo("SALARY", 200.5)
  ```


### contains

A
annie_wangli 已提交
471
contains(field: string, value: string): RdbPredicates
A
annie_wangli 已提交
472 473 474

Sets the **RdbPredicates** to match a string containing the specified value.

A
annie_wangli 已提交
475
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
476

A
annie_wangli 已提交
477 478 479 480 481
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| value | string | Yes| Value to match the **RdbPredicates**.|
A
annie_wangli 已提交
482

A
annie_wangli 已提交
483 484 485 486
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
487

A
annie_wangli 已提交
488
**Example**
A
Annie_wang 已提交
489
  ```js
A
annie_wangli 已提交
490 491 492 493 494 495 496 497 498 499 500 501
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.contains("NAME", "os")
  ```


### beginsWith

beginsWith(field: string, value: string): RdbPredicates


Sets the **RdbPredicates** to match a string that starts with the specified value.

A
annie_wangli 已提交
502
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
503

A
annie_wangli 已提交
504 505 506 507 508
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| value | string | Yes| Value to match the **RdbPredicates**.|
A
annie_wangli 已提交
509

A
annie_wangli 已提交
510 511 512 513
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
514

A
annie_wangli 已提交
515
**Example**
A
Annie_wang 已提交
516
  ```js
A
annie_wangli 已提交
517 518 519 520 521 522 523 524 525 526 527 528
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.beginsWith("NAME", "os")
  ```


### endsWith

endsWith(field: string, value: string): RdbPredicates


Sets the **RdbPredicates** to match a string that ends with the specified value.

A
annie_wangli 已提交
529
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
530

A
annie_wangli 已提交
531 532 533 534 535
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| value | string | Yes| Value to match the **RdbPredicates**.|
A
annie_wangli 已提交
536

A
annie_wangli 已提交
537 538 539 540
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
541

A
annie_wangli 已提交
542
**Example**
A
Annie_wang 已提交
543
  ```js
A
annie_wangli 已提交
544 545 546 547 548 549 550 551 552 553 554 555
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.endsWith("NAME", "se")
  ```


### isNull

isNull(field: string): RdbPredicates


Sets the **RdbPredicates** to match the field whose value is null.

A
annie_wangli 已提交
556
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
557

A
annie_wangli 已提交
558 559 560 561
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
A
annie_wangli 已提交
562

A
annie_wangli 已提交
563 564 565 566
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
567 568

- Example
A
Annie_wang 已提交
569
  ```js
A
annie_wangli 已提交
570 571 572 573 574 575 576 577 578 579 580 581
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.isNull("NAME")
  ```


### isNotNull

isNotNull(field: string): RdbPredicates


Sets the **RdbPredicates** to match the field whose value is not null.

A
annie_wangli 已提交
582
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
583

A
annie_wangli 已提交
584 585 586 587
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
A
annie_wangli 已提交
588

A
annie_wangli 已提交
589 590 591 592
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
593

A
annie_wangli 已提交
594
**Example**
A
Annie_wang 已提交
595
  ```js
A
annie_wangli 已提交
596 597 598 599 600 601 602 603 604 605 606 607
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.isNotNull("NAME")
  ```


### like

like(field: string, value: string): RdbPredicates


Sets the **RdbPredicates** to match a string that is similar to the specified value.

A
annie_wangli 已提交
608
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
609

A
annie_wangli 已提交
610 611 612 613 614
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| value | string | Yes| Value to match the **RdbPredicates**.|
A
annie_wangli 已提交
615

A
annie_wangli 已提交
616 617 618 619
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
620

A
annie_wangli 已提交
621
**Example**
A
Annie_wang 已提交
622
  ```js
A
annie_wangli 已提交
623 624 625 626 627 628 629 630 631 632 633 634
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.like("NAME", "%os%")
  ```


### glob

glob(field: string, value: string): RdbPredicates


Sets the **RdbPredicates** to match the specified string.

A
annie_wangli 已提交
635
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
636

A
annie_wangli 已提交
637 638 639 640 641
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| value | string | Yes| Value to match the **RdbPredicates**.<br><br>Wildcards are supported. ***** indicates zero, one, or multiple digits or characters. **?** indicates a single digit or character.|
A
annie_wangli 已提交
642

A
annie_wangli 已提交
643 644 645 646
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
647

A
annie_wangli 已提交
648
**Example**
A
Annie_wang 已提交
649
  ```js
A
annie_wangli 已提交
650 651 652 653 654 655 656 657 658 659 660 661
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.glob("NAME", "?h*g")
  ```


### between

between(field: string, low: ValueType, high: ValueType): RdbPredicates


Sets the **RdbPredicates** to match the field with data type **ValueType** and value within the specified range.

A
annie_wangli 已提交
662
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
663

A
annie_wangli 已提交
664 665 666 667 668 669
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| low | [ValueType](#valuetype) | Yes| Minimum value to match the **RdbPredicates**.|
| high | [ValueType](#valuetype) | Yes| Maximum value to match the **RdbPredicates**.|
A
annie_wangli 已提交
670

A
annie_wangli 已提交
671 672 673 674
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
675

A
annie_wangli 已提交
676
**Example**
A
Annie_wang 已提交
677
  ```js
A
annie_wangli 已提交
678 679 680 681 682 683 684 685 686 687 688 689
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.between("AGE", 10, 50)
  ```


### notBetween

notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates


Sets the **RdbPredicates** to match the field with data type **ValueType** and value out of the specified range.

A
annie_wangli 已提交
690
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
691

A
annie_wangli 已提交
692 693 694 695 696 697
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| low | [ValueType](#valuetype) | Yes| Minimum value to match the **RdbPredicates**.|
| high | [ValueType](#valuetype) | Yes| Maximum value to match the **RdbPredicates**.|
A
annie_wangli 已提交
698

A
annie_wangli 已提交
699 700 701 702
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
703

A
annie_wangli 已提交
704
**Example**
A
Annie_wang 已提交
705
  ```js
A
annie_wangli 已提交
706 707 708 709 710 711 712
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.notBetween("AGE", 10, 50)
  ```


### greaterThan

A
annie_wangli 已提交
713
greaterThan(field: string, value: ValueType): RdbPredicates
A
annie_wangli 已提交
714 715 716

Sets the **RdbPredicates** to match the field with data type **ValueType** and value greater than the specified value.

A
annie_wangli 已提交
717
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
718

A
annie_wangli 已提交
719 720 721 722 723
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**.|
A
annie_wangli 已提交
724

A
annie_wangli 已提交
725 726 727 728
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
729

A
annie_wangli 已提交
730
**Example**
A
Annie_wang 已提交
731
  ```js
A
annie_wangli 已提交
732 733 734 735 736 737 738 739 740 741 742 743
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.greaterThan("AGE", 18)
  ```


### lessThan

lessThan(field: string, value: ValueType): RdbPredicates


Sets the **RdbPredicates** to match the field with data type **ValueType** and value less than the specified value.

A
annie_wangli 已提交
744
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
745

A
annie_wangli 已提交
746 747 748 749 750
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**.|
A
annie_wangli 已提交
751

A
annie_wangli 已提交
752 753 754 755
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
756

A
annie_wangli 已提交
757
**Example**
A
Annie_wang 已提交
758
  ```js
A
annie_wangli 已提交
759 760 761 762 763 764 765 766 767 768 769 770 771
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.lessThan("AGE", 20)
  ```


### greaterThanOrEqualTo


greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates


Sets the **RdbPredicates** to match the field with data type **ValueType** and value greater than or equal to the specified value.

A
annie_wangli 已提交
772
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
773

A
annie_wangli 已提交
774 775 776 777 778
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**.|
A
annie_wangli 已提交
779

A
annie_wangli 已提交
780 781 782 783
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
784

A
annie_wangli 已提交
785
**Example**
A
Annie_wang 已提交
786
  ```js
A
annie_wangli 已提交
787 788 789 790 791 792 793 794 795 796 797 798 799
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.greaterThanOrEqualTo("AGE", 18)
  ```


### lessThanOrEqualTo


lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates


Sets the **RdbPredicates** to match the field with data type **ValueType** and value less than or equal to the specified value.

A
annie_wangli 已提交
800
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
801

A
annie_wangli 已提交
802 803 804 805 806
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**.|
A
annie_wangli 已提交
807

A
annie_wangli 已提交
808 809 810 811
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
812

A
annie_wangli 已提交
813
**Example**
A
Annie_wang 已提交
814
  ```js
A
annie_wangli 已提交
815 816 817 818 819 820 821 822 823 824 825 826 827
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.lessThanOrEqualTo("AGE", 20)
  ```


### orderByAsc


orderByAsc(field: string): RdbPredicates


Sets the **RdbPredicates** to match the column with values sorted in ascending order.

A
annie_wangli 已提交
828
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
829

A
annie_wangli 已提交
830 831 832 833
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
A
annie_wangli 已提交
834

A
annie_wangli 已提交
835 836 837 838
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
839

A
annie_wangli 已提交
840
**Example**
A
Annie_wang 已提交
841
  ```js
A
annie_wangli 已提交
842 843 844 845 846 847 848 849 850 851 852 853 854
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.orderByAsc("NAME")
  ```


### orderByDesc


orderByDesc(field: string): RdbPredicates


Sets the **RdbPredicates** to match the column with values sorted in descending order.

A
annie_wangli 已提交
855
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
856

A
annie_wangli 已提交
857 858 859 860
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
A
annie_wangli 已提交
861

A
annie_wangli 已提交
862 863 864 865
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
866

A
annie_wangli 已提交
867
**Example**
A
Annie_wang 已提交
868
  ```js
A
annie_wangli 已提交
869 870 871 872 873 874 875 876 877 878 879 880
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.orderByDesc("AGE")
  ```


### distinct

distinct(): RdbPredicates


Sets the **RdbPredicates** to filter out duplicate records.

A
annie_wangli 已提交
881
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
882

A
annie_wangli 已提交
883 884 885 886
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that can filter out duplicate records.|
A
annie_wangli 已提交
887

A
annie_wangli 已提交
888
**Example**
A
Annie_wang 已提交
889
  ```js
A
annie_wangli 已提交
890 891
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.equalTo("NAME", "Rose").distinct("NAME")
A
annie_wangli 已提交
892 893 894 895 896 897 898
  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.")
  })
A
annie_wangli 已提交
899 900 901 902 903 904 905 906 907 908
  ```


### limitAs

limitAs(value: number): RdbPredicates


Sets the **RdbPredicates** to specify the maximum number of records.

A
annie_wangli 已提交
909
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
910

A
annie_wangli 已提交
911 912 913 914
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Maximum number of records.|
A
annie_wangli 已提交
915

A
annie_wangli 已提交
916 917 918 919
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the maximum number of records.|
A
annie_wangli 已提交
920

A
annie_wangli 已提交
921
**Example**
A
Annie_wang 已提交
922
  ```js
A
annie_wangli 已提交
923 924 925 926 927 928 929 930 931 932 933 934
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.equalTo("NAME", "Rose").limitAs(3)
  ```


### offsetAs

offsetAs(rowOffset: number): RdbPredicates


Sets the **RdbPredicates** to specify the start position of the returned result.

A
annie_wangli 已提交
935
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
936

A
annie_wangli 已提交
937 938 939 940
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| rowOffset | number | Yes| Number of rows to offset from the beginning. The value is a positive integer.|
A
annie_wangli 已提交
941

A
annie_wangli 已提交
942 943 944 945
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the start position of the returned result.|
A
annie_wangli 已提交
946

A
annie_wangli 已提交
947
**Example**
A
Annie_wang 已提交
948
  ```js
A
annie_wangli 已提交
949 950 951 952 953 954 955 956 957 958 959 960
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.equalTo("NAME", "Rose").offsetAs(3)
  ```


### groupBy

groupBy(fields: Array&lt;string&gt;): RdbPredicates


Sets the **RdbPredicates** to group rows that have the same value into summary rows.

A
annie_wangli 已提交
961
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
962

A
annie_wangli 已提交
963 964 965 966
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| fields | Array&lt;string&gt; | Yes| Names of columns to group.|
A
annie_wangli 已提交
967

A
annie_wangli 已提交
968 969 970 971
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that groups rows with the same value.|
A
annie_wangli 已提交
972

A
annie_wangli 已提交
973
**Example**
A
Annie_wang 已提交
974
  ```js
A
annie_wangli 已提交
975 976 977 978 979 980 981
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.groupBy(["AGE", "NAME"])
  ```


### indexedBy

A
annie_wangli 已提交
982
indexedBy(field: string): RdbPredicates
A
annie_wangli 已提交
983 984 985

Sets the **RdbPredicates** object to specify the index column.

A
annie_wangli 已提交
986
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
987

A
annie_wangli 已提交
988 989 990 991
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Name of the index column.|
A
annie_wangli 已提交
992

A
annie_wangli 已提交
993
**Return value**
A
annie_wangli 已提交
994

A
annie_wangli 已提交
995 996 997 998 999
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the index column.|

**Example**
A
Annie_wang 已提交
1000
  ```js
A
annie_wangli 已提交
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.indexedBy("SALARY_INDEX")
  ```


### in

in(field: string, value: Array&lt;ValueType&gt;): RdbPredicates


Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value within the specified range.

A
annie_wangli 已提交
1013
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1014

A
annie_wangli 已提交
1015 1016 1017 1018 1019
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| value | Array&lt;[ValueType](#valuetype)&gt; | Yes| Array of **ValueType**s to match.|
A
annie_wangli 已提交
1020 1021


A
annie_wangli 已提交
1022 1023 1024 1025
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
1026

A
annie_wangli 已提交
1027
**Example**
A
Annie_wang 已提交
1028
  ```js
A
annie_wangli 已提交
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.in("AGE", [18, 20])
  ```


### notIn

notIn(field: string, value: Array&lt;ValueType&gt;): RdbPredicates


Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value out of the specified range.

A
annie_wangli 已提交
1041
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1042

A
annie_wangli 已提交
1043 1044 1045 1046 1047
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| value | Array&lt;[ValueType](#valuetype)&gt; | Yes| Array of **ValueType**s to match.|
A
annie_wangli 已提交
1048 1049


A
annie_wangli 已提交
1050 1051 1052 1053
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
1054

A
annie_wangli 已提交
1055
**Example**
A
Annie_wang 已提交
1056
  ```js
A
annie_wangli 已提交
1057 1058 1059 1060 1061 1062
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.notIn("NAME", ["Lisa", "Rose"])
  ```


## RdbStore
Z
zengyawen 已提交
1063 1064 1065 1066

Provides methods to manage an RDB store.


A
annie_wangli 已提交
1067 1068 1069
### insert

insert(name: string, values: ValuesBucket, callback: AsyncCallback&lt;number&gt;):void
Z
zengyawen 已提交
1070

A
Annie_wang 已提交
1071
Inserts a row of data into a table. This API uses a callback to return the result.
Z
zengyawen 已提交
1072

A
annie_wangli 已提交
1073
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1074

A
annie_wangli 已提交
1075 1076 1077 1078 1079 1080 1081 1082
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the target table.|
| values | [ValuesBucket](#valuesbucket) | Yes| Row of data to insert.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|

**Example**
A
Annie_wang 已提交
1083
  ```js
A
annie_wangli 已提交
1084 1085 1086 1087 1088 1089 1090
  const valueBucket = {
      "NAME": "Lisa",
      "AGE": 18,
      "SALARY": 100.5,
      "CODES": new Uint8Array([1, 2, 3, 4, 5]),
  }
  rdbStore.insert("EMPLOYEE", valueBucket, function (err, ret) {
A
annie_wangli 已提交
1091 1092
      console.log("insert first done: " + ret)
  })
A
annie_wangli 已提交
1093 1094 1095 1096 1097 1098
  ```


### insert

insert(name: string, values: ValuesBucket):Promise&lt;number&gt;
Z
zengyawen 已提交
1099

A
Annie_wang 已提交
1100
Inserts a row of data into a table. This API uses a promise to return the result.
Z
zengyawen 已提交
1101

A
annie_wangli 已提交
1102
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1103

A
annie_wangli 已提交
1104 1105 1106 1107 1108
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the target table.|
| values | [ValuesBucket](#valuesbucket) | Yes| Row of data to insert.|
A
annie_wangli 已提交
1109

A
annie_wangli 已提交
1110 1111 1112 1113 1114 1115
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|

**Example**
A
Annie_wang 已提交
1116
  ```js
A
annie_wangli 已提交
1117 1118 1119 1120 1121 1122
  const valueBucket = {
      "NAME": "Lisa",
      "AGE": 18,
      "SALARY": 100.5,
      "CODES": new Uint8Array([1, 2, 3, 4, 5]),
  }
A
annie_wangli 已提交
1123 1124 1125 1126 1127 1128
  let promiseinsert = rdbStore.insert("EMPLOYEE", valueBucket)
  promiseinsert.then(async (ret) => {
      console.log("insert first done: " + ret)
  }).catch((err) => {
      console.log("insert err.")
  })
A
annie_wangli 已提交
1129 1130 1131 1132 1133 1134 1135
  ```


### update

update(values: ValuesBucket, rdbPredicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void

A
Annie_wang 已提交
1136
Updates data in the database based on the specified RdbPredicates object. This API uses a callback to return the result.
A
annie_wangli 已提交
1137

A
annie_wangli 已提交
1138
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1139

A
annie_wangli 已提交
1140 1141 1142 1143 1144 1145 1146 1147
**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.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the number of rows updated.|

**Example**
A
Annie_wang 已提交
1148
  ```js
A
annie_wangli 已提交
1149 1150 1151 1152 1153 1154 1155 1156 1157
  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) {
A
Annie_wang 已提交
1158
      console.log("updated row count: " + ret)})
A
annie_wangli 已提交
1159 1160 1161 1162 1163 1164 1165
  ```


### update

update(values: ValuesBucket, rdbPredicates: RdbPredicates):Promise&lt;number&gt;

A
Annie_wang 已提交
1166
Updates data in the database based on the specified RdbPredicates object. This API uses a promise to return the result.
A
annie_wangli 已提交
1167

A
annie_wangli 已提交
1168
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1169

A
annie_wangli 已提交
1170 1171 1172 1173 1174
**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.|
A
annie_wangli 已提交
1175

A
annie_wangli 已提交
1176 1177 1178 1179 1180 1181
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Promise used to return the number of rows updated.|

**Example**
A
Annie_wang 已提交
1182
  ```js
A
annie_wangli 已提交
1183 1184 1185 1186 1187 1188 1189 1190
  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")
A
annie_wangli 已提交
1191 1192
  let promiseupdate = rdbStore.update(valueBucket, predicates)
  promiseupdate.then(async (ret) => {
A
Annie_wang 已提交
1193
       console.log("updated row count: " + ret)
A
annie_wangli 已提交
1194 1195 1196
  }).catch((err) => {
      console.log("update err.")
  })
A
annie_wangli 已提交
1197 1198 1199 1200 1201 1202 1203 1204
  ```


### delete

delete(rdbPredicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void


A
Annie_wang 已提交
1205
Deletes data from the database based on the specified RdbPredicates object. This API uses a callback to return the result.
A
annie_wangli 已提交
1206

A
annie_wangli 已提交
1207
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1208

A
annie_wangli 已提交
1209 1210 1211 1212 1213
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| rdbPredicates | [RdbPredicates](#rdbpredicates) | Yes| Conditions specified for deleting data.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of rows updated.|
A
annie_wangli 已提交
1214

A
annie_wangli 已提交
1215
**Example**
A
Annie_wang 已提交
1216
  ```js
A
annie_wangli 已提交
1217 1218 1219
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.equalTo("NAME", "Lisa")
  rdbStore.delete(predicates, function (err, rows) {
A
annie_wangli 已提交
1220 1221
      console.log("delete rows: " + rows)
  })
A
annie_wangli 已提交
1222 1223 1224 1225 1226 1227 1228
  ```


### delete

delete(rdbPredicates: RdbPredicates):Promise&lt;number&gt;

A
Annie_wang 已提交
1229
Deletes data from the database based on the specified RdbPredicates object. This API uses a promise to return the result.
A
annie_wangli 已提交
1230

A
annie_wangli 已提交
1231
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1232

A
annie_wangli 已提交
1233 1234 1235 1236
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| rdbPredicates | [RdbPredicates](#rdbpredicates) | Yes| Conditions specified for deleting data.|
A
annie_wangli 已提交
1237

A
annie_wangli 已提交
1238 1239 1240 1241 1242 1243
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Promise used to return the number of rows updated.|

**Example**
A
Annie_wang 已提交
1244
  ```js
A
annie_wangli 已提交
1245 1246 1247 1248 1249 1250 1251 1252
  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.")
  })
A
annie_wangli 已提交
1253 1254 1255 1256 1257 1258
  ```


### query

query(rdbPredicates: RdbPredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
Z
zengyawen 已提交
1259

A
Annie_wang 已提交
1260
Queries data in the database based on specified conditions. This API uses a callback to return the result.
Z
zengyawen 已提交
1261

A
annie_wangli 已提交
1262
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1263

A
annie_wangli 已提交
1264 1265 1266 1267 1268 1269 1270 1271
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| rdbPredicates | [RdbPredicates](#rdbpredicates) | Yes| Query conditions specified by the **RdbPredicates** object.|
| columns | Array&lt;string&gt; | Yes| Columns to query. If this parameter is not specified, the query applies to all columns.|
| callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|

**Example**
A
Annie_wang 已提交
1272
  ```js
A
annie_wangli 已提交
1273 1274 1275
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.equalTo("NAME", "Rose")
  rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
A
annie_wangli 已提交
1276 1277 1278
      console.log("resultSet column names:" + resultSet.columnNames)
      console.log("resultSet column count:" + resultSet.columnCount)
  })
A
annie_wangli 已提交
1279 1280 1281 1282 1283 1284
  ```


### query

query(rdbPredicates: RdbPredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt;
Z
zengyawen 已提交
1285

A
Annie_wang 已提交
1286
Queries data in the database based on specified conditions. This API uses a promise to return the result.
Z
zengyawen 已提交
1287

A
annie_wangli 已提交
1288
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1289

A
annie_wangli 已提交
1290 1291 1292 1293 1294
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| rdbPredicates | [RdbPredicates](#rdbpredicates) | Yes| Query conditions specified by the **RdbPredicates** object.|
| columns | Array&lt;string&gt; | No| Columns to query. If this parameter is not specified, the query applies to all columns.|
A
annie_wangli 已提交
1295

A
annie_wangli 已提交
1296 1297 1298 1299 1300 1301
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;[ResultSet](../apis/js-apis-data-resultset.md)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|

**Example**
A
Annie_wang 已提交
1302
  ```js
A
annie_wangli 已提交
1303 1304
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.equalTo("NAME", "Rose")
A
annie_wangli 已提交
1305 1306 1307 1308 1309 1310 1311
  let promisequery = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
  promisequery.then((resultSet) => {
      console.log("resultSet column names:" + resultSet.columnNames)
      console.log("resultSet column count:" + resultSet.columnCount)
  }).catch((err) => {
      console.log("query err.")
  })
A
annie_wangli 已提交
1312 1313 1314 1315 1316 1317 1318
  ```


### querySql<sup>8+</sup>

querySql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void

A
Annie_wang 已提交
1319
Queries data in the RDB store using the specified SQL statement. This API uses a callback to return the result.
A
annie_wangli 已提交
1320

A
annie_wangli 已提交
1321
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1322

A
annie_wangli 已提交
1323 1324 1325 1326 1327 1328 1329 1330
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes| Values of the parameters in the SQL statement.|
| callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|

**Example**
A
Annie_wang 已提交
1331
  ```js
A
annie_wangli 已提交
1332
  rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) {
A
annie_wangli 已提交
1333 1334 1335
      console.log("resultSet column names:" + resultSet.columnNames)
      console.log("resultSet column count:" + resultSet.columnCount)
  })
A
annie_wangli 已提交
1336 1337 1338 1339 1340 1341 1342
  ```


### querySql<sup>8+</sup>

querySql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;ResultSet&gt;

A
Annie_wang 已提交
1343
Queries data in the RDB store using the specified SQL statement. This API uses a promise to return the result.
A
annie_wangli 已提交
1344

A
annie_wangli 已提交
1345
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1346

A
annie_wangli 已提交
1347 1348 1349 1350 1351
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | No| Values of the parameters in the SQL statement.|
A
annie_wangli 已提交
1352

A
annie_wangli 已提交
1353 1354 1355 1356 1357 1358
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;[ResultSet](../apis/js-apis-data-resultset.md)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|

**Example**
A
Annie_wang 已提交
1359
  ```js
A
annie_wangli 已提交
1360 1361 1362 1363 1364 1365 1366
  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.")
  })
A
annie_wangli 已提交
1367 1368 1369 1370 1371 1372
  ```


### executeSql

executeSql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;void&gt;):void
Z
zengyawen 已提交
1373

A
Annie_wang 已提交
1374
Runs the SQL statement that contains the specified parameters but does not return a value. This API uses a callback to return the execution result.
Z
zengyawen 已提交
1375

A
annie_wangli 已提交
1376
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1377

A
annie_wangli 已提交
1378 1379 1380 1381 1382 1383 1384 1385
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes| Values of the parameters in the SQL statement.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|

**Example**
A
Annie_wang 已提交
1386
  ```js
A
annie_wangli 已提交
1387
  rdbStore.executeSql("DELETE FROM EMPLOYEE", null, function () {
A
annie_wangli 已提交
1388 1389
      console.info('delete done.')
  })
A
annie_wangli 已提交
1390 1391 1392 1393 1394 1395
  ```


### executeSql

executeSql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;void&gt;
Z
zengyawen 已提交
1396

A
Annie_wang 已提交
1397
Runs the SQL statement that contains the specified parameters but does not return a value. This API uses a promise to return the execution result.
Z
zengyawen 已提交
1398

A
annie_wangli 已提交
1399
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1400

A
annie_wangli 已提交
1401 1402 1403 1404 1405
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | No| Values of the parameters in the SQL statement.|
A
annie_wangli 已提交
1406

A
annie_wangli 已提交
1407 1408 1409 1410 1411 1412
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**
A
Annie_wang 已提交
1413
  ```js
A
annie_wangli 已提交
1414 1415 1416 1417 1418 1419
  let promiseexecuteSql = rdbStore.executeSql("DELETE FROM EMPLOYEE")
  promiseexecuteSql.then(() => {
      console.info('delete done.')
  }).catch((err) => {
      console.log("executeSql err.")
  })
A
annie_wangli 已提交
1420 1421
  ```

A
annie_wangli 已提交
1422 1423 1424 1425 1426
### beginTransaction<sup>8+</sup>

beginTransaction():void

Starts the transaction before executing an SQL statement.
A
annie_wangli 已提交
1427

A
annie_wangli 已提交
1428 1429 1430
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Example**
A
Annie_wang 已提交
1431
```js
A
annie_wangli 已提交
1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454
  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()
```


### commit<sup>8+</sup>

commit():void

Commits the executed SQL statements.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Example**
A
Annie_wang 已提交
1455
```js
A
annie_wangli 已提交
1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479
  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()
```


### rollBack<sup>8+</sup>

rollBack():void;

Rolls back the SQL statements that have been executed.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Example**
A
Annie_wang 已提交
1480
```js
A
annie_wangli 已提交
1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502
  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()
  }
```


### setDistributedTables<sup>8+</sup>

setDistributedTables(tables: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
1503

A
Annie_wang 已提交
1504
Sets a list of distributed tables. This API uses a callback to return the result.
A
annie_wangli 已提交
1505

A
annie_wangli 已提交
1506
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1507

A
annie_wangli 已提交
1508 1509 1510 1511 1512 1513 1514
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| tables | Array&lt;string&gt; | Yes| Names of the distributed tables to set.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|

**Example**
A
Annie_wang 已提交
1515
  ```js
A
annie_wangli 已提交
1516 1517 1518 1519 1520 1521 1522 1523 1524 1525
  rdbStore.setDistributedTables(["EMPLOYEE"], function (err) {
      if (err) {
          console.info('setDistributedTables failed.')
          return
      }
      console.info('setDistributedTables success.')
  })
  ```


A
annie_wangli 已提交
1526
### setDistributedTables<sup>8+</sup>
A
annie_wangli 已提交
1527

A
annie_wangli 已提交
1528
 setDistributedTables(tables: Array&lt;string&gt;): Promise&lt;void&gt;
A
annie_wangli 已提交
1529

A
Annie_wang 已提交
1530
Sets a list of distributed tables. This API uses a promise to return the result.
A
annie_wangli 已提交
1531

A
annie_wangli 已提交
1532
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1533

A
annie_wangli 已提交
1534 1535 1536 1537
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| tables | Array&lt;string&gt; | Yes| Names of the distributed tables to set.|
A
annie_wangli 已提交
1538

A
annie_wangli 已提交
1539 1540 1541 1542 1543 1544
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**
A
Annie_wang 已提交
1545
  ```js
A
annie_wangli 已提交
1546 1547
  let promiseset = rdbStore.setDistributedTables(["EMPLOYEE"])
  promiseset.then(() => {
A
annie_wangli 已提交
1548 1549
      console.info("setDistributedTables success.")
  }).catch((err) => {
A
annie_wangli 已提交
1550
      console.info("setDistributedTables failed.")
A
annie_wangli 已提交
1551 1552 1553
  })
  ```

A
annie_wangli 已提交
1554
### obtainDistributedTableName<sup>8+</sup>
A
annie_wangli 已提交
1555

A
annie_wangli 已提交
1556
obtainDistributedTableName(device: string, table: string, callback: AsyncCallback&lt;string&gt;): void
A
annie_wangli 已提交
1557

A
Annie_wang 已提交
1558
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 callback to return the result.
A
annie_wangli 已提交
1559

A
annie_wangli 已提交
1560
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1561

A
annie_wangli 已提交
1562 1563 1564 1565 1566 1567 1568 1569
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| device | string | Yes| Remote device.|
| table | string | Yes| Local table name.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback invoked to return the result. If the operation succeeds, the distributed table name of the remote device is returned.|

**Example**
A
Annie_wang 已提交
1570
  ```js
A
annie_wangli 已提交
1571 1572 1573 1574 1575 1576 1577 1578 1579 1580
  rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) {
      if (err) {
          console.info('obtainDistributedTableName failed.')
          return
      }
      console.info('obtainDistributedTableName success, tableName=.' + tableName)
   })
  ```


A
annie_wangli 已提交
1581
### obtainDistributedTableName<sup>8+</sup>
A
annie_wangli 已提交
1582

A
annie_wangli 已提交
1583
 obtainDistributedTableName(device: string, table: string): Promise&lt;string&gt;
A
annie_wangli 已提交
1584

A
Annie_wang 已提交
1585
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.
A
annie_wangli 已提交
1586

A
annie_wangli 已提交
1587 1588 1589 1590 1591 1592 1593
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| device | string | Yes| Remote device.|
| table | string | Yes| Local table name.|
A
annie_wangli 已提交
1594

A
annie_wangli 已提交
1595 1596 1597 1598
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;string&gt; | Promise used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.|
A
annie_wangli 已提交
1599

A
annie_wangli 已提交
1600
**Example**
A
Annie_wang 已提交
1601
  ```js
A
annie_wangli 已提交
1602 1603
  let promiseDistr = rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE")
  promiseDistr.then((tableName) => {
A
annie_wangli 已提交
1604 1605 1606 1607 1608 1609
      console.info('obtainDistributedTableName success, tableName=' + tableName)
  }).catch((err) => {
      console.info('obtainDistributedTableName failed.')
  })
  ```

A
annie_wangli 已提交
1610
### sync<sup>8+</sup>
A
annie_wangli 已提交
1611

A
annie_wangli 已提交
1612
sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback&lt;Array&lt;[string, number]&gt;&gt;): void
A
annie_wangli 已提交
1613

A
Annie_wang 已提交
1614
Synchronizes data between devices. This API uses a callback to return the result.
A
annie_wangli 已提交
1615

A
annie_wangli 已提交
1616
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1617

A
annie_wangli 已提交
1618 1619 1620 1621 1622 1623 1624 1625
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
| callback | AsyncCallback&lt;Array&lt;[string, number]&gt;&gt; | Yes| Callback invoked to send the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |

**Example**
A
Annie_wang 已提交
1626
  ```js
A
annie_wangli 已提交
1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641
  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])
       }
  })
  ```


A
annie_wangli 已提交
1642
### sync<sup>8+</sup>
A
annie_wangli 已提交
1643

A
annie_wangli 已提交
1644
 sync(mode: SyncMode, predicates: RdbPredicates): Promise&lt;Array&lt;[string, number]&gt;&gt;
A
annie_wangli 已提交
1645

A
Annie_wang 已提交
1646
Synchronizes data between devices. This API uses a promise to return the result.
A
annie_wangli 已提交
1647

A
annie_wangli 已提交
1648
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1649

A
annie_wangli 已提交
1650 1651 1652 1653 1654
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
A
annie_wangli 已提交
1655

A
annie_wangli 已提交
1656 1657 1658 1659 1660 1661 1662
**Return value**

| Type| Description|
| -------- | -------- |
| Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise used to return the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of each device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |

**Example**
A
Annie_wang 已提交
1663
  ```js
A
annie_wangli 已提交
1664 1665 1666 1667
  let predicatesync = new data_rdb.RdbPredicates('EMPLOYEE')
  predicatesync.inDevices(['12345678abcde'])
  let promisesync = rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicatesync)
  promisesync.then((result) =>{
A
annie_wangli 已提交
1668 1669 1670 1671
      console.log('sync done.')
      for (let i = 0; i < result.length; i++) {
          console.log('device=' + result[i][0] + ' status=' + result[i][1])
      }
A
annie_wangli 已提交
1672 1673 1674
  }).catch((err) => {
      console.log('sync failed')
  })
A
annie_wangli 已提交
1675 1676
  ```

A
annie_wangli 已提交
1677
### on('dataChange')<sup>8+</sup>
A
annie_wangli 已提交
1678

A
annie_wangli 已提交
1679
on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void
A
annie_wangli 已提交
1680 1681 1682

Registers an observer for this RDB store. When the data in the RDB store changes, a callback is invoked to return the data changes.

A
annie_wangli 已提交
1683
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1684

A
annie_wangli 已提交
1685 1686 1687 1688 1689 1690 1691 1692 1693
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| event | string | Yes| The value is'dataChange', which indicates a data change event.|
| type | [SubscribeType](#subscribetype8) | Yes| Type defined in **SubscribeType**.|
| observer | Callback&lt;Array&lt;string&gt;&gt; | Yes| Observer that listens for the data changes in the RDB store.|

**Example**
A
Annie_wang 已提交
1694
  ```js
A
annie_wangli 已提交
1695 1696
  function storeObserver(devices) {
      for (let i = 0; i < devices.length; i++) {
A
Annie_wang 已提交
1697
          console.log('device=' + devices[i] + ' data changed')
A
annie_wangli 已提交
1698 1699 1700 1701 1702 1703 1704
      }
  }
  try {
      rdbStore.on('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver)
  } catch (err) {
      console.log('register observer failed')
  }
A
annie_wangli 已提交
1705 1706
  ```

A
annie_wangli 已提交
1707
### off('dataChange')<sup>8+</sup>
A
annie_wangli 已提交
1708

A
annie_wangli 已提交
1709
off(event:'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void
A
annie_wangli 已提交
1710

A
Annie_wang 已提交
1711
Deletes the specified observer of the RDB store. This API uses a callback to return the result.
A
annie_wangli 已提交
1712

A
annie_wangli 已提交
1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| event | string | Yes| The value is'dataChange', which indicates a data change event.|
| type | [SubscribeType](#subscribetype8)    | Yes| Type defined in **SubscribeType**.|
| observer | Callback&lt;Array&lt;string&gt;&gt; | Yes| Data change observer registered.|

**Example**
A
annie_wangli 已提交
1724

A
Annie_wang 已提交
1725
  ```js
A
annie_wangli 已提交
1726 1727
  function storeObserver(devices) {
      for (let i = 0; i < devices.length; i++) {
A
Annie_wang 已提交
1728
          console.log('device=' + devices[i] + ' data changed')
A
annie_wangli 已提交
1729 1730 1731
      }
  }
  try {
A
annie_wangli 已提交
1732
      rdbStore.off('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver)
A
annie_wangli 已提交
1733 1734 1735 1736 1737 1738
  } catch (err) {
      console.log('unregister observer failed')
  }
  ```

## StoreConfig
Z
zengyawen 已提交
1739 1740 1741

Manages the configuration of an RDB store.

A
annie_wangli 已提交
1742 1743
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

A
annie_wangli 已提交
1744 1745 1746 1747 1748 1749
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Database file name.|


## ValueType
Z
zengyawen 已提交
1750 1751 1752

Defines the data types allowed.

A
annie_wangli 已提交
1753 1754
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

A
annie_wangli 已提交
1755 1756 1757 1758 1759 1760 1761 1762
| Name| Description|
| -------- | -------- |
| number | Number.|
| string | String.|
| boolean | Boolean.|


## ValuesBucket
Z
zengyawen 已提交
1763 1764 1765

Defines a bucket to store key-value pairs.

A
annie_wangli 已提交
1766
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
Z
zengyawen 已提交
1767

A
annie_wangli 已提交
1768 1769 1770 1771 1772
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| [key:&nbsp;string] | [ValueType](#valuetype)\|&nbsp;Uint8Array&nbsp;\|&nbsp;null | Yes| Defines a bucket to store key-value pairs.|


A
annie_wangli 已提交
1773
## SyncMode<sup>8+</sup>
A
annie_wangli 已提交
1774 1775 1776

Defines the database synchronization mode.

A
annie_wangli 已提交
1777 1778 1779 1780 1781 1782
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

| Name      | Default Value| Description|
| --------  | ----- |----- |
| SYNC_MODE_PUSH | 0 | Data is pushed from a local device to a remote device.|
| SYNC_MODE_PULL | 1 | Data is pulled from a remote device to a local device.|
A
annie_wangli 已提交
1783

A
annie_wangli 已提交
1784
## SubscribeType<sup>8+</sup>
A
annie_wangli 已提交
1785 1786 1787

Defines the subscription type.

A
annie_wangli 已提交
1788 1789 1790 1791 1792
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

| Name     | Default Value| Description|
| -------- | ----- |---- |
| SUBSCRIBE_TYPE_REMOTE | 0 | Subscribe to remote data changes.|