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

Z
zengyawen 已提交
3
> ![icon-note.gif](public_sys-resources/icon-note.gif) **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 7 8


## Modules to Import
Z
zengyawen 已提交
9

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

A
Annie_wang 已提交
14 15 16 17 18 19 20
## data_rdb.getRdbStore

getRdbStore(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
A
annie_wangli 已提交
21

A
Annie_wang 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
**Parameters**

| 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**

```js
const STORE_CONFIG = { name: "RdbTest.db"}
const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
data_rdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) {
    rdbStore.executeSql(SQL_CREATE_TABLE, null, function() {
        console.info('create table done.')
        })
})
```
A
annie_wangli 已提交
41 42
## data_rdb.getRdbStore

A
Annie_wang 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
getRdbStore(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|
| -------- | -------- | -------- | -------- |
| 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(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.")
})
```


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

A
annie_wangli 已提交
83 84
getRdbStore(context: Context, config: StoreConfig, version: number, callback: AsyncCallback&lt;RdbStore&gt;): void

A
Annie_wang 已提交
85
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 已提交
86

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

Z
zengyawen 已提交
89
**Parameters**
A
Annie_wang 已提交
90

Z
zengyawen 已提交
91 92
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
93
| 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).|
Z
zengyawen 已提交
94 95 96 97 98 99
| 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 已提交
100
```js
Z
zengyawen 已提交
101 102
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)"
A
Annie_wang 已提交
103 104 105 106
data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) {
    rdbStore.executeSql(SQL_CREATE_TABLE, null, function() {
        console.info('create table done.')
        })    
Z
zengyawen 已提交
107 108
})
```
A
annie_wangli 已提交
109

A
Annie_wang 已提交
110
## data_rdb.getRdbStore<sup>8+</sup>
A
annie_wangli 已提交
111 112

getRdbStore(context: Context, config: StoreConfig, version: number): Promise&lt;RdbStore&gt;
Z
zengyawen 已提交
113

A
Annie_wang 已提交
114
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 已提交
115

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

Z
zengyawen 已提交
118
**Parameters**
A
annie_wangli 已提交
119

Z
zengyawen 已提交
120 121
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
122
| 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).|
Z
zengyawen 已提交
123 124 125 126 127 128 129 130 131 132 133
| 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 已提交
134
```js
Z
zengyawen 已提交
135 136
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)"
A
Annie_wang 已提交
137
let promisegetRdb = data_rdb.getRdbStore(this.context, STORE_CONFIG, 1);
Z
zengyawen 已提交
138 139 140 141 142 143 144 145 146 147 148
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_wangli 已提交
149 150 151

## data_rdb.deleteRdbStore

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

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

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

Z
zengyawen 已提交
158 159 160 161 162 163 164
**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 已提交
165
  ```js
Z
zengyawen 已提交
166 167 168
  data_rdb.deleteRdbStore("RdbTest.db", function (err, rdbStore) {
      console.info('delete store done.')
  })
A
annie_wangli 已提交
169
  ```
A
Annie_wang 已提交
170
  ## data_rdb.deleteRdbStore
A
annie_wangli 已提交
171

A
Annie_wang 已提交
172 173 174 175 176 177 178 179 180 181 182 183 184 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 219 220
deleteRdbStore(name: string): Promise&lt;void&gt;

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

**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|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to|

**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 已提交
221 222

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

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

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

Z
zengyawen 已提交
228 229 230
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
231
| 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).|
Z
zengyawen 已提交
232
| name | string | Yes| Name of the RDB store to delete.|
A
annie_wangli 已提交
233

Z
zengyawen 已提交
234 235 236
**Return value**
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
237
| Promise&lt;void&gt; | Promise used to|
Z
zengyawen 已提交
238 239

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

A
Annie_wang 已提交
249

A
annie_wangli 已提交
250
## RdbPredicates
Z
zengyawen 已提交
251 252 253

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

A
annie_wangli 已提交
254 255 256 257 258 259 260 261

### constructor

constructor(name: string)


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

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

Z
zengyawen 已提交
264 265 266 267
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Database table name.|
A
annie_wangli 已提交
268

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

Z
zengyawen 已提交
274
### inDevices<sup>8+</sup>
A
annie_wangli 已提交
275

Z
zengyawen 已提交
276
inDevices(devices: Array&lt;string&gt;): RdbPredicates
A
annie_wangli 已提交
277 278 279 280


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

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

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

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

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

Z
zengyawen 已提交
299
### inAllDevices<sup>8+</sup>
A
annie_wangli 已提交
300

Z
zengyawen 已提交
301
inAllDevices(): RdbPredicates
A
annie_wangli 已提交
302 303 304 305


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

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

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

Z
zengyawen 已提交
313
**Example**
A
Annie_wang 已提交
314
  ```js
A
annie_wangli 已提交
315 316 317 318 319 320 321 322 323 324 325
  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.

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

Z
zengyawen 已提交
328 329 330 331 332
**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 已提交
333

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

Z
zengyawen 已提交
339
**Example**
A
Annie_wang 已提交
340
  ```js
A
annie_wangli 已提交
341 342 343 344 345 346 347 348 349 350 351 352
  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.

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

Z
zengyawen 已提交
355 356 357 358 359
**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 已提交
360

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

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


### beginWrap

beginWrap(): RdbPredicates


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

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

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

Z
zengyawen 已提交
387
**Example**
A
Annie_wang 已提交
388
  ```js
A
annie_wangli 已提交
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
  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**.

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

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

Z
zengyawen 已提交
413
**Example**
A
Annie_wang 已提交
414
  ```js
A
annie_wangli 已提交
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
  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**.

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

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

Z
zengyawen 已提交
439
**Example**
A
Annie_wang 已提交
440
  ```js
A
annie_wangli 已提交
441 442 443 444 445 446 447 448 449 450 451 452 453 454
  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**.

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

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

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


### contains

Z
zengyawen 已提交
473
contains(field: string, value: string): RdbPredicates
A
annie_wangli 已提交
474 475 476

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

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

Z
zengyawen 已提交
479 480 481 482 483
**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 已提交
484

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

Z
zengyawen 已提交
490
**Example**
A
Annie_wang 已提交
491
  ```js
A
annie_wangli 已提交
492 493 494 495 496 497 498 499 500 501 502 503
  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.

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

Z
zengyawen 已提交
506 507 508 509 510
**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 已提交
511

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

Z
zengyawen 已提交
517
**Example**
A
Annie_wang 已提交
518
  ```js
A
annie_wangli 已提交
519 520 521 522 523 524 525 526 527 528 529 530
  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.

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

Z
zengyawen 已提交
533 534 535 536 537
**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 已提交
538

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

Z
zengyawen 已提交
544
**Example**
A
Annie_wang 已提交
545
  ```js
A
annie_wangli 已提交
546 547 548 549 550 551 552 553 554 555 556 557
  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.

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

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

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

- Example
A
Annie_wang 已提交
571
  ```js
A
annie_wangli 已提交
572 573 574 575 576 577 578 579 580 581 582 583
  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.

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

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

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

Z
zengyawen 已提交
596
**Example**
A
Annie_wang 已提交
597
  ```js
A
annie_wangli 已提交
598 599 600 601 602 603 604 605 606 607 608 609
  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.

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

Z
zengyawen 已提交
612 613 614 615 616
**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 已提交
617

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

Z
zengyawen 已提交
623
**Example**
A
Annie_wang 已提交
624
  ```js
A
annie_wangli 已提交
625 626 627 628 629 630 631 632 633 634 635 636
  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.

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

Z
zengyawen 已提交
639 640 641 642 643
**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 已提交
644

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

Z
zengyawen 已提交
650
**Example**
A
Annie_wang 已提交
651
  ```js
A
annie_wangli 已提交
652 653 654 655 656 657 658 659 660 661 662 663
  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.

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

Z
zengyawen 已提交
666 667 668 669 670 671
**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 已提交
672

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

Z
zengyawen 已提交
678
**Example**
A
Annie_wang 已提交
679
  ```js
A
annie_wangli 已提交
680 681 682 683 684 685 686 687 688 689 690 691
  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.

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

Z
zengyawen 已提交
694 695 696 697 698 699
**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 已提交
700

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

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


### greaterThan

Z
zengyawen 已提交
715
greaterThan(field: string, value: ValueType): RdbPredicates
A
annie_wangli 已提交
716 717 718

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

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

Z
zengyawen 已提交
721 722 723 724 725
**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 已提交
726

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

Z
zengyawen 已提交
732
**Example**
A
Annie_wang 已提交
733
  ```js
A
annie_wangli 已提交
734 735 736 737 738 739 740 741 742 743 744 745
  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.

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

Z
zengyawen 已提交
748 749 750 751 752
**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 已提交
753

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

Z
zengyawen 已提交
759
**Example**
A
Annie_wang 已提交
760
  ```js
A
annie_wangli 已提交
761 762 763 764 765 766 767 768 769 770 771 772 773
  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.

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

Z
zengyawen 已提交
776 777 778 779 780
**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 已提交
781

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

Z
zengyawen 已提交
787
**Example**
A
Annie_wang 已提交
788
  ```js
A
annie_wangli 已提交
789 790 791 792 793 794 795 796 797 798 799 800 801
  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.

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

Z
zengyawen 已提交
804 805 806 807 808
**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 已提交
809

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

Z
zengyawen 已提交
815
**Example**
A
Annie_wang 已提交
816
  ```js
A
annie_wangli 已提交
817 818 819 820 821 822 823 824 825 826 827 828 829
  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.

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

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

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

Z
zengyawen 已提交
842
**Example**
A
Annie_wang 已提交
843
  ```js
A
annie_wangli 已提交
844 845 846 847 848 849 850 851 852 853 854 855 856
  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.

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

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

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

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


### distinct

distinct(): RdbPredicates


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

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

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

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


### limitAs

limitAs(value: number): RdbPredicates


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

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

Z
zengyawen 已提交
913 914 915 916
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Maximum number of records.|
A
annie_wangli 已提交
917

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

Z
zengyawen 已提交
923
**Example**
A
Annie_wang 已提交
924
  ```js
A
annie_wangli 已提交
925 926 927 928 929 930 931 932 933 934 935 936
  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.

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

Z
zengyawen 已提交
939 940 941 942
**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 已提交
943

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

Z
zengyawen 已提交
949
**Example**
A
Annie_wang 已提交
950
  ```js
A
annie_wangli 已提交
951 952 953 954 955 956 957 958 959 960 961 962
  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.

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

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

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

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


### indexedBy

Z
zengyawen 已提交
984
indexedBy(field: string): RdbPredicates
A
annie_wangli 已提交
985 986 987

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

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

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

Z
zengyawen 已提交
995
**Return value**
A
annie_wangli 已提交
996

Z
zengyawen 已提交
997 998 999 1000 1001
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the index column.|

**Example**
A
Annie_wang 已提交
1002
  ```js
A
annie_wangli 已提交
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
  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.

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

Z
zengyawen 已提交
1017 1018 1019 1020 1021
**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 已提交
1022 1023


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

Z
zengyawen 已提交
1029
**Example**
A
Annie_wang 已提交
1030
  ```js
A
annie_wangli 已提交
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
  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.

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

Z
zengyawen 已提交
1045 1046 1047 1048 1049
**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 已提交
1050 1051


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

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


## RdbStore
Z
zengyawen 已提交
1065 1066 1067 1068

Provides methods to manage an RDB store.


A
annie_wangli 已提交
1069 1070 1071
### insert

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

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

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

Z
zengyawen 已提交
1077 1078 1079 1080 1081 1082 1083 1084
**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 已提交
1085
  ```js
A
annie_wangli 已提交
1086 1087 1088 1089 1090 1091 1092
  const valueBucket = {
      "NAME": "Lisa",
      "AGE": 18,
      "SALARY": 100.5,
      "CODES": new Uint8Array([1, 2, 3, 4, 5]),
  }
  rdbStore.insert("EMPLOYEE", valueBucket, function (err, ret) {
Z
zengyawen 已提交
1093 1094
      console.log("insert first done: " + ret)
  })
A
annie_wangli 已提交
1095 1096 1097 1098 1099 1100
  ```


### insert

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

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

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

Z
zengyawen 已提交
1106 1107 1108 1109 1110
**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 已提交
1111

Z
zengyawen 已提交
1112 1113 1114 1115 1116 1117
**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 已提交
1118
  ```js
A
annie_wangli 已提交
1119 1120 1121 1122 1123 1124
  const valueBucket = {
      "NAME": "Lisa",
      "AGE": 18,
      "SALARY": 100.5,
      "CODES": new Uint8Array([1, 2, 3, 4, 5]),
  }
Z
zengyawen 已提交
1125 1126 1127 1128 1129 1130
  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 已提交
1131 1132 1133 1134 1135 1136 1137
  ```


### update

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

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

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

Z
zengyawen 已提交
1142 1143 1144 1145 1146 1147 1148 1149
**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 已提交
1150
  ```js
A
annie_wangli 已提交
1151 1152 1153 1154 1155 1156 1157 1158 1159
  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 已提交
1160
      console.log("updated row count: " + ret)})
A
annie_wangli 已提交
1161 1162 1163 1164 1165 1166 1167
  ```


### update

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

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

Z
zengyawen 已提交
1170 1171 1172 1173 1174 1175 1176
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**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 已提交
1177

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

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


### delete

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


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

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

Z
zengyawen 已提交
1211 1212 1213 1214 1215
**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 已提交
1216

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


### delete

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

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

Z
zengyawen 已提交
1233 1234 1235 1236 1237 1238
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

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

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

Z
zengyawen 已提交
1245
**Example**
A
Annie_wang 已提交
1246
  ```js
Z
zengyawen 已提交
1247 1248 1249 1250 1251 1252 1253 1254
  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 已提交
1255 1256 1257 1258 1259 1260
  ```


### query

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

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

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

Z
zengyawen 已提交
1266 1267 1268 1269 1270 1271 1272 1273
**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 已提交
1274
  ```js
A
annie_wangli 已提交
1275 1276 1277
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.equalTo("NAME", "Rose")
  rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
Z
zengyawen 已提交
1278 1279 1280
      console.log("resultSet column names:" + resultSet.columnNames)
      console.log("resultSet column count:" + resultSet.columnCount)
  })
A
annie_wangli 已提交
1281 1282 1283 1284 1285 1286
  ```


### query

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

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

Z
zengyawen 已提交
1290 1291 1292 1293 1294 1295 1296
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**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 已提交
1297

Z
zengyawen 已提交
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.|
A
annie_wangli 已提交
1302

Z
zengyawen 已提交
1303
**Example**
A
Annie_wang 已提交
1304
  ```js
A
annie_wangli 已提交
1305 1306
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.equalTo("NAME", "Rose")
Z
zengyawen 已提交
1307 1308 1309 1310 1311 1312 1313
  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 已提交
1314 1315 1316 1317 1318 1319 1320
  ```


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

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

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

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

Z
zengyawen 已提交
1325 1326 1327 1328 1329 1330 1331 1332
**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 已提交
1333
  ```js
A
annie_wangli 已提交
1334
  rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) {
Z
zengyawen 已提交
1335 1336 1337
      console.log("resultSet column names:" + resultSet.columnNames)
      console.log("resultSet column count:" + resultSet.columnCount)
  })
A
annie_wangli 已提交
1338 1339 1340 1341 1342 1343 1344
  ```


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

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

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

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

Z
zengyawen 已提交
1349 1350 1351 1352 1353
**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 已提交
1354

Z
zengyawen 已提交
1355 1356 1357 1358 1359 1360
**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 已提交
1361
  ```js
Z
zengyawen 已提交
1362 1363 1364 1365 1366 1367 1368
  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 已提交
1369 1370 1371 1372 1373 1374
  ```


### executeSql

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

A
Annie_wang 已提交
1376
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 已提交
1377

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

Z
zengyawen 已提交
1380 1381 1382 1383 1384 1385 1386 1387
**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 已提交
1388
  ```js
A
annie_wangli 已提交
1389
  rdbStore.executeSql("DELETE FROM EMPLOYEE", null, function () {
Z
zengyawen 已提交
1390 1391
      console.info('delete done.')
  })
A
annie_wangli 已提交
1392 1393 1394 1395 1396 1397
  ```


### executeSql

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

A
Annie_wang 已提交
1399
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 已提交
1400

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

Z
zengyawen 已提交
1403 1404 1405 1406 1407
**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 已提交
1408

Z
zengyawen 已提交
1409 1410 1411 1412 1413 1414
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|

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

Z
zengyawen 已提交
1424 1425 1426 1427 1428 1429 1430 1431 1432
### beginTransaction<sup>8+</sup>

beginTransaction():void

Starts the transaction before executing an SQL statement.

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

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

Z
zengyawen 已提交
1452 1453 1454 1455 1456
Commits the executed SQL statements.

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

**Example**
A
Annie_wang 已提交
1457
```js
Z
zengyawen 已提交
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481
  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 已提交
1482
```js
Z
zengyawen 已提交
1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504
  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 已提交
1505

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

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

Z
zengyawen 已提交
1510 1511 1512 1513 1514 1515 1516
**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 已提交
1517
  ```js
A
annie_wangli 已提交
1518 1519 1520 1521 1522 1523 1524 1525 1526 1527
  rdbStore.setDistributedTables(["EMPLOYEE"], function (err) {
      if (err) {
          console.info('setDistributedTables failed.')
          return
      }
      console.info('setDistributedTables success.')
  })
  ```


Z
zengyawen 已提交
1528
### setDistributedTables<sup>8+</sup>
A
annie_wangli 已提交
1529

Z
zengyawen 已提交
1530
 setDistributedTables(tables: Array&lt;string&gt;): Promise&lt;void&gt;
A
annie_wangli 已提交
1531

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

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

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

Z
zengyawen 已提交
1541 1542 1543 1544 1545 1546
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|

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

Z
zengyawen 已提交
1556
### obtainDistributedTableName<sup>8+</sup>
A
annie_wangli 已提交
1557

Z
zengyawen 已提交
1558
obtainDistributedTableName(device: string, table: string, callback: AsyncCallback&lt;string&gt;): void
A
annie_wangli 已提交
1559

A
Annie_wang 已提交
1560
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 已提交
1561

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

Z
zengyawen 已提交
1564 1565 1566 1567 1568 1569 1570 1571
**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 已提交
1572
  ```js
A
annie_wangli 已提交
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582
  rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) {
      if (err) {
          console.info('obtainDistributedTableName failed.')
          return
      }
      console.info('obtainDistributedTableName success, tableName=.' + tableName)
   })
  ```


Z
zengyawen 已提交
1583
### obtainDistributedTableName<sup>8+</sup>
A
annie_wangli 已提交
1584

Z
zengyawen 已提交
1585
 obtainDistributedTableName(device: string, table: string): Promise&lt;string&gt;
A
annie_wangli 已提交
1586

A
Annie_wang 已提交
1587
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 已提交
1588

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

Z
zengyawen 已提交
1591 1592 1593 1594 1595
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| device | string | Yes| Remote device.|
| table | string | Yes| Local table name.|
A
annie_wangli 已提交
1596

Z
zengyawen 已提交
1597 1598 1599 1600 1601 1602
**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.|

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

Z
zengyawen 已提交
1612
### sync<sup>8+</sup>
A
annie_wangli 已提交
1613

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

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

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

Z
zengyawen 已提交
1620 1621 1622 1623 1624 1625 1626 1627
**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 已提交
1628
  ```js
A
annie_wangli 已提交
1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643
  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])
       }
  })
  ```


Z
zengyawen 已提交
1644
### sync<sup>8+</sup>
A
annie_wangli 已提交
1645

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

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

Z
zengyawen 已提交
1650 1651 1652 1653 1654 1655 1656
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**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 已提交
1657

Z
zengyawen 已提交
1658
**Return value**
A
annie_wangli 已提交
1659

Z
zengyawen 已提交
1660 1661 1662 1663 1664
| 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 已提交
1665
  ```js
Z
zengyawen 已提交
1666 1667 1668 1669
  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 已提交
1670 1671 1672 1673
      console.log('sync done.')
      for (let i = 0; i < result.length; i++) {
          console.log('device=' + result[i][0] + ' status=' + result[i][1])
      }
Z
zengyawen 已提交
1674 1675 1676
  }).catch((err) => {
      console.log('sync failed')
  })
A
annie_wangli 已提交
1677 1678
  ```

Z
zengyawen 已提交
1679
### on('dataChange')<sup>8+</sup>
A
annie_wangli 已提交
1680

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

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

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

Z
zengyawen 已提交
1687 1688 1689 1690 1691 1692 1693 1694 1695
**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 已提交
1696
  ```js
A
annie_wangli 已提交
1697 1698
  function storeObserver(devices) {
      for (let i = 0; i < devices.length; i++) {
A
Annie_wang 已提交
1699
          console.log('device=' + devices[i] + ' data changed')
Z
zengyawen 已提交
1700 1701 1702 1703 1704 1705 1706
      }
  }
  try {
      rdbStore.on('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver)
  } catch (err) {
      console.log('register observer failed')
  }
A
annie_wangli 已提交
1707 1708
  ```

Z
zengyawen 已提交
1709
### off('dataChange')<sup>8+</sup>
A
annie_wangli 已提交
1710

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

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

Z
zengyawen 已提交
1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725
**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 已提交
1726

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

## StoreConfig
Z
zengyawen 已提交
1741 1742 1743

Manages the configuration of an RDB store.

Z
zengyawen 已提交
1744 1745
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

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


## ValueType
Z
zengyawen 已提交
1752 1753 1754

Defines the data types allowed.

Z
zengyawen 已提交
1755 1756
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

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


## ValuesBucket
Z
zengyawen 已提交
1765 1766 1767

Defines a bucket to store key-value pairs.

Z
zengyawen 已提交
1768
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
Z
zengyawen 已提交
1769

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


Z
zengyawen 已提交
1775
## SyncMode<sup>8+</sup>
A
annie_wangli 已提交
1776 1777 1778

Defines the database synchronization mode.

Z
zengyawen 已提交
1779 1780 1781 1782 1783 1784
**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 已提交
1785

Z
zengyawen 已提交
1786
## SubscribeType<sup>8+</sup>
A
annie_wangli 已提交
1787 1788 1789

Defines the subscription type.

Z
zengyawen 已提交
1790 1791 1792 1793 1794
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

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