js-apis-data-dataSharePredicates.md 28.7 KB
Newer Older
A
Annie_wang 已提交
1 2
# Data Share Predicates

A
Annie_wang 已提交
3
You can use **DataSharePredicates** to specify conditions for [updating](js-apis-data-dataShare.md#update), [deleting](js-apis-data-dataShare.md#delete), and [querying](js-apis-data-dataShare.md#query) data when **DataShare** is used to manage data.
A
Annie_wang 已提交
4

A
Annie_wang 已提交
5
> **NOTE**
A
Annie_wang 已提交
6
>
A
Annie_wang 已提交
7 8 9
> 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.
>
> The APIs provided by this module are system APIs.
A
Annie_wang 已提交
10 11 12 13 14 15 16 17


## Modules to Import

```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
```

A
Annie_wang 已提交
18 19 20 21
## DataSharePredicates
Provides methods for setting different **DataSharePredicates** objects.

### equalTo
A
Annie_wang 已提交
22 23 24

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

A
Annie_wang 已提交
25
Sets a **DataSharePredicates** object to match the data that is equal to the specified value.
A
Annie_wang 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

Currently, only the relational database (RDB) and key-value database (KVDB, schema) support this **DataSharePredicates** object.

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

**Parameters**

| Name| Type                                               | Mandatory| Description                  |
| ------ | --------------------------------------------------- | ---- | ---------------------- |
| field  | string                                              | Yes  | Column name in the database table.    |
| value  | [ValueType](js-apis-data-ValuesBucket.md#valuetype) | Yes  | Value to match.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
42
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
43 44 45 46 47 48 49 50

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "Rose")
```

A
Annie_wang 已提交
51
### notEqualTo
A
Annie_wang 已提交
52 53 54

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

A
Annie_wang 已提交
55
Sets a **DataSharePredicates** object to match the data that is not equal to the specified value.
A
Annie_wang 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.

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

**Parameters**

| Name| Type                                               | Mandatory| Description                  |
| ------ | --------------------------------------------------- | ---- | ---------------------- |
| field  | string                                              | Yes  | Column name in the database table.    |
| value  | [ValueType](js-apis-data-ValuesBucket.md#valuetype) | Yes  | Value to match.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
72
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
73 74 75 76 77 78 79 80

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.notEqualTo("NAME", "Rose")
```

A
Annie_wang 已提交
81
### beginWrap
A
Annie_wang 已提交
82 83 84

beginWrap(): DataSharePredicates

A
Annie_wang 已提交
85 86 87
Adds a left parenthesis to this **DataSharePredicates**.

Currently, only the RDB supports this **DataSharePredicates** object.
A
Annie_wang 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

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

**Return value**

| Type                                       | Description                  |
| ------------------------------------------- | ---------------------- |
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object with a left parenthesis.|

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "lisi")
    .beginWrap()
    .equalTo("AGE", 18)
    .or()
    .equalTo("SALARY", 200.5)
    .endWrap()
```

A
Annie_wang 已提交
109
### endWrap
A
Annie_wang 已提交
110 111 112

endWrap(): DataSharePredicates

A
Annie_wang 已提交
113 114 115
Adds a right parenthesis to this **DataSharePredicates** object.

Currently, only the RDB supports this **DataSharePredicates** object.
A
Annie_wang 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

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

**Return value**

| Type                                       | Description                  |
| ------------------------------------------- | ---------------------- |
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object with a right parenthesis.|

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "lisi")
    .beginWrap()
    .equalTo("AGE", 18)
    .or()
    .equalTo("SALARY", 200.5)
    .endWrap()
```

A
Annie_wang 已提交
137
### or
A
Annie_wang 已提交
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161

or(): DataSharePredicates

Adds the OR condition to this **DataSharePredicates** object.

Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.

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

**Return value**

| Type                                       | Description                  |
| ------------------------------------------- | ---------------------- |
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object with the OR condition.|

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "lisi")
    .or()
    .equalTo("NAME", "Rose")
```

A
Annie_wang 已提交
162
### and
A
Annie_wang 已提交
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186

and(): DataSharePredicates

Adds the AND condition to this **DataSharePredicates** object.

Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.

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

**Return value**

| Type                                       | Description                  |
| ------------------------------------------- | ---------------------- |
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object with the AND condition.|

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "lisi")
    .and()
    .equalTo("SALARY", 200.5)
```

