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

A
Annie_wang 已提交
3 4 5 6
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:

A
Annie_wang 已提交
7
- [RdbPredicates](#rdbpredicates): provides predicates indicating the nature, feature, or relationship of a data entity in an RDB store. It is used to define the operation conditions for an RDB store.
A
Annie_wang 已提交
8 9
- [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
| 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 已提交
39 40
FA model:

A
Annie_wang 已提交
41
```js
A
Annie_wang 已提交
42 43 44 45 46
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()

// Call getRdbStore.
A
Annie_wang 已提交
47
const STORE_CONFIG = { name: "RdbTest.db"}
A
Annie_wang 已提交
48
data_rdb.getRdbStore(context, STORE_CONFIG, 1, function (err, rdbStore) {
A
Annie_wang 已提交
49
    if (err) {
A
Annie_wang 已提交
50
        console.info("Failed to get RdbStore, err: " + err)
A
Annie_wang 已提交
51 52
        return
    }
A
Annie_wang 已提交
53
    console.log("Got RdbStore successfully.")
A
Annie_wang 已提交
54
})
A
annie_wangli 已提交
55
```
A
Annie_wang 已提交
56

A
Annie_wang 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
Stage model:

```ts
// Obtain the context.
import Ability from '@ohos.application.Ability'
var context
class MainAbility extends Ability{
    onWindowStageCreate(windowStage){
        context = this.context
    }
}

// Call getRdbStore.
const STORE_CONFIG = { name: "RdbTest.db"}
data_rdb.getRdbStore(context, STORE_CONFIG, 1, function (err, rdbStore) {
    if (err) {
        console.info("Failed to get RdbStore, err: " + err)
        return
    }
    console.log("Got RdbStore successfully.")
})
```
A
Annie_wang 已提交
79
## data_rdb.getRdbStore
A
Annie_wang 已提交
80 81 82 83 84 85 86 87 88 89 90

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 已提交
91
| 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 已提交
92 93 94 95 96 97 98 99 100 101 102
| 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 已提交
103 104
FA model:

A
Annie_wang 已提交
105
```js
A
Annie_wang 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()

// Call getRdbStore.
const STORE_CONFIG = { name: "RdbTest.db" }
let promise = data_rdb.getRdbStore(context, STORE_CONFIG, 1);
promise.then(async (rdbStore) => {
    console.log("Got RdbStore successfully.")
}).catch((err) => {
    console.log("Failed to get RdbStore, err: " + err)
})
```

Stage model:

```ts
// Obtain the context.
import Ability from '@ohos.application.Ability'
var context
class MainAbility extends Ability{
    onWindowStageCreate(windowStage){
        context = this.context
    }
}

// Call getRdbStore.
A
Annie_wang 已提交
133
const STORE_CONFIG = { name: "RdbTest.db" }
A
Annie_wang 已提交
134
let promise = data_rdb.getRdbStore(context, STORE_CONFIG, 1);
A
Annie_wang 已提交
135
promise.then(async (rdbStore) => {
A
Annie_wang 已提交
136
    console.log("Got RdbStore successfully.")
A
Annie_wang 已提交
137
}).catch((err) => {
A
Annie_wang 已提交
138
    console.log("Failed to get RdbStore, err: " + err)
A
Annie_wang 已提交
139
})
A
annie_wangli 已提交
140
```
A
annie_wangli 已提交
141 142 143

## data_rdb.deleteRdbStore

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

A
Annie_wang 已提交
146
Deletes an RDB store. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
147 148 149 150

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

**Parameters**
A
Annie_wang 已提交
151

A
Annie_wang 已提交
152 153
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
154
| 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 已提交
155 156 157 158
| 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 已提交
159 160 161

FA model:

A
Annie_wang 已提交
162
```js
A
Annie_wang 已提交
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()

// Call deleteRdbStore.
data_rdb.deleteRdbStore(context, "RdbTest.db", function (err) {
    if (err) {
        console.info("Failed to delete RdbStore, err: " + err)
        return
    }
    console.log("Deleted RdbStore successfully.")
})
```

Stage model:

```ts
// Obtain the context.
import Ability from '@ohos.application.Ability'
var context
class MainAbility extends Ability{
    onWindowStageCreate(windowStage){
        context = this.context
    }
}

// Call deleteRdbStore.
data_rdb.deleteRdbStore(context, "RdbTest.db", function (err) {
A
Annie_wang 已提交
191
    if (err) {
A
Annie_wang 已提交
192
        console.info("Failed to delete RdbStore, err: " + err)
A
Annie_wang 已提交
193 194
        return
    }
A
Annie_wang 已提交
195
    console.log("Deleted RdbStore successfully.")
A
Annie_wang 已提交
196 197
})
```
A
Annie_wang 已提交
198

A
Annie_wang 已提交
199
## data_rdb.deleteRdbStore
A
annie_wangli 已提交
200 201

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

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

A
annie_wangli 已提交
205
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
206

A
annie_wangli 已提交
207
**Parameters**
A
Annie_wang 已提交
208

A
annie_wangli 已提交
209 210
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
211
| 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 已提交
212
| name | string | Yes| Name of the RDB store to delete.|
A
annie_wangli 已提交
213

A
annie_wangli 已提交
214
**Return value**
A
Annie_wang 已提交
215

A
annie_wangli 已提交
216 217
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
218
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
219 220

**Example**
A
Annie_wang 已提交
221 222 223

FA model:

A
Annie_wang 已提交
224
```js
A
Annie_wang 已提交
225 226 227 228 229 230
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()

// Call deleteRdbStore.
let promise = data_rdb.deleteRdbStore(context, "RdbTest.db")
A
Annie_wang 已提交
231
promise.then(()=>{
A
Annie_wang 已提交
232
    console.log("Deleted RdbStore successfully.")
A
Annie_wang 已提交
233
}).catch((err) => {
A
Annie_wang 已提交
234
    console.info("Failed to delete RdbStore, err: " + err)
A
Annie_wang 已提交
235 236
})
```
A
annie_wangli 已提交
237

A
Annie_wang 已提交
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
Stage model:

```ts
// Obtain the context.
import Ability from '@ohos.application.Ability'
var context
class MainAbility extends Ability{
    onWindowStageCreate(windowStage){
        context = this.context
    }
}

// Call deleteRdbStore.
let promise = data_rdb.deleteRdbStore(context, "RdbTest.db")
promise.then(()=>{
    console.log("Deleted RdbStore successfully.")
}).catch((err) => {
    console.info("Failed to delete RdbStore, err: " + err)
})
```
A
annie_wangli 已提交
258

A
annie_wangli 已提交
259
## RdbPredicates
Z
zengyawen 已提交
260 261 262

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

A
annie_wangli 已提交
263 264 265 266 267 268 269 270

### constructor

constructor(name: string)


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

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

A
annie_wangli 已提交
273
**Parameters**
A
Annie_wang 已提交
274

A
annie_wangli 已提交
275 276 277
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Database table name.|
A
annie_wangli 已提交
278

A
annie_wangli 已提交
279
**Example**
A
Annie_wang 已提交
280

A
Annie_wang 已提交
281 282 283
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
```
A
annie_wangli 已提交
284

A
annie_wangli 已提交
285
### inDevices<sup>8+</sup>
A
annie_wangli 已提交
286

A
annie_wangli 已提交
287
inDevices(devices: Array&lt;string&gt;): RdbPredicates
A
annie_wangli 已提交
288 289


A
Annie_wang 已提交
290
Sets an **RdbPredicates** to specify the remote devices on the network to connect during distributed database synchronization.
A
annie_wangli 已提交
291

A
annie_wangli 已提交
292
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
293

A
annie_wangli 已提交
294
**Parameters**
A
Annie_wang 已提交
295

A
annie_wangli 已提交
296 297
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
298
| devices | Array&lt;string&gt; | Yes| IDs of the remote devices in the same network.|
A
annie_wangli 已提交
299

A
annie_wangli 已提交
300
**Return value**
A
Annie_wang 已提交
301

A
annie_wangli 已提交
302 303
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
304
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
305

A
annie_wangli 已提交
306
**Example**
A
Annie_wang 已提交
307

A
Annie_wang 已提交
308 309 310 311
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.inDevices(['12345678abcde'])
```
A
annie_wangli 已提交
312

A
annie_wangli 已提交
313
### inAllDevices<sup>8+</sup>
A
annie_wangli 已提交
314

A
annie_wangli 已提交
315
inAllDevices(): RdbPredicates
A
annie_wangli 已提交
316 317


A
Annie_wang 已提交
318
Sets an **RdbPredicates** to specify all remote devices on the network to connect during distributed database synchronization.
A
annie_wangli 已提交
319

A
annie_wangli 已提交
320
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
321

A
annie_wangli 已提交
322
**Return value**
A
Annie_wang 已提交
323

A
annie_wangli 已提交
324 325
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
326
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
327

A
annie_wangli 已提交
328
**Example**
A
Annie_wang 已提交
329

A
Annie_wang 已提交
330 331 332 333
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.inAllDevices()
```
A
annie_wangli 已提交
334 335 336 337 338 339

### equalTo

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


A
Annie_wang 已提交
340
Sets an **RdbPredicates** to match the field with data type **ValueType** and value equal to the specified value.
A
annie_wangli 已提交
341

A
annie_wangli 已提交
342
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
343

A
annie_wangli 已提交
344
**Parameters**
A
Annie_wang 已提交
345

A
annie_wangli 已提交
346 347 348 349
| 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 已提交
350

A
annie_wangli 已提交
351
**Return value**
A
Annie_wang 已提交
352

A
annie_wangli 已提交
353 354
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
355
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
356

A
annie_wangli 已提交
357
**Example**
A
Annie_wang 已提交
358

A
Annie_wang 已提交
359 360 361 362
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "lisi")
```
A
annie_wangli 已提交
363 364 365 366 367 368 369


### notEqualTo

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


A
Annie_wang 已提交
370
Sets an **RdbPredicates** to match the field with data type **ValueType** and value not equal to the specified value.
A
annie_wangli 已提交
371

A
annie_wangli 已提交
372
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
373

A
annie_wangli 已提交
374
**Parameters**
A
Annie_wang 已提交
375

A
annie_wangli 已提交
376 377 378 379
| 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 已提交
380

A
annie_wangli 已提交
381
**Return value**
A
Annie_wang 已提交
382

A
annie_wangli 已提交
383 384
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
385
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
386

A
annie_wangli 已提交
387
**Example**
A
Annie_wang 已提交
388

A
Annie_wang 已提交
389 390 391 392
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.notEqualTo("NAME", "lisi")
```
A
annie_wangli 已提交
393 394 395 396 397 398 399 400 401


### beginWrap

beginWrap(): RdbPredicates


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

A
annie_wangli 已提交
402
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
403

A
annie_wangli 已提交
404
**Return value**
A
Annie_wang 已提交
405

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

A
annie_wangli 已提交
410
**Example**
A
Annie_wang 已提交
411

A
Annie_wang 已提交
412 413 414 415 416 417 418 419 420
```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 已提交
421 422 423 424 425 426 427

### endWrap

endWrap(): RdbPredicates

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

A
annie_wangli 已提交
428
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
429

A
annie_wangli 已提交
430
**Return value**
A
Annie_wang 已提交
431

A
annie_wangli 已提交
432 433 434
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a right parenthesis.|
A
annie_wangli 已提交
435

A
annie_wangli 已提交
436
**Example**
A
Annie_wang 已提交
437

A
Annie_wang 已提交
438 439 440 441 442 443 444 445 446
```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 已提交
447 448 449 450 451 452 453

### or

or(): RdbPredicates

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

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

A
annie_wangli 已提交
456
**Return value**
A
Annie_wang 已提交
457

A
annie_wangli 已提交
458 459 460
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the OR condition.|
A
annie_wangli 已提交
461

A
annie_wangli 已提交
462
**Example**
A
Annie_wang 已提交
463

A
Annie_wang 已提交
464 465 466 467 468 469
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa")
    .or()
    .equalTo("NAME", "Rose")
```
A
annie_wangli 已提交
470 471 472 473 474 475 476

### and

and(): RdbPredicates

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

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

A
annie_wangli 已提交
479
**Return value**
A
Annie_wang 已提交
480

A
annie_wangli 已提交
481 482 483
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the AND condition.|
A
annie_wangli 已提交
484

A
annie_wangli 已提交
485
**Example**
A
Annie_wang 已提交
486

A
Annie_wang 已提交
487 488 489 490 491 492
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa")
    .and()
    .equalTo("SALARY", 200.5)
```
A
annie_wangli 已提交
493 494 495

### contains

A
annie_wangli 已提交
496
contains(field: string, value: string): RdbPredicates
A
annie_wangli 已提交
497

A
Annie_wang 已提交
498
Sets an **RdbPredicates** to match a string containing the specified value.
A
annie_wangli 已提交
499

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

A
annie_wangli 已提交
502
**Parameters**
A
Annie_wang 已提交
503

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

A
annie_wangli 已提交
509
**Return value**
A
Annie_wang 已提交
510

A
annie_wangli 已提交
511 512
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
513
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
514

A
annie_wangli 已提交
515
**Example**
A
Annie_wang 已提交
516

A
Annie_wang 已提交
517 518 519 520
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.contains("NAME", "os")
```
A
annie_wangli 已提交
521 522 523 524 525

### beginsWith

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

A
Annie_wang 已提交
526
Sets an **RdbPredicates** to match a string that starts with the specified value.
A
annie_wangli 已提交
527

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

A
annie_wangli 已提交
530
**Parameters**
A
Annie_wang 已提交
531

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

A
annie_wangli 已提交
537
**Return value**
A
Annie_wang 已提交
538

A
annie_wangli 已提交
539 540
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
541
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
542

A
annie_wangli 已提交
543
**Example**
A
Annie_wang 已提交
544

A
Annie_wang 已提交
545 546 547 548
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.beginsWith("NAME", "os")
```
A
annie_wangli 已提交
549 550 551 552 553

### endsWith

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

A
Annie_wang 已提交
554
Sets an **RdbPredicates** to match a string that ends with the specified value.
A
annie_wangli 已提交
555

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

A
annie_wangli 已提交
558
**Parameters**
A
Annie_wang 已提交
559

A
annie_wangli 已提交
560 561 562 563
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| value | string | Yes| Value to match the **RdbPredicates**.|
A
annie_wangli 已提交
564

A
annie_wangli 已提交
565
**Return value**
A
Annie_wang 已提交
566

A
annie_wangli 已提交
567 568
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
569
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
570

A
annie_wangli 已提交
571
**Example**
A
Annie_wang 已提交
572

A
Annie_wang 已提交
573 574 575 576
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.endsWith("NAME", "se")
```
A
annie_wangli 已提交
577 578 579 580 581

### isNull

isNull(field: string): RdbPredicates

A
Annie_wang 已提交
582
Sets an **RdbPredicates** to match the field whose value is null.
A
annie_wangli 已提交
583

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

A
annie_wangli 已提交
586
**Parameters**
A
Annie_wang 已提交
587

A
annie_wangli 已提交
588 589 590
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
A
annie_wangli 已提交
591

A
annie_wangli 已提交
592
**Return value**
A
Annie_wang 已提交
593

A
annie_wangli 已提交
594 595
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
596
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
597

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

### isNotNull

isNotNull(field: string): RdbPredicates

A
Annie_wang 已提交
608
Sets an **RdbPredicates** to match the field whose value is not null.
A
annie_wangli 已提交
609

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

A
annie_wangli 已提交
612
**Parameters**
A
Annie_wang 已提交
613

A
annie_wangli 已提交
614 615 616
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
A
annie_wangli 已提交
617

A
annie_wangli 已提交
618
**Return value**
A
Annie_wang 已提交
619

A
annie_wangli 已提交
620 621
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
622
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
623

A
annie_wangli 已提交
624
**Example**
A
Annie_wang 已提交
625

A
Annie_wang 已提交
626 627 628 629
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.isNotNull("NAME")
```
A
annie_wangli 已提交
630 631 632 633 634

### like

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

A
Annie_wang 已提交
635
Sets an **RdbPredicates** to match a string that is similar to the specified value.
A
annie_wangli 已提交
636

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

A
annie_wangli 已提交
639
**Parameters**
A
Annie_wang 已提交
640

A
annie_wangli 已提交
641 642 643 644
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| value | string | Yes| Value to match the **RdbPredicates**.|
A
annie_wangli 已提交
645

A
annie_wangli 已提交
646
**Return value**
A
Annie_wang 已提交
647

A
annie_wangli 已提交
648 649
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
650
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
651

A
annie_wangli 已提交
652
**Example**
A
Annie_wang 已提交
653

A
Annie_wang 已提交
654 655 656 657
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.like("NAME", "%os%")
```
A
annie_wangli 已提交
658 659 660 661 662

### glob

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

A
Annie_wang 已提交
663
Sets an **RdbPredicates** to match the specified string.
A
annie_wangli 已提交
664

A
annie_wangli 已提交
665
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
666

A
annie_wangli 已提交
667
**Parameters**
A
Annie_wang 已提交
668

A
annie_wangli 已提交
669 670 671
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
A
Annie_wang 已提交
672
| 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 已提交
673

A
annie_wangli 已提交
674
**Return value**
A
Annie_wang 已提交
675

A
annie_wangli 已提交
676 677
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
678
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
679

A
annie_wangli 已提交
680
**Example**
A
Annie_wang 已提交
681

A
Annie_wang 已提交
682 683 684 685
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.glob("NAME", "?h*g")
```
A
annie_wangli 已提交
686 687 688 689 690

### between

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

A
Annie_wang 已提交
691
Sets an **RdbPredicates** to match the field with data type **ValueType** and value within the specified range.
A
annie_wangli 已提交
692

A
annie_wangli 已提交
693
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
694

A
annie_wangli 已提交
695
**Parameters**
A
Annie_wang 已提交
696

A
annie_wangli 已提交
697 698 699 700 701
| 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 已提交
702

A
annie_wangli 已提交
703
**Return value**
A
Annie_wang 已提交
704

A
annie_wangli 已提交
705 706
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
707
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
708

A
annie_wangli 已提交
709
**Example**
A
Annie_wang 已提交
710

A
Annie_wang 已提交
711 712 713 714
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.between("AGE", 10, 50)
```
A
annie_wangli 已提交
715 716 717 718 719

### notBetween

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

A
Annie_wang 已提交
720
Sets an **RdbPredicates** to match the field with data type **ValueType** and value out of the specified range.
A
annie_wangli 已提交
721

A
annie_wangli 已提交
722
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
723

A
annie_wangli 已提交
724
**Parameters**
A
Annie_wang 已提交
725

A
annie_wangli 已提交
726 727 728 729 730
| 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 已提交
731

A
annie_wangli 已提交
732
**Return value**
A
Annie_wang 已提交
733

A
annie_wangli 已提交
734 735
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
736
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
737

A
annie_wangli 已提交
738
**Example**
A
Annie_wang 已提交
739

A
Annie_wang 已提交
740 741 742 743
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.notBetween("AGE", 10, 50)
```
A
annie_wangli 已提交
744 745 746

### greaterThan

A
annie_wangli 已提交
747
greaterThan(field: string, value: ValueType): RdbPredicates
A
annie_wangli 已提交
748

A
Annie_wang 已提交
749
Sets an **RdbPredicates** to match the field with data type **ValueType** and value greater than the specified value.
A
annie_wangli 已提交
750

A
annie_wangli 已提交
751
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
752

A
annie_wangli 已提交
753
**Parameters**
A
Annie_wang 已提交
754

A
annie_wangli 已提交
755 756 757 758
| 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 已提交
759

A
annie_wangli 已提交
760
**Return value**
A
Annie_wang 已提交
761

A
annie_wangli 已提交
762 763
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
764
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
765

A
annie_wangli 已提交
766
**Example**
A
Annie_wang 已提交
767

A
Annie_wang 已提交
768 769 770 771
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.greaterThan("AGE", 18)
```
A
annie_wangli 已提交
772 773 774 775 776

### lessThan

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

A
Annie_wang 已提交
777
Sets an **RdbPredicates** to match the field with data type **ValueType** and value less than the specified value.
A
annie_wangli 已提交
778

A
annie_wangli 已提交
779
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
780

A
annie_wangli 已提交
781
**Parameters**
A
Annie_wang 已提交
782

A
annie_wangli 已提交
783 784 785 786
| 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 已提交
787

A
annie_wangli 已提交
788
**Return value**
A
Annie_wang 已提交
789

A
annie_wangli 已提交
790 791
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
792
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
793

A
annie_wangli 已提交
794
**Example**
A
Annie_wang 已提交
795

A
Annie_wang 已提交
796 797 798 799
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.lessThan("AGE", 20)
```
A
annie_wangli 已提交
800 801 802 803 804

### greaterThanOrEqualTo

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

A
Annie_wang 已提交
805
Sets an **RdbPredicates** to match the field with data type **ValueType** and value greater than or equal to the specified value.
A
annie_wangli 已提交
806

A
annie_wangli 已提交
807
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
808

A
annie_wangli 已提交
809
**Parameters**
A
Annie_wang 已提交
810

A
annie_wangli 已提交
811 812 813 814
| 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 已提交
815

A
annie_wangli 已提交
816
**Return value**
A
Annie_wang 已提交
817

A
annie_wangli 已提交
818 819
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
820
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
821

A
annie_wangli 已提交
822
**Example**
A
Annie_wang 已提交
823

A
Annie_wang 已提交
824 825 826 827
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.greaterThanOrEqualTo("AGE", 18)
```
A
annie_wangli 已提交
828 829 830 831 832

### lessThanOrEqualTo

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

A
Annie_wang 已提交
833
Sets an **RdbPredicates** to match the field with data type **ValueType** and value less than or equal to the specified value.
A
annie_wangli 已提交
834

A
annie_wangli 已提交
835
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
836

A
annie_wangli 已提交
837
**Parameters**
A
Annie_wang 已提交
838

A
annie_wangli 已提交
839 840 841 842
| 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 已提交
843

A
annie_wangli 已提交
844
**Return value**
A
Annie_wang 已提交
845

A
annie_wangli 已提交
846 847
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
848
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
849

A
annie_wangli 已提交
850
**Example**
A
Annie_wang 已提交
851

A
Annie_wang 已提交
852 853 854 855
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.lessThanOrEqualTo("AGE", 20)
```
A
annie_wangli 已提交
856 857 858 859 860

### orderByAsc

orderByAsc(field: string): RdbPredicates

A
Annie_wang 已提交
861
Sets an **RdbPredicates** to match the column with values sorted in ascending order.
A
annie_wangli 已提交
862

A
annie_wangli 已提交
863
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
864

A
annie_wangli 已提交
865
**Parameters**
A
Annie_wang 已提交
866

A
annie_wangli 已提交
867 868 869
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
A
annie_wangli 已提交
870

A
annie_wangli 已提交
871
**Return value**
A
Annie_wang 已提交
872

A
annie_wangli 已提交
873 874
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
875
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
876

A
annie_wangli 已提交
877
**Example**
A
Annie_wang 已提交
878

A
Annie_wang 已提交
879 880 881 882
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.orderByAsc("NAME")
```
A
annie_wangli 已提交
883 884 885 886 887

### orderByDesc

orderByDesc(field: string): RdbPredicates

A
Annie_wang 已提交
888
Sets an **RdbPredicates** to match the column with values sorted in descending order.
A
annie_wangli 已提交
889

A
annie_wangli 已提交
890
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
891

A
annie_wangli 已提交
892
**Parameters**
A
Annie_wang 已提交
893

A
annie_wangli 已提交
894 895 896
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
A
annie_wangli 已提交
897

A
annie_wangli 已提交
898
**Return value**
A
Annie_wang 已提交
899

A
annie_wangli 已提交
900 901
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
902
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
903

A
annie_wangli 已提交
904
**Example**
A
Annie_wang 已提交
905

A
Annie_wang 已提交
906 907 908 909
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.orderByDesc("AGE")
```
A
annie_wangli 已提交
910 911 912 913 914

### distinct

distinct(): RdbPredicates

A
Annie_wang 已提交
915
Sets an **RdbPredicates** to filter out duplicate records.
A
annie_wangli 已提交
916

A
annie_wangli 已提交
917
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
918

A
annie_wangli 已提交
919
**Return value**
A
Annie_wang 已提交
920

A
annie_wangli 已提交
921 922 923
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that can filter out duplicate records.|
A
annie_wangli 已提交
924

A
annie_wangli 已提交
925
**Example**
A
Annie_wang 已提交
926

A
Annie_wang 已提交
927 928
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
A
Annie_wang 已提交
929
predicates.equalTo("NAME", "Rose").distinct()
A
Annie_wang 已提交
930
```
A
annie_wangli 已提交
931 932 933 934 935

### limitAs

limitAs(value: number): RdbPredicates

A
Annie_wang 已提交
936
Sets an **RdbPredicates** to specify the maximum number of records.
A
annie_wangli 已提交
937

A
annie_wangli 已提交
938
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
939

A
annie_wangli 已提交
940
**Parameters**
A
Annie_wang 已提交
941

A
annie_wangli 已提交
942 943 944
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Maximum number of records.|
A
annie_wangli 已提交
945

A
annie_wangli 已提交
946
**Return value**
A
Annie_wang 已提交
947

A
annie_wangli 已提交
948 949 950
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the maximum number of records.|
A
annie_wangli 已提交
951

A
annie_wangli 已提交
952
**Example**
A
Annie_wang 已提交
953

A
Annie_wang 已提交
954 955 956 957
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose").limitAs(3)
```
A
annie_wangli 已提交
958 959 960 961 962

### offsetAs

offsetAs(rowOffset: number): RdbPredicates

A
Annie_wang 已提交
963
Sets an **RdbPredicates** to specify the start position of the returned result.
A
annie_wangli 已提交
964

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

A
annie_wangli 已提交
967
**Parameters**
A
Annie_wang 已提交
968

A
annie_wangli 已提交
969 970 971
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| rowOffset | number | Yes| Number of rows to offset from the beginning. The value is a positive integer.|
A
annie_wangli 已提交
972

A
annie_wangli 已提交
973
**Return value**
A
Annie_wang 已提交
974

A
annie_wangli 已提交
975 976 977
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the start position of the returned result.|
A
annie_wangli 已提交
978

A
annie_wangli 已提交
979
**Example**
A
Annie_wang 已提交
980

A
Annie_wang 已提交
981 982 983 984
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose").offsetAs(3)
```
A
annie_wangli 已提交
985 986 987 988 989

### groupBy

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

A
Annie_wang 已提交
990
Sets an **RdbPredicates** to group rows that have the same value into summary rows.
A
annie_wangli 已提交
991

A
annie_wangli 已提交
992
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
993

A
annie_wangli 已提交
994
**Parameters**
A
Annie_wang 已提交
995

A
annie_wangli 已提交
996 997 998
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| fields | Array&lt;string&gt; | Yes| Names of columns to group.|
A
annie_wangli 已提交
999

A
annie_wangli 已提交
1000
**Return value**
A
Annie_wang 已提交
1001

A
annie_wangli 已提交
1002 1003 1004
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that groups rows with the same value.|
A
annie_wangli 已提交
1005

A
annie_wangli 已提交
1006
**Example**
A
Annie_wang 已提交
1007

A
Annie_wang 已提交
1008 1009 1010 1011
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.groupBy(["AGE", "NAME"])
```
A
annie_wangli 已提交
1012 1013 1014

### indexedBy

A
annie_wangli 已提交
1015
indexedBy(field: string): RdbPredicates
A
annie_wangli 已提交
1016

A
Annie_wang 已提交
1017
Sets an **RdbPredicates** object to specify the index column.
A
annie_wangli 已提交
1018

A
annie_wangli 已提交
1019
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1020

A
annie_wangli 已提交
1021
**Parameters**
A
Annie_wang 已提交
1022

A
annie_wangli 已提交
1023 1024 1025
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Name of the index column.|
A
annie_wangli 已提交
1026

A
annie_wangli 已提交
1027
**Return value**
A
annie_wangli 已提交
1028

A
Annie_wang 已提交
1029

A
annie_wangli 已提交
1030 1031 1032 1033 1034
| Type| Description|
| -------- | -------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the index column.|

**Example**
A
Annie_wang 已提交
1035

A
Annie_wang 已提交
1036 1037 1038 1039
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.indexedBy("SALARY_INDEX")
```
A
annie_wangli 已提交
1040 1041 1042 1043 1044

### in

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

A
Annie_wang 已提交
1045
Sets an **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value within the specified range.
A
annie_wangli 已提交
1046

A
annie_wangli 已提交
1047
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1048

A
annie_wangli 已提交
1049
**Parameters**
A
Annie_wang 已提交
1050

A
annie_wangli 已提交
1051 1052 1053 1054
| 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 已提交
1055

A
annie_wangli 已提交
1056
**Return value**
A
Annie_wang 已提交
1057

A
annie_wangli 已提交
1058 1059
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
1060
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
1061

A
annie_wangli 已提交
1062
**Example**
A
Annie_wang 已提交
1063

A
Annie_wang 已提交
1064 1065 1066 1067
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.in("AGE", [18, 20])
```
A
annie_wangli 已提交
1068 1069 1070 1071 1072

### notIn

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

A
Annie_wang 已提交
1073
Sets an **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value out of the specified range.
A
annie_wangli 已提交
1074

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

A
annie_wangli 已提交
1077
**Parameters**
A
Annie_wang 已提交
1078

A
annie_wangli 已提交
1079 1080 1081 1082
| 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 已提交
1083

A
annie_wangli 已提交
1084
**Return value**
A
Annie_wang 已提交
1085

A
annie_wangli 已提交
1086 1087
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
1088
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
A
annie_wangli 已提交
1089

A
annie_wangli 已提交
1090
**Example**
A
Annie_wang 已提交
1091

A
Annie_wang 已提交
1092 1093 1094 1095
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.notIn("NAME", ["Lisa", "Rose"])
```
A
annie_wangli 已提交
1096 1097

## RdbStore
Z
zengyawen 已提交
1098 1099 1100

Provides methods to manage an RDB store.

A
Annie_wang 已提交
1101 1102
Before using the following APIs, use [executeSql](#executesql) to initialize the database table structure and related data. For details, see [RDB Development](../../database/database-relational-guidelines.md).

A
annie_wangli 已提交
1103 1104
### insert

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

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

A
annie_wangli 已提交
1109
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1110

A
annie_wangli 已提交
1111
**Parameters**
A
Annie_wang 已提交
1112

A
annie_wangli 已提交
1113 1114
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1115
| table | string | Yes| Name of the target table.|
A
annie_wangli 已提交
1116 1117 1118 1119
| 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 已提交
1120

A
Annie_wang 已提交
1121 1122 1123 1124 1125 1126 1127
```js
const valueBucket = {
    "NAME": "Lisa",
    "AGE": 18,
    "SALARY": 100.5,
    "CODES": new Uint8Array([1, 2, 3, 4, 5]),
}
A
Annie_wang 已提交
1128 1129 1130 1131
rdbStore.insert("EMPLOYEE", valueBucket, function (status, rowId) {
    if (status) {
        console.log("Failed to insert data");
        return;
A
Annie_wang 已提交
1132
    }
A
Annie_wang 已提交
1133
    console.log("Inserted data successfully, rowId = " + rowId);
A
Annie_wang 已提交
1134 1135
})
```
A
annie_wangli 已提交
1136 1137 1138

### insert

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

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

A
annie_wangli 已提交
1143
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1144

A
annie_wangli 已提交
1145
**Parameters**
A
Annie_wang 已提交
1146

A
annie_wangli 已提交
1147 1148
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1149
| table | string | Yes| Name of the target table.|
A
annie_wangli 已提交
1150
| values | [ValuesBucket](#valuesbucket) | Yes| Row of data to insert.|
A
annie_wangli 已提交
1151

A
annie_wangli 已提交
1152
**Return value**
A
Annie_wang 已提交
1153

A
annie_wangli 已提交
1154 1155 1156 1157 1158
| 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 已提交
1159

A
Annie_wang 已提交
1160 1161 1162 1163 1164 1165 1166 1167
```js
const valueBucket = {
    "NAME": "Lisa",
    "AGE": 18,
    "SALARY": 100.5,
    "CODES": new Uint8Array([1, 2, 3, 4, 5]),
}
let promise = rdbStore.insert("EMPLOYEE", valueBucket)
A
Annie_wang 已提交
1168
promise.then((rowId) => {
A
Annie_wang 已提交
1169
    console.log("Inserted data successfully, rowId = " + rowId);
A
Annie_wang 已提交
1170 1171
}).catch((status) => {
    console.log("Failed to insert data");
A
Annie_wang 已提交
1172 1173
})
```
A
annie_wangli 已提交
1174

A
Annie_wang 已提交
1175 1176 1177 1178 1179 1180 1181 1182 1183
### batchInsert<sup>9+</sup>

batchInsert(table: string, values: Array&lt;ValuesBucket&gt;, callback: AsyncCallback&lt;number&gt;):void

Batch inserts data into a table. This API uses an asynchronous callback to return the result.

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

**Parameters**
A
Annie_wang 已提交
1184

A
Annie_wang 已提交
1185 1186 1187 1188 1189 1190 1191
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| table | string | Yes| Name of the target table.|
| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | Yes| An array of data to insert.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the result. If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.|

**Example**
A
Annie_wang 已提交
1192

A
Annie_wang 已提交
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
```js
const valueBucket1 = {
    "NAME": "Lisa",
    "AGE": 18,
    "SALARY": 100.5,
    "CODES": new Uint8Array([1, 2, 3, 4, 5])
}
const valueBucket2 = {
    "NAME": "Jack",
    "AGE": 19,
    "SALARY": 101.5,
    "CODES": new Uint8Array([6, 7, 8, 9, 10])
}
const valueBucket3 = {
    "NAME": "Tom",
    "AGE": 20,
    "SALARY": 102.5,
    "CODES": new Uint8Array([11, 12, 13, 14, 15])
}

var valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
rdbStore.batchInsert("EMPLOYEE", valueBuckets, function(status, insertNum) {
    if (status) {
A
Annie_wang 已提交
1216
        console.log("Failed to batch insert data, status = " + status);
A
Annie_wang 已提交
1217 1218
        return;
    }
A
Annie_wang 已提交
1219
    console.log("Batch inserted data successfully. The number of values that were inserted = " + insertNum);
A
Annie_wang 已提交
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231
})
```

### batchInsert<sup>9+</sup>

batchInsert(table: string, values: Array&lt;ValuesBucket&gt;):Promise&lt;number&gt;

Batch inserts data into a table. This API uses a promise to return the result.

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

**Parameters**
A
Annie_wang 已提交
1232

A
Annie_wang 已提交
1233 1234 1235 1236 1237 1238
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| table | string | Yes| Name of the target table.|
| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | Yes| An array of data to insert.|

**Return value**
A
Annie_wang 已提交
1239

A
Annie_wang 已提交
1240 1241 1242 1243 1244
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Promise used to return the result. If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.|

**Example**
A
Annie_wang 已提交
1245

A
Annie_wang 已提交
1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268
```js
const valueBucket1 = {
    "NAME": "Lisa",
    "AGE": 18,
    "SALARY": 100.5,
    "CODES": new Uint8Array([1, 2, 3, 4, 5])
}
const valueBucket2 = {
    "NAME": "Jack",
    "AGE": 19,
    "SALARY": 101.5,
    "CODES": new Uint8Array([6, 7, 8, 9, 10])
}
const valueBucket3 = {
    "NAME": "Tom",
    "AGE": 20,
    "SALARY": 102.5,
    "CODES": new Uint8Array([11, 12, 13, 14, 15])
}

var valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
let promise = rdbStore.batchInsert("EMPLOYEE", valueBuckets);
promise.then((insertNum) => {
A
Annie_wang 已提交
1269
    console.log("Batch inserted data successfully. The number of values that were inserted = " + insertNum);
A
Annie_wang 已提交
1270
}).catch((status) => {
A
Annie_wang 已提交
1271
    console.log("Failed to batch insert data, status = " + status);
A
Annie_wang 已提交
1272 1273
})
```
A
annie_wangli 已提交
1274 1275 1276

### update

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

A
Annie_wang 已提交
1279
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 已提交
1280

A
annie_wangli 已提交
1281
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1282

A
annie_wangli 已提交
1283
**Parameters**
A
Annie_wang 已提交
1284

A
annie_wangli 已提交
1285 1286
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1287
| values | [ValuesBucket](#valuesbucket) | Yes| Data to update in the RDB store. The key-value pair is associated with the column name in the target table.|
A
Annie_wang 已提交
1288
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Update conditions specified by the **RdbPredicates** object.|
A
Annie_wang 已提交
1289
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of rows updated.|
A
annie_wangli 已提交
1290 1291

**Example**
A
Annie_wang 已提交
1292

A
Annie_wang 已提交
1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
```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 已提交
1304
        console.info("Failed to update data, err: " + err)
A
Annie_wang 已提交
1305 1306 1307 1308 1309
        return
    }
    console.log("Updated row count: " + ret)
})
```
A
annie_wangli 已提交
1310 1311 1312

### update

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

A
Annie_wang 已提交
1315
Updates data based on the specified **RdbPredicates** object. This API uses a promise to return the result.
A
annie_wangli 已提交
1316

A
annie_wangli 已提交
1317
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1318

A
annie_wangli 已提交
1319
**Parameters**
A
Annie_wang 已提交
1320

A
annie_wangli 已提交
1321 1322
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1323
| values | [ValuesBucket](#valuesbucket) | Yes| Data to update in the RDB store. The key-value pair is associated with the column name in the target table.|
A
Annie_wang 已提交
1324
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Update conditions specified by the **RdbPredicates** object.|
A
annie_wangli 已提交
1325

A
annie_wangli 已提交
1326
**Return value**
A
Annie_wang 已提交
1327

A
annie_wangli 已提交
1328 1329 1330 1331 1332
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Promise used to return the number of rows updated.|

**Example**
A
Annie_wang 已提交
1333

A
Annie_wang 已提交
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346
```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 已提交
1347
    console.info("Failed to update data, err: " + err)
A
Annie_wang 已提交
1348 1349
})
```
A
annie_wangli 已提交
1350

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

A
Annie_wang 已提交
1354
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 已提交
1355

A
Annie_wang 已提交
1356 1357
**System API**: This is a system API.

A
Annie_wang 已提交
1358 1359 1360
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**
A
Annie_wang 已提交
1361

A
Annie_wang 已提交
1362 1363 1364
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| table | string | Yes| Name of the target table.|
A
Annie_wang 已提交
1365
| 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.|
1366
| predicates | [DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates)| Yes|  Update conditions specified by the **DataSharePredicates** object.|
A
Annie_wang 已提交
1367
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of rows updated.|
A
Annie_wang 已提交
1368 1369

**Example**
A
Annie_wang 已提交
1370

A
Annie_wang 已提交
1371
```js
A
Annie_wang 已提交
1372
import dataSharePredicates from '@ohos.data.dataSharePredicates'
A
Annie_wang 已提交
1373 1374 1375 1376 1377 1378
const valueBucket = {
    "NAME": "Rose",
    "AGE": 22,
    "SALARY": 200.5,
    "CODES": new Uint8Array([1, 2, 3, 4, 5]),
}
A
Annie_wang 已提交
1379
let predicates = new dataSharePredicates.DataSharePredicates()
A
Annie_wang 已提交
1380 1381 1382
predicates.equalTo("NAME", "Lisa")
rdbStore.update("EMPLOYEE", valueBucket, predicates, function (err, ret) {
    if (err) {
A
Annie_wang 已提交
1383
        console.info("Failed to update data, err: " + err)
A
Annie_wang 已提交
1384 1385 1386 1387 1388
        return
    }
    console.log("Updated row count: " + ret)
})
```
A
Annie_wang 已提交
1389

A
Annie_wang 已提交
1390 1391
### update<sup>9+</sup>

A
Annie_wang 已提交
1392
update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates):Promise&lt;number&gt;
A
Annie_wang 已提交
1393

A
Annie_wang 已提交
1394
Updates data in the RDB store based on the specified **DataSharePredicates** object. This API uses a promise to return the result.
A
Annie_wang 已提交
1395

A
Annie_wang 已提交
1396 1397
**System API**: This is a system API.

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

**Parameters**
A
Annie_wang 已提交
1401

A
Annie_wang 已提交
1402 1403 1404
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| table | string | Yes| Name of the target table.|
A
Annie_wang 已提交
1405
| 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.|
1406
| predicates | [DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes| Update conditions specified by the **DataSharePredicates** object.|
A
Annie_wang 已提交
1407 1408

**Return value**
A
Annie_wang 已提交
1409

A
Annie_wang 已提交
1410 1411 1412 1413 1414
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Promise used to return the number of rows updated.|

**Example**
A
Annie_wang 已提交
1415

A
Annie_wang 已提交
1416
```js
A
Annie_wang 已提交
1417
import dataSharePredicates from '@ohos.data.dataSharePredicates'
A
Annie_wang 已提交
1418 1419 1420 1421 1422 1423
const valueBucket = {
    "NAME": "Rose",
    "AGE": 22,
    "SALARY": 200.5,
    "CODES": new Uint8Array([1, 2, 3, 4, 5]),
}
A
Annie_wang 已提交
1424
let predicates = new dataSharePredicates.DataSharePredicates()
A
Annie_wang 已提交
1425 1426 1427 1428 1429
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 已提交
1430
    console.info("Failed to update data, err: " + err)
A
Annie_wang 已提交
1431 1432
})
```
A
annie_wangli 已提交
1433 1434 1435

### delete

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

A
Annie_wang 已提交
1438
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 已提交
1439

A
annie_wangli 已提交
1440
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1441

A
annie_wangli 已提交
1442
**Parameters**
A
Annie_wang 已提交
1443

A
annie_wangli 已提交
1444 1445
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1446
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Conditions specified by the **RdbPredicates** object for deleting data.|
A
annie_wangli 已提交
1447
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of rows updated.|
A
annie_wangli 已提交
1448

A
annie_wangli 已提交
1449
**Example**
A
Annie_wang 已提交
1450

A
Annie_wang 已提交
1451 1452 1453 1454 1455
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa")
rdbStore.delete(predicates, function (err, rows) {
    if (err) {
A
Annie_wang 已提交
1456
        console.info("Failed to delete data, err: " + err)
A
Annie_wang 已提交
1457 1458
        return
    }
A
Annie_wang 已提交
1459
    console.log("Deleted rows: " + rows)
A
Annie_wang 已提交
1460 1461
})
```
A
annie_wangli 已提交
1462 1463 1464

### delete

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

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

A
annie_wangli 已提交
1469
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1470

A
annie_wangli 已提交
1471
**Parameters**
A
Annie_wang 已提交
1472

A
annie_wangli 已提交
1473 1474
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1475
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Conditions specified by the **RdbPredicates** object for deleting data.|
A
annie_wangli 已提交
1476

A
annie_wangli 已提交
1477
**Return value**
A
Annie_wang 已提交
1478

A
annie_wangli 已提交
1479 1480
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
1481
| Promise&lt;number&gt; | Promise used to return the number of rows updated.|
A
annie_wangli 已提交
1482 1483

**Example**
A
Annie_wang 已提交
1484

A
Annie_wang 已提交
1485 1486 1487 1488 1489
```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa")
let promise = rdbStore.delete(predicates)
promise.then((rows) => {
A
Annie_wang 已提交
1490
    console.log("Deleted rows: " + rows)
A
Annie_wang 已提交
1491
}).catch((err) => {
A
Annie_wang 已提交
1492
    console.info("Failed to delete data, err: " + err)
A
Annie_wang 已提交
1493 1494
})
```
A
annie_wangli 已提交
1495

A
Annie_wang 已提交
1496 1497
### delete<sup>9+</sup>

A
Annie_wang 已提交
1498
delete(table: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;number&gt;):void
A
Annie_wang 已提交
1499

A
Annie_wang 已提交
1500
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 已提交
1501

A
Annie_wang 已提交
1502 1503
**System API**: This is a system API.

A
Annie_wang 已提交
1504 1505 1506
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**
A
Annie_wang 已提交
1507

A
Annie_wang 已提交
1508 1509 1510
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| table | string | Yes| Name of the target table.|
1511
| predicates | [DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes|  Conditions specified by the **DataSharePredicates** object for deleting data.|
A
Annie_wang 已提交
1512 1513 1514
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of rows updated.|

**Example**
A
Annie_wang 已提交
1515

A
Annie_wang 已提交
1516
```js
A
Annie_wang 已提交
1517 1518
import dataSharePredicates from '@ohos.data.dataSharePredicates'
let predicates = new dataSharePredicates.DataSharePredicates()
A
Annie_wang 已提交
1519 1520 1521
predicates.equalTo("NAME", "Lisa")
rdbStore.delete("EMPLOYEE", predicates, function (err, rows) {
    if (err) {
A
Annie_wang 已提交
1522
        console.info("Failed to delete data, err: " + err)
A
Annie_wang 已提交
1523 1524
        return
    }
A
Annie_wang 已提交
1525
    console.log("Deleted rows: " + rows)
A
Annie_wang 已提交
1526 1527
})
```
A
Annie_wang 已提交
1528

A
Annie_wang 已提交
1529 1530
### delete<sup>9+</sup>

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

A
Annie_wang 已提交
1533
Deletes data from the RDB store based on the specified **DataSharePredicates** object. This API uses a promise to return the result.
A
Annie_wang 已提交
1534

A
Annie_wang 已提交
1535 1536
**System API**: This is a system API.

A
Annie_wang 已提交
1537 1538 1539
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**
A
Annie_wang 已提交
1540

A
Annie_wang 已提交
1541 1542 1543
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| table | string | Yes| Name of the target table.|
1544
| predicates | [DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes| Conditions specified by the **DataSharePredicates** object for deleting data.|
A
Annie_wang 已提交
1545 1546

**Return value**
A
Annie_wang 已提交
1547

A
Annie_wang 已提交
1548 1549
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
1550
| Promise&lt;number&gt; | Promise used to return the number of rows updated.|
A
Annie_wang 已提交
1551 1552

**Example**
A
Annie_wang 已提交
1553

A
Annie_wang 已提交
1554
```js
A
Annie_wang 已提交
1555 1556
import dataSharePredicates from '@ohos.data.dataSharePredicates'
let predicates = new dataSharePredicates.DataSharePredicates()
A
Annie_wang 已提交
1557 1558 1559
predicates.equalTo("NAME", "Lisa")
let promise = rdbStore.delete("EMPLOYEE", predicates)
promise.then((rows) => {
A
Annie_wang 已提交
1560
    console.log("Deleted rows: " + rows)
A
Annie_wang 已提交
1561
}).catch((err) => {
A
Annie_wang 已提交
1562
    console.info("Failed to delete data, err: " + err)
A
Annie_wang 已提交
1563 1564
})
```
A
annie_wangli 已提交
1565 1566 1567

### query

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

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

A
annie_wangli 已提交
1572
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1573

A
annie_wangli 已提交
1574
**Parameters**
A
Annie_wang 已提交
1575

A
annie_wangli 已提交
1576 1577
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1578
| predicates | [RdbPredicates](#rdbpredicates) | Yes| Query conditions specified by the **RdbPredicates** object.|
A
annie_wangli 已提交
1579 1580 1581 1582
| 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 已提交
1583

A
Annie_wang 已提交
1584 1585 1586 1587 1588
```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 已提交
1589
        console.info("Failed to query data, err: " + err)
A
Annie_wang 已提交
1590 1591
        return
    }
A
Annie_wang 已提交
1592 1593
    console.log("ResultSet column names: " + resultSet.columnNames)
    console.log("ResultSet column count: " + resultSet.columnCount)
A
Annie_wang 已提交
1594 1595
})
```
A
annie_wangli 已提交
1596 1597 1598

### query

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

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

A
annie_wangli 已提交
1603
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1604

A
annie_wangli 已提交
1605
**Parameters**
A
Annie_wang 已提交
1606

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

A
annie_wangli 已提交
1612
**Return value**
A
Annie_wang 已提交
1613

A
annie_wangli 已提交
1614 1615
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
1616
| 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.|
A
annie_wangli 已提交
1617 1618

**Example**
A
Annie_wang 已提交
1619

A
Annie_wang 已提交
1620
  ```js
A
annie_wangli 已提交
1621 1622
  let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
  predicates.equalTo("NAME", "Rose")
A
Annie_wang 已提交
1623 1624
  let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
  promise.then((resultSet) => {
A
Annie_wang 已提交
1625 1626
      console.log("ResultSet column names: " + resultSet.columnNames)
      console.log("ResultSet column count: " + resultSet.columnCount)
A
annie_wangli 已提交
1627
  }).catch((err) => {
A
Annie_wang 已提交
1628
      console.info("Failed to query data, err: " + err)
A
annie_wangli 已提交
1629
  })
A
annie_wangli 已提交
1630 1631
  ```

A
Annie_wang 已提交
1632 1633
### query<sup>9+</sup>

A
Annie_wang 已提交
1634
query(table: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
A
Annie_wang 已提交
1635

A
Annie_wang 已提交
1636
Queries data from the RDB store based on specified conditions. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1637

A
Annie_wang 已提交
1638 1639
**System API**: This is a system API.

A
Annie_wang 已提交
1640 1641 1642
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**
A
Annie_wang 已提交
1643

A
Annie_wang 已提交
1644 1645
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1646
| table | string | Yes| Name of the target table.|
1647
| predicates | [DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes| Query conditions specified by the **DataSharePredicates** object.|
A
Annie_wang 已提交
1648 1649 1650 1651
| 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 已提交
1652

A
Annie_wang 已提交
1653
```js
A
Annie_wang 已提交
1654 1655
import dataSharePredicates from '@ohos.data.dataSharePredicates'
let predicates = new dataSharePredicates.DataSharePredicates()
A
Annie_wang 已提交
1656 1657 1658
predicates.equalTo("NAME", "Rose")
rdbStore.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
    if (err) {
A
Annie_wang 已提交
1659
        console.info("Failed to query data, err: " + err)
A
Annie_wang 已提交
1660 1661 1662 1663 1664 1665 1666 1667 1668
        return
    }
    console.log("ResultSet column names: " + resultSet.columnNames)
    console.log("ResultSet column count: " + resultSet.columnCount)
})
```

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

A
Annie_wang 已提交
1669
query(table: string, predicates: dataSharePredicates.DataSharePredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt;
A
Annie_wang 已提交
1670

A
Annie_wang 已提交
1671
Queries data from the RDB store based on specified conditions. This API uses a promise to return the result.
A
Annie_wang 已提交
1672

A
Annie_wang 已提交
1673 1674
**System API**: This is a system API.

A
Annie_wang 已提交
1675 1676 1677
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**
A
Annie_wang 已提交
1678

A
Annie_wang 已提交
1679 1680
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1681
| table | string | Yes| Name of the target table.|
1682
| predicates | [DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes| Query conditions specified by the **DataSharePredicates** object.|
A
Annie_wang 已提交
1683 1684 1685
| columns | Array&lt;string&gt; | No| Columns to query. If this parameter is not specified, the query applies to all columns.|

**Return value**
A
Annie_wang 已提交
1686

A
Annie_wang 已提交
1687 1688 1689 1690 1691
| 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**
A
Annie_wang 已提交
1692

A
Annie_wang 已提交
1693
```js
A
Annie_wang 已提交
1694 1695
import dataSharePredicates from '@ohos.data.dataSharePredicates'
let predicates = new dataSharePredicates.DataSharePredicates()
A
Annie_wang 已提交
1696 1697 1698 1699 1700 1701
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 已提交
1702
    console.info("Failed to query data, err: " + err)
A
Annie_wang 已提交
1703 1704
})
```
A
annie_wangli 已提交
1705

A
Annie_wang 已提交
1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719
### remoteQuery<sup>9+</sup>

remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array&lt;string&gt; , callback: AsyncCallback&lt;ResultSet&gt;): void

Queries data from the RDB store of a remote device based on specified conditions. This API uses an asynchronous callback to return the result.

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| device | string | Yes| Network ID of the remote device.|
| table | string | Yes| Name of the target table.|
A
Annie_wang 已提交
1720
| predicates | [RdbPredicates](#rdbpredicates)  | Yes| Query conditions specified by the **RdbPredicates** object.|
A
Annie_wang 已提交
1721 1722 1723 1724 1725 1726
| 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#resultset)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|

**Example**

```js
A
Annie_wang 已提交
1727
let predicates = new data_rdb.RdbPredicates('EMPLOYEE')
A
Annie_wang 已提交
1728
predicates.greaterThan("id", 0)
A
Annie_wang 已提交
1729 1730
rdbStore.remoteQuery("deviceId", "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"],
    function(err, resultSet){
A
Annie_wang 已提交
1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753
    if (err) {
        console.info("Failed to remoteQuery, err: " + err)
        return
    }
    console.info("ResultSet column names: " + resultSet.columnNames)
    console.info("ResultSet column count: " + resultSet.columnCount)
})
```

### remoteQuery<sup>9+</sup>

remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array&lt;string&gt;): Promise&lt;ResultSet&gt;

Queries data from the RDB store of a remote device based on specified conditions. This API uses a promise to return the result.

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| device | string | Yes| Network ID of the remote device.|
| table | string | Yes| Name of the target table.|
A
Annie_wang 已提交
1754
| predicates | [RdbPredicates](#rdbpredicates)  | Yes| Query conditions specified by the **RdbPredicates** object.|
A
Annie_wang 已提交
1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765
| 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#resultset)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|

**Example**

```js
A
Annie_wang 已提交
1766
let predicates = new data_rdb.RdbPredicates('EMPLOYEE')
A
Annie_wang 已提交
1767
predicates.greaterThan("id", 0)
A
Annie_wang 已提交
1768
let promise = rdbStore.remoteQuery("deviceId", "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
A
Annie_wang 已提交
1769 1770 1771 1772 1773 1774 1775 1776
promise.then((resultSet) => {
    console.info("ResultSet column names: " + resultSet.columnNames)
    console.info("ResultSet column count: " + resultSet.columnCount)
}).catch((err) => {
    console.info("Failed to remoteQuery , err: " + err)
})
```

A
annie_wangli 已提交
1777 1778 1779 1780
### querySql<sup>8+</sup>

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

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

A
annie_wangli 已提交
1783
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1784

A
annie_wangli 已提交
1785
**Parameters**
A
Annie_wang 已提交
1786

A
annie_wangli 已提交
1787 1788 1789
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.|
A
Annie_wang 已提交
1790
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes| Arguments in the SQL statement.|
A
annie_wangli 已提交
1791 1792 1793
| 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 已提交
1794

A
Annie_wang 已提交
1795 1796 1797
```js
rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) {
    if (err) {
A
Annie_wang 已提交
1798
        console.info("Failed to query data, err: " + err)
A
Annie_wang 已提交
1799 1800
        return
    }
A
Annie_wang 已提交
1801 1802
    console.log("ResultSet column names: " + resultSet.columnNames)
    console.log("ResultSet column count: " + resultSet.columnCount)
A
Annie_wang 已提交
1803 1804
})
```
A
annie_wangli 已提交
1805 1806 1807 1808 1809

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

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

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

A
annie_wangli 已提交
1812
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1813

A
annie_wangli 已提交
1814
**Parameters**
A
Annie_wang 已提交
1815

A
annie_wangli 已提交
1816 1817 1818
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.|
A
Annie_wang 已提交
1819
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | No| Arguments in the SQL statement.|
A
annie_wangli 已提交
1820

A
annie_wangli 已提交
1821
**Return value**
A
Annie_wang 已提交
1822

A
annie_wangli 已提交
1823 1824
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
1825
| 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.|
A
annie_wangli 已提交
1826 1827

**Example**
A
Annie_wang 已提交
1828

A
Annie_wang 已提交
1829 1830 1831
```js
let promise = rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'])
promise.then((resultSet) => {
A
Annie_wang 已提交
1832 1833
    console.log("ResultSet column names: " + resultSet.columnNames)
    console.log("ResultSet column count: " + resultSet.columnCount)
A
Annie_wang 已提交
1834
}).catch((err) => {
A
Annie_wang 已提交
1835
    console.info("Failed to query data, err: " + err)
A
Annie_wang 已提交
1836 1837
})
```
A
annie_wangli 已提交
1838 1839 1840 1841

### executeSql

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

A
Annie_wang 已提交
1843
Executes an SQL statement that contains specified arguments but returns no value. This API uses an asynchronous callback to return the result.
Z
zengyawen 已提交
1844

A
annie_wangli 已提交
1845
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1846

A
annie_wangli 已提交
1847
**Parameters**
A
Annie_wang 已提交
1848

A
annie_wangli 已提交
1849 1850 1851
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.|
A
Annie_wang 已提交
1852
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes| Arguments in the SQL statement.|
A
Annie_wang 已提交
1853
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|
A
annie_wangli 已提交
1854 1855

**Example**
A
Annie_wang 已提交
1856

A
Annie_wang 已提交
1857 1858 1859 1860
```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 已提交
1861
        console.info("Failed to execute SQL, err: " + err)
