1/* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { AsyncCallback } from './@ohos.base'; 17import rdb from './@ohos.data.rdb'; 18 19/** 20 * Provides predicates for implementing diverse query methods. 21 * 22 * @namespace dataAbility 23 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 24 * @since 7 25 */ 26declare namespace dataAbility { 27 /** 28 * Create an RdbPredicates by table name and DataAbilityPredicates. 29 * This method is similar to = of the SQL statement. 30 * 31 * @param { string } name - Indicates the table name. 32 * @param { DataAbilityPredicates } dataAbilityPredicates - Indicates the dataAbility predicates. 33 * @returns { rdb.RdbPredicates } Returns an RdbPredicates. 34 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 35 * @since 7 36 */ 37 function createRdbPredicates(name: string, dataAbilityPredicates: DataAbilityPredicates): rdb.RdbPredicates; 38 39 /** 40 * Manages relational database configurations. 41 * 42 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 43 * @since 7 44 */ 45 class DataAbilityPredicates { 46 /** 47 * Configure the DataAbilityPredicates to match the field whose data type is ValueType and value is equal 48 * to a specified value. 49 * This method is similar to = of the SQL statement. 50 * 51 * @param { string } field - Indicates the column name in the database table. 52 * @param { ValueType } value - Indicates the value to match with the DataAbilityPredicates. 53 * @returns { DataAbilityPredicates } Returns the DataAbilityPredicates that match the specified field. 54 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 55 * @since 7 56 */ 57 equalTo(field: string, value: ValueType): DataAbilityPredicates; 58 59 /** 60 * Configure the DataAbilityPredicates to match the field whose data type is ValueType and value is unequal to 61 * a specified value. 62 * Configure the data capability predicate to match a field where the data type is a value type and the value is 63 * not equal to the specified value. 64 * This method is similar to != of the SQL statement. 65 * 66 * @param { string } field - Indicates the column name in the database table. 67 * @param { ValueType } value - Indicates the value to match with the DataAbilityPredicates. 68 * @returns { DataAbilityPredicates } Returns the DataAbilityPredicates that match the specified field. 69 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 70 * @since 7 71 */ 72 notEqualTo(field: string, value: ValueType): DataAbilityPredicates; 73 74 /** 75 * Adds a left parenthesis to the DataAbilityPredicates. 76 * This method is similar to ( of the SQL statement and needs to be used together with endWrap(). 77 * 78 * @returns { DataAbilityPredicates } Returns the DataAbilityPredicates with the left parenthesis. 79 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 80 * @since 7 81 */ 82 beginWrap(): DataAbilityPredicates; 83 84 /** 85 * Adds a right parenthesis to the DataAbilityPredicates. 86 * This method is similar to ) of the SQL statement and needs to be used together 87 * with beginWrap(). 88 * 89 * @returns { DataAbilityPredicates } Returns the DataAbilityPredicates with the right parenthesis. 90 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 91 * @since 7 92 */ 93 endWrap(): DataAbilityPredicates; 94 95 /** 96 * Adds an or condition to the DataAbilityPredicates. 97 * This method is similar to or of the SQL statement. 98 * 99 * @returns { DataAbilityPredicates } Returns the DataAbilityPredicates with the or condition. 100 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 101 * @since 7 102 */ 103 or(): DataAbilityPredicates; 104 105 /** 106 * Adds an and condition to the DataAbilityPredicates. 107 * This method is similar to and of the SQL statement. 108 * 109 * @returns { DataAbilityPredicates } Returns the DataAbilityPredicates with the and condition. 110 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 111 * @since 7 112 */ 113 and(): DataAbilityPredicates; 114 115 /** 116 * Configure the DataAbilityPredicates to match the field whose data type is string and value 117 * contains a specified value. 118 * This method is similar to contains of the SQL statement. 119 * 120 * @param { string } field - Indicates the column name in the database table. 121 * @param { string } value - Indicates the value to match with the DataAbilityPredicates. 122 * @returns { DataAbilityPredicates } Returns the DataAbilityPredicates that match the specified field. 123 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 124 * @since 7 125 */ 126 contains(field: string, value: string): DataAbilityPredicates; 127 128 /** 129 * Configure the DataAbilityPredicates to match the field whose data type is string and value starts 130 * with a specified string. 131 * This method is similar to value% of the SQL statement. 132 * 133 * @param { string } field - Indicates the column name in the database table. 134 * @param { string } value - Indicates the value to match with the DataAbilityPredicates. 135 * @returns { DataAbilityPredicates } Returns the DataAbilityPredicates that match the specified field. 136 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 137 * @since 7 138 */ 139 beginsWith(field: string, value: string): DataAbilityPredicates; 140 141 /** 142 * Configure the DataAbilityPredicates to match the field whose data type is string and value 143 * ends with a specified string. 144 * This method is similar to %value of the SQL statement. 145 * 146 * @param { string } field - Indicates the column name in the database table. 147 * @param { string } value - Indicates the value to match with the DataAbilityPredicates. 148 * @returns { DataAbilityPredicates } Returns the DataAbilityPredicates that match the specified field. 149 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 150 * @since 7 151 */ 152 endsWith(field: string, value: string): DataAbilityPredicates; 153 154 /** 155 * Configure the DataAbilityPredicates to match the fields whose value is null. 156 * This method is similar to is null of the SQL statement. 157 * 158 * @param { string } field - Indicates the column name in the database table. 159 * @returns { DataAbilityPredicates } Returns the DataAbilityPredicates that match the specified field. 160 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 161 * @since 7 162 */ 163 isNull(field: string): DataAbilityPredicates; 164 165 /** 166 * Configure the DataAbilityPredicates to match the specified fields whose value is not null. 167 * This method is similar to is not null of the SQL statement. 168 * 169 * @param { string } field - Indicates the column name in the database table. 170 * @returns { DataAbilityPredicates } Returns the DataAbilityPredicates that match the specified field. 171 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 172 * @since 7 173 */ 174 isNotNull(field: string): DataAbilityPredicates; 175 176 /** 177 * Configure the DataAbilityPredicates to match the fields whose data type is string and value is 178 * similar to a specified string. 179 * This method is similar to like of the SQL statement. 180 * 181 * @param { string } field - Indicates the column name in the database table. 182 * @param { string } value - Indicates the value to match with the DataAbilityPredicates. The percent sign (%) 183 * in the value is a wildcard (like * in a regular expression). 184 * @returns { DataAbilityPredicates } Returns the DataAbilityPredicates that match the specified field. 185 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 186 * @since 7 187 */ 188 like(field: string, value: string): DataAbilityPredicates; 189 190 /** 191 * Configure DataAbilityPredicates to match the specified field whose data type is string and the value contains 192 * a wildcard.Different from like, the input parameters of this method are case-sensitive. 193 * 194 * @param { string } field - Indicates the column name in the database table. 195 * @param { string } value - Indicates the value to match with DataAbilityPredicates. 196 * @returns { DataAbilityPredicates } Returns the SQL statement with the specified DataAbilityPredicates. 197 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 198 * @since 7 199 */ 200 glob(field: string, value: string): DataAbilityPredicates; 201 202 /** 203 * Restricts the value of the field to the range between low value and high value. 204 * 205 * @param { string } field - Indicates the column name. 206 * @param { ValueType } low - Indicates the minimum value. 207 * @param { ValueType } high - Indicates the maximum value. 208 * @returns { DataAbilityPredicates } Returns the SQL query statement with the specified DataAbilityPredicates. 209 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 210 * @since 7 211 */ 212 between(field: string, low: ValueType, high: ValueType): DataAbilityPredicates; 213 214 /** 215 * Configure DataAbilityPredicates to match the specified field whose data type is int and value is 216 * out of a given range. 217 * 218 * @param { string } field - Indicates the column name in the database table. 219 * @param { ValueType } low - Indicates the minimum value to match with DataAbilityPredicates}. 220 * @param { ValueType } high - Indicates the maximum value to match with DataAbilityPredicates}. 221 * @returns { DataAbilityPredicates } Returns the SQL query statement with the specified DataAbilityPredicates. 222 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 223 * @since 7 224 */ 225 notBetween(field: string, low: ValueType, high: ValueType): DataAbilityPredicates; 226 227 /** 228 * Restricts the value of the field to be greater than the specified value. 229 * 230 * @param { string } field - Indicates the column name. 231 * @param { ValueType } value - Indicates the String field. 232 * @returns { DataAbilityPredicates } Returns the SQL query statement with the specified DataAbilityPredicates. 233 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 234 * @since 7 235 */ 236 greaterThan(field: string, value: ValueType): DataAbilityPredicates; 237 238 /** 239 * Restricts the value of the field to be smaller than the specified value. 240 * 241 * @param { string } field - Indicates the column name. 242 * @param { ValueType } value - Indicates the String field. 243 * @returns { DataAbilityPredicates } Returns the SQL query statement with the specified DataAbilityPredicates. 244 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 245 * @since 7 246 */ 247 lessThan(field: string, value: ValueType): DataAbilityPredicates; 248 249 /** 250 * Restricts the value of the field to be greater than or equal to the specified value. 251 * 252 * @param { string } field - Indicates the column name. 253 * @param { ValueType } value - Indicates the String field. 254 * @returns { DataAbilityPredicates } Returns the SQL query statement with the specified DataAbilityPredicates. 255 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 256 * @since 7 257 */ 258 greaterThanOrEqualTo(field: string, value: ValueType): DataAbilityPredicates; 259 260 /** 261 * Restricts the value of the field to be smaller than or equal to the specified value. 262 * 263 * @param { string } field - Indicates the column name. 264 * @param { ValueType } value - Indicates the String field. 265 * @returns { DataAbilityPredicates } Returns the SQL query statement with the specified DataAbilityPredicates. 266 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 267 * @since 7 268 */ 269 lessThanOrEqualTo(field: string, value: ValueType): DataAbilityPredicates; 270 271 /** 272 * Restricts the ascending order of the return list. When there are several orders, 273 * the one close to the head has the highest priority. 274 * 275 * @param { string } field - Indicates the column name for sorting the return list. 276 * @returns { DataAbilityPredicates } Returns the SQL query statement with the specified DataAbilityPredicates. 277 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 278 * @since 7 279 */ 280 orderByAsc(field: string): DataAbilityPredicates; 281 282 /** 283 * Restricts the descending order of the return list. When there are several orders, 284 * the one close to the head has the highest priority. 285 * 286 * @param { string } field - Indicates the column name for sorting the return list. 287 * @returns { DataAbilityPredicates } Returns the SQL query statement with the specified DataAbilityPredicates. 288 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 289 * @since 7 290 */ 291 orderByDesc(field: string): DataAbilityPredicates; 292 293 /** 294 * Restricts each row of the query result to be unique. 295 * 296 * @returns { DataAbilityPredicates } Returns the SQL query statement with the specified DataAbilityPredicates. 297 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 298 * @since 7 299 */ 300 distinct(): DataAbilityPredicates; 301 302 /** 303 * Restricts the max number of return records. 304 * 305 * @param { number } value - Indicates the max length of the return list. 306 * @returns { DataAbilityPredicates } Returns the SQL query statement with the specified DataAbilityPredicates. 307 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 308 * @since 7 309 */ 310 limitAs(value: number): DataAbilityPredicates; 311 312 /** 313 * Configure DataAbilityPredicates to specify the start position of the returned result. 314 * Use this method together with limit(int). 315 * 316 * @param { number } rowOffset - Indicates the start position of the returned result. The value is a positive integer. 317 * @returns { DataAbilityPredicates } Returns the SQL query statement with the specified AbsPredicates. 318 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 319 * @since 7 320 */ 321 offsetAs(rowOffset: number): DataAbilityPredicates; 322 323 /** 324 * Configure DataAbilityPredicates to group query results by specified columns. 325 * 326 * @param { Array<string> } fields - Indicates the specified columns by which query results are grouped. 327 * @returns { DataAbilityPredicates } Returns the DataAbilityPredicates with the specified columns by which query 328 * results are grouped. 329 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 330 * @since 7 331 */ 332 groupBy(fields: Array<string>): DataAbilityPredicates; 333 334 /** 335 * Configure DataAbilityPredicates to specify the index column. 336 * Before using this method, you need to create an index column. 337 * 338 * @param { string } field - Indicates the name of the index column. 339 * @returns { DataAbilityPredicates } Returns DataAbilityPredicates with the specified index column. 340 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 341 * @since 7 342 */ 343 indexedBy(field: string): DataAbilityPredicates; 344 345 /** 346 * Configure DataAbilityPredicates to match the specified field whose data type is ValueType array and values 347 * are within a given range. 348 * 349 * @param { string } field - Indicates the column name in the database table. 350 * @param { Array<ValueType> } value - Indicates the values to match with DataAbilityPredicates. 351 * @returns { DataAbilityPredicates } Returns DataAbilityPredicates that matches the specified field. 352 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 353 * @since 7 354 */ 355 in(field: string, value: Array<ValueType>): DataAbilityPredicates; 356 357 /** 358 * Configure {@code DataAbilityPredicates} to match the specified field whose data type is String array and values 359 * are out of a given range. 360 * 361 * @param { string } field - Indicates the column name in the database table. 362 * @param { Array<ValueType> } value - Indicates the values to match with DataAbilityPredicates. 363 * @returns { DataAbilityPredicates } Returns DataAbilityPredicates that matches the specified field. 364 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 365 * @since 7 366 */ 367 notIn(field: string, value: Array<ValueType>): DataAbilityPredicates; 368 } 369 /** 370 * Indicates possible value types 371 * 372 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 373 * @since 7 374 */ 375 type ValueType = number | string | boolean; 376} 377 378export default dataAbility; 379