A
Annie_wang 已提交
187
### contains
A
Annie_wang 已提交
188 189 190

contains(field: string, value: string): DataSharePredicates

A
Annie_wang 已提交
191 192 193
Sets a **DataSharePredicates** object to match the data that contains the specified value.

Currently, only the RDB supports this **DataSharePredicates** object.
A
Annie_wang 已提交
194 195 196 197 198 199 200 201

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

**Parameters**

| Name| Type  | Mandatory| Description                |
| ------ | ------ | ---- | -------------------- |
| field  | string | Yes  | Column name in the database table.  |
A
Annie_wang 已提交
202
| value  | string | Yes  | Value to match.|
A
Annie_wang 已提交
203 204 205 206 207

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
208
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
209 210 211 212 213 214 215 216

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.contains("NAME", "os")
```

A
Annie_wang 已提交
217
### beginsWith
A
Annie_wang 已提交
218 219 220

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

A
Annie_wang 已提交
221 222 223
Sets a **DataSharePredicates** object to match the data that begins with the specified value.

Currently, only the RDB supports this **DataSharePredicates** object.
A
Annie_wang 已提交
224 225 226 227 228 229 230 231

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

**Parameters**

| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| field  | string | Yes  | Column name in the database table.    |
A
Annie_wang 已提交
232
| value  | string | Yes  | Start value to match.|
A
Annie_wang 已提交
233 234 235 236 237

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
238
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
239 240 241 242 243 244 245 246

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.beginsWith("NAME", "os")
```

A
Annie_wang 已提交
247
### endsWith
A
Annie_wang 已提交
248 249 250

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

A
Annie_wang 已提交
251 252 253
Sets a **DataSharePredicates** object to match the data that ends with the specified value.

Currently, only the RDB supports this **DataSharePredicates** object.
A
Annie_wang 已提交
254 255 256 257 258 259 260 261

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

**Parameters**

| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| field  | string | Yes  | Column name in the database table.    |
A
Annie_wang 已提交
262
| value  | string | Yes  | End value to match.|
A
Annie_wang 已提交
263 264 265 266 267

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
268
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
269 270 271 272 273 274 275 276

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.endsWith("NAME", "os")
```

A
Annie_wang 已提交
277
### isNull
A
Annie_wang 已提交
278 279 280

isNull(field: string): DataSharePredicates

A
Annie_wang 已提交
281
Sets a **DataSharePredicates** object to match the data whose value is null.
A
Annie_wang 已提交
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296

Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.

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

**Parameters**

| Name| Type  | Mandatory| Description              |
| ------ | ------ | ---- | ------------------ |
| field  | string | Yes  | Column name in the database table.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
297
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
298 299 300 301 302 303 304 305

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.isNull("NAME")
```

A
Annie_wang 已提交
306
### isNotNull
A
Annie_wang 已提交
307 308 309

isNotNull(field: string): DataSharePredicates

A
Annie_wang 已提交
310
Sets a **DataSharePredicates** object to match the data whose value is not null.
A
Annie_wang 已提交
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325

Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.

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

**Parameters**

| Name| Type  | Mandatory| Description              |
| ------ | ------ | ---- | ------------------ |
| field  | string | Yes  | Column name in the database table.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
326
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
327 328 329 330 331 332 333 334

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.isNotNull("NAME")
```

A
Annie_wang 已提交
335
### like
A
Annie_wang 已提交
336 337 338

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

A
Annie_wang 已提交
339
Sets a **DataSharePredicates** object to match the data that is similar to the specified value.
A
Annie_wang 已提交
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355

Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.

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

**Parameters**

| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| field  | string | Yes  | Column name in the database table.    |
| value  | string | Yes  | Value to match.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
356
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
357 358 359 360 361 362 363 364

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.like("NAME", "%os%")
```

A
Annie_wang 已提交
365
### unlike
A
Annie_wang 已提交
366 367 368

unlike(field: string, value: string): DataSharePredicates

A
Annie_wang 已提交
369
Sets a **DataSharePredicates** object to match the data that is not not similar to the specified value.
A
Annie_wang 已提交
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385

Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.

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

