1# @ohos.data.rdb (RDB Store)
2
3The 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. The worker threads are not supported.
4
5This module provides the following RDB-related functions:
6
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.
8- [RdbStore](#rdbstore): provides APIs for managing an RDB store.
9
10> **NOTE**
11>
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.
13>
14> - The APIs of this module are no longer maintained since API version 9. You are advised to use [@ohos.data.relationalStore](js-apis-data-relationalStore.md).
15
16
17## Modules to Import
18
19```ts
20import data_rdb from '@ohos.data.rdb';
21```
22## data_rdb.getRdbStore
23
24getRdbStore(context: Context, config: StoreConfig, version: number, callback: AsyncCallback<RdbStore>): void
25
26Obtains 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.
27
28**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
29
30**Parameters**
31
32| Name  | Type                                      | Mandatory | Description                                                        |
33| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ |
34| context  | Context                                    | Yes  | Application context.<br>For details about the application context of the FA model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md). |
35| config   | [StoreConfig](#storeconfig)                | Yes  | Configuration of the RDB store.                               |
36| version  | number                                     | Yes  | RDB store version.<br>Currently, automatic RDB upgrades and downgrades performed based on **version** is not supported.                                                |
37| callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | Yes  | Callback used to return the RDB store obtained.                    |
38
39**Example**
40
41FA model:
42
43```js
44import featureAbility from '@ohos.ability.featureAbility';
45import relationalStore from '@ohos.data.relationalStore';
46import window from '@ohos.window';
47import { BusinessError } from '@ohos.base';
48
49const STORE_CONFIG: data_rdb.StoreConfig = { name: "RdbTest.db"}
50data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, (err, rdbStore) => {
51  if (err) {
52    console.info("Failed to get RdbStore, err: " + err)
53    return
54  }
55  console.log("Got RdbStore successfully.")
56})
57```
58
59Stage model:
60
61```ts
62import UIAbility from '@ohos.app.ability.UIAbility';
63import { BusinessError } from "@ohos.base";
64import window from '@ohos.window';
65
66const STORE_CONFIG: data_rdb.StoreConfig = { name: "RdbTest.db"}
67class EntryAbility extends UIAbility {
68  onWindowStageCreate(windowStage: window.WindowStage){
69    data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, (err: BusinessError, rdbStore: data_rdb.RdbStore) => {
70      if (err) {
71        console.info("Failed to get RdbStore, err: " + err)
72        return
73      }
74      console.log("Got RdbStore successfully.")
75    })
76  }
77}
78```
79
80## data_rdb.getRdbStore
81
82getRdbStore(context: Context, config: StoreConfig, version: number): Promise&lt;RdbStore&gt;
83
84Obtains 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.
85
86**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
87
88**Parameters**
89
90| Name | Type                       | Mandatory | Description                                                        |
91| ------- | --------------------------- | ---- | ------------------------------------------------------------ |
92| context | Context                     | Yes  | Application context.<br>For details about the application context of the FA model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md). |
93| config  | [StoreConfig](#storeconfig) | Yes  | Configuration of the RDB store.                               |
94| version | number                      | Yes  | RDB store version.<br>Currently, automatic RDB upgrades and downgrades performed based on **version** is not supported.                                                |
95
96**Return value**
97
98| Type                                | Description                           |
99| ------------------------------------ | ------------------------------- |
100| Promise&lt;[RdbStore](#rdbstore)&gt; | Promise used to return the **RdbStore** object. |
101
102**Example**
103
104FA model:
105
106```js
107import featureAbility from '@ohos.ability.featureAbility';
108
109const STORE_CONFIG: data_rdb.StoreConfig = { name: "RdbTest.db"}
110let promise = data_rdb.getRdbStore(this.context, STORE_CONFIG, 1);
111promise.then(async (rdbStore) => {
112  console.log("Got RdbStore successfully.")
113}).catch((err: BusinessError) => {
114  console.log("Failed to get RdbStore, err: " + err)
115})
116```
117
118Stage model:
119
120```ts
121import UIAbility from '@ohos.app.ability.UIAbility';
122import { BusinessError } from "@ohos.base";
123import window from '@ohos.window';
124
125const STORE_CONFIG: data_rdb.StoreConfig = { name: "RdbTest.db"}
126class EntryAbility extends UIAbility {
127  onWindowStageCreate(windowStage: window.WindowStage){
128    context = this.context
129  }
130}
131
132// Call getRdbStore.
133let promise = data_rdb.getRdbStore(this.context, STORE_CONFIG, 1);
134promise.then(async (rdbStore: data_rdb.RdbStore) => {
135  console.log("Got RdbStore successfully.")
136}).catch((err: BusinessError) => {
137  console.log("Failed to get RdbStore, err: " + err)
138})
139```
140
141## data_rdb.deleteRdbStore
142
143deleteRdbStore(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void
144
145Deletes an RDB store. This API uses an asynchronous callback to return the result.
146
147**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
148
149**Parameters**
150
151| Name  | Type                     | Mandatory | Description                                                        |
152| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
153| context  | Context                   | Yes  | Application context.<br>For details about the application context of the FA model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md). |
154| name     | string                    | Yes  | Name of the RDB store to delete.                                                |
155| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.                                      |
156
157**Example**
158
159FA model:
160
161```js
162import featureAbility from '@ohos.ability.featureAbility';
163
164data_rdb.deleteRdbStore(this.context, "RdbTest.db", (err) => {
165  if (err) {
166    console.info("Failed to delete RdbStore, err: " + err)
167    return
168  }
169  console.log("Deleted RdbStore successfully.")
170})
171```
172
173Stage model:
174
175```ts
176import UIAbility from '@ohos.app.ability.UIAbility';
177import window from '@ohos.window';
178
179class EntryAbility extends UIAbility {
180  onWindowStageCreate(windowStage: window.WindowStage){
181    context = this.context
182  }
183}
184
185// Call deleteRdbStore.
186data_rdb.deleteRdbStore(this.context, "RdbTest.db", (err) => {
187  if (err) {
188    console.info("Failed to delete RdbStore, err: " + err)
189    return
190  }
191  console.log("Deleted RdbStore successfully.")
192})
193```
194
195## data_rdb.deleteRdbStore
196
197deleteRdbStore(context: Context, name: string): Promise&lt;void&gt;
198
199Deletes an RDB store. This API uses a promise to return the result.
200
201**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
202
203**Parameters**
204
205| Name | Type   | Mandatory | Description                                                        |
206| ------- | ------- | ---- | ------------------------------------------------------------ |
207| context | Context | Yes  | Application context.<br>For details about the application context of the FA model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md). |
208| name    | string  | Yes  | Name of the RDB store to delete.                                                |
209
210**Return value**
211
212| Type               | Description                     |
213| ------------------- | ------------------------- |
214| Promise&lt;void&gt; | Promise that returns no value. |
215
216**Example**
217
218FA model:
219
220```js
221import featureAbility from '@ohos.ability.featureAbility';
222
223let promise = data_rdb.deleteRdbStore(this.context, "RdbTest.db")
224promise.then(() => {
225  console.log("Deleted RdbStore successfully.")
226}).catch((err: BusinessError) => {
227  console.info("Failed to delete RdbStore, err: " + err)
228})
229```
230
231Stage model:
232
233```ts
234import UIAbility from '@ohos.app.ability.UIAbility';
235import { BusinessError } from "@ohos.base";
236import window from '@ohos.window';
237
238class EntryAbility extends UIAbility {
239  onWindowStageCreate(windowStage: window.WindowStage){
240    context = this.context
241  }
242}
243
244// Call deleteRdbStore.
245let promise = data_rdb.deleteRdbStore(this.context, "RdbTest.db")
246promise.then(()=>{
247  console.log("Deleted RdbStore successfully.")
248}).catch((err: BusinessError) => {
249  console.info("Failed to delete RdbStore, err: " + err)
250})
251```
252
253## ValueType
254
255type ValueType = number | string | boolean
256
257Defines the data types allowed.
258
259**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
260
261| Type   | Description                |
262| ------- | -------------------- |
263| number  | Number.  |
264| string  | String.  |
265| boolean | Boolean. |
266
267
268## ValuesBucket
269
270type ValuesBucket = { [key: string]: ValueType | Uint8Array | null }
271
272Defines the types of the key and value in a KV pair.
273
274**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
275
276| Key Type | Value Type                                                     |
277| ------ | ----------------------------------------------------------- |
278| string | [ValueType](#valuetype)\|&nbsp;Uint8Array&nbsp;\|&nbsp;null |
279
280## SyncMode<sup>8+</sup>
281
282Defines the database sync mode.
283
284**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
285
286| Name          | Value  | Description                              |
287| -------------- | ---- | ---------------------------------- |
288| SYNC_MODE_PUSH | 0    | Data is pushed from a local device to a remote device. |
289| SYNC_MODE_PULL | 1    | Data is pulled from a remote device to a local device.  |
290
291## SubscribeType<sup>8+</sup>
292
293Defines the subscription type.
294
295**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
296
297**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
298
299| Name                 | Value  | Description              |
300| --------------------- | ---- | ------------------ |
301| SUBSCRIBE_TYPE_REMOTE | 0    | Subscribe to remote data changes. |
302
303## StoreConfig
304
305Defines the RDB store configuration.
306
307**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
308
309| Name | Type | Mandatory | Description |
310| -------- | -------- | -------- | -------- |
311| name | string | Yes | Database file name. |
312
313## RdbPredicates
314
315Defines predicates for an RDB store. This class determines whether the conditional expression for the RDB store is true or false.
316
317### constructor
318
319constructor(name: string)
320
321A constructor used to create an **RdbPredicates** object.
322
323**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
324
325**Parameters**
326
327| Name | Type | Mandatory | Description |
328| -------- | -------- | -------- | -------- |
329| name | string | Yes | Database table name. |
330
331**Example**
332
333```ts
334let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
335```
336
337### inDevices<sup>8+</sup>
338
339inDevices(devices: Array&lt;string&gt;): RdbPredicates
340
341Sets an **RdbPredicates** to specify the remote devices to connect on the network during distributed database sync.
342
343> **NOTE**
344>
345> The value of **devices** can be obtained by <!--RP2-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP2End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
346
347**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
348
349**Parameters**
350
351| Name | Type | Mandatory | Description |
352| -------- | -------- | -------- | -------- |
353| devices | Array&lt;string&gt; | Yes | IDs of the remote devices in the same network. |
354
355**Return value**
356
357| Type | Description |
358| -------- | -------- |
359| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
360
361**Example**
362
363```ts
364import deviceManager from '@ohos.distributedHardware.deviceManager';
365
366let dmInstance: deviceManager.DeviceManager;
367let deviceIds: Array<string> = [];
368let devices: Array<string> = [];
369
370deviceManager.createDeviceManager("com.example.appdatamgrverify", (err: BusinessError, manager: void) => {
371  if (err) {
372    console.log("create device manager failed, err=" + err);
373    return;
374  }
375  dmInstance = manager;
376  devices = dmInstance.getTrustedDeviceListSync();
377  for (let i = 0; i < devices.length; i++) {
378    deviceIds[i] = devices[i].deviceId;
379  }
380})
381
382let predicates = new data_rdb.RdbPredicates("EMPLOYEE");
383predicates.inDevices(deviceIds);
384
385let predicates = new data_rdb.RdbPredicates("EMPLOYEE");
386predicates.inDevices(deviceIds);
387```
388
389### inAllDevices<sup>8+</sup>
390
391inAllDevices(): RdbPredicates
392
393Sets an **RdbPredicates** to specify all remote devices on the network to connect during distributed database sync.
394
395**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
396
397**Return value**
398
399| Type | Description |
400| -------- | -------- |
401| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
402
403**Example**
404
405```ts
406let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
407predicates.inAllDevices()
408```
409
410### equalTo
411
412equalTo(field: string, value: ValueType): RdbPredicates
413
414Sets an **RdbPredicates** to match the field with data type **ValueType** and value equal to the specified value.
415
416**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
417
418**Parameters**
419
420| Name | Type | Mandatory | Description |
421| -------- | -------- | -------- | -------- |
422| field | string | Yes | Column name in the database table. |
423| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**. |
424
425**Return value**
426
427| Type | Description |
428| -------- | -------- |
429| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
430
431**Example**
432
433```ts
434let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
435predicates.equalTo("NAME", "lisi")
436```
437
438
439### notEqualTo
440
441notEqualTo(field: string, value: ValueType): RdbPredicates
442
443Sets an **RdbPredicates** to match the field with data type **ValueType** and value not equal to the specified value.
444
445**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
446
447**Parameters**
448
449| Name | Type | Mandatory | Description |
450| -------- | -------- | -------- | -------- |
451| field | string | Yes | Column name in the database table. |
452| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**. |
453
454**Return value**
455
456| Type | Description |
457| -------- | -------- |
458| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
459
460**Example**
461
462```ts
463let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
464predicates.notEqualTo("NAME", "lisi")
465```
466
467
468### beginWrap
469
470beginWrap(): RdbPredicates
471
472Adds a left parenthesis to the **RdbPredicates**.
473
474**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
475
476**Return value**
477
478| Type | Description |
479| -------- | -------- |
480| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a left parenthesis. |
481
482**Example**
483
484```ts
485let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
486predicates.equalTo("NAME", "lisi")
487    .beginWrap()
488    .equalTo("AGE", 18)
489    .or()
490    .equalTo("SALARY", 200.5)
491    .endWrap()
492```
493
494### endWrap
495
496endWrap(): RdbPredicates
497
498Adds a right parenthesis to the **RdbPredicates**.
499
500**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
501
502**Return value**
503
504| Type | Description |
505| -------- | -------- |
506| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a right parenthesis. |
507
508**Example**
509
510```ts
511let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
512predicates.equalTo("NAME", "lisi")
513    .beginWrap()
514    .equalTo("AGE", 18)
515    .or()
516    .equalTo("SALARY", 200.5)
517    .endWrap()
518```
519
520### or
521
522or(): RdbPredicates
523
524Adds the OR condition to the **RdbPredicates**.
525
526**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
527
528**Return value**
529
530| Type | Description |
531| -------- | -------- |
532| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the OR condition. |
533
534**Example**
535
536```ts
537let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
538predicates.equalTo("NAME", "Lisa")
539    .or()
540    .equalTo("NAME", "Rose")
541```
542
543### and
544
545and(): RdbPredicates
546
547Adds the AND condition to the **RdbPredicates**.
548
549**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
550
551**Return value**
552
553| Type | Description |
554| -------- | -------- |
555| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the AND condition. |
556
557**Example**
558
559```ts
560let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
561predicates.equalTo("NAME", "Lisa")
562    .and()
563    .equalTo("SALARY", 200.5)
564```
565
566### contains
567
568contains(field: string, value: string): RdbPredicates
569
570Sets an **RdbPredicates** to match a string containing the specified value.
571
572**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
573
574**Parameters**
575
576| Name | Type | Mandatory | Description |
577| -------- | -------- | -------- | -------- |
578| field | string | Yes | Column name in the database table. |
579| value | string | Yes | Value to match the **RdbPredicates**. |
580
581**Return value**
582
583| Type | Description |
584| -------- | -------- |
585| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
586
587**Example**
588
589```ts
590let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
591predicates.contains("NAME", "os")
592```
593
594### beginsWith
595
596beginsWith(field: string, value: string): RdbPredicates
597
598Sets an **RdbPredicates** to match a string that starts with the specified value.
599
600**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
601
602**Parameters**
603
604| Name | Type | Mandatory | Description |
605| -------- | -------- | -------- | -------- |
606| field | string | Yes | Column name in the database table. |
607| value | string | Yes | Value to match the **RdbPredicates**. |
608
609**Return value**
610
611| Type | Description |
612| -------- | -------- |
613| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
614
615**Example**
616
617```ts
618let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
619predicates.beginsWith("NAME", "os")
620```
621
622### endsWith
623
624endsWith(field: string, value: string): RdbPredicates
625
626Sets an **RdbPredicates** to match a string that ends with the specified value.
627
628**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
629
630**Parameters**
631
632| Name | Type | Mandatory | Description |
633| -------- | -------- | -------- | -------- |
634| field | string | Yes | Column name in the database table. |
635| value | string | Yes | Value to match the **RdbPredicates**. |
636
637**Return value**
638
639| Type | Description |
640| -------- | -------- |
641| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
642
643**Example**
644
645```ts
646let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
647predicates.endsWith("NAME", "se")
648```
649
650### isNull
651
652isNull(field: string): RdbPredicates
653
654Sets an **RdbPredicates** to match the field whose value is null.
655
656**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
657
658**Parameters**
659
660| Name | Type | Mandatory | Description |
661| -------- | -------- | -------- | -------- |
662| field | string | Yes | Column name in the database table. |
663
664**Return value**
665
666| Type | Description |
667| -------- | -------- |
668| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
669
670**Example**
671```ts
672let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
673predicates.isNull("NAME")
674```
675
676### isNotNull
677
678isNotNull(field: string): RdbPredicates
679
680Sets an **RdbPredicates** to match the field whose value is not null.
681
682**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
683
684**Parameters**
685
686| Name | Type | Mandatory | Description |
687| -------- | -------- | -------- | -------- |
688| field | string | Yes | Column name in the database table. |
689
690**Return value**
691
692| Type | Description |
693| -------- | -------- |
694| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
695
696**Error codes**
697
698For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
699
700| **Error Code** | **Error Message**                                                                                                      |
701| --------- |----------------------------------------------------------------------------------------------------------------|
702| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
703
704**Example**
705
706```ts
707let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
708predicates.isNotNull("NAME")
709```
710
711### like
712
713like(field: string, value: string): RdbPredicates
714
715Sets an **RdbPredicates** to match a string that is similar to the specified value.
716
717**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
718
719**Parameters**
720
721| Name | Type | Mandatory | Description |
722| -------- | -------- | -------- | -------- |
723| field | string | Yes | Column name in the database table. |
724| value | string | Yes | Value to match the **RdbPredicates**. |
725
726**Return value**
727
728| Type | Description |
729| -------- | -------- |
730| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
731
732**Example**
733
734```ts
735let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
736predicates.like("NAME", "%os%")
737```
738
739### glob
740
741glob(field: string, value: string): RdbPredicates
742
743Sets an **RdbPredicates** to match the specified string.
744
745**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
746
747**Parameters**
748
749| Name | Type | Mandatory | Description |
750| -------- | -------- | -------- | -------- |
751| field | string | Yes | Column name in the database table. |
752| 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. |
753
754**Return value**
755
756| Type | Description |
757| -------- | -------- |
758| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
759
760**Example**
761
762```ts
763let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
764predicates.glob("NAME", "?h*g")
765```
766
767### between
768
769between(field: string, low: ValueType, high: ValueType): RdbPredicates
770
771Sets an **RdbPredicates** to match the field with data type **ValueType** and value within the specified range.
772
773**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
774
775**Parameters**
776
777| Name | Type | Mandatory | Description |
778| -------- | -------- | -------- | -------- |
779| field | string | Yes | Column name in the database table. |
780| low | [ValueType](#valuetype) | Yes | Minimum value to match the **RdbPredicates**. |
781| high | [ValueType](#valuetype) | Yes | Maximum value to match the **RdbPredicates**. |
782
783**Return value**
784
785| Type | Description |
786| -------- | -------- |
787| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
788
789**Example**
790
791```ts
792let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
793predicates.between("AGE", 10, 50)
794```
795
796### notBetween
797
798notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates
799
800Sets an **RdbPredicates** to match the field with data type **ValueType** and value out of the specified range.
801
802**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
803
804**Parameters**
805
806| Name | Type | Mandatory | Description |
807| -------- | -------- | -------- | -------- |
808| field | string | Yes | Column name in the database table. |
809| low | [ValueType](#valuetype) | Yes | Minimum value to match the **RdbPredicates**. |
810| high | [ValueType](#valuetype) | Yes | Maximum value to match the **RdbPredicates**. |
811
812**Return value**
813
814| Type | Description |
815| -------- | -------- |
816| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
817
818**Example**
819
820```ts
821let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
822predicates.notBetween("AGE", 10, 50)
823```
824
825### greaterThan
826
827greaterThan(field: string, value: ValueType): RdbPredicates
828
829Sets an **RdbPredicates** to match the field with data type **ValueType** and value greater than the specified value.
830
831**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
832
833**Parameters**
834
835| Name | Type | Mandatory | Description |
836| -------- | -------- | -------- | -------- |
837| field | string | Yes | Column name in the database table. |
838| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**. |
839
840**Return value**
841
842| Type | Description |
843| -------- | -------- |
844| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
845
846**Example**
847
848```ts
849let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
850predicates.greaterThan("AGE", 18)
851```
852
853### lessThan
854
855lessThan(field: string, value: ValueType): RdbPredicates
856
857Sets an **RdbPredicates** to match the field with data type **ValueType** and value less than the specified value.
858
859**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
860
861**Parameters**
862
863| Name | Type | Mandatory | Description |
864| -------- | -------- | -------- | -------- |
865| field | string | Yes | Column name in the database table. |
866| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**. |
867
868**Return value**
869
870| Type | Description |
871| -------- | -------- |
872| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
873
874**Example**
875
876```ts
877let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
878predicates.lessThan("AGE", 20)
879```
880
881### greaterThanOrEqualTo
882
883greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates
884
885Sets an **RdbPredicates** to match the field with data type **ValueType** and value greater than or equal to the specified value.
886
887**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
888
889**Parameters**
890
891| Name | Type | Mandatory | Description |
892| -------- | -------- | -------- | -------- |
893| field | string | Yes | Column name in the database table. |
894| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**. |
895
896**Return value**
897
898| Type | Description |
899| -------- | -------- |
900| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
901
902**Example**
903
904```ts
905let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
906predicates.greaterThanOrEqualTo("AGE", 18)
907```
908
909### lessThanOrEqualTo
910
911lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates
912
913Sets an **RdbPredicates** to match the field with data type **ValueType** and value less than or equal to the specified value.
914
915**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
916
917**Parameters**
918
919| Name | Type | Mandatory | Description |
920| -------- | -------- | -------- | -------- |
921| field | string | Yes | Column name in the database table. |
922| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**. |
923
924**Return value**
925
926| Type | Description |
927| -------- | -------- |
928| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
929
930**Example**
931
932```ts
933let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
934predicates.lessThanOrEqualTo("AGE", 20)
935```
936
937### orderByAsc
938
939orderByAsc(field: string): RdbPredicates
940
941Sets an **RdbPredicates** to match the column with values sorted in ascending order.
942
943**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
944
945**Parameters**
946
947| Name | Type | Mandatory | Description |
948| -------- | -------- | -------- | -------- |
949| field | string | Yes | Column name in the database table. |
950
951**Return value**
952
953| Type | Description |
954| -------- | -------- |
955| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
956
957**Example**
958
959```ts
960let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
961predicates.orderByAsc("NAME")
962```
963
964### orderByDesc
965
966orderByDesc(field: string): RdbPredicates
967
968Sets an **RdbPredicates** to match the column with values sorted in descending order.
969
970**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
971
972**Parameters**
973
974| Name | Type | Mandatory | Description |
975| -------- | -------- | -------- | -------- |
976| field | string | Yes | Column name in the database table. |
977
978**Return value**
979
980| Type | Description |
981| -------- | -------- |
982| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
983
984**Example**
985
986```ts
987let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
988predicates.orderByDesc("AGE")
989```
990
991### distinct
992
993distinct(): RdbPredicates
994
995Sets an **RdbPredicates** to filter out duplicate records.
996
997**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
998
999**Return value**
1000
1001| Type | Description |
1002| -------- | -------- |
1003| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that can filter out duplicate records. |
1004
1005**Example**
1006
1007```ts
1008let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
1009predicates.equalTo("NAME", "Rose").distinct()
1010```
1011
1012### limitAs
1013
1014limitAs(value: number): RdbPredicates
1015
1016Sets an **RdbPredicates** to specify the maximum number of records.
1017
1018**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1019
1020**Parameters**
1021
1022| Name | Type | Mandatory | Description |
1023| -------- | -------- | -------- | -------- |
1024| value | number | Yes | Maximum number of records. |
1025
1026**Return value**
1027
1028| Type | Description |
1029| -------- | -------- |
1030| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the maximum number of records. |
1031
1032**Example**
1033
1034```ts
1035let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
1036predicates.equalTo("NAME", "Rose").limitAs(3)
1037```
1038
1039### offsetAs
1040
1041offsetAs(rowOffset: number): RdbPredicates
1042
1043Sets an **RdbPredicates** to specify the start position of the returned result.
1044
1045**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1046
1047**Parameters**
1048
1049| Name | Type | Mandatory | Description |
1050| -------- | -------- | -------- | -------- |
1051| rowOffset | number | Yes | Number of rows to offset from the beginning. The value is a positive integer. |
1052
1053**Return value**
1054
1055| Type | Description |
1056| -------- | -------- |
1057| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the start position of the returned result. |
1058
1059**Example**
1060
1061```ts
1062let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
1063predicates.equalTo("NAME", "Rose").offsetAs(3)
1064```
1065
1066### groupBy
1067
1068groupBy(fields: Array&lt;string&gt;): RdbPredicates
1069
1070Sets an **RdbPredicates** to group rows that have the same value into summary rows.
1071
1072**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1073
1074**Parameters**
1075
1076| Name | Type | Mandatory | Description |
1077| -------- | -------- | -------- | -------- |
1078| fields | Array&lt;string&gt; | Yes | Names of columns to group. |
1079
1080**Return value**
1081
1082| Type | Description |
1083| -------- | -------- |
1084| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that groups rows with the same value. |
1085
1086**Example**
1087
1088```ts
1089let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
1090predicates.groupBy(["AGE", "NAME"])
1091```
1092
1093### indexedBy
1094
1095indexedBy(field: string): RdbPredicates
1096
1097Sets an **RdbPredicates** object to specify the index column.
1098
1099**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1100
1101**Parameters**
1102
1103| Name | Type | Mandatory | Description |
1104| -------- | -------- | -------- | -------- |
1105| field | string | Yes | Name of the index column. |
1106
1107**Return value**
1108
1109
1110| Type | Description |
1111| -------- | -------- |
1112| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the index column. |
1113
1114**Example**
1115
1116```ts
1117let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
1118predicates.indexedBy("SALARY_INDEX")
1119```
1120
1121### in
1122
1123in(field: string, value: Array&lt;ValueType&gt;): RdbPredicates
1124
1125Sets an **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value within the specified range.
1126
1127**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1128
1129**Parameters**
1130
1131| Name | Type | Mandatory | Description |
1132| -------- | -------- | -------- | -------- |
1133| field | string | Yes | Column name in the database table. |
1134| value | Array&lt;[ValueType](#valuetype)&gt; | Yes | Array of **ValueType**s to match. |
1135
1136**Return value**
1137
1138| Type | Description |
1139| -------- | -------- |
1140| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
1141
1142**Example**
1143
1144```ts
1145let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
1146predicates.in("AGE", [18, 20])
1147```
1148
1149### notIn
1150
1151notIn(field: string, value: Array&lt;ValueType&gt;): RdbPredicates
1152
1153Sets an **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value out of the specified range.
1154
1155**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1156
1157**Parameters**
1158
1159| Name | Type | Mandatory | Description |
1160| -------- | -------- | -------- | -------- |
1161| field | string | Yes | Column name in the database table. |
1162| value | Array&lt;[ValueType](#valuetype)&gt; | Yes | Array of **ValueType**s to match. |
1163
1164**Return value**
1165
1166| Type | Description |
1167| -------- | -------- |
1168| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created. |
1169
1170**Example**
1171
1172```ts
1173let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
1174predicates.notIn("NAME", ["Lisa", "Rose"])
1175```
1176
1177## RdbStore
1178
1179Provides methods to manage an RDB store.
1180
1181Before using the APIs of this class, use [executeSql](#executesql8) to initialize the database table structure and related data.
1182
1183### insert
1184
1185insert(table: string, values: ValuesBucket, callback: AsyncCallback&lt;number&gt;):void
1186
1187Inserts a row of data into a table. This API uses an asynchronous callback to return the result.
1188
1189**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1190
1191**Parameters**
1192
1193| Name | Type | Mandatory | Description |
1194| -------- | -------- | -------- | -------- |
1195| table | string | Yes | Name of the target table. |
1196| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert. |
1197| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned. |
1198
1199**Example**
1200
1201```ts
1202import { ValuesBucket } from '@ohos.data.ValuesBucket';
1203
1204let key1 = "NAME";
1205let key2 = "AGE";
1206let key3 = "SALARY";
1207let key4 = "CODES";
1208let value1 = "Lisi";
1209let value2 = 18;
1210let value3 = 100.5;
1211let value4 = new Uint8Array([1, 2, 3, 4, 5]);
1212const valueBucket: ValuesBucket = {
1213  key1: value1,
1214  key2: value2,
1215  key3: value3,
1216  key4: value4,
1217};
1218
1219rdbStore.insert("EMPLOYEE", valueBucket, (status: number, rowId: number) => {
1220  if (status) {
1221    console.log("Failed to insert data");
1222    return;
1223  }
1224  console.log("Inserted data successfully, rowId = " + rowId);
1225})
1226```
1227
1228### insert
1229
1230insert(table: string, values: ValuesBucket):Promise&lt;number&gt;
1231
1232Inserts a row of data into a table. This API uses a promise to return the result.
1233
1234**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1235
1236**Parameters**
1237
1238| Name | Type | Mandatory | Description |
1239| -------- | -------- | -------- | -------- |
1240| table | string | Yes | Name of the target table. |
1241| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert. |
1242
1243**Return value**
1244
1245| Type | Description |
1246| -------- | -------- |
1247| 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. |
1248
1249**Example**
1250
1251```ts
1252import { ValuesBucket } from '@ohos.data.ValuesBucket';
1253
1254let key1 = "NAME";
1255let key2 = "AGE";
1256let key3 = "SALARY";
1257let key4 = "CODES";
1258let value1 = "Lisi";
1259let value2 = 18;
1260let value3 = 100.5;
1261let value4 = new Uint8Array([1, 2, 3, 4, 5]);
1262const valueBucket: ValuesBucket = {
1263  key1: value1,
1264  key2: value2,
1265  key3: value3,
1266  key4: value4,
1267};
1268
1269let promise: void = rdbStore.insert("EMPLOYEE", valueBucket)
1270promise.then((rowId: BusinessError) => {
1271  console.log("Inserted data successfully, rowId = " + rowId);
1272}).catch((status: number) => {
1273  console.log("Failed to insert data");
1274})
1275```
1276
1277### batchInsert
1278
1279batchInsert(table: string, values: Array&lt;ValuesBucket&gt;, callback: AsyncCallback&lt;number&gt;):void
1280
1281Batch inserts data into a table. This API uses an asynchronous callback to return the result.
1282
1283**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1284
1285**Parameters**
1286
1287| Name | Type | Mandatory | Description |
1288| -------- | -------- | -------- | -------- |
1289| table | string | Yes | Name of the target table. |
1290| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | Yes | An array of data to insert. |
1291| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the result. If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned. |
1292
1293**Example**
1294
1295```ts
1296import { ValuesBucket } from '@ohos.data.ValuesBucket';
1297
1298let key1 = "NAME";
1299let key2 = "AGE";
1300let key3 = "SALARY";
1301let key4 = "CODES";
1302let value1 = "Lisa";
1303let value2 = 18;
1304let value3 = 100.5;
1305let value4 = new Uint8Array([1, 2, 3, 4, 5]);
1306let value5 = "Jack";
1307let value6 = 19;
1308let value7 = 101.5;
1309let value8 = new Uint8Array([6, 7, 8, 9, 10]);
1310let value9 = "Tom";
1311let value10 = 20;
1312let value11 = 102.5;
1313let value12 = new Uint8Array([11, 12, 13, 14, 15]);
1314const valueBucket1: ValuesBucket = {
1315  key1: value1,
1316  key2: value2,
1317  key3: value3,
1318  key4: value4,
1319};
1320const valueBucket2: ValuesBucket = {
1321  key1: value5,
1322  key2: value6,
1323  key3: value7,
1324  key4: value8,
1325};
1326const valueBucket3: ValuesBucket = {
1327  key1: value9,
1328  key2: value10,
1329  key3: value11,
1330  key4: value12,
1331};
1332
1333let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
1334rdbStore.batchInsert("EMPLOYEE", valueBuckets, (status: number, insertNum: number) => {
1335  if (status) {
1336    console.log("batchInsert is failed, status = " + status);
1337    return;
1338  }
1339  console.log("batchInsert is successful, the number of values that were inserted = " + insertNum);
1340})
1341```
1342
1343### batchInsert
1344
1345batchInsert(table: string, values: Array&lt;ValuesBucket&gt;):Promise&lt;number&gt;
1346
1347Batch inserts data into a table. This API uses a promise to return the result.
1348
1349**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1350
1351**Parameters**
1352
1353| Name | Type | Mandatory | Description |
1354| -------- | -------- | -------- | -------- |
1355| table | string | Yes | Name of the target table. |
1356| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | Yes | An array of data to insert. |
1357
1358**Return value**
1359
1360| Type | Description |
1361| -------- | -------- |
1362| 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. |
1363
1364**Example**
1365
1366```ts
1367import { ValuesBucket } from '@ohos.data.ValuesBucket';
1368
1369let key1 = "NAME";
1370let key2 = "AGE";
1371let key3 = "SALARY";
1372let key4 = "CODES";
1373let value1 = "Lisa";
1374let value2 = 18;
1375let value3 = 100.5;
1376let value4 = new Uint8Array([1, 2, 3, 4, 5]);
1377let value5 = "Jack";
1378let value6 = 19;
1379let value7 = 101.5;
1380let value8 = new Uint8Array([6, 7, 8, 9, 10]);
1381let value9 = "Tom";
1382let value10 = 20;
1383let value11 = 102.5;
1384let value12 = new Uint8Array([11, 12, 13, 14, 15]);
1385const valueBucket1: ValuesBucket = {
1386  key1: value1,
1387  key2: value2,
1388  key3: value3,
1389  key4: value4,
1390};
1391const valueBucket2: ValuesBucket = {
1392  key1: value5,
1393  key2: value6,
1394  key3: value7,
1395  key4: value8,
1396};
1397const valueBucket3: ValuesBucket = {
1398  key1: value9,
1399  key2: value10,
1400  key3: value11,
1401  key4: value12,
1402};
1403
1404let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
1405let promise: void = rdbStore.batchInsert("EMPLOYEE", valueBuckets);
1406promise.then((insertNum: number) => {
1407  console.log("batchInsert is successful, the number of values that were inserted = " + insertNum);
1408}).catch((status: number) => {
1409  console.log("batchInsert is failed, status = " + status);
1410})
1411```
1412
1413### update
1414
1415update(values: ValuesBucket, predicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void
1416
1417Updates data in the RDB store based on the specified **RdbPredicates** object. This API uses an asynchronous callback to return the result.
1418
1419**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1420
1421**Parameters**
1422
1423| Name | Type | Mandatory | Description |
1424| -------- | -------- | -------- | -------- |
1425| 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. |
1426| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. |
1427| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the number of rows updated. |
1428
1429**Example**
1430
1431```ts
1432import { ValuesBucket } from '@ohos.data.ValuesBucket';
1433
1434let key1 = "NAME";
1435let key2 = "AGE";
1436let key3 = "SALARY";
1437let key4 = "CODES";
1438let value1 = "Lisa";
1439let value2 = 18;
1440let value3 = 100.5;
1441let value4 = new Uint8Array([1, 2, 3, 4, 5]);
1442
1443const valueBucket: ValuesBucket = {
1444  key1: value1,
1445  key2: value2,
1446  key3: value3,
1447  key4: value4,
1448};
1449let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
1450predicates.equalTo("NAME", "Lisa")
1451rdbStore.update(valueBucket, predicates, (err: BusinessError, rows: number) => {
1452  if (err) {
1453    console.info("Failed to update data, err: " + err)
1454    return
1455  }
1456  console.log("Updated row count: " + rows)
1457})
1458```
1459
1460### update
1461
1462update(values: ValuesBucket, predicates: RdbPredicates):Promise&lt;number&gt;
1463
1464Updates data based on the specified **RdbPredicates** object. This API uses a promise to return the result.
1465
1466**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1467
1468**Parameters**
1469
1470| Name | Type | Mandatory | Description |
1471| -------- | -------- | -------- | -------- |
1472| 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. |
1473| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. |
1474
1475**Return value**
1476
1477| Type | Description |
1478| -------- | -------- |
1479| Promise&lt;number&gt; | Promise used to return the number of rows updated. |
1480
1481**Example**
1482
1483```ts
1484import { ValuesBucket } from '@ohos.data.ValuesBucket';
1485
1486let key1 = "NAME";
1487let key2 = "AGE";
1488let key3 = "SALARY";
1489let key4 = "CODES";
1490let value1 = "Lisa";
1491let value2 = 18;
1492let value3 = 100.5;
1493let value4 = new Uint8Array([1, 2, 3, 4, 5]);
1494
1495const valueBucket: ValuesBucket = {
1496  key1: value1,
1497  key2: value2,
1498  key3: value3,
1499  key4: value4,
1500};
1501let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
1502predicates.equalTo("NAME", "Lisa")
1503let promise: void = rdbStore.update(valueBucket, predicates)
1504promise.then(async (rows: number) => {
1505  console.log("Updated row count: " + rows)
1506}).catch((err: BusinessError) => {
1507  console.info("Failed to update data, err: " + err)
1508})
1509```
1510
1511### delete
1512
1513delete(predicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void
1514
1515Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses an asynchronous callback to return the result.
1516
1517**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1518
1519**Parameters**
1520
1521| Name | Type | Mandatory | Description |
1522| -------- | -------- | -------- | -------- |
1523| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data. |
1524| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the number of rows updated. |
1525
1526**Example**
1527
1528```ts
1529let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
1530predicates.equalTo("NAME", "Lisa")
1531rdbStore.delete(predicates, (err: BusinessError, rows: number) => {
1532  if (err) {
1533    console.info("Failed to delete data, err: " + err)
1534    return
1535  }
1536  console.log("Deleted rows: " + rows)
1537})
1538```
1539
1540### delete
1541
1542delete(predicates: RdbPredicates):Promise&lt;number&gt;
1543
1544Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result.
1545
1546**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1547
1548**Parameters**
1549
1550| Name | Type | Mandatory | Description |
1551| -------- | -------- | -------- | -------- |
1552| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data. |
1553
1554**Return value**
1555
1556| Type | Description |
1557| -------- | -------- |
1558| Promise&lt;number&gt; | Promise used to return the number of rows updated. |
1559
1560**Example**
1561
1562```ts
1563let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
1564predicates.equalTo("NAME", "Lisa")
1565let promise: void = rdbStore.delete(predicates)
1566promise.then((rows: number) => {
1567  console.log("Deleted rows: " + rows)
1568}).catch((err: BusinessError) => {
1569  console.info("Failed to delete data, err: " + err)
1570})
1571```
1572
1573### query
1574
1575query(predicates: RdbPredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
1576
1577Queries data from the RDB store based on specified conditions. This API uses an asynchronous callback to return the result.
1578
1579**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1580
1581**Parameters**
1582
1583| Name | Type | Mandatory | Description |
1584| -------- | -------- | -------- | -------- |
1585| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. |
1586| columns | Array&lt;string&gt; | Yes | Columns to query. If this parameter is not specified, the query applies to all columns. |
1587| callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned. |
1588
1589**Example**
1590
1591```ts
1592let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
1593predicates.equalTo("NAME", "Rose")
1594rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], (err: BusinessError, resultSet: void) => {
1595  if (err) {
1596    console.info("Failed to query data, err: " + err)
1597    return
1598  }
1599  console.log("ResultSet column names: " + resultSet.columnNames)
1600  console.log("ResultSet column count: " + resultSet.columnCount)
1601})
1602```
1603
1604### query
1605
1606query(predicates: RdbPredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt;
1607
1608Queries data from the RDB store based on specified conditions. This API uses a promise to return the result.
1609
1610**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1611
1612**Parameters**
1613
1614| Name | Type | Mandatory | Description |
1615| -------- | -------- | -------- | -------- |
1616| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. |
1617| columns | Array&lt;string&gt; | No | Columns to query. If this parameter is not specified, the query applies to all columns. |
1618
1619**Return value**
1620
1621| Type | Description |
1622| -------- | -------- |
1623| 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. |
1624
1625**Example**
1626
1627```ts
1628let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
1629predicates.equalTo("NAME", "Rose")
1630let promise: void = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
1631promise.then((resultSet: void) => {
1632  console.log("ResultSet column names: " + resultSet.columnNames)
1633  console.log("ResultSet column count: " + resultSet.columnCount)
1634}).catch((err: BusinessError) => {
1635  console.info("Failed to query data, err: " + err)
1636})
1637```
1638
1639### querySql<sup>8+</sup>
1640
1641querySql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
1642
1643Queries data in the RDB store using the specified SQL statement. This API uses an asynchronous callback to return the result.
1644
1645**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1646
1647**Parameters**
1648
1649| Name | Type | Mandatory | Description |
1650| -------- | -------- | -------- | -------- |
1651| sql | string | Yes | SQL statement to run. |
1652| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, the value of this parameter must be an empty array. |
1653| callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned. |
1654
1655**Example**
1656
1657```ts
1658rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], (err: BusinessError, resultSet: void) => {
1659  if (err) {
1660    console.info("Failed to query data, err: " + err)
1661    return
1662  }
1663  console.log("ResultSet column names: " + resultSet.columnNames)
1664  console.log("ResultSet column count: " + resultSet.columnCount)
1665})
1666```
1667
1668### querySql<sup>8+</sup>
1669
1670querySql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;ResultSet&gt;
1671
1672Queries data using the specified SQL statement. This API uses a promise to return the result.
1673
1674**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1675
1676**Parameters**
1677
1678| Name | Type | Mandatory | Description |
1679| -------- | -------- | -------- | -------- |
1680| sql | string | Yes | SQL statement to run. |
1681| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | No | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, leave this parameter blank. |
1682
1683**Return value**
1684
1685| Type | Description |
1686| -------- | -------- |
1687| 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. |
1688
1689**Example**
1690
1691```ts
1692let promise: void = rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'")
1693promise.then((resultSet: void) => {
1694  console.log("ResultSet column names: " + resultSet.columnNames)
1695  console.log("ResultSet column count: " + resultSet.columnCount)
1696}).catch((err: BusinessError) => {
1697  console.info("Failed to query data, err: " + err)
1698})
1699```
1700
1701### executeSql<sup>8+</sup>
1702
1703executeSql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;void&gt;):void
1704
1705Executes an SQL statement that contains specified arguments but returns no value. This API uses an asynchronous callback to return the result.
1706
1707**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1708
1709**Parameters**
1710
1711| Name | Type | Mandatory | Description |
1712| -------- | -------- | -------- | -------- |
1713| sql | string | Yes | SQL statement to run. |
1714| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, the value of this parameter must be an empty array. |
1715| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
1716
1717**Example**
1718
1719```ts
1720const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = ?"
1721rdbStore.executeSql(SQL_DELETE_TABLE, ['zhangsan'], (err: BusinessError) => {
1722  if (err) {
1723    console.info("Failed to execute SQL, err: " + err)
1724    return
1725  }
1726  console.info('Delete table done.')
1727})
1728```
1729
1730### executeSql<sup>8+</sup>
1731
1732executeSql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;void&gt;
1733
1734Executes an SQL statement that contains specified arguments but returns no value. This API uses a promise to return the result.
1735
1736**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1737
1738**Parameters**
1739
1740| Name | Type | Mandatory | Description |
1741| -------- | -------- | -------- | -------- |
1742| sql | string | Yes | SQL statement to run. |
1743| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | No | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, leave this parameter blank. |
1744
1745**Return value**
1746
1747| Type | Description |
1748| -------- | -------- |
1749| Promise&lt;void&gt; | Promise that returns no value. |
1750
1751**Example**
1752
1753```ts
1754const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'"
1755let promise = rdbStore.executeSql(SQL_DELETE_TABLE)
1756promise.then(() => {
1757  console.info('Delete table done.')
1758}).catch((err: BusinessError) => {
1759  console.info("Failed to execute SQL, err: " + err)
1760})
1761```
1762
1763### beginTransaction<sup>8+</sup>
1764
1765beginTransaction():void
1766
1767Starts the transaction before executing an SQL statement.
1768
1769**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1770
1771**Example**
1772
1773```ts
1774import featureAbility from '@ohos.ability.featureAbility';
1775import { ValuesBucket } from '@ohos.data.ValuesBucket';
1776
1777let key1 = "NAME";
1778let key2 = "AGE";
1779let key3 = "SALARY";
1780let key4 = "blobType";
1781let value1 = "Lisa";
1782let value2 = 18;
1783let value3 = 100.5;
1784let value4 = new Uint8Array([1, 2, 3]);
1785
1786const valueBucket: ValuesBucket = {
1787  key1: value1,
1788  key2: value2,
1789  key3: value3,
1790  key4: value4,
1791};
1792
1793data_rdb.getRdbStore(this.context, "RdbTest.db", 1, async (err: BusinessError, rdbStore) => {
1794  rdbStore.beginTransaction()
1795  await rdbStore.insert("test", valueBucket)
1796  rdbStore.commit()
1797})
1798```
1799
1800### commit<sup>8+</sup>
1801
1802commit():void
1803
1804Commits the executed SQL statements.
1805
1806**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1807
1808**Example**
1809
1810```ts
1811import { ValuesBucket } from '@ohos.data.ValuesBucket';
1812import featureAbility from '@ohos.ability.featureAbility';
1813
1814let key1 = "NAME";
1815let key2 = "AGE";
1816let key3 = "SALARY";
1817let key4 = "blobType";
1818let value1 = "Lisa";
1819let value2 = 18;
1820let value3 = 100.5;
1821let value4 = new Uint8Array([1, 2, 3]);
1822
1823const valueBucket: ValuesBucket = {
1824  key1: value1,
1825  key2: value2,
1826  key3: value3,
1827  key4: value4,
1828};
1829
1830data_rdb.getRdbStore(this.context, "RdbTest.db", 1, async (err: BusinessError, rdbStore) => {
1831  rdbStore.beginTransaction()
1832  await rdbStore.insert("test", valueBucket)
1833  rdbStore.commit()
1834})
1835```
1836
1837### rollBack<sup>8+</sup>
1838
1839rollBack():void
1840
1841Rolls back the SQL statements that have been executed.
1842
1843**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1844
1845**Example**
1846
1847```ts
1848import { ValuesBucket } from '@ohos.data.ValuesBucket';
1849import featureAbility from '@ohos.ability.featureAbility';
1850
1851let key1 = "NAME";
1852let key2 = "AGE";
1853let key3 = "SALARY";
1854let key4 = "blobType";
1855let value1 = "Lisa";
1856let value2 = 18;
1857let value3 = 100.5;
1858let value4 = new Uint8Array([1, 2, 3]);
1859
1860const valueBucket: ValuesBucket = {
1861  key1: value1,
1862  key2: value2,
1863  key3: value3,
1864  key4: value4,
1865};
1866
1867const STORE_CONFIG = { name: "RdbTest.db"}
1868data_rdb.getRdbStore(this,context, "RdbTest.db", 1, async (err: BusinessError, rdbStore) => {
1869    try {
1870		rdbStore.beginTransaction()
1871		await rdbStore.insert("test", valueBucket)
1872		rdbStore.commit()
1873	} catch (e) {
1874		rdbStore.rollBack()
1875	}
1876})
1877```
1878
1879### setDistributedTables<sup>8+</sup>
1880
1881setDistributedTables(tables: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void
1882
1883Sets distributed tables. This API uses an asynchronous callback to return the result.
1884
1885**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
1886
1887**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1888
1889**Parameters**
1890
1891| Name | Type | Mandatory | Description |
1892| -------- | -------- | -------- | -------- |
1893| tables | Array&lt;string&gt; | Yes | Names of the distributed tables to set. |
1894| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
1895
1896**Example**
1897
1898```ts
1899rdbStore.setDistributedTables(["EMPLOYEE"], (err: BusinessError) => {
1900  if (err) {
1901    console.info('Failed to set distributed tables, err: ' + err)
1902    return
1903  }
1904  console.info('Set distributed tables successfully.')
1905})
1906```
1907
1908### setDistributedTables<sup>8+</sup>
1909
1910 setDistributedTables(tables: Array&lt;string&gt;): Promise&lt;void&gt;
1911
1912Sets distributed tables. This API uses a promise to return the result.
1913
1914**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
1915
1916**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1917
1918**Parameters**
1919
1920| Name | Type | Mandatory | Description |
1921| -------- | -------- | -------- | -------- |
1922| tables | Array&lt;string&gt; | Yes | Names of the distributed tables to set. |
1923
1924**Return value**
1925
1926| Type | Description |
1927| -------- | -------- |
1928| Promise&lt;void&gt; | Promise that returns no value. |
1929
1930**Example**
1931
1932```ts
1933let promise: void = rdbStore.setDistributedTables(["EMPLOYEE"])
1934promise.then(() => {
1935  console.info("Set distributed tables successfully.")
1936}).catch((err: BusinessError) => {
1937  console.info("Failed to set distributed tables, err: " + err)
1938})
1939```
1940
1941### obtainDistributedTableName<sup>8+</sup>
1942
1943obtainDistributedTableName(device: string, table: string, callback: AsyncCallback&lt;string&gt;): void
1944
1945Obtains the distributed table name of a remote device based on the local table name of the device. The distributed table name is required when the RDB store of a remote device is queried.
1946
1947> **NOTE**<br/>
1948>
1949> The value of **device** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
1950
1951**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
1952
1953**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1954
1955**Parameters**
1956
1957| Name | Type | Mandatory | Description |
1958| -------- | -------- | -------- | -------- |
1959| device | string | Yes | ID of the remote device. |
1960| table | string | Yes | Local table name of the remote device. |
1961| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the result. If the operation succeeds, the distributed table name of the remote device is returned. |
1962
1963**Example**
1964
1965```ts
1966import deviceManager from '@ohos.distributedHardware.deviceManager';
1967
1968let dmInstance: Array<string>;
1969
1970deviceManager.createDeviceManager("com.example.appdatamgrverify", (err: BusinessError, manager: void) => {
1971  if (err) {
1972    console.log("create device manager failed, err=" + err);
1973    return;
1974  }
1975  dmInstance = manager;
1976  let devices: Array<string> = dmInstance.getTrustedDeviceListSync();
1977  let deviceId: Array<string> = devices[0].deviceId;
1978})
1979
1980rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", (err: BusinessError, tableName: String) {
1981  if (err) {
1982    console.info('Failed to obtain DistributedTableName, err: ' + err)
1983    return
1984  }
1985  console.info('Obtained distributed table name successfully, tableName=.' + tableName)
1986})
1987```
1988
1989### obtainDistributedTableName<sup>8+</sup>
1990
1991 obtainDistributedTableName(device: string, table: string): Promise&lt;string&gt;
1992
1993Obtains the distributed table name of a remote device based on the local table name of the device. The distributed table name is required when the RDB store of a remote device is queried.
1994
1995> **NOTE**<br/>
1996>
1997> The value of **device** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
1998
1999**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
2000
2001**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2002
2003**Parameters**
2004
2005| Name | Type | Mandatory | Description |
2006| -------- | -------- | -------- | -------- |
2007| device | string | Yes | ID of the remote device. |
2008| table | string | Yes | Local table name of the remote device. |
2009
2010**Return value**
2011
2012| Type | Description |
2013| -------- | -------- |
2014| Promise&lt;string&gt; | Promise used to return the result. If the operation succeeds, the distributed table name of the remote device is returned. |
2015
2016**Example**
2017
2018```ts
2019import deviceManager from '@ohos.distributedHardware.deviceManager';
2020
2021let dmInstance: Array<string>;
2022
2023deviceManager.createDeviceManager("com.example.appdatamgrverify", (err: BusinessError, manager: void) => {
2024  if (err) {
2025    console.log("create device manager failed, err=" + err);
2026    return;
2027  }
2028  dmInstance = manager;
2029  let devices: Array<string> = dmInstance.getTrustedDeviceListSync();
2030  let deviceId: Array<string> = devices[0].deviceId;
2031})
2032
2033let promise: void = rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE")
2034promise.then((tableName: String) => {
2035  console.info('Obtained distributed table name successfully, tableName= ' + tableName)
2036}).catch((err: BusinessError) => {
2037  console.info('Failed to obtain DistributedTableName, err: ' + err)
2038})
2039```
2040
2041### sync<sup>8+</sup>
2042
2043sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback&lt;Array&lt;[string, number]&gt;&gt;): void
2044
2045Synchronizes data between devices. This API uses an asynchronous callback to return the result.
2046
2047**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
2048
2049**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2050
2051**Parameters**
2052
2053| Name | Type | Mandatory | Description |
2054| -------- | -------- | -------- | -------- |
2055| mode | [SyncMode](#syncmode8) | Yes | Data sync mode. The value can be **push** or **pull**. |
2056| predicates | [RdbPredicates](#rdbpredicates) | Yes | **RdbPredicates** object that specifies the data and devices to synchronize. |
2057| callback | AsyncCallback&lt;Array&lt;[string, number]&gt;&gt; | Yes | Callback used to send the sync result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the sync status of that device. The value **0** indicates a successful sync. Other values indicate a sync failure. |
2058
2059**Example**
2060
2061```ts
2062import deviceManager from '@ohos.distributedHardware.deviceManager';
2063
2064let dmInstance: Array<string>;
2065
2066deviceManager.createDeviceManager("com.example.appdatamgrverify", (err: BusinessError, manager: void) => {
2067  if (err) {
2068    console.log("create device manager failed, err=" + err);
2069    return;
2070  }
2071  dmInstance = manager;
2072  let devices: Array<string> = dmInstance.getTrustedDeviceListSync();
2073  for (let i = 0; i < devices.length; i++) {
2074    let deviceIds: Array<string> = devices[i].deviceId;
2075  }
2076})
2077
2078let predicates = new data_rdb.RdbPredicates('EMPLOYEE')
2079predicates.inDevices(deviceIds)
2080rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicates, (err: BusinessError, result: void) {
2081  if (err) {
2082    console.log('Sync failed, err: ' + err)
2083    return
2084  }
2085  console.log('Sync done.')
2086  for (let i = 0; i < result.length; i++) {
2087    console.log('device=' + result[i][0] + ' status=' + result[i][1])
2088  }
2089})
2090```
2091
2092### sync<sup>8+</sup>
2093
2094 sync(mode: SyncMode, predicates: RdbPredicates): Promise&lt;Array&lt;[string, number]&gt;&gt;
2095
2096Synchronizes data between devices. This API uses a promise to return the result.
2097
2098**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
2099
2100**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2101
2102**Parameters**
2103
2104| Name | Type | Mandatory | Description |
2105| -------- | -------- | -------- | -------- |
2106| mode | [SyncMode](#syncmode8) | Yes | Data sync mode. The value can be **push** or **pull**. |
2107| predicates | [RdbPredicates](#rdbpredicates) | Yes | **RdbPredicates** object that specifies the data and devices to synchronize. |
2108
2109**Return value**
2110
2111| Type | Description |
2112| -------- | -------- |
2113| Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise used to send the sync result. <br>**string** indicates the device ID. <br>**number** indicates the sync status of that device. The value **0** indicates a successful sync. Other values indicate a sync failure.  |
2114
2115**Example**
2116
2117```ts
2118import deviceManager from '@ohos.distributedHardware.deviceManager';
2119
2120let dmInstance: Array<string>;
2121
2122deviceManager.createDeviceManager("com.example.appdatamgrverify", (err: BusinessError, manager: void) => {
2123  if (err) {
2124    console.log("create device manager failed, err=" + err);
2125    return;
2126  }
2127  dmInstance = manager;
2128  let devices: Array<string> = dmInstance.getTrustedDeviceListSync();
2129  for (let i = 0; i < devices.length; i++) {
2130    let deviceIds: Array<string> = devices[i].deviceId;
2131  }
2132})
2133
2134let predicates = new data_rdb.RdbPredicates('EMPLOYEE')
2135predicates.inDevices(deviceIds)
2136let promise: void = rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicates)
2137promise.then((result: void) =>{
2138  console.log('Sync done.')
2139  for (let i = 0; i < result.length; i++) {
2140    console.log('device=' + result[i][0] + ' status=' + result[i][1])
2141  }
2142}).catch((err: BusinessError) => {
2143  console.log('Sync failed')
2144})
2145```
2146
2147### on('dataChange')<sup>8+</sup>
2148
2149on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void
2150
2151Registers an observer for this RDB store. When the data in the RDB store changes, a callback is invoked to return the data changes.
2152
2153**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2154
2155**Parameters**
2156
2157| Name | Type | Mandatory | Description |
2158| -------- | -------- | -------- | -------- |
2159| event | string | Yes| Event type. The value is 'dataChange', which indicates data changes. |
2160| type | [SubscribeType](#subscribetype8) | Yes | Subscription type to register. |
2161| observer | Callback&lt;Array&lt;string&gt;&gt; | Yes | Observer that listens for the data changes in the RDB store. **Array<string>** indicates the ID of the peer device whose data in the database is changed. |
2162
2163**Example**
2164
2165```ts
2166let devices: Array<string>;
2167
2168try {
2169  rdbStore.on('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, (storeObserver: Array<string>) => {
2170    for (let i = 0; i < devices.length; i++) {
2171      console.log('device=' + devices[i] + ' data changed')
2172    }
2173  })
2174} catch (err) {
2175  console.log('Failed to register observer')
2176}
2177```
2178
2179### off('dataChange')<sup>8+</sup>
2180
2181off(event:'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void
2182
2183Unregisters the observer of the specified type from the RDB store. This API uses a callback to return the result.
2184
2185**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2186
2187**Parameters**
2188
2189| Name | Type | Mandatory | Description |
2190| -------- | -------- | -------- | -------- |
2191| event | string | Yes| Event type. The value is 'dataChange', which indicates data changes. |
2192| type | [SubscribeType](#subscribetype8)    | Yes| Subscription type to unregister.|
2193| observer | Callback&lt;Array&lt;string&gt;&gt; | Yes| Data change observer to unregister. **Array<string>** indicates the ID of the peer device whose data in the database is changed.|
2194
2195**Example**
2196
2197```ts
2198let devices: Array<string>;
2199
2200try {
2201  rdbStore.off('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, (storeObserver: Array<string>) => {
2202    for (let i = 0; i < devices.length; i++) {
2203      console.log('device=' + devices[i] + ' data changed')
2204    }
2205  })
2206} catch (err) {
2207  console.log('Failed to unregister observer')
2208}
2209```
2210