• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Class (RdbPredicates)
2
3> **NOTE**
4>
5> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
6
7Defines the predicates for an RDB store. This class determines whether the conditional expression for the RDB store is true or false. Multiple predicates statements can be concatenated by using **and()** by default. **RdbPredicates** cannot be passed across threads using Sendable.
8
9## Module to Import
10
11```ts
12import { relationalStore } from '@kit.ArkData';
13```
14
15## constructor
16
17constructor(name: string)
18
19A constructor used to create an **RdbPredicates** object.
20
21**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
22
23**Parameters**
24
25| Name| Type  | Mandatory| Description        |
26| ------ | ------ | ---- | ------------ |
27| name   | string | Yes  | Database table name.|
28
29**Error codes**
30
31For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
32
33| **ID**| **Error Message**                                                                                                      |
34| --------- |----------------------------------------------------------------------------------------------------------------|
35| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
36
37**Example**:
38
39```ts
40let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
41```
42
43## inDevices
44
45inDevices(devices: Array<string>): RdbPredicates
46
47Creates an **RdbPredicates** object to specify the remote devices to connect on the network during distributed database sync.
48
49> **NOTE**
50>
51> **devices** can be obtained by using [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync).
52When calling **sync()**, you need to call **inDevices** to specify the devices. If **inDevices** is not used, data will be synced to all devices on the network by default.
53
54**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
55
56**Parameters**
57
58| Name | Type               | Mandatory| Description                      |
59| ------- | ------------------- | ---- | -------------------------- |
60| devices | Array<string> | Yes  | IDs of the remote devices to connect.|
61
62**Return value**
63
64| Type                                | Description                      |
65| ------------------------------------ | -------------------------- |
66| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
67
68**Error codes**
69
70For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
71
72| **ID**| **Error Message**                                                                                                      |
73| --------- |----------------------------------------------------------------------------------------------------------------|
74| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
75
76**Example**:
77
78```ts
79import { distributedDeviceManager } from '@kit.DistributedServiceKit';
80import { BusinessError } from '@kit.BasicServicesKit';
81
82let dmInstance: distributedDeviceManager.DeviceManager;
83let deviceIds: Array<string> = [];
84
85try {
86  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
87  let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync();
88  for (let i = 0; i < devices.length; i++) {
89    deviceIds[i] = devices[i].networkId!;
90  }
91} catch (err) {
92  let code = (err as BusinessError).code;
93  let message = (err as BusinessError).message;
94  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
95}
96
97let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
98predicates.inDevices(deviceIds);
99```
100
101## inAllDevices
102
103inAllDevices(): RdbPredicates
104
105Creates an **RdbPredicates** object to specify all remote devices on the network to connect during distributed database sync.
106
107
108**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
109
110**Return value**
111
112| Type                                | Description                      |
113| ------------------------------------ | -------------------------- |
114| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
115
116**Example**:
117
118```ts
119let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
120predicates.inAllDevices();
121```
122
123## equalTo
124
125equalTo(field: string, value: ValueType): RdbPredicates
126
127Creates an **RdbPredicates** object to search for the records in the specified column that are equal to the given value.
128
129**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
130
131**Parameters**
132
133| Name| Type                   | Mandatory| Description                  |
134| ------ | ----------------------- | ---- | ---------------------- |
135| field  | string                  | Yes  | Column name in the database table.    |
136| value  | [ValueType](arkts-apis-data-relationalStore-t.md#valuetype) | Yes  | Value to match.|
137
138**Return value**
139
140| Type                                | Description                      |
141| ------------------------------------ | -------------------------- |
142| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
143
144**Error codes**
145
146For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
147
148| **ID**| **Error Message**                                                                                                      |
149| --------- |----------------------------------------------------------------------------------------------------------------|
150| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
151
152**Example**:
153
154```ts
155// Find all the records in the NAME column where the value is Lisa.
156let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
157predicates.equalTo("NAME", "Lisa");
158```
159
160
161## notEqualTo
162
163notEqualTo(field: string, value: ValueType): RdbPredicates
164
165Creates an **RdbPredicates** object to search for the records in the specified column that are not equal to the given value.
166
167**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
168
169**Parameters**
170
171| Name| Type                   | Mandatory| Description                  |
172| ------ | ----------------------- | ---- | ---------------------- |
173| field  | string                  | Yes  | Column name in the database table.    |
174| value  | [ValueType](arkts-apis-data-relationalStore-t.md#valuetype) | Yes  | Value to match.|
175
176**Return value**
177
178| Type                                | Description                      |
179| ------------------------------------ | -------------------------- |
180| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
181
182**Error codes**
183
184For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
185
186| **ID**| **Error Message**                                                                                                      |
187| --------- |----------------------------------------------------------------------------------------------------------------|
188| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
189
190**Example**:
191
192```ts
193// Find all the records in the NAME column where the value is not Lisa.
194let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
195predicates.notEqualTo("NAME", "Lisa");
196```
197
198
199## beginWrap
200
201beginWrap(): RdbPredicates
202
203Creates an **RdbPredicates** object to add a left parenthesis.
204
205**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
206
207**Return value**
208
209| Type                                | Description                     |
210| ------------------------------------ | ------------------------- |
211| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | **RdbPredicates** object created.|
212
213**Example**:
214
215```ts
216let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
217predicates.equalTo("NAME", "Lisa")
218  .beginWrap()
219  .equalTo("AGE", 18)
220  .or()
221  .equalTo("SALARY", 200.5)
222  .endWrap();
223```
224
225## endWrap
226
227endWrap(): RdbPredicates
228
229Creates an **RdbPredicates** object to add a right parenthesis.
230
231**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
232
233**Return value**
234
235| Type                                | Description                     |
236| ------------------------------------ | ------------------------- |
237| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | **RdbPredicates** object created.|
238
239**Example**:
240
241```ts
242let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
243predicates.equalTo("NAME", "Lisa")
244  .beginWrap()
245  .equalTo("AGE", 18)
246  .or()
247  .equalTo("SALARY", 200.5)
248  .endWrap();
249```
250
251## or
252
253or(): RdbPredicates
254
255Creates an **RdbPredicates** object to add the OR condition.
256
257**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
258
259**Return value**
260
261| Type                                | Description                     |
262| ------------------------------------ | ------------------------- |
263| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | **RdbPredicates** object created.|
264
265**Example**:
266
267```ts
268// Find all records in the NAME column where the value is Lisa or Rose.
269let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
270predicates.equalTo("NAME", "Lisa")
271  .or()
272  .equalTo("NAME", "Rose");
273```
274
275## and
276
277and(): RdbPredicates
278
279Creates an **RdbPredicates** object to add the AND condition.
280
281**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
282
283**Return value**
284
285| Type                                | Description                     |
286| ------------------------------------ | ------------------------- |
287| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | **RdbPredicates** object created.|
288
289**Example**:
290
291```ts
292// Find the records in the EMPLOYEE table where the NAME column is Lisa and the SALARY column is 200.5.
293let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
294predicates.equalTo("NAME", "Lisa")
295  .and()
296  .equalTo("SALARY", 200.5);
297```
298
299## contains
300
301contains(field: string, value: string): RdbPredicates
302
303Creates an **RdbPredicates** object to search for the records in the specified column that contain the given value.
304
305**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
306
307**Parameters**
308
309| Name| Type  | Mandatory| Description                  |
310| ------ | ------ | ---- | ---------------------- |
311| field  | string | Yes  | Column name in the database table.    |
312| value  | string | Yes  | Value to match.|
313
314**Return value**
315
316| Type                                | Description                      |
317| ------------------------------------ | -------------------------- |
318| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
319
320**Error codes**
321
322For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
323
324| **ID**| **Error Message**                                                                                                      |
325| --------- |----------------------------------------------------------------------------------------------------------------|
326| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
327
328**Example**:
329
330```ts
331// Find all the records that contain the string 'os' in the NAME column, for example, Rose.
332let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
333predicates.contains("NAME", "os");
334```
335
336## beginsWith
337
338beginsWith(field: string, value: string): RdbPredicates
339
340Creates an **RdbPredicates** object to search for the records in the specified column that begin with the given value.
341
342**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
343
344**Parameters**
345
346| Name| Type  | Mandatory| Description                  |
347| ------ | ------ | ---- | ---------------------- |
348| field  | string | Yes  | Column name in the database table.    |
349| value  | string | Yes  | Value to match.|
350
351**Return value**
352
353| Type                                | Description                      |
354| ------------------------------------ | -------------------------- |
355| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
356
357**Error codes**
358
359For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
360
361| **ID**| **Error Message**                                                                                                      |
362| --------- |----------------------------------------------------------------------------------------------------------------|
363| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
364
365**Example**:
366
367```ts
368// Find all the records that start with "Li" in the NAME column, for example, Lisa.
369let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
370predicates.beginsWith("NAME", "Li");
371```
372
373## endsWith
374
375endsWith(field: string, value: string): RdbPredicates
376
377Creates an **RdbPredicates** object to search for the records in the specified column that end with the given value.
378
379**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
380
381**Parameters**
382
383| Name| Type  | Mandatory| Description                  |
384| ------ | ------ | ---- | ---------------------- |
385| field  | string | Yes  | Column name in the database table.    |
386| value  | string | Yes  | Value to match.|
387
388**Return value**
389
390| Type                                | Description                      |
391| ------------------------------------ | -------------------------- |
392| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
393
394**Error codes**
395
396For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
397
398| **ID**| **Error Message**                                                                                                      |
399| --------- |----------------------------------------------------------------------------------------------------------------|
400| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
401
402**Example**:
403
404```ts
405// Find all the records that end with "se" in the NAME column, for example, Rose.
406let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
407predicates.endsWith("NAME", "se");
408```
409
410## isNull
411
412isNull(field: string): RdbPredicates
413
414Creates an **RdbPredicates** object to search for the records in the specified column that are **null**.
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
424**Return value**
425
426| Type                                | Description                      |
427| ------------------------------------ | -------------------------- |
428| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
429
430**Error codes**
431
432For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
433
434| **ID**| **Error Message**                                                                                                      |
435| --------- |----------------------------------------------------------------------------------------------------------------|
436| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
437
438**Example**:
439
440```ts
441let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
442predicates.isNull("NAME");
443```
444
445## isNotNull
446
447isNotNull(field: string): RdbPredicates
448
449Creates an **RdbPredicates** object to search for the records in the specified column that are not **null**.
450
451**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
452
453**Parameters**
454
455| Name| Type  | Mandatory| Description              |
456| ------ | ------ | ---- | ------------------ |
457| field  | string | Yes  | Column name in the database table.|
458
459**Return value**
460
461| Type                                | Description                      |
462| ------------------------------------ | -------------------------- |
463| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
464
465**Error codes**
466
467For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
468
469| **ID**| **Error Message**                                                                                                      |
470| --------- |----------------------------------------------------------------------------------------------------------------|
471| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
472
473**Example**:
474
475```ts
476let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
477predicates.isNotNull("NAME");
478```
479
480## like
481
482like(field: string, value: string): RdbPredicates
483
484Creates an **RdbPredicates** object to search for the records in the specified column that are similar to the given value.
485
486**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
487
488**Parameters**
489
490| Name| Type  | Mandatory| Description                  |
491| ------ | ------ | ---- | ---------------------- |
492| field  | string | Yes  | Column name in the database table.    |
493| value  | string | Yes  | Value to match.|
494
495**Return value**
496
497| Type                                | Description                      |
498| ------------------------------------ | -------------------------- |
499| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
500
501**Error codes**
502
503For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
504
505| **ID**| **Error Message**                                                                                                      |
506| --------- |----------------------------------------------------------------------------------------------------------------|
507| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
508
509**Example**:
510
511```ts
512// Find all the records that are similar to "os" in the NAME column, for example, Rose.
513let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
514predicates.like("NAME", "%os%");
515```
516
517## glob
518
519glob(field: string, value: string): RdbPredicates
520
521Creates an **RdbPredicates** object to search for the records in the specified column that match the given string.
522
523**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
524
525**Parameters**
526
527| Name| Type  | Mandatory| Description                                                        |
528| ------ | ------ | ---- | ------------------------------------------------------------ |
529| field  | string | Yes  | Column name in the database table.                                          |
530| value  | string | Yes  | Value to match.<br>Wildcards are supported. ***** indicates zero, one, or multiple digits or characters. **?** indicates a single digit or character.|
531
532**Return value**
533
534| Type                                | Description                      |
535| ------------------------------------ | -------------------------- |
536| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
537
538**Error codes**
539
540For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
541
542| **ID**| **Error Message**                                                                                                      |
543| --------- |----------------------------------------------------------------------------------------------------------------|
544| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
545
546**Example**:
547
548```ts
549// Find the strings that match "?h*g" in the NAME column.
550let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
551predicates.glob("NAME", "?h*g");
552```
553
554## between
555
556between(field: string, low: ValueType, high: ValueType): RdbPredicates
557
558Creates an **RdbPredicates** object to search for the records that are within the given range (including the min. and max. values) in the specified column.
559
560**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
561
562**Parameters**
563
564| Name| Type                   | Mandatory| Description                      |
565| ------ | ----------------------- | ---- | -------------------------- |
566| field  | string                  | Yes  | Column name in the database table.        |
567| low    | [ValueType](arkts-apis-data-relationalStore-t.md#valuetype) | Yes  | Minimum value of the range to set.  |
568| high   | [ValueType](arkts-apis-data-relationalStore-t.md#valuetype) | Yes  | Maximum value of the range to set.|
569
570**Return value**
571
572| Type                                | Description                      |
573| ------------------------------------ | -------------------------- |
574| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
575
576**Error codes**
577
578For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
579
580| **ID**| **Error Message**                                                                                                      |
581| --------- |----------------------------------------------------------------------------------------------------------------|
582| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
583
584**Example**:
585
586```ts
587// Find the records that are greater than or equal to 10 and less than or equal to 50 in the AGE column.
588let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
589predicates.between("AGE", 10, 50);
590```
591
592## notBetween
593
594notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates
595
596Creates an **RdbPredicates** object to search for the records that are out of the given range (excluding the min. and max. values) in the specified column.
597
598**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
599
600**Parameters**
601
602| Name| Type                   | Mandatory| Description                      |
603| ------ | ----------------------- | ---- | -------------------------- |
604| field  | string                  | Yes  | Column name in the database table.        |
605| low    | [ValueType](arkts-apis-data-relationalStore-t.md#valuetype) | Yes  | Minimum value of the range to set.  |
606| high   | [ValueType](arkts-apis-data-relationalStore-t.md#valuetype) | Yes  | Maximum value of the range to set.|
607
608**Return value**
609
610| Type                                | Description                      |
611| ------------------------------------ | -------------------------- |
612| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
613
614**Error codes**
615
616For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
617
618| **ID**| **Error Message**                                                                                                      |
619| --------- |----------------------------------------------------------------------------------------------------------------|
620| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
621
622**Example**:
623
624```ts
625// Find the records that are less than 10 or greater than 50 in the AGE column.
626let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
627predicates.notBetween("AGE", 10, 50);
628```
629
630## greaterThan
631
632greaterThan(field: string, value: ValueType): RdbPredicates
633
634Creates an **RdbPredicates** object to search for the records that are greater than the given value in the specified column.
635
636**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
637
638**Parameters**
639
640| Name| Type                   | Mandatory| Description                  |
641| ------ | ----------------------- | ---- | ---------------------- |
642| field  | string                  | Yes  | Column name in the database table.    |
643| value  | [ValueType](arkts-apis-data-relationalStore-t.md#valuetype) | Yes  | Value to match.|
644
645**Return value**
646
647| Type                                | Description                      |
648| ------------------------------------ | -------------------------- |
649| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
650
651**Error codes**
652
653For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
654
655| **ID**| **Error Message**                                                                                                      |
656| --------- |----------------------------------------------------------------------------------------------------------------|
657| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
658
659**Example**:
660
661```ts
662// Find all the records that are greater than 18 in the AGE column.
663let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
664predicates.greaterThan("AGE", 18);
665```
666
667## lessThan
668
669lessThan(field: string, value: ValueType): RdbPredicates
670
671Creates an **RdbPredicates** object to search for the records that are less than the given value in the specified column.
672
673**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
674
675**Parameters**
676
677| Name| Type                   | Mandatory| Description                  |
678| ------ | ----------------------- | ---- | ---------------------- |
679| field  | string                  | Yes  | Column name in the database table.    |
680| value  | [ValueType](arkts-apis-data-relationalStore-t.md#valuetype) | Yes  | Value to match.|
681
682**Return value**
683
684| Type                                | Description                      |
685| ------------------------------------ | -------------------------- |
686| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
687
688**Error codes**
689
690For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
691
692| **ID**| **Error Message**                                                                                                      |
693| --------- |----------------------------------------------------------------------------------------------------------------|
694| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
695
696**Example**:
697
698```ts
699// Find all the records that are less than 20 in the AGE column.
700let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
701predicates.lessThan("AGE", 20);
702```
703
704## greaterThanOrEqualTo
705
706greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates
707
708Creates an **RdbPredicates** object to search for the records that are greater than or equal to the given value in the specified column.
709
710**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
711
712**Parameters**
713
714| Name| Type                   | Mandatory| Description                  |
715| ------ | ----------------------- | ---- | ---------------------- |
716| field  | string                  | Yes  | Column name in the database table.    |
717| value  | [ValueType](arkts-apis-data-relationalStore-t.md#valuetype) | Yes  | Value to match.|
718
719**Return value**
720
721| Type                                | Description                      |
722| ------------------------------------ | -------------------------- |
723| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
724
725**Error codes**
726
727For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
728
729| **ID**| **Error Message**                                                                                                      |
730| --------- |----------------------------------------------------------------------------------------------------------------|
731| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
732
733**Example**:
734
735```ts
736// Find all the records that are greater than or equal to 18 in the AGE column.
737let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
738predicates.greaterThanOrEqualTo("AGE", 18);
739```
740
741## lessThanOrEqualTo
742
743lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates
744
745Creates an **RdbPredicates** object to search for the records that are less than or equal to the given value in the specified column.
746
747**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
748
749**Parameters**
750
751| Name| Type                   | Mandatory| Description                  |
752| ------ | ----------------------- | ---- | ---------------------- |
753| field  | string                  | Yes  | Column name in the database table.    |
754| value  | [ValueType](arkts-apis-data-relationalStore-t.md#valuetype) | Yes  | Value to match.|
755
756**Return value**
757
758| Type                                | Description                      |
759| ------------------------------------ | -------------------------- |
760| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
761
762**Error codes**
763
764For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
765
766| **ID**| **Error Message**                                                                                                      |
767| --------- |----------------------------------------------------------------------------------------------------------------|
768| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
769
770**Example**:
771
772```ts
773// Find all the records that are less than or equal to 20 in the AGE column.
774let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
775predicates.lessThanOrEqualTo("AGE", 20);
776```
777
778## orderByAsc
779
780orderByAsc(field: string): RdbPredicates
781
782Creates an **RdbPredicates** object to sort the records in the specified column in ascending order.
783
784**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
785
786**Parameters**
787
788| Name| Type  | Mandatory| Description              |
789| ------ | ------ | ---- | ------------------ |
790| field  | string | Yes  | Column name in the database table.|
791
792**Return value**
793
794| Type                                | Description                      |
795| ------------------------------------ | -------------------------- |
796| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
797
798**Error codes**
799
800For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
801
802| **ID**| **Error Message**                                                                                                      |
803| --------- |----------------------------------------------------------------------------------------------------------------|
804| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
805
806**Example**:
807
808```ts
809let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
810predicates.orderByAsc("NAME");
811```
812
813## orderByDesc
814
815orderByDesc(field: string): RdbPredicates
816
817Creates an **RdbPredicates** object to sort the records in the specified column in descending order.
818
819**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
820
821**Parameters**
822
823| Name| Type  | Mandatory| Description              |
824| ------ | ------ | ---- | ------------------ |
825| field  | string | Yes  | Column name in the database table.|
826
827**Return value**
828
829| Type                                | Description                      |
830| ------------------------------------ | -------------------------- |
831| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
832
833**Error codes**
834
835For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
836
837| **ID**| **Error Message**                                                                                                      |
838| --------- |----------------------------------------------------------------------------------------------------------------|
839| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
840
841**Example**:
842
843```ts
844let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
845predicates.orderByDesc("AGE");
846```
847
848## distinct
849
850distinct(): RdbPredicates
851
852Creates an **RdbPredicates** object to filter out duplicate records.
853
854**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
855
856**Return value**
857
858| Type                                | Description                          |
859| ------------------------------------ | ------------------------------ |
860| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | **RdbPredicates** object that can filter out duplicate records.|
861
862**Example**:
863
864```ts
865let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
866predicates.equalTo("NAME", "Rose").distinct(); // Deduplicate result sets whose NAME is Rose.
867```
868
869## limitAs
870
871limitAs(value: number): RdbPredicates
872
873Creates a **RdbPredicates** object to limit the number of records.
874
875**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
876
877**Parameters**
878
879| Name| Type  | Mandatory| Description            |
880| ------ | ------ | ---- | ---------------- |
881| value  | number | Yes  | Maximum number of data records. The value should be a positive integer. If a value less than or equal to **0** is specified, the number of records is not limited.|
882
883**Return value**
884
885| Type                                | Description                                |
886| ------------------------------------ | ------------------------------------ |
887| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that specify the maximum number of records.|
888
889**Error codes**
890
891For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
892
893| **ID**| **Error Message**              |
894| --------- |--------------------------|
895| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
896
897**Example**:
898
899```ts
900let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
901predicates.equalTo("NAME", "Rose").limitAs(3);
902```
903
904## offsetAs
905
906offsetAs(rowOffset: number): RdbPredicates
907
908Creates an **RdbPredicates** object to set the start position of the query result. This API must be used together with **limitAs**. Otherwise, no result will be returned. To query all rows after the specified offset, pass in a parameter less than or equal to **0** in **limitAs**.
909
910**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
911
912**Parameters**
913
914| Name   | Type  | Mandatory| Description                              |
915| --------- | ------ | ---- | ---------------------------------- |
916| rowOffset | number | Yes  | Start position of the query result. By default, the start position is the beginning of the result set. If **rowOffset** is a negative number, the start position is the beginning of the result set. If **rowOffset** exceeds the end of the result set, the query result is empty.|
917
918**Return value**
919
920| Type                                | Description                                |
921| ------------------------------------ | ------------------------------------ |
922| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that specify the start position of the returned result.|
923
924**Error codes**
925
926For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
927
928| **ID**| **Error Message**                                                                                                      |
929| --------- |----------------------------------------------------------------------------------------------------------------|
930| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
931
932**Example**:
933
934```ts
935let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
936predicates.equalTo("NAME", "Rose").limitAs(-1).offsetAs(3);
937```
938
939## groupBy
940
941groupBy(fields: Array&lt;string&gt;): RdbPredicates
942
943Creates a **RdbPredicates** object to group the query results based on the specified columns.
944
945**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
946
947**Parameters**
948
949| Name| Type               | Mandatory| Description                |
950| ------ | ------------------- | ---- | -------------------- |
951| fields | Array&lt;string&gt; | Yes  | Names of columns to group.|
952
953**Return value**
954
955| Type                                | Description                  |
956| ------------------------------------ | ---------------------- |
957| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that group rows with the same value.|
958
959**Error codes**
960
961For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
962
963| **ID**| **Error Message**                                                                                                      |
964| --------- |----------------------------------------------------------------------------------------------------------------|
965| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
966
967**Example**:
968
969```ts
970let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
971predicates.groupBy(["AGE", "NAME"]);
972```
973
974## indexedBy
975
976indexedBy(field: string): RdbPredicates
977
978Creates a **RdbPredicates** object to specify the index column.
979
980**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
981
982**Parameters**
983
984| Name| Type  | Mandatory| Description          |
985| ------ | ------ | ---- | -------------- |
986| field  | string | Yes  | Name of the index column.|
987
988**Return value**
989
990| Type                                | Description                                 |
991| ------------------------------------ | ------------------------------------- |
992| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | **RdbPredicates** object created.|
993
994**Error codes**
995
996For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
997
998| **ID**| **Error Message**                                                                                                      |
999| --------- |----------------------------------------------------------------------------------------------------------------|
1000| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1001
1002**Example**:
1003
1004```ts
1005let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1006predicates.indexedBy("SALARY");
1007```
1008
1009## in
1010
1011in(field: string, value: Array&lt;ValueType&gt;): RdbPredicates
1012
1013Creates an **RdbPredicates** object to search for the records that are in the given range in the specified column.
1014
1015**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1016
1017**Parameters**
1018
1019| Name| Type                                | Mandatory| Description                                   |
1020| ------ | ------------------------------------ | ---- | --------------------------------------- |
1021| field  | string                               | Yes  | Column name in the database table.                     |
1022| value  | Array&lt;[ValueType](arkts-apis-data-relationalStore-t.md#valuetype)&gt; | Yes  | Array of **ValueType**s to match.|
1023
1024**Return value**
1025
1026| Type                                | Description                      |
1027| ------------------------------------ | -------------------------- |
1028| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
1029
1030**Error codes**
1031
1032For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1033
1034| **ID**| **Error Message**                                                                                                      |
1035| --------- |----------------------------------------------------------------------------------------------------------------|
1036| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1037
1038**Example**:
1039
1040```ts
1041// Find records that are within [18, 20] in the AGE column.
1042let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1043predicates.in("AGE", [18, 20]);
1044```
1045
1046## notIn
1047
1048notIn(field: string, value: Array&lt;ValueType&gt;): RdbPredicates
1049
1050Creates an **RdbPredicates** object to search for the records that are out of the given range in the specified column.
1051
1052**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1053
1054**Parameters**
1055
1056| Name| Type                                | Mandatory| Description                                 |
1057| ------ | ------------------------------------ | ---- | ------------------------------------- |
1058| field  | string                               | Yes  | Column name in the database table.                   |
1059| value  | Array&lt;[ValueType](arkts-apis-data-relationalStore-t.md#valuetype)&gt; | Yes  | Array of **ValueType**s to match.|
1060
1061**Return value**
1062
1063| Type                                | Description                      |
1064| ------------------------------------ | -------------------------- |
1065| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
1066
1067**Error codes**
1068
1069For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1070
1071| **ID**| **Error Message**                                                                                                      |
1072| --------- |----------------------------------------------------------------------------------------------------------------|
1073| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1074
1075**Example**:
1076
1077```ts
1078// Find the records that are not within [Lisa, Rose] in the NAME column.
1079let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1080predicates.notIn("NAME", ["Lisa", "Rose"]);
1081```
1082
1083## notContains<sup>12+</sup>
1084
1085notContains(field: string, value: string): RdbPredicates
1086
1087Creates an **RdbPredicates** object to search for the records that do not contain the given value in the specified column.
1088
1089**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1090
1091**Parameters**
1092
1093| Name| Type  | Mandatory| Description                  |
1094| ------ | ------ | ---- | ---------------------- |
1095| field  | string | Yes  | Column name in the database table.    |
1096| value  | string | Yes  | Value to match.|
1097
1098**Return value**
1099
1100| Type                           | Description                      |
1101| ------------------------------- | -------------------------- |
1102| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
1103
1104**Error codes**
1105
1106For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1107
1108| **ID**| **Error Message**                                                                                                      |
1109| --------- |----------------------------------------------------------------------------------------------------------------|
1110| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1111
1112**Example**:
1113
1114```ts
1115// Find the records that do not contain the string "os" in the NAME column, for example, Lisa.
1116let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1117predicates.notContains("NAME", "os");
1118```
1119
1120## notLike<sup>12+</sup>
1121
1122notLike(field: string, value: string): RdbPredicates
1123
1124Creates an **RdbPredicates** object to search for the records that are not similar to the given value in the specified column.
1125
1126**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1127
1128**Parameters**
1129
1130| Name| Type  | Mandatory| Description                  |
1131| ------ | ------ | ---- | ---------------------- |
1132| field  | string | Yes  | Column name in the database table.    |
1133| value  | string | Yes  | Value to match.|
1134
1135**Return value**
1136
1137| Type                           | Description                      |
1138| ------------------------------- | -------------------------- |
1139| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
1140
1141**Error codes**
1142
1143For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1144
1145| **ID**| **Error Message**                                                                                                      |
1146| --------- |----------------------------------------------------------------------------------------------------------------|
1147| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1148
1149**Example**:
1150
1151```ts
1152// Find the records that are not "os" in the NAME column, for example, Rose.
1153let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1154predicates.notLike("NAME", "os");
1155```
1156
1157## having<sup>20+</sup>
1158
1159having(conditions:string, args?: Array\<ValueType>): RdbPredicates
1160
1161Filters for group data that meets the conditions.
1162
1163**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1164
1165**Parameters**
1166
1167| Name| Type  | Mandatory| Description                  |
1168| ------ | ------ | ---- | ---------------------- |
1169| conditions  | string | Yes  | Condition used to filter the data obtained using [groupBy](#groupby). This parameter cannot be empty and must be used with [groupBy](#groupby). |
1170| args  | Array<[ValueType](arkts-apis-data-relationalStore-t.md#valuetype)> | No  | Parameters used in **conditions**, which replace the placeholder in the conditional statement. If this parameter is not specified, the default value is an empty array.|
1171
1172**Return value**
1173
1174| Type                           | Description                      |
1175| ------------------------------- | -------------------------- |
1176| [RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Predicates that match the specified field.|
1177
1178**Error codes**
1179
1180For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md).
1181
1182| **ID**| **Error Message**                                                                                                      |
1183| --------- |----------------------------------------------------------------------------------------------------------------|
1184| 14800001       | Invalid arguments. Possible causes: 1. Empty conditions; 2. Missing GROUP BY clause. |
1185
1186**Example 1**:
1187
1188```ts
1189// Pass a complete condition.
1190let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1191predicates.groupBy(["AGE"]);
1192predicates.having("NAME = zhangsan");
1193```
1194**Example 2**:
1195
1196```ts
1197// Use placeholders in the condition and pass values to args to replace the placeholders.
1198let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1199predicates.groupBy(["AGE"]);
1200predicates.having("NAME = ?", ["zhangsan"]);
1201```
1202