1# @ohos.data.dataSharePredicates (DataShare Predicates) 2 3**DataSharePredicates** provides a filter object to query data in a database by using **DataShare** APIs. It is often used to update, delete, and query data. 4 5The APIs provided by **DataSharePredicates** correspond to the filter criteria of the database. Before using the APIs, you need to have basic database knowledge. 6 7> **NOTE** 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. 10> 11> - The APIs of this module can be used only in the stage model. 12 13 14 15## Modules to Import 16 17```ts 18import { dataSharePredicates } from '@kit.ArkData'; 19``` 20 21## DataSharePredicates 22Provides methods for setting different **DataSharePredicates** objects. This type is not multi-thread safe. If a **DataSharePredicates** instance is operated by multiple threads at the same time in an application, use a lock for the instance. 23 24### equalTo<sup>10+</sup> 25 26equalTo(field: string, value: ValueType): DataSharePredicates 27 28Sets a **DataSharePredicates** object to match the data that is equal to the specified value. 29 30Currently, only the relational database (RDB) and key-value database (KVDB, schema) support this **DataSharePredicates** object. 31 32**System capability**: SystemCapability.DistributedDataManager.DataShare.Core 33 34**Parameters** 35 36| Name| Type | Mandatory| Description | 37| ------ | --------------------------------------------------- | ---- | ---------------------- | 38| field | string | Yes | Column name in the database table. | 39| value | [ValueType](js-apis-data-valuesBucket.md#valuetype) | Yes | Value to match.| 40 41**Return value** 42 43| Type | Description | 44| ------------------------------------------- | -------------------------- | 45| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.| 46 47**Example** 48 49```ts 50let predicates = new dataSharePredicates.DataSharePredicates() 51predicates.equalTo("NAME", "Rose") 52``` 53 54 55### and<sup>10+</sup> 56 57and(): DataSharePredicates 58 59Adds the AND condition to this **DataSharePredicates** object. 60 61Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object. 62 63**System capability**: SystemCapability.DistributedDataManager.DataShare.Core 64 65**Return value** 66 67| Type | Description | 68| ------------------------------------------- | ---------------------- | 69| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object with the AND condition.| 70 71**Example** 72 73```ts 74let predicates = new dataSharePredicates.DataSharePredicates() 75predicates.equalTo("NAME", "lisi") 76 .and() 77 .equalTo("SALARY", 200.5) 78``` 79 80### orderByAsc<sup>10+</sup> 81 82orderByAsc(field: string): DataSharePredicates 83 84Sets a **DataSharePredicates** object that sorts data in ascending order. 85 86Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object. 87 88**System capability**: SystemCapability.DistributedDataManager.DataShare.Core 89 90**Parameters** 91 92| Name| Type | Mandatory| Description | 93| ------ | ------ | ---- | ------------------ | 94| field | string | Yes | Column name in the database table.| 95 96**Return value** 97 98| Type | Description | 99| ------------------------------------------- | -------------------------- | 100| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.| 101 102**Example** 103 104```ts 105let predicates = new dataSharePredicates.DataSharePredicates() 106predicates.orderByAsc("AGE") 107``` 108 109### orderByDesc<sup>10+</sup> 110 111orderByDesc(field: string): DataSharePredicates 112 113Sets a **DataSharePredicates** object that sorts data in descending order. 114 115Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object. 116 117**System capability**: SystemCapability.DistributedDataManager.DataShare.Core 118 119**Parameters** 120 121| Name| Type | Mandatory| Description | 122| ------ | ------ | ---- | ------------------ | 123| field | string | Yes | Column name in the database table.| 124 125**Return value** 126 127| Type | Description | 128| ------------------------------------------- | -------------------------- | 129| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.| 130 131**Example** 132 133```ts 134let predicates = new dataSharePredicates.DataSharePredicates() 135predicates.orderByDesc("AGE") 136``` 137 138### limit<sup>10+</sup> 139 140limit(total: number, offset: number): DataSharePredicates 141 142Sets a **DataSharePredicates** object to specify the number of results and the start position. 143 144Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object. 145 146**System capability**: SystemCapability.DistributedDataManager.DataShare.Core 147 148**Parameters** 149 150| Name | Type | Mandatory| Description | 151| -------- | ------ | ---- | -------------- | 152| total | number | Yes | Number of results. | 153| offset | number | Yes | Start position.| 154 155**Return value** 156 157| Type | Description | 158| ------------------------------------------- | -------------------------- | 159| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.| 160 161**Example** 162 163```ts 164let predicates = new dataSharePredicates.DataSharePredicates() 165predicates.equalTo("NAME", "Rose").limit(10, 3) 166``` 167 168### in<sup>10+</sup> 169 170in(field: string, value: Array<ValueType>): DataSharePredicates 171 172Sets a **DataSharePredicates** object to match the data that is within the specified value. 173 174Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object. 175 176**System capability**: SystemCapability.DistributedDataManager.DataShare.Core 177 178**Parameters** 179 180| Name | Type | Mandatory| Description | 181| ------- | ---------------- | ---- | --------------------------------------- | 182| field | string | Yes| Column name in the database table. | 183| value | Array<[ValueType](js-apis-data-valuesBucket.md#valuetype)> | Yes | Array of the values to match.| 184 185**Return value** 186 187| Type | Description | 188| ------------------------------------------- | -------------------------- | 189| [DataSharePredicates](#datasharepredicates) | **DataSharePredicates** object created.| 190 191**Example** 192 193```ts 194let predicates = new dataSharePredicates.DataSharePredicates() 195predicates.in("AGE", [18, 20]) 196``` 197