A
Annie_wang 已提交
1862 1863
        return
    }
A
Annie_wang 已提交
1864
    console.info('Created table successfully.')
A
Annie_wang 已提交
1865 1866
})
```
A
annie_wangli 已提交
1867 1868 1869 1870

### executeSql

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

A
Annie_wang 已提交
1872
Executes an SQL statement that contains specified arguments but returns no value. This API uses a promise to return the result.
Z
zengyawen 已提交
1873

A
annie_wangli 已提交
1874
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
1875

A
annie_wangli 已提交
1876
**Parameters**
A
Annie_wang 已提交
1877

A
annie_wangli 已提交
1878 1879 1880
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.|
A
Annie_wang 已提交
1881
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | No| Arguments in the SQL statement.|
A
annie_wangli 已提交
1882

A
annie_wangli 已提交
1883
**Return value**
A
Annie_wang 已提交
1884

A
annie_wangli 已提交
1885 1886
| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
1887
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1888 1889

**Example**
A
Annie_wang 已提交
1890

A
Annie_wang 已提交
1891 1892 1893 1894
```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 已提交
1895
    console.info('Created table successfully.')
A
Annie_wang 已提交
1896
}).catch((err) => {
A
Annie_wang 已提交
1897
    console.info("Failed to execute SQL, err: " + err)
A
Annie_wang 已提交
1898 1899
})
```
A
annie_wangli 已提交
1900

A
annie_wangli 已提交
1901 1902 1903 1904 1905
### beginTransaction<sup>8+</sup>

beginTransaction():void

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

A
annie_wangli 已提交
1907 1908 1909
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Example**
A
Annie_wang 已提交
1910

A
Annie_wang 已提交
1911
```js
A
Annie_wang 已提交
1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()
const STORE_CONFIG = { name: "RdbTest.db"}
data_rdb.getRdbStore(context, STORE_CONFIG, 1, async function (err, rdbStore) {
    rdbStore.beginTransaction()
	const valueBucket = {
		"name": "lisi",
		"age": 18,
		"salary": 100.5,
		"blobType": new Uint8Array([1, 2, 3]),
	}
	await rdbStore.insert("test", valueBucket)
	rdbStore.commit()
})
A
annie_wangli 已提交
1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936
```

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

commit():void

Commits the executed SQL statements.

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

**Example**
A
Annie_wang 已提交
1937

A
Annie_wang 已提交
1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()
const STORE_CONFIG = { name: "RdbTest.db"}
data_rdb.getRdbStore(context, STORE_CONFIG, 1, async function (err, rdbStore) {
    rdbStore.beginTransaction()
	const valueBucket = {
		"name": "lisi",
		"age": 18,
		"salary": 100.5,
		"blobType": new Uint8Array([1, 2, 3]),
	}
	await rdbStore.insert("test", valueBucket)
	rdbStore.commit()
})
A
annie_wangli 已提交
1953 1954 1955 1956
```

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