**Parameters**

| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| field  | string | Yes  | Column name in the database table.    |
| value  | string | Yes  | Value to match.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
386
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
387 388 389 390 391 392 393 394

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.unlike("NAME", "%os%")
```

A
Annie_wang 已提交
395
### glob
A
Annie_wang 已提交
396 397 398

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

A
Annie_wang 已提交
399 400 401
Sets a **DataSharePredicates** object to match the specified string.

Currently, only the RDB supports this **DataSharePredicates** object.
A
Annie_wang 已提交
402 403 404 405 406 407 408 409 410 411 412 413 414 415

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

**Parameters**

| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| field  | string | Yes  | Column name in the database table.    |
| value  | string | Yes  | Value to match.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
416
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
417 418 419 420 421 422 423 424

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.glob("NAME", "?h*g")
```

A
Annie_wang 已提交
425
### between
A
Annie_wang 已提交
426 427 428

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

A
Annie_wang 已提交
429 430 431
Sets a **DataSharePredicates** object to match the data that is within the specified range.

Currently, only the RDB supports this **DataSharePredicates** object.
A
Annie_wang 已提交
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446

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

**Parameters**

| Name| Type                                               | Mandatory| Description                    |
| ------ | --------------------------------------------------- | ---- | ------------------------ |
| field  | string                                              | Yes  | Column name in the database table.      |
| low    | [ValueType](js-apis-data-ValuesBucket.md#valuetype) | Yes  | The lowest value of the range.|
| high   | [ValueType](js-apis-data-ValuesBucket.md#valuetype) | Yes  | The highest value of the range.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
447
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
448 449 450 451 452 453 454 455

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.between("AGE", 10, 50)
```

A
Annie_wang 已提交
456
### notBetween
A
Annie_wang 已提交
457 458 459

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

A
Annie_wang 已提交
460 461 462
Sets a **DataSharePredicates** object to match the data that is out of the specified range.

Currently, only the RDB supports this **DataSharePredicates** object.
A
Annie_wang 已提交
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477

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

**Parameters**

| Name| Type                                               | Mandatory| Description                    |
| ------ | --------------------------------------------------- | ---- | ------------------------ |
| field  | string                                              | Yes  | Column name in the database table.      |
| low    | [ValueType](js-apis-data-ValuesBucket.md#valuetype) | Yes  | The lowest value of the range.|
| high   | [ValueType](js-apis-data-ValuesBucket.md#valuetype) | Yes  | The highest value of the range.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
478
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
479 480 481 482 483 484 485 486

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.notBetween("AGE", 10, 50)
```

A
Annie_wang 已提交
487
### greaterThan
A
Annie_wang 已提交
488 489 490

greaterThan(field: string, value: ValueType): DataSharePredicates

A
Annie_wang 已提交
491
Sets a **DataSharePredicates** object to match the data that is greater than the specified value.
A
Annie_wang 已提交
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507

Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.

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

**Parameters**

| Name | Type     | Mandatory| Description                  |
| ------- | --------- | ---- | ---------------------- |
| field   | string    | Yes  | Column name in the database table.    |
| value | [ValueType](js-apis-data-ValuesBucket.md#valuetype) | Yes  | Value to match.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
508
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
509 510 511 512 513 514 515 516

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.greaterThan("AGE", 10)
```

A
Annie_wang 已提交
517
### lessThan
A
Annie_wang 已提交
518 519 520

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

A
Annie_wang 已提交
521
Sets a **DataSharePredicates** object to match the data that is less than the specified value.
A
Annie_wang 已提交
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537

Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.

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

**Parameters**

| Name| Type                                               | Mandatory| Description                  |
| ------ | --------------------------------------------------- | ---- | ---------------------- |
| field  | string                                              | Yes  | Column name in the database table.    |
| value  | [ValueType](js-apis-data-ValuesBucket.md#valuetype) | Yes  | Value to match.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
538
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
539 540 541 542 543 544 545 546

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.lessThan("AGE", 50)
```

A
Annie_wang 已提交
547
### greaterThanOrEqualTo
A
Annie_wang 已提交
548 549 550

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

A
Annie_wang 已提交
551
Sets a **DataSharePredicates** object to match the data that is greater than or equal to the specified value.
A
Annie_wang 已提交
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567

Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.

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

**Parameters**

| Name | Type     | Mandatory| Description                  |
| ------- | --------- | ---- | ---------------------- |
| field   | string    | Yes  | Column name in the database table.    |
| value | [ValueType](js-apis-data-ValuesBucket.md#valuetype) | Yes  | Value to match.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
568
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
569 570 571 572 573 574 575 576

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.greaterThanOrEqualTo("AGE", 10)
```

A
Annie_wang 已提交
577
### lessThanOrEqualTo
A
Annie_wang 已提交
578 579 580

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

A
Annie_wang 已提交
581
Sets a **DataSharePredicates** object to match the data that is less than or equal to the specified value.
A
Annie_wang 已提交
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597

Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.

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

**Parameters**

| Name | Type     | Mandatory| Description                  |
| ------- | --------- | ---- | ---------------------- |
| field   | string    | Yes  | Column name in the database table.    |
| value | [ValueType](js-apis-data-ValuesBucket.md#valuetype) | Yes  | Value to match.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
598
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
599 600 601 602 603 604 605 606

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.lessThanOrEqualTo("AGE", 50)
```

A
Annie_wang 已提交
607
### orderByAsc
A
Annie_wang 已提交
608 609 610

orderByAsc(field: string): DataSharePredicates

A
Annie_wang 已提交
611
Sets a **DataSharePredicates** object that sorts data in ascending order.
A
Annie_wang 已提交
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626

Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.

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

**Parameters**

| Name| Type  | Mandatory| Description              |
| ------ | ------ | ---- | ------------------ |
| field  | string | Yes  | Column name in the database table.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
627
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
628 629 630 631 632 633 634 635

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.orderByAsc("AGE")
```

A
Annie_wang 已提交
636
### orderByDesc
A
Annie_wang 已提交
637 638 639

orderByDesc(field: string): DataSharePredicates

A
Annie_wang 已提交
640
Sets a **DataSharePredicates** object that sorts data in descending order.
A
Annie_wang 已提交
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655

Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.

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

**Parameters**

| Name| Type  | Mandatory| Description              |
| ------ | ------ | ---- | ------------------ |
| field  | string | Yes  | Column name in the database table.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
656
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
657 658 659 660 661 662 663 664

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.orderByDesc("AGE")
```

A
Annie_wang 已提交
665
### distinct
A
Annie_wang 已提交
666 667 668

distinct(): DataSharePredicates

A
Annie_wang 已提交
669 670 671
Sets a **DataSharePredicates** object to filter out duplicate data records.

Currently, only the RDB supports this **DataSharePredicates** object.
A
Annie_wang 已提交
672 673 674 675 676 677 678

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

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
679
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
680 681 682 683 684 685 686 687

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "Rose").distinct()
```

A
Annie_wang 已提交
688
### limit
A
Annie_wang 已提交
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708

limit(total: number, offset: number): DataSharePredicates

Sets a **DataSharePredicates** object to specify the number of results and the start position.

Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.

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

**Parameters**

| Name  | Type  | Mandatory| Description          |
| -------- | ------ | ---- | -------------- |
| total    | number | Yes  | Number of results.  |
| offset | number | Yes  | Start position.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
709
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
710 711 712 713 714 715 716 717

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "Rose").limit(10, 3)
```

A
Annie_wang 已提交
718
### groupBy
A
Annie_wang 已提交
719 720 721

groupBy(fields: Array<string>): DataSharePredicates

A
Annie_wang 已提交
722 723 724
Sets a **DataSharePredicates** object group the records according to the specified fields.

Currently, only the RDB supports this **DataSharePredicates** object.
A
Annie_wang 已提交
725 726 727 728 729 730 731

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

**Parameters**

| Name| Type         | Mandatory| Description                |
| ------ | ------------- | ---- | -------------------- |
A
Annie_wang 已提交
732
| fields | Array<string> | Yes  | Names of the columns by which the records are grouped.|
A
Annie_wang 已提交
733 734 735 736 737

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
738
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
739 740 741 742 743 744 745 746

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.groupBy(["AGE", "NAME"])
```

A
Annie_wang 已提交
747
### indexedBy
A
Annie_wang 已提交
748 749 750

indexedBy(field: string): DataSharePredicates

A
Annie_wang 已提交
751 752 753
Sets a **DataSharePredicates** object to list data by the specified index.

Currently, only the RDB supports this **DataSharePredicates** object.
A
Annie_wang 已提交
754 755 756 757 758 759 760 761 762 763 764 765 766

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

**Parameters**

| Name| Type  | Mandatory| Description          |
| ------ | ------ | ---- | -------------- |
| field  | string | Yes  | Name of the index column.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
767
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
768 769 770 771 772 773 774 775

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.indexedBy("SALARY_INDEX")
```

A
Annie_wang 已提交
776
### in
A
Annie_wang 已提交
777 778 779

in(field: string, value: Array<ValueType>): DataSharePredicates

A
Annie_wang 已提交
780
Sets a **DataSharePredicates** object to match the data that is within the specified value.
A
Annie_wang 已提交
781 782 783 784 785 786 787 788 789 790

Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.

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

**Parameters**

| Name | Type            | Mandatory| Description                                   |
| ------- | ---------------- | ---- | --------------------------------------- |
| field   | string           | Yes| Column name in the database table.                     |
A
Annie_wang 已提交
791
| value | Array<[ValueType](js-apis-data-ValuesBucket.md#valuetype)> | Yes  | Array of the values to match.|
A
Annie_wang 已提交
792 793 794 795 796

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
797
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
798 799 800 801 802 803 804 805

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.in("AGE", [18, 20])
```

A
Annie_wang 已提交
806
### notIn
A
Annie_wang 已提交
807 808 809

notIn(field: string, value: Array<ValueType>): DataSharePredicates

A
Annie_wang 已提交
810
Sets a **DataSharePredicates** object to match the data that is not in the specified value.
A
Annie_wang 已提交
811 812 813 814 815 816 817 818 819 820

Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.

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

**Parameters**

| Name | Type            | Mandatory| Description                                   |
| ------- | ---------------- | ---- | --------------------------------------- |
| field   | string           | Yes  | Column name in the database table.                     |
A
Annie_wang 已提交
821
| value | Array<[ValueType](js-apis-data-ValuesBucket.md#valuetype)> | Yes  | Array of the values to match.|
A
Annie_wang 已提交
822 823 824 825 826

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
827
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
828 829 830 831 832 833 834 835

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.notIn("NAME", ["Lisa", "Rose"])
```

A
Annie_wang 已提交
836
### prefixKey
A
Annie_wang 已提交
837 838 839

prefixKey(prefix: string): DataSharePredicates

A
Annie_wang 已提交
840 841 842
Sets a **DataSharePredicates** object to match the data with the specified key prefix.

Currently, only the KVDB supports this **DataSharePredicates** object.
A
Annie_wang 已提交
843 844 845 846 847 848 849 850 851 852 853 854 855

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

**Parameters**

| Name| Type  | Mandatory| Description          |
| ------ | ------ | ---- | -------------- |
| prefix | string | Yes  | Key prefix to match.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
856
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
857 858 859 860 861 862 863 864

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.prefixKey("NAME")
```

A
Annie_wang 已提交
865
### inKeys
A
Annie_wang 已提交
866 867 868

inKeys(keys: Array<string>): DataSharePredicates

A
Annie_wang 已提交
869 870 871
Sets a **DataSharePredicates** object to match the data whose keys are within the given range.

Currently, only the KVDB supports this **DataSharePredicates** object.
A
Annie_wang 已提交
872 873 874 875 876 877 878 879 880 881 882 883 884

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

**Parameters**

| Name| Type         | Mandatory| Description              |
| ------ | ------------- | ---- | ------------------ |
| inKeys | Array<string> | Yes  | Array of the keys to match.|

**Return value**

| Type                                       | Description                      |
| ------------------------------------------- | -------------------------- |
A
Annie_wang 已提交
885
| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.|
A
Annie_wang 已提交
886 887 888 889 890 891 892

**Example**

```ts
let predicates = new dataSharePredicates.DataSharePredicates()
predicates.inKeys(["Lisa", "Rose"])
```