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

A
Annie_wang 已提交
3 4 5 6 7 8 9
The relational database (RDB) manages data based on relational models. With the underlying SQLite database, the RDB provides a complete mechanism for managing local databases. To satisfy different needs in complicated scenarios, the RDB offers a series of methods for performing operations such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements.

This module provides the following RDB-related functions:

- [RdbPredicates](#rdbpredicates): predicates indicating the nature, feature, or relationship of a data entity in an RDB store. It is used to define the operation conditions for an RDB store.
- [RdbStore](#rdbstore): provides APIs for managing an RDB store.

A
Annie_wang 已提交
10
> **NOTE**<br/>
A
Annie_wang 已提交
11
> 
A
annie_wangli 已提交
12
> 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 已提交
13

A
annie_wangli 已提交
14
## Modules to Import
Z
zengyawen 已提交
15

A
Annie_wang 已提交
16 17
```js
import data_rdb from '@ohos.data.rdb';
Z
zengyawen 已提交
18
```
A
annie_wangli 已提交
19 20 21

## data_rdb.getRdbStore

A
Annie_wang 已提交
22 23
getRdbStore(context: Context, config: StoreConfig, version: number, callback: AsyncCallback&lt;RdbStore&gt;): void

A
Annie_wang 已提交
24
Obtains an 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_wang 已提交
25 26 27 28 29 30 31

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
32
| context | Context | Yes| Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).|
A
Annie_wang 已提交
33 34 35 36 37 38 39 40 41
| 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"}
data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) {
A
Annie_wang 已提交
42
    if (err) {
A
Annie_wang 已提交
43
        console.info("Failed to get RdbStore, err: " + err)
A
Annie_wang 已提交
44 45
        return
    }
A
Annie_wang 已提交
46
    console.log("Got RdbStore successfully.")
A
Annie_wang 已提交
47
})
A
annie_wangli 已提交
48
```
A
Annie_wang 已提交
49

A
Annie_wang 已提交
50
## data_rdb.getRdbStore
A
Annie_wang 已提交
51 52 53 54 55 56 57 58 59 60 61

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|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
62
| context | Context | Yes|Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).|
A
Annie_wang 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75
| 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" }
A
Annie_wang 已提交
76 77
let promise = data_rdb.getRdbStore(this.context, STORE_CONFIG, 1);
promise.then(async (rdbStore) => {
A
Annie_wang 已提交
78
    console.log("Got RdbStore successfully.")
A
Annie_wang 已提交
79
}).catch((err) => {
A
Annie_wang 已提交
80
    console.log("Failed to get RdbStore, err: " + err)
A
Annie_wang 已提交
81
})
A
annie_wangli 已提交
82
```
A
annie_wangli 已提交
83 84 85

## data_rdb.deleteRdbStore

A
Annie_wang 已提交
86 87
deleteRdbStore(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
88
Deletes an RDB store. This API uses an asynchronous callback to return the result. 
A
Annie_wang 已提交
89 90 91 92 93 94

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

**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
95
| context | Context | Yes| Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).|
A
Annie_wang 已提交
96 97 98 99
| 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 已提交
100 101 102
```js
data_rdb.deleteRdbStore(this.context, "RdbTest.db", function (err, rdbStore) {
    if (err) {
A
Annie_wang 已提交
103
        console.info("Failed to delete RdbStore, err: " + err)
A
Annie_wang 已提交
104 105
        return
    }
A
Annie_wang 已提交
106
    console.log("Deleted RdbStore successfully.")
A
Annie_wang 已提交
107 108
})
```
A
Annie_wang 已提交
109

A
Annie_wang 已提交
110
## data_rdb.deleteRdbStore
A
annie_wangli 已提交
111 112

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

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

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

A
annie_wangli 已提交
118 119 120
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
121
| context | Context | Yes| Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).|
A
annie_wangli 已提交
122
| name | string | Yes| Name of the RDB store to delete.|
A
annie_wangli 已提交
123

A
annie_wangli 已提交
124 125 126
**Return value**
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
127
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
128 129

**Example**
A
Annie_wang 已提交
130
```js
A
Annie_wang 已提交
131
let promise = data_rdb.deleteRdbStore(this.context, "RdbTest.db")
A
Annie_wang 已提交
132
promise.then(()=>{
A
Annie_wang 已提交
133
    console.log("Deleted RdbStore successfully.")
A
Annie_wang 已提交
134
}).catch((err) => {
A
Annie_wang 已提交
135
    console.info("Failed to delete RdbStore, err: " + err)
A
Annie_wang 已提交
136 137
})
```
A
annie_wangli 已提交
138

A
annie_wangli 已提交
139

A
annie_wangli 已提交
140
## RdbPredicates
Z
zengyawen 已提交
141 142 143

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

A
annie_wangli 已提交
144 145 146 147 148 149 150 151

### constructor

constructor(name: string)


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

A
annie_wangli 已提交
152
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
153

A
annie_wangli 已提交
154 155 156 157
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Database table name.|
A
annie_wangli 已提交
158

A
annie_wangli 已提交
159
**Example**
A
Annie_wang 已提交
160 161 162
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
```
A
annie_wangli 已提交
163

A
annie_wangli 已提交
164
### inDevices<sup>8+</sup>
A
annie_wangli 已提交
165

A
annie_wangli 已提交
166
inDevices(devices: Array&lt;string&gt;): RdbPredicates
A
annie_wangli 已提交
167 168 169 170


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

A
annie_wangli 已提交
171
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
172

A
annie_wangli 已提交
173 174 175 176
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| devices | Array&lt;string&gt; | Yes| ID of the remote device to specify.|
A
annie_wangli 已提交
177

A
annie_wangli 已提交
178 179 180 181
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
182

A
annie_wangli 已提交
183
**Example**
A
Annie_wang 已提交
184 185 186 187
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.inDevices(['12345678abcde'])
```
A
annie_wangli 已提交
188

A
annie_wangli 已提交
189
### inAllDevices<sup>8+</sup>
A
annie_wangli 已提交
190

A
annie_wangli 已提交
191
inAllDevices(): RdbPredicates
A
annie_wangli 已提交
192 193 194 195


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

A
annie_wangli 已提交
196
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
197

A
annie_wangli 已提交
198 199 200 201
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
202

A
annie_wangli 已提交
203
**Example**
A
Annie_wang 已提交
204 205 206 207
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.inAllDevices()
```
A
annie_wangli 已提交
208 209 210 211 212 213 214 215

### 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 已提交
216
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
217

A
annie_wangli 已提交
218 219 220 221 222
**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 已提交
223

A
annie_wangli 已提交
224 225 226 227
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
228

A
annie_wangli 已提交
229
**Example**
A
Annie_wang 已提交
230 231 232 233
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "lisi")
```
A
annie_wangli 已提交
234 235 236 237 238 239 240 241 242


### 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 已提交
243
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
244

A
annie_wangli 已提交
245 246 247 248 249
**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 已提交
250

A
annie_wangli 已提交
251 252 253 254
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
255

A
annie_wangli 已提交
256
**Example**
A
Annie_wang 已提交
257 258 259 260
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.notEqualTo("NAME", "lisi")
```
A
annie_wangli 已提交
261 262 263 264 265 266 267 268 269


### beginWrap

beginWrap(): RdbPredicates


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

A
annie_wangli 已提交
270
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
271

A
annie_wangli 已提交
272 273 274 275
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a left parenthesis.|
A
annie_wangli 已提交
276

A
annie_wangli 已提交
277
**Example**
A
Annie_wang 已提交
278 279 280 281 282 283 284 285 286
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "lisi")
    .beginWrap()
    .equalTo("AGE", 18)
    .or()
    .equalTo("SALARY", 200.5)
    .endWrap()
```
A
annie_wangli 已提交
287 288 289 290 291 292 293 294 295


### endWrap

endWrap(): RdbPredicates


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

A
annie_wangli 已提交
296
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
297

A
annie_wangli 已提交
298 299 300 301
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a right parenthesis.|
A
annie_wangli 已提交
302

A
annie_wangli 已提交
303
**Example**
A
Annie_wang 已提交
304 305 306 307 308 309 310 311 312
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "lisi")
    .beginWrap()
    .equalTo("AGE", 18)
    .or()
    .equalTo("SALARY", 200.5)
    .endWrap()
```
A
annie_wangli 已提交
313 314 315 316 317 318 319 320 321


### or

or(): RdbPredicates


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

A
annie_wangli 已提交
322
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
323

A
annie_wangli 已提交
324 325 326 327
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the OR condition.|
A
annie_wangli 已提交
328

A
annie_wangli 已提交
329
**Example**
A
Annie_wang 已提交
330 331 332 333 334 335
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa")
    .or()
    .equalTo("NAME", "Rose")
```
A
annie_wangli 已提交
336 337 338 339 340 341 342 343 344


### and

and(): RdbPredicates


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

A
annie_wangli 已提交
345
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
346

A
annie_wangli 已提交
347 348 349 350
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the AND condition.|
A
annie_wangli 已提交
351

A
annie_wangli 已提交
352
**Example**
A
Annie_wang 已提交
353 354 355 356 357 358
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa")
    .and()
    .equalTo("SALARY", 200.5)
```
A
annie_wangli 已提交
359 360 361 362


### contains

A
annie_wangli 已提交
363
contains(field: string, value: string): RdbPredicates
A
annie_wangli 已提交
364 365 366

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

A
annie_wangli 已提交
367
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
368

A
annie_wangli 已提交
369 370 371 372 373
**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 已提交
374

A
annie_wangli 已提交
375 376 377 378
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
379

A
annie_wangli 已提交
380
**Example**
A
Annie_wang 已提交
381 382 383 384
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.contains("NAME", "os")
```
A
annie_wangli 已提交
385 386 387 388 389 390 391 392 393


### beginsWith

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


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

A
annie_wangli 已提交
394
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
395

A
annie_wangli 已提交
396 397 398 399 400
**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 已提交
401

A
annie_wangli 已提交
402 403 404 405
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
406

A
annie_wangli 已提交
407
**Example**
A
Annie_wang 已提交
408 409 410 411
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.beginsWith("NAME", "os")
```
A
annie_wangli 已提交
412 413 414 415 416 417 418 419 420


### endsWith

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


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

A
annie_wangli 已提交
421
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
422

A
annie_wangli 已提交
423 424 425 426 427
**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 已提交
428

A
annie_wangli 已提交
429 430 431 432
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
433

A
annie_wangli 已提交
434
**Example**
A
Annie_wang 已提交
435 436 437 438
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.endsWith("NAME", "se")
```
A
annie_wangli 已提交
439 440 441 442 443 444 445 446 447


### isNull

isNull(field: string): RdbPredicates


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

A
annie_wangli 已提交
448
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
449

A
annie_wangli 已提交
450 451 452 453
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
A
annie_wangli 已提交
454

A
annie_wangli 已提交
455 456 457 458
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
459 460

- Example
A
Annie_wang 已提交
461 462 463 464
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.isNull("NAME")
```
A
annie_wangli 已提交
465 466 467 468 469 470 471 472 473


### isNotNull

isNotNull(field: string): RdbPredicates


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

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

A
annie_wangli 已提交
476 477 478 479
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
A
annie_wangli 已提交
480

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

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


### like

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


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

A
annie_wangli 已提交
500
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
501

A
annie_wangli 已提交
502 503 504 505 506
**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 已提交
507

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

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


### glob

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


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

A
annie_wangli 已提交
527
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
528

A
annie_wangli 已提交
529 530 531 532
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
A
Annie_wang 已提交
533
| 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 已提交
534

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

A
annie_wangli 已提交
540
**Example**
A
Annie_wang 已提交
541 542 543 544
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.glob("NAME", "?h*g")
```
A
annie_wangli 已提交
545 546 547 548 549 550 551 552 553


### 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 已提交
554
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
555

A
annie_wangli 已提交
556 557 558 559 560 561
**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 已提交
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

A
annie_wangli 已提交
568
**Example**
A
Annie_wang 已提交
569 570 571 572
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.between("AGE", 10, 50)
```
A
annie_wangli 已提交
573 574 575 576 577 578 579 580 581


### 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 已提交
582
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
583

A
annie_wangli 已提交
584 585 586 587 588 589
**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 已提交
590

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

A
annie_wangli 已提交
596
**Example**
A
Annie_wang 已提交
597 598 599 600
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.notBetween("AGE", 10, 50)
```
A
annie_wangli 已提交
601 602 603 604


### greaterThan

A
annie_wangli 已提交
605
greaterThan(field: string, value: ValueType): RdbPredicates
A
annie_wangli 已提交
606 607 608

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

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

A
annie_wangli 已提交
611 612 613 614 615
**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 已提交
616

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

A
annie_wangli 已提交
622
**Example**
A
Annie_wang 已提交
623 624 625 626
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.greaterThan("AGE", 18)
```
A
annie_wangli 已提交
627 628 629 630 631 632 633 634 635


### 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 已提交
636
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
637

A
annie_wangli 已提交
638 639 640 641 642
**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 已提交
643

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

A
annie_wangli 已提交
649
**Example**
A
Annie_wang 已提交
650 651 652 653
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.lessThan("AGE", 20)
```
A
annie_wangli 已提交
654 655 656 657 658 659 660 661 662 663


### 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 已提交
664
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
665

A
annie_wangli 已提交
666 667 668 669 670
**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 已提交
671

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

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


### 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 已提交
692
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
693

A
annie_wangli 已提交
694 695 696 697 698
**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 已提交
699

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

A
annie_wangli 已提交
705
**Example**
A
Annie_wang 已提交
706 707 708 709
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.lessThanOrEqualTo("AGE", 20)
```
A
annie_wangli 已提交
710 711 712 713 714 715 716 717 718 719


### orderByAsc


orderByAsc(field: string): RdbPredicates


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

A
annie_wangli 已提交
720
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
721

A
annie_wangli 已提交
722 723 724 725
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
A
annie_wangli 已提交
726

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

A
annie_wangli 已提交
732
**Example**
A
Annie_wang 已提交
733 734 735 736
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.orderByAsc("NAME")
```
A
annie_wangli 已提交
737 738 739 740 741 742 743 744 745 746


### orderByDesc


orderByDesc(field: string): RdbPredicates


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

A
annie_wangli 已提交
747
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
748

A
annie_wangli 已提交
749 750 751 752
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
A
annie_wangli 已提交
753

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

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


### distinct

distinct(): RdbPredicates


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

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

A
annie_wangli 已提交
775 776 777 778
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that can filter out duplicate records.|
A
annie_wangli 已提交
779

A
annie_wangli 已提交
780
**Example**
A
Annie_wang 已提交
781 782 783 784 785
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose").distinct("NAME")
let promise = rdbStore.query(predicates, ["NAME"])
promise.then((resultSet) => {
A
Annie_wang 已提交
786 787
    console.log("ResultSet column names: " + resultSet.columnNames)
    console.log("ResultSet column count: " + resultSet.columnCount)
A
Annie_wang 已提交
788
}).catch((err) => {
A
Annie_wang 已提交
789
    console.log("Query err.")
A
Annie_wang 已提交
790 791
})
```
A
annie_wangli 已提交
792 793 794 795 796 797 798 799 800


### limitAs

limitAs(value: number): RdbPredicates


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

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

A
annie_wangli 已提交
803 804 805 806
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Maximum number of records.|
A
annie_wangli 已提交
807

A
annie_wangli 已提交
808 809 810 811
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the maximum number of records.|
A
annie_wangli 已提交
812

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


### offsetAs

offsetAs(rowOffset: number): RdbPredicates


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

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

A
annie_wangli 已提交
829 830 831 832
**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 已提交
833

A
annie_wangli 已提交
834 835 836 837
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the start position of the returned result.|
A
annie_wangli 已提交
838

A
annie_wangli 已提交
839
**Example**
A
Annie_wang 已提交
840 841 842 843
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose").offsetAs(3)
```
A
annie_wangli 已提交
844 845 846 847 848 849 850 851 852


### 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 已提交
853
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
854

A
annie_wangli 已提交
855 856 857 858
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| fields | Array&lt;string&gt; | Yes| Names of columns to group.|
A
annie_wangli 已提交
859

A
annie_wangli 已提交
860 861 862 863
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that groups rows with the same value.|
A
annie_wangli 已提交
864

A
annie_wangli 已提交
865
**Example**
A
Annie_wang 已提交
866 867 868 869
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.groupBy(["AGE", "NAME"])
```
A
annie_wangli 已提交
870 871 872 873


### indexedBy

A
annie_wangli 已提交
874
indexedBy(field: string): RdbPredicates
A
annie_wangli 已提交
875 876 877

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

A
annie_wangli 已提交
878
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
879

A
annie_wangli 已提交
880 881 882 883
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Name of the index column.|
A
annie_wangli 已提交
884

A
annie_wangli 已提交
885
**Return value**
A
annie_wangli 已提交
886

A
annie_wangli 已提交
887 888 889 890 891
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the index column.|

**Example**
A
Annie_wang 已提交
892 893 894 895
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.indexedBy("SALARY_INDEX")
```
A
annie_wangli 已提交
896 897 898 899 900 901 902 903 904


### 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 已提交
905
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
906

A
annie_wangli 已提交
907 908 909 910 911
**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 已提交
912 913


A
annie_wangli 已提交
914 915 916 917
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
918

A
annie_wangli 已提交
919
**Example**
A
Annie_wang 已提交
920 921 922 923
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.in("AGE", [18, 20])
```
A
annie_wangli 已提交
924 925 926 927 928 929 930 931 932


### 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 已提交
933
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
934

A
annie_wangli 已提交
935 936 937 938 939
**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 已提交
940 941


A
annie_wangli 已提交
942 943 944 945
**Return value**
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that matches the specified field.|
A
annie_wangli 已提交
946

A
annie_wangli 已提交
947
**Example**
A
Annie_wang 已提交
948 949 950 951
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.notIn("NAME", ["Lisa", "Rose"])
```
A
annie_wangli 已提交
952 953 954


## RdbStore
Z
zengyawen 已提交
955 956 957 958

Provides methods to manage an RDB store.


A
annie_wangli 已提交
959 960
### insert

A
Annie_wang 已提交
961
insert(table: string, values: ValuesBucket, callback: AsyncCallback&lt;number&gt;):void
Z
zengyawen 已提交
962

A
Annie_wang 已提交
963
Inserts a row of data into a table. This API uses an asynchronous callback to return the result.
Z
zengyawen 已提交
964

A
annie_wangli 已提交
965
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
966

A
annie_wangli 已提交
967 968 969
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
970
| table | string | Yes| Name of the target table.|
A
annie_wangli 已提交
971 972 973 974
| 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 已提交
975 976 977 978 979 980 981 982 983
```js
const valueBucket = {
    "NAME": "Lisa",
    "AGE": 18,
    "SALARY": 100.5,
    "CODES": new Uint8Array([1, 2, 3, 4, 5]),
}
rdbStore.insert("EMPLOYEE", valueBucket, function (err, ret) {
    if (err) {
A
Annie_wang 已提交
984
        console.info("Failed to insert data, err: " + err)
A
Annie_wang 已提交
985 986
        return
    }
A
Annie_wang 已提交
987
    console.log("Inserted first row: " + ret)
A
Annie_wang 已提交
988 989
})
```
A
annie_wangli 已提交
990 991 992 993


### insert

A
Annie_wang 已提交
994
insert(table: string, values: ValuesBucket):Promise&lt;number&gt;
Z
zengyawen 已提交
995

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

A
annie_wangli 已提交
998
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
999

A
annie_wangli 已提交
1000 1001 1002
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1003
| table | string | Yes| Name of the target table.|
A
annie_wangli 已提交
1004
| values | [ValuesBucket](#valuesbucket) | Yes| Row of data to insert.|
A
annie_wangli 已提交
1005

A
annie_wangli 已提交
1006 1007 1008 1009 1010 1011
**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 已提交
1012 1013 1014 1015 1016 1017 1018 1019 1020
```js
const valueBucket = {
    "NAME": "Lisa",
    "AGE": 18,
    "SALARY": 100.5,
    "CODES": new Uint8Array([1, 2, 3, 4, 5]),
}
let promise = rdbStore.insert("EMPLOYEE", valueBucket)
promise.then(async (ret) => {
A
Annie_wang 已提交
1021
    console.log("Inserted first row: " + ret)
A
Annie_wang 已提交
1022
}).catch((err) => {
A
Annie_wang 已提交
1023
    console.log("Failed to insert data, err: " + err)
A
Annie_wang 已提交
1024 1025
})
```
A
annie_wangli 已提交
1026 1027 1028 1029


### update

A
Annie_wang 已提交
1030
update(values: ValuesBucket, predicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void
A
annie_wangli 已提交
1031

A
Annie_wang 已提交
1032
Updates data in the RDB store based on the specified **RdbPredicates** object. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1033

A
annie_wangli 已提交
1034
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1035

A
annie_wangli 已提交
1036 1037 1038
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1039
| values | [ValuesBucket](#valuesbucket) | Yes| Rows of data to update in the RDB store. The key-value pair is associated with the column name in the target table.|
A
Annie_wang 已提交
1040
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Update conditions specified by the **RdbPredicates** object.|
A
Annie_wang 已提交
1041
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of rows updated.|
A
annie_wangli 已提交
1042 1043

**Example**
A
Annie_wang 已提交
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
```js
const valueBucket = {
    "NAME": "Rose",
    "AGE": 22,
    "SALARY": 200.5,
    "CODES": new Uint8Array([1, 2, 3, 4, 5]),
}
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa")
rdbStore.update(valueBucket, predicates, function (err, ret) {
    if (err) {
A
Annie_wang 已提交
1055
        console.info("Failed to update data, err: " + err)
A
Annie_wang 已提交
1056 1057 1058 1059 1060
        return
    }
    console.log("Updated row count: " + ret)
})
```
A
annie_wangli 已提交
1061 1062 1063 1064


### update

A
Annie_wang 已提交
1065
update(values: ValuesBucket, predicates: RdbPredicates):Promise&lt;number&gt;
A
annie_wangli 已提交
1066

A
Annie_wang 已提交
1067
Updates data in the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result.
A
annie_wangli 已提交
1068

A
annie_wangli 已提交
1069
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1070

A
annie_wangli 已提交
1071 1072 1073
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1074
| values | [ValuesBucket](#valuesbucket) | Yes| Rows of data to update in the RDB store. The key-value pair is associated with the column name in the target table.|
A
Annie_wang 已提交
1075
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Update conditions specified by the **RdbPredicates** object.|
A
annie_wangli 已提交
1076

A
annie_wangli 已提交
1077 1078 1079 1080 1081 1082
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Promise used to return the number of rows updated.|

**Example**
A
Annie_wang 已提交
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
```js
const valueBucket = {
    "NAME": "Rose",
    "AGE": 22,
    "SALARY": 200.5,
    "CODES": new Uint8Array([1, 2, 3, 4, 5]),
}
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa")
let promise = rdbStore.update(valueBucket, predicates)
promise.then(async (ret) => {
    console.log("Updated row count: " + ret)
}).catch((err) => {
A
Annie_wang 已提交
1096
    console.info("Failed to update data, err: " + err)
A
Annie_wang 已提交
1097 1098
})
```
A
annie_wangli 已提交
1099

A
Annie_wang 已提交
1100
### update<sup>9+</sup>
A
Annie_wang 已提交
1101
update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;number&gt;):void
A
Annie_wang 已提交
1102

A
Annie_wang 已提交
1103
Updates data in the RDB store based on the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1104 1105 1106 1107 1108 1109 1110

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

**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| table | string | Yes| Name of the target table.|
A
Annie_wang 已提交
1111
| values | [ValuesBucket](#valuesbucket) | Yes| Rows of data to update in the RDB store. The key-value pair is associated with the column name in the target table.|
1112
| predicates | [DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates)| Yes|  Update conditions specified by the **DataSharePredicates** object.|
A
Annie_wang 已提交
1113
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of rows updated.|
A
Annie_wang 已提交
1114 1115 1116

**Example**
```js
A
Annie_wang 已提交
1117
import dataSharePredicates from '@ohos.data.dataSharePredicates'
A
Annie_wang 已提交
1118 1119 1120 1121 1122 1123
const valueBucket = {
    "NAME": "Rose",
    "AGE": 22,
    "SALARY": 200.5,
    "CODES": new Uint8Array([1, 2, 3, 4, 5]),
}
A
Annie_wang 已提交
1124
let predicates = new dataSharePredicates.DataSharePredicates()
A
Annie_wang 已提交
1125 1126 1127
predicates.equalTo("NAME", "Lisa")
rdbStore.update("EMPLOYEE", valueBucket, predicates, function (err, ret) {
    if (err) {
A
Annie_wang 已提交
1128
        console.info("Failed to update data, err: " + err)
A
Annie_wang 已提交
1129 1130 1131 1132 1133 1134 1135
        return
    }
    console.log("Updated row count: " + ret)
})
```
### update<sup>9+</sup>

A
Annie_wang 已提交
1136
update(table: string, values: ValuesBucket, predicates: DataSharePredicates):Promise&lt;number&gt;
A
Annie_wang 已提交
1137

A
Annie_wang 已提交
1138
Updates data in the RDB store based on the specified **DataSharePredicates** object. This API uses a promise to return the result.
A
Annie_wang 已提交
1139 1140 1141 1142 1143 1144 1145

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

**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| table | string | Yes| Name of the target table.|
A
Annie_wang 已提交
1146
| values | [ValuesBucket](#valuesbucket) | Yes| Rows of data to update in the RDB store. The key-value pair is associated with the column name in the target table.|
1147
| predicates | [DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes| Update conditions specified by the **DataSharePredicates** object.|
A
Annie_wang 已提交
1148 1149 1150 1151 1152 1153 1154 1155

**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Promise used to return the number of rows updated.|

**Example**
```js
A
Annie_wang 已提交
1156
import dataSharePredicates from '@ohos.data.dataSharePredicates'
A
Annie_wang 已提交
1157 1158 1159 1160 1161 1162
const valueBucket = {
    "NAME": "Rose",
    "AGE": 22,
    "SALARY": 200.5,
    "CODES": new Uint8Array([1, 2, 3, 4, 5]),
}
A
Annie_wang 已提交
1163
let predicates = new dataSharePredicates.DataSharePredicates()
A
Annie_wang 已提交
1164 1165 1166 1167 1168
predicates.equalTo("NAME", "Lisa")
let promise = rdbStore.update("EMPLOYEE", valueBucket, predicates)
promise.then(async (ret) => {
    console.log("Updated row count: " + ret)
}).catch((err) => {
A
Annie_wang 已提交
1169
    console.info("Failed to update data, err: " + err)
A
Annie_wang 已提交
1170 1171
})
```
A
annie_wangli 已提交
1172 1173 1174

### delete

A
Annie_wang 已提交
1175
delete(predicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void
A
annie_wangli 已提交
1176 1177


A
Annie_wang 已提交
1178
Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1179

A
annie_wangli 已提交
1180
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1181

A
annie_wangli 已提交
1182 1183 1184
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1185
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Conditions specified by the **RdbPredicates** object for deleting data.|
A
annie_wangli 已提交
1186
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of rows updated.|
A
annie_wangli 已提交
1187

A
annie_wangli 已提交
1188
**Example**
A
Annie_wang 已提交
1189 1190 1191 1192 1193
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa")
rdbStore.delete(predicates, function (err, rows) {
    if (err) {
A
Annie_wang 已提交
1194
        console.info("Failed to delete data, err: " + err)
A
Annie_wang 已提交
1195 1196
        return
    }
A
Annie_wang 已提交
1197
    console.log("Deleted rows: " + rows)
A
Annie_wang 已提交
1198 1199
})
```
A
annie_wangli 已提交
1200 1201 1202 1203


### delete

A
Annie_wang 已提交
1204
delete(predicates: RdbPredicates):Promise&lt;number&gt;
A
annie_wangli 已提交
1205

A
Annie_wang 已提交
1206
Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result.
A
annie_wangli 已提交
1207

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

A
annie_wangli 已提交
1210 1211 1212
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1213
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Conditions specified by the **RdbPredicates** object for deleting data.|
A
annie_wangli 已提交
1214

A
annie_wangli 已提交
1215 1216 1217
**Return value**
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
1218
| Promise&lt;number&gt; |  Promise used to return the number of rows updated.|
A
annie_wangli 已提交
1219 1220

**Example**
A
Annie_wang 已提交
1221 1222 1223 1224 1225
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa")
let promise = rdbStore.delete(predicates)
promise.then((rows) => {
A
Annie_wang 已提交
1226
    console.log("Deleted rows: " + rows)
A
Annie_wang 已提交
1227
}).catch((err) => {
A
Annie_wang 已提交
1228
    console.info("Failed to delete data, err: " + err)
A
Annie_wang 已提交
1229 1230
})
```
A
annie_wangli 已提交
1231

A
Annie_wang 已提交
1232 1233
### delete<sup>9+</sup>

A
Annie_wang 已提交
1234
delete(table: string, predicates: DataSharePredicates, callback: AsyncCallback&lt;number&gt;):void
A
Annie_wang 已提交
1235 1236


A
Annie_wang 已提交
1237
Deletes data from the RDB store based on the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1238 1239 1240 1241 1242 1243 1244

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

**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| table | string | Yes| Name of the target table.|
1245
| predicates | [DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes|  Conditions specified by the **DataSharePredicates** object for deleting data.|
A
Annie_wang 已提交
1246 1247 1248 1249
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of rows updated.|

**Example**
```js
A
Annie_wang 已提交
1250 1251
import dataSharePredicates from '@ohos.data.dataSharePredicates'
let predicates = new dataSharePredicates.DataSharePredicates()
A
Annie_wang 已提交
1252 1253 1254
predicates.equalTo("NAME", "Lisa")
rdbStore.delete("EMPLOYEE", predicates, function (err, rows) {
    if (err) {
A
Annie_wang 已提交
1255
        console.info("Failed to delete data, err: " + err)
A
Annie_wang 已提交
1256 1257
        return
    }
A
Annie_wang 已提交
1258
    console.log("Deleted rows: " + rows)
A
Annie_wang 已提交
1259 1260 1261 1262
})
```
### delete<sup>9+</sup>

A
Annie_wang 已提交
1263
delete(table: string, predicates: dataSharePredicates.DataSharePredicates):Promise&lt;number&gt;
A
Annie_wang 已提交
1264

A
Annie_wang 已提交
1265
Deletes data from the RDB store based on the specified **DataSharePredicates** object. This API uses a promise to return the result.
A
Annie_wang 已提交
1266 1267 1268 1269 1270 1271 1272

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

**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| table | string | Yes| Name of the target table.|
1273
| predicates | [DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes| Conditions specified by the **DataSharePredicates** object for deleting data.|
A
Annie_wang 已提交
1274 1275 1276 1277

**Return value**
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
1278
| Promise&lt;number&gt; |  Promise used to return the number of rows updated.|
A
Annie_wang 已提交
1279 1280 1281

**Example**
```js
A
Annie_wang 已提交
1282 1283
import dataSharePredicates from '@ohos.data.dataSharePredicates'
let predicates = new dataSharePredicates.DataSharePredicates()
A
Annie_wang 已提交
1284 1285 1286
predicates.equalTo("NAME", "Lisa")
let promise = rdbStore.delete("EMPLOYEE", predicates)
promise.then((rows) => {
A
Annie_wang 已提交
1287
    console.log("Deleted rows: " + rows)
A
Annie_wang 已提交
1288
}).catch((err) => {
A
Annie_wang 已提交
1289
    console.info("Failed to delete data, err: " + err)
A
Annie_wang 已提交
1290 1291
})
```
A
annie_wangli 已提交
1292 1293 1294

### query

A
Annie_wang 已提交
1295
query(predicates: RdbPredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
Z
zengyawen 已提交
1296

A
Annie_wang 已提交
1297
Queries data in the RDB store based on specified conditions. This API uses an asynchronous callback to return the result.
Z
zengyawen 已提交
1298

A
annie_wangli 已提交
1299
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1300

A
annie_wangli 已提交
1301 1302 1303
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1304
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Query conditions specified by the **RdbPredicates** object.|
A
annie_wangli 已提交
1305 1306 1307 1308
| 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 已提交
1309 1310 1311 1312 1313
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose")
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
    if (err) {
A
Annie_wang 已提交
1314
        console.info("Failed to query data, err: " + err)
A
Annie_wang 已提交
1315 1316
        return
    }
A
Annie_wang 已提交
1317 1318
    console.log("ResultSet column names: " + resultSet.columnNames)
    console.log("ResultSet column count: " + resultSet.columnCount)
A
Annie_wang 已提交
1319 1320
})
```
A
annie_wangli 已提交
1321 1322 1323 1324


### query

A
Annie_wang 已提交
1325
query(predicates: RdbPredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt;
Z
zengyawen 已提交
1326

A
Annie_wang 已提交
1327
Queries data in the RDB store based on specified conditions. This API uses a promise to return the result.
Z
zengyawen 已提交
1328

A
annie_wangli 已提交
1329
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1330

A
annie_wangli 已提交
1331 1332 1333
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1334
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Query conditions specified by the **RdbPredicates** object.|
A
annie_wangli 已提交
1335
| columns | Array&lt;string&gt; | No| Columns to query. If this parameter is not specified, the query applies to all columns.|
A
annie_wangli 已提交
1336

A
annie_wangli 已提交
1337 1338 1339 1340 1341 1342
**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 已提交
1343
  ```js
A
annie_wangli 已提交
1344 1345
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.equalTo("NAME", "Rose")
A
Annie_wang 已提交
1346 1347
  let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
  promise.then((resultSet) => {
A
Annie_wang 已提交
1348 1349
      console.log("ResultSet column names: " + resultSet.columnNames)
      console.log("ResultSet column count: " + resultSet.columnCount)
A
annie_wangli 已提交
1350
  }).catch((err) => {
A
Annie_wang 已提交
1351
      console.info("Failed to query data, err: " + err)
A
annie_wangli 已提交
1352
  })
A
annie_wangli 已提交
1353 1354
  ```

A
Annie_wang 已提交
1355 1356
### query<sup>9+</sup>

A
Annie_wang 已提交
1357
query(predicates: DataSharePredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
A
Annie_wang 已提交
1358

A
Annie_wang 已提交
1359
Queries data in the RDB store based on specified conditions. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1360 1361 1362 1363 1364 1365

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

**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
1366
| predicates | [DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes| Query conditions specified by the **DataSharePredicates** object.|
A
Annie_wang 已提交
1367 1368 1369 1370 1371
| 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**
```js
A
Annie_wang 已提交
1372 1373
import dataSharePredicates from '@ohos.data.dataSharePredicates'
let predicates = new dataSharePredicates.DataSharePredicates()
A
Annie_wang 已提交
1374 1375 1376
predicates.equalTo("NAME", "Rose")
rdbStore.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
    if (err) {
A
Annie_wang 已提交
1377
        console.info("Failed to query data, err: " + err)
A
Annie_wang 已提交
1378 1379 1380 1381 1382 1383 1384 1385 1386
        return
    }
    console.log("ResultSet column names: " + resultSet.columnNames)
    console.log("ResultSet column count: " + resultSet.columnCount)
})
```

### query<sup>9+</sup>

A
Annie_wang 已提交
1387
query(predicates: DataSharePredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt;
A
Annie_wang 已提交
1388

A
Annie_wang 已提交
1389
Queries data in the RDB store based on specified conditions. This API uses a promise to return the result.
A
Annie_wang 已提交
1390 1391 1392 1393 1394 1395

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

**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
1396
| predicates | [DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes| Query conditions specified by the **DataSharePredicates** object.|
A
Annie_wang 已提交
1397 1398 1399 1400 1401 1402 1403 1404 1405
| columns | Array&lt;string&gt; | No| Columns to query. If this parameter is not specified, the query applies to all columns.|

**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|

**Example**
```js
A
Annie_wang 已提交
1406 1407
import dataSharePredicates from '@ohos.data.dataSharePredicates'
let predicates = new dataSharePredicates.DataSharePredicates()
A
Annie_wang 已提交
1408 1409 1410 1411 1412 1413
predicates.equalTo("NAME", "Rose")
let promise = rdbStore.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
promise.then((resultSet) => {
    console.log("ResultSet column names: " + resultSet.columnNames)
    console.log("ResultSet column count: " + resultSet.columnCount)
}).catch((err) => {
A
Annie_wang 已提交
1414
    console.info("Failed to query data, err: " + err)
A
Annie_wang 已提交
1415 1416
})
```
A
annie_wangli 已提交
1417 1418 1419 1420 1421

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

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

A
Annie_wang 已提交
1422
Queries data in the RDB store using the specified SQL statement. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1423

A
annie_wangli 已提交
1424
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1425

A
annie_wangli 已提交
1426 1427 1428 1429 1430 1431 1432 1433
**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 已提交
1434 1435 1436
```js
rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) {
    if (err) {
A
Annie_wang 已提交
1437
        console.info("Failed to query data, err: " + err)
A
Annie_wang 已提交
1438 1439
        return
    }
A
Annie_wang 已提交
1440 1441
    console.log("ResultSet column names: " + resultSet.columnNames)
    console.log("ResultSet column count: " + resultSet.columnCount)
A
Annie_wang 已提交
1442 1443
})
```
A
annie_wangli 已提交
1444 1445 1446 1447 1448 1449


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

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

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

A
annie_wangli 已提交
1452
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1453

A
annie_wangli 已提交
1454 1455 1456 1457 1458
**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 已提交
1459

A
annie_wangli 已提交
1460 1461 1462 1463 1464 1465
**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 已提交
1466 1467 1468
```js
let promise = rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'])
promise.then((resultSet) => {
A
Annie_wang 已提交
1469 1470
    console.log("ResultSet column names: " + resultSet.columnNames)
    console.log("ResultSet column count: " + resultSet.columnCount)
A
Annie_wang 已提交
1471
}).catch((err) => {
A
Annie_wang 已提交
1472
    console.info("Failed to query data, err: " + err)
A
Annie_wang 已提交
1473 1474
})
```
A
annie_wangli 已提交
1475 1476 1477 1478 1479


### executeSql

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

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

A
annie_wangli 已提交
1483
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1484

A
annie_wangli 已提交
1485 1486 1487 1488 1489 1490 1491 1492
**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 已提交
1493 1494 1495 1496
```js
const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
rdbStore.executeSql(SQL_CREATE_TABLE, null, function(err) {
    if (err) {
A
Annie_wang 已提交
1497
        console.info("Failed to execute SQL, err: " + err)
A
Annie_wang 已提交
1498 1499
        return
    }
A
Annie_wang 已提交
1500
    console.info('Create table done.')
A
Annie_wang 已提交
1501 1502
})
```
A
annie_wangli 已提交
1503 1504 1505 1506 1507


### executeSql

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

A
Annie_wang 已提交
1509
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 已提交
1510

A
annie_wangli 已提交
1511
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1512

A
annie_wangli 已提交
1513 1514 1515 1516 1517
**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 已提交
1518

A
annie_wangli 已提交
1519 1520 1521 1522 1523 1524
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**
A
Annie_wang 已提交
1525 1526 1527 1528
```js
const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
let promise = rdbStore.executeSql(SQL_CREATE_TABLE)
promise.then(() => {
A
Annie_wang 已提交
1529
    console.info('Create table done.')
A
Annie_wang 已提交
1530
}).catch((err) => {
A
Annie_wang 已提交
1531
    console.info("Failed to execute SQL, err: " + err)
A
Annie_wang 已提交
1532 1533
})
```
A
annie_wangli 已提交
1534

A
annie_wangli 已提交
1535 1536 1537 1538 1539
### beginTransaction<sup>8+</sup>

beginTransaction():void

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

A
annie_wangli 已提交
1541 1542 1543
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Example**
A
Annie_wang 已提交
1544
```js
A
Annie_wang 已提交
1545 1546 1547 1548 1549 1550 1551 1552 1553
rdbStore.beginTransaction()
const valueBucket = {
    "name": "lisi",
    "age": 18,
    "salary": 100.5,
    "blobType": new Uint8Array([1, 2, 3]),
}
rdbStore.insert("test", valueBucket, function (err, ret) {
    if (err) {
A
Annie_wang 已提交
1554
        console.info("Failed to insert data, err: " + err)
A
Annie_wang 已提交
1555 1556
        return
    }
A
Annie_wang 已提交
1557
    console.log("Inserted data successfully: " + ret)
A
Annie_wang 已提交
1558 1559
})
rdbStore.commit()
A
annie_wangli 已提交
1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571
```


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

commit():void

Commits the executed SQL statements.

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

**Example**
A
Annie_wang 已提交
1572
```js
A
Annie_wang 已提交
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582
rdbStore.beginTransaction()
const valueBucket = {
    "name": "lisi",
    "age": 18,
    "salary": 100.5,
    "blobType": new Uint8Array([1, 2, 3]),
}

rdbStore.insert("test", valueBucket, function (err, ret) {
    if (err) {
A
Annie_wang 已提交
1583
        console.info("Failed to insert data, err: " + err)
A
Annie_wang 已提交
1584 1585
        return
    }
A
Annie_wang 已提交
1586
    console.log("Inserted data successfully: " + ret)
A
Annie_wang 已提交
1587 1588
})
rdbStore.commit()
A
annie_wangli 已提交
1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600
```


### 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 已提交
1601
```js
A
Annie_wang 已提交
1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612
try {
    rdbStore.beginTransaction()
    const valueBucket = {
        "id": 1,
        "name": "lisi",
        "age": 18,
        "salary": 100.5,
        "blobType": new Uint8Array([1, 2, 3]),
    }
    rdbStore.insert("test", valueBucket, function (err, ret) {
        if (err) {
A
Annie_wang 已提交
1613
            console.info("Failed to insert data, err: " + err)
A
Annie_wang 已提交
1614 1615
            return
        }
A
Annie_wang 已提交
1616
        console.log("Inserted data successfully: " + ret)
A
Annie_wang 已提交
1617 1618 1619 1620 1621
    })
    rdbStore.commit()
} catch (e) {
    rdbStore.rollBack()
}
A
annie_wangli 已提交
1622 1623
```

A
Annie_wang 已提交
1624 1625 1626 1627
### backup<sup>9+</sup>

backup(destName:string, callback: AsyncCallback&lt;void&gt;):void

A
Annie_wang 已提交
1628
Backs up an RDB store. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1629 1630 1631 1632 1633 1634

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

**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1635
| destName | string | Yes| Name of the RDB store backup file.|
A
Annie_wang 已提交
1636 1637 1638 1639 1640 1641
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|

**Example**
```js
rdbStore.backup("dbBackup.db", function(err) {
    if (err) {
A
Annie_wang 已提交
1642
        console.info('Failed to back up data, err: ' + err)
A
Annie_wang 已提交
1643 1644
        return
    }
A
Annie_wang 已提交
1645
    console.info('Backup successful.')
A
Annie_wang 已提交
1646 1647 1648 1649 1650 1651 1652
})
```

### backup<sup>9+</sup>

backup(destName:string): Promise&lt;void&gt;

A
Annie_wang 已提交
1653
Backs up an RDB store. This API uses a promise to return the result.
A
Annie_wang 已提交
1654 1655 1656 1657 1658 1659

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

**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1660
| destName | string | Yes| Name of the RDB store backup file.|
A
Annie_wang 已提交
1661 1662 1663 1664 1665 1666 1667 1668 1669 1670

**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**
```js
let promiseBackup = rdbStore.backup("dbBackup.db")
promiseBackup.then(()=>{
A
Annie_wang 已提交
1671
    console.info('Backup successful.')
A
Annie_wang 已提交
1672
}).catch((err)=>{
A
Annie_wang 已提交
1673
    console.info('Failed to back up data, err: ' + err)
A
Annie_wang 已提交
1674 1675 1676 1677 1678 1679 1680
})
```

### restore<sup>9+</sup>

restore(srcName:string, callback: AsyncCallback&lt;void&gt;):void

A
Annie_wang 已提交
1681
Restores an RDB store using a backup file. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1682 1683 1684 1685 1686 1687

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

**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1688
| srcName | string | Yes| Name of the RDB store backup file.|
A
Annie_wang 已提交
1689 1690 1691 1692 1693 1694
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|

**Example**
```js
rdbStore.restore("dbBackup.db", function(err) {
    if (err) {
A
Annie_wang 已提交
1695
        console.info('Failed to restore data, err: ' + err)
A
Annie_wang 已提交
1696 1697
        return
    }
A
Annie_wang 已提交
1698
    console.info('Restore successful.')
A
Annie_wang 已提交
1699 1700 1701 1702 1703 1704 1705
})
```

### restore<sup>9+</sup>

restore(srcName:string): Promise&lt;void&gt;

A
Annie_wang 已提交
1706
Restores an RDB store using a backup file. This API uses a promise to return the result.
A
Annie_wang 已提交
1707 1708 1709 1710 1711 1712

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

**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1713
| srcName | string | Yes| Name of the RDB store backup file.|
A
Annie_wang 已提交
1714 1715 1716 1717 1718 1719 1720 1721 1722 1723

**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**
```js
let promiseRestore = rdbStore.restore("dbBackup.db")
promiseRestore.then(()=>{
A
Annie_wang 已提交
1724
    console.info('Restore successful.')
A
Annie_wang 已提交
1725
}).catch((err)=>{
A
Annie_wang 已提交
1726
    console.info('Failed to restore data, err: ' + err)
A
Annie_wang 已提交
1727 1728
})
```
A
annie_wangli 已提交
1729 1730 1731 1732

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

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

A
Annie_wang 已提交
1734 1735 1736
Sets a list of distributed tables. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
A
annie_wangli 已提交
1737

A
annie_wangli 已提交
1738
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1739

A
annie_wangli 已提交
1740 1741 1742 1743 1744 1745 1746
**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 已提交
1747 1748 1749
```js
rdbStore.setDistributedTables(["EMPLOYEE"], function (err) {
    if (err) {
A
Annie_wang 已提交
1750
        console.info('Failed to set distributed tables, err: ' + err)
A
Annie_wang 已提交
1751 1752
        return
    }
A
Annie_wang 已提交
1753
    console.info('Set distributed tables successfully.')
A
Annie_wang 已提交
1754
})
A
annie_wangli 已提交
1755 1756 1757
  ```


A
annie_wangli 已提交
1758
### setDistributedTables<sup>8+</sup>
A
annie_wangli 已提交
1759

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

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

A
Annie_wang 已提交
1764 1765
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

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

A
annie_wangli 已提交
1768 1769 1770 1771
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| tables | Array&lt;string&gt; | Yes| Names of the distributed tables to set.|
A
annie_wangli 已提交
1772

A
annie_wangli 已提交
1773 1774 1775 1776 1777 1778
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**
A
Annie_wang 已提交
1779 1780 1781
```js
let promise = rdbStore.setDistributedTables(["EMPLOYEE"])
promise.then(() => {
A
Annie_wang 已提交
1782
    console.info("Set distributed tables successfully.")
A
Annie_wang 已提交
1783
}).catch((err) => {
A
Annie_wang 已提交
1784
    console.info("Failed to set distributed tables, err: " + err)
A
Annie_wang 已提交
1785 1786
})
```
A
annie_wangli 已提交
1787

A
annie_wangli 已提交
1788
### obtainDistributedTableName<sup>8+</sup>
A
annie_wangli 已提交
1789

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

A
Annie_wang 已提交
1792 1793 1794
Obtains the distributed table name for a remote device based on the local table name. The distributed table name is required when the database of a remote device is queried. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
A
annie_wangli 已提交
1795

A
annie_wangli 已提交
1796
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1797

A
annie_wangli 已提交
1798 1799 1800 1801 1802 1803 1804 1805
**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 已提交
1806
```js
A
Annie_wang 已提交
1807
rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE", function (err, tableName) {
A
Annie_wang 已提交
1808
    if (err) {
A
Annie_wang 已提交
1809
        console.info('Failed to obtain DistributedTableName, err: ' + err)
A
Annie_wang 已提交
1810 1811
        return
    }
A
Annie_wang 已提交
1812
    console.info('Obtained distributed table name successfully, tableName=.' + tableName)
A
Annie_wang 已提交
1813 1814
})
```
A
annie_wangli 已提交
1815 1816


A
annie_wangli 已提交
1817
### obtainDistributedTableName<sup>8+</sup>
A
annie_wangli 已提交
1818

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

A
Annie_wang 已提交
1821
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 已提交
1822

A
Annie_wang 已提交
1823 1824
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

A
annie_wangli 已提交
1825 1826 1827 1828 1829 1830 1831
**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 已提交
1832

A
annie_wangli 已提交
1833 1834 1835 1836
**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 已提交
1837

A
annie_wangli 已提交
1838
**Example**
A
Annie_wang 已提交
1839
```js
A
Annie_wang 已提交
1840
let promise = rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE")
A
Annie_wang 已提交
1841
promise.then((tableName) => {
A
Annie_wang 已提交
1842
    console.info('Obtained distributed table name successfully, tableName= ' + tableName)
A
Annie_wang 已提交
1843
}).catch((err) => {
A
Annie_wang 已提交
1844
    console.info('Failed to obtain DistributedTableName, err: ' + err)
A
Annie_wang 已提交
1845 1846
})
```
A
annie_wangli 已提交
1847

A
annie_wangli 已提交
1848
### sync<sup>8+</sup>
A
annie_wangli 已提交
1849

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

A
Annie_wang 已提交
1852 1853 1854
Synchronizes data between devices. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
A
annie_wangli 已提交
1855

A
annie_wangli 已提交
1856
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1857

A
annie_wangli 已提交
1858 1859 1860 1861 1862 1863 1864 1865
**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 已提交
1866
```js
A
Annie_wang 已提交
1867
let predicates = new data_rdb.RdbPredicates('EMPLOYEE')
A
Annie_wang 已提交
1868
predicates.inDevices(['12345678abcde'])
A
Annie_wang 已提交
1869
rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) {
A
Annie_wang 已提交
1870
    if (err) {
A
Annie_wang 已提交
1871
        console.log('Sync failed, err: ' + err)
A
Annie_wang 已提交
1872 1873
        return
    }
A
Annie_wang 已提交
1874
    console.log('Sync done.')
A
Annie_wang 已提交
1875 1876 1877 1878 1879
    for (let i = 0; i < result.length; i++) {
        console.log('device=' + result[i][0] + ' status=' + result[i][1])
    }
})
```
A
annie_wangli 已提交
1880 1881


A
annie_wangli 已提交
1882
### sync<sup>8+</sup>
A
annie_wangli 已提交
1883

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

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

A
Annie_wang 已提交
1888 1889
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

A
annie_wangli 已提交
1890
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1891

A
annie_wangli 已提交
1892 1893 1894 1895 1896
**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 已提交
1897

A
annie_wangli 已提交
1898 1899 1900 1901 1902 1903 1904
**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 已提交
1905 1906 1907 1908 1909
```js
let predicates = new data_rdb.RdbPredicates('EMPLOYEE')
predicates.inDevices(['12345678abcde'])
let promise = rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicates)
promise.then((result) =>{
A
Annie_wang 已提交
1910
    console.log('Sync done.')
A
Annie_wang 已提交
1911 1912 1913 1914
    for (let i = 0; i < result.length; i++) {
        console.log('device=' + result[i][0] + ' status=' + result[i][1])
    }
}).catch((err) => {
A
Annie_wang 已提交
1915
    console.log('Sync failed')
A
Annie_wang 已提交
1916 1917
})
```
A
annie_wangli 已提交
1918

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

A
annie_wangli 已提交
1921
on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void
A
annie_wangli 已提交
1922 1923 1924

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_wang 已提交
1925 1926
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

A
annie_wangli 已提交
1927
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1928

A
annie_wangli 已提交
1929 1930 1931 1932 1933 1934 1935 1936 1937
**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 已提交
1938 1939 1940 1941 1942 1943 1944 1945 1946
```js
function storeObserver(devices) {
    for (let i = 0; i < devices.length; i++) {
        console.log('device=' + devices[i] + ' data changed')
    }
}
try {
    rdbStore.on('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver)
} catch (err) {
A
Annie_wang 已提交
1947
    console.log('Failed to register observer')
A
Annie_wang 已提交
1948 1949
}
```
A
annie_wangli 已提交
1950

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

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

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

A
Annie_wang 已提交
1957 1958
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

A
annie_wangli 已提交
1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969
**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_wang 已提交
1970 1971 1972 1973 1974 1975 1976 1977 1978
```js
function storeObserver(devices) {
    for (let i = 0; i < devices.length; i++) {
        console.log('device=' + devices[i] + ' data changed')
    }
}
try {
    rdbStore.off('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver)
} catch (err) {
A
Annie_wang 已提交
1979
    console.log('Failed to unregister observer')
A
Annie_wang 已提交
1980 1981
}
```
A
annie_wangli 已提交
1982 1983

## StoreConfig
Z
zengyawen 已提交
1984 1985 1986

Manages the configuration of an RDB store.

A
annie_wangli 已提交
1987 1988
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

A
annie_wangli 已提交
1989 1990 1991 1992 1993 1994
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Database file name.|


## ValueType
Z
zengyawen 已提交
1995 1996 1997

Defines the data types allowed.

A
annie_wangli 已提交
1998 1999
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

A
annie_wangli 已提交
2000 2001 2002 2003 2004 2005 2006 2007
| Name| Description|
| -------- | -------- |
| number | Number.|
| string | String.|
| boolean | Boolean.|


## ValuesBucket
Z
zengyawen 已提交
2008 2009 2010

Defines a bucket to store key-value pairs.

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

A
annie_wangli 已提交
2013 2014 2015 2016 2017
| 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 已提交
2018
## SyncMode<sup>8+</sup>
A
annie_wangli 已提交
2019 2020 2021

Defines the database synchronization mode.

A
annie_wangli 已提交
2022 2023 2024 2025 2026 2027
**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 已提交
2028

A
annie_wangli 已提交
2029
## SubscribeType<sup>8+</sup>
A
annie_wangli 已提交
2030 2031 2032

Defines the subscription type.

A
Annie_wang 已提交
2033 2034
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

A
annie_wangli 已提交
2035 2036 2037 2038 2039
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

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