A
Annie_wang 已提交
1957
rollBack():void
A
annie_wangli 已提交
1958 1959 1960 1961 1962 1963

Rolls back the SQL statements that have been executed.

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

**Example**
A
Annie_wang 已提交
1964

A
Annie_wang 已提交
1965
```js
A
Annie_wang 已提交
1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()
const STORE_CONFIG = { name: "RdbTest.db"}
data_rdb.getRdbStore(context, STORE_CONFIG, 1, async function (err, rdbStore) {
    try {
		rdbStore.beginTransaction()
		const valueBucket = {
			"id": 1,
			"name": "lisi",
			"age": 18,
			"salary": 100.5,
			"blobType": new Uint8Array([1, 2, 3]),
		}
		await rdbStore.insert("test", valueBucket)
		rdbStore.commit()
	} catch (e) {
		rdbStore.rollBack()
	}
})
A
annie_wangli 已提交
1985 1986
```

A
Annie_wang 已提交
1987 1988 1989 1990
### backup<sup>9+</sup>

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

A
Annie_wang 已提交
1991
Backs up an RDB store. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1992 1993 1994 1995

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

**Parameters**
A
Annie_wang 已提交
1996

A
Annie_wang 已提交
1997 1998
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1999
| destName | string | Yes| Name of the RDB store backup file.|
A
Annie_wang 已提交
2000 2001 2002
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|

**Example**
A
Annie_wang 已提交
2003

A
Annie_wang 已提交
2004 2005 2006
```js
rdbStore.backup("dbBackup.db", function(err) {
    if (err) {
A
Annie_wang 已提交
2007
        console.info('Failed to back up data, err: ' + err)
A
Annie_wang 已提交
2008 2009
        return
    }
A
Annie_wang 已提交
2010
    console.info('Backed up data successfully.')
A
Annie_wang 已提交
2011 2012 2013 2014 2015 2016 2017
})
```

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

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

A
Annie_wang 已提交
2018
Backs up an RDB store. This API uses a promise to return the result.
A
Annie_wang 已提交
2019 2020 2021 2022

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

**Parameters**
A
Annie_wang 已提交
2023

A
Annie_wang 已提交
2024 2025
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
2026
| destName | string | Yes| Name of the RDB store backup file.|
A
Annie_wang 已提交
2027 2028

**Return value**
A
Annie_wang 已提交
2029

A
Annie_wang 已提交
2030 2031 2032 2033 2034
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**
A
Annie_wang 已提交
2035

A
Annie_wang 已提交
2036 2037 2038
```js
let promiseBackup = rdbStore.backup("dbBackup.db")
promiseBackup.then(()=>{
A
Annie_wang 已提交
2039
    console.info('Backed up data successfully.')
A
Annie_wang 已提交
2040
}).catch((err)=>{
A
Annie_wang 已提交
2041
    console.info('Failed to back up data, err: ' + err)
A
Annie_wang 已提交
2042 2043 2044 2045 2046 2047 2048
})
```

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

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

A
Annie_wang 已提交
2049
Restores an RDB store from a backup file. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
2050 2051 2052 2053

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

**Parameters**
A
Annie_wang 已提交
2054

A
Annie_wang 已提交
2055 2056
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
2057
| srcName | string | Yes| Name of the RDB store backup file.|
A
Annie_wang 已提交
2058 2059 2060
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|

**Example**
A
Annie_wang 已提交
2061

A
Annie_wang 已提交
2062 2063 2064
```js
rdbStore.restore("dbBackup.db", function(err) {
    if (err) {
A
Annie_wang 已提交
2065
        console.info('Failed to restore data, err: ' + err)
A
Annie_wang 已提交
2066 2067
        return
    }
A
Annie_wang 已提交
2068
    console.info('Restored data successfully.')
A
Annie_wang 已提交
2069 2070 2071 2072 2073 2074 2075
})
```

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

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

A
Annie_wang 已提交
2076
Restores an RDB store from a backup file. This API uses a promise to return the result.
A
Annie_wang 已提交
2077 2078 2079 2080

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

**Parameters**
A
Annie_wang 已提交
2081

A
Annie_wang 已提交
2082 2083
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
2084
| srcName | string | Yes| Name of the RDB store backup file.|
A
Annie_wang 已提交
2085 2086

**Return value**
A
Annie_wang 已提交
2087

A
Annie_wang 已提交
2088 2089 2090 2091 2092
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**
A
Annie_wang 已提交
2093

A
Annie_wang 已提交
2094 2095 2096
```js
let promiseRestore = rdbStore.restore("dbBackup.db")
promiseRestore.then(()=>{
A
Annie_wang 已提交
2097
    console.info('Restored data successfully.')
A
Annie_wang 已提交
2098
}).catch((err)=>{
A
Annie_wang 已提交
2099
    console.info('Failed to restore data, err: ' + err)
A
Annie_wang 已提交
2100 2101
})
```
A
annie_wangli 已提交
2102 2103 2104 2105

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

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

A
Annie_wang 已提交
2107
Sets distributed tables. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
2108 2109

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

A
annie_wangli 已提交
2111
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
2112

A
annie_wangli 已提交
2113
**Parameters**
A
Annie_wang 已提交
2114

A
annie_wangli 已提交
2115 2116 2117 2118 2119 2120
| 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 已提交
2121

A
Annie_wang 已提交
2122 2123 2124
```js
rdbStore.setDistributedTables(["EMPLOYEE"], function (err) {
    if (err) {
A
Annie_wang 已提交
2125
        console.info('Failed to set distributed tables, err: ' + err)
A
Annie_wang 已提交
2126 2127
        return
    }
A
Annie_wang 已提交
2128
    console.info('Set distributed tables successfully.')
A
Annie_wang 已提交
2129
})
A
Annie_wang 已提交
2130
```
A
annie_wangli 已提交
2131

A
annie_wangli 已提交
2132
### setDistributedTables<sup>8+</sup>
A
annie_wangli 已提交
2133

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

A
Annie_wang 已提交
2136
Sets distributed tables. This API uses a promise to return the result.
A
annie_wangli 已提交
2137

A
Annie_wang 已提交
2138 2139
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

A
annie_wangli 已提交
2140
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
2141

A
annie_wangli 已提交
2142
**Parameters**
A
Annie_wang 已提交
2143

A
annie_wangli 已提交
2144 2145 2146
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| tables | Array&lt;string&gt; | Yes| Names of the distributed tables to set.|
A
annie_wangli 已提交
2147

A
annie_wangli 已提交
2148
**Return value**
A
Annie_wang 已提交
2149

A
annie_wangli 已提交
2150 2151 2152 2153 2154
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**
A
Annie_wang 已提交
2155

A
Annie_wang 已提交
2156 2157 2158
```js
let promise = rdbStore.setDistributedTables(["EMPLOYEE"])
promise.then(() => {
A
Annie_wang 已提交
2159
    console.info("Set distributed tables successfully.")
A
Annie_wang 已提交
2160
}).catch((err) => {
A
Annie_wang 已提交
2161
    console.info("Failed to set distributed tables, err: " + err)
A
Annie_wang 已提交
2162 2163
})
```
A
annie_wangli 已提交
2164

A
annie_wangli 已提交
2165
### obtainDistributedTableName<sup>8+</sup>
A
annie_wangli 已提交
2166

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

A
Annie_wang 已提交
2169
Obtains the distributed table name for a remote device based on the local table name. This API uses an asynchronous callback to return the result. The distributed table name is required when the RDB store of a remote device is queried.
A
Annie_wang 已提交
2170 2171

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

A
annie_wangli 已提交
2173
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
2174

A
annie_wangli 已提交
2175
**Parameters**
A
Annie_wang 已提交
2176

A
annie_wangli 已提交
2177 2178 2179 2180 2181 2182 2183
| 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 已提交
2184

A
Annie_wang 已提交
2185
```js
A
Annie_wang 已提交
2186
rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE", function (err, tableName) {
A
Annie_wang 已提交
2187
    if (err) {
A
Annie_wang 已提交
2188
        console.info('Failed to obtain DistributedTableName, err: ' + err)
A
Annie_wang 已提交
2189 2190
        return
    }
A
Annie_wang 已提交
2191
    console.info('Obtained distributed table name successfully, tableName=.' + tableName)
A
Annie_wang 已提交
2192 2193
})
```
A
annie_wangli 已提交
2194

A
annie_wangli 已提交
2195
### obtainDistributedTableName<sup>8+</sup>
A
annie_wangli 已提交
2196

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

A
Annie_wang 已提交
2199
Obtains the distributed table name for a remote device based on the local table name. This API uses a promise to return the result. The distributed table name is required when the RDB store of a remote device is queried.
A
annie_wangli 已提交
2200

A
Annie_wang 已提交
2201 2202
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

A
annie_wangli 已提交
2203 2204 2205
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**
A
Annie_wang 已提交
2206

A
annie_wangli 已提交
2207 2208 2209 2210
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| device | string | Yes| Remote device.|
| table | string | Yes| Local table name.|
A
annie_wangli 已提交
2211

A
annie_wangli 已提交
2212
**Return value**
A
Annie_wang 已提交
2213

A
annie_wangli 已提交
2214 2215 2216
| 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 已提交
2217

A
annie_wangli 已提交
2218
**Example**
A
Annie_wang 已提交
2219

A
Annie_wang 已提交
2220
```js
A
Annie_wang 已提交
2221
let promise = rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE")
A
Annie_wang 已提交
2222
promise.then((tableName) => {
A
Annie_wang 已提交
2223
    console.info('Obtained distributed table name successfully, tableName= ' + tableName)
A
Annie_wang 已提交
2224
}).catch((err) => {
A
Annie_wang 已提交
2225
    console.info('Failed to obtain DistributedTableName, err: ' + err)
A
Annie_wang 已提交
2226 2227
})
```
A
annie_wangli 已提交
2228

A
annie_wangli 已提交
2229
### sync<sup>8+</sup>
A
annie_wangli 已提交
2230

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

A
Annie_wang 已提交
2233 2234 2235
Synchronizes data between devices. This API uses an asynchronous callback to return the result.

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

A
annie_wangli 已提交
2237
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
2238

A
annie_wangli 已提交
2239
**Parameters**
A
Annie_wang 已提交
2240

A
annie_wangli 已提交
2241 2242 2243 2244
| 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_wang 已提交
2245
| 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 that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
A
annie_wangli 已提交
2246 2247

**Example**
A
Annie_wang 已提交
2248

A
Annie_wang 已提交
2249
```js
A
Annie_wang 已提交
2250
let predicates = new data_rdb.RdbPredicates('EMPLOYEE')
A
Annie_wang 已提交
2251
predicates.inDevices(['12345678abcde'])
A
Annie_wang 已提交
2252
rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) {
A
Annie_wang 已提交
2253
    if (err) {
A
Annie_wang 已提交
2254
        console.log('Sync failed, err: ' + err)
A
Annie_wang 已提交
2255 2256
        return
    }
A
Annie_wang 已提交
2257
    console.log('Sync done.')
A
Annie_wang 已提交
2258 2259 2260 2261 2262
    for (let i = 0; i < result.length; i++) {
        console.log('device=' + result[i][0] + ' status=' + result[i][1])
    }
})
```
A
annie_wangli 已提交
2263

A
annie_wangli 已提交
2264
### sync<sup>8+</sup>
A
annie_wangli 已提交
2265

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

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

A
Annie_wang 已提交
2270 2271
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

A
annie_wangli 已提交
2272
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
2273

A
annie_wangli 已提交
2274
**Parameters**
A
Annie_wang 已提交
2275

A
annie_wangli 已提交
2276 2277 2278 2279
| 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 已提交
2280

A
annie_wangli 已提交
2281 2282 2283 2284
**Return value**

| Type| Description|
| -------- | -------- |
A
Annie_wang 已提交
2285
| 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 that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
A
annie_wangli 已提交
2286 2287

**Example**
A
Annie_wang 已提交
2288

A
Annie_wang 已提交
2289 2290 2291 2292 2293
```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 已提交
2294
    console.log('Sync done.')
A
Annie_wang 已提交
2295 2296 2297 2298
    for (let i = 0; i < result.length; i++) {
        console.log('device=' + result[i][0] + ' status=' + result[i][1])
    }
}).catch((err) => {
A
Annie_wang 已提交
2299
    console.log('Sync failed')
A
Annie_wang 已提交
2300 2301
})
```
A
annie_wangli 已提交
2302

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

A
annie_wangli 已提交
2305
on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void
A
annie_wangli 已提交
2306 2307 2308

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 已提交
2309 2310
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

A
annie_wangli 已提交
2311
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
annie_wangli 已提交
2312

A
annie_wangli 已提交
2313 2314 2315 2316 2317 2318 2319 2320 2321
**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 已提交
2322

A
Annie_wang 已提交
2323 2324 2325 2326 2327 2328 2329 2330 2331
```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 已提交
2332
    console.log('Failed to register observer')
A
Annie_wang 已提交
2333 2334
}
```
A
annie_wangli 已提交
2335

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

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

A
Annie_wang 已提交
2340
Unregisters the observer of the specified type from the RDB store. This API uses a callback to return the result.
A
annie_wangli 已提交
2341

A
Annie_wang 已提交
2342 2343
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

A
annie_wangli 已提交
2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354
**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 已提交
2355

A
Annie_wang 已提交
2356 2357 2358 2359 2360 2361 2362 2363 2364
```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 已提交
2365
    console.log('Failed to unregister observer')
A
Annie_wang 已提交
2366 2367
}
```
A
annie_wangli 已提交
2368 2369

## StoreConfig
Z
zengyawen 已提交
2370

A
Annie_wang 已提交
2371
Defines the RDB store configuration.
Z
zengyawen 已提交
2372

A
annie_wangli 已提交
2373 2374
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

A
annie_wangli 已提交
2375 2376 2377
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Database file name.|
A
Annie_wang 已提交
2378
| encrypt<sup>9+</sup> | boolean | No| Whether to encrypt the RDB store.<br>The value **true** means to encrypt the RDB store, and the value **false** means the opposite.|
A
annie_wangli 已提交
2379 2380

## ValueType
Z
zengyawen 已提交
2381 2382 2383

Defines the data types allowed.

A
annie_wangli 已提交
2384 2385
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

A
Annie_wang 已提交
2386
| Type| Description|
A
annie_wangli 已提交
2387 2388 2389 2390 2391 2392 2393
| -------- | -------- |
| number | Number.|
| string | String.|
| boolean | Boolean.|


## ValuesBucket
Z
zengyawen 已提交
2394

A
Annie_wang 已提交
2395
Defines the types of the key and value in a KV pair.
Z
zengyawen 已提交
2396

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

A
Annie_wang 已提交
2399 2400 2401
| Key Type| Value Type|
| -------- | -------- |
| string | [ValueType](#valuetype)\|&nbsp;Uint8Array&nbsp;\|&nbsp;null | 
A
annie_wangli 已提交
2402

A
annie_wangli 已提交
2403
## SyncMode<sup>8+</sup>
A
annie_wangli 已提交
2404 2405 2406

Defines the database synchronization mode.

A
annie_wangli 已提交
2407 2408 2409 2410 2411 2412
**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 已提交
2413

A
annie_wangli 已提交
2414
## SubscribeType<sup>8+</sup>
A
annie_wangli 已提交
2415 2416 2417

Defines the subscription type.

A
Annie_wang 已提交
2418 2419
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

A
annie_wangli 已提交
2420 2421 2422 2423 2424
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

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