• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2022 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 { ValueType } from './@ohos.data.ValuesBucket';
17
18/**
19 *
20 * This module provides data share services based on the ExtensionAbility.
21 *
22 * @namespace dataSharePredicates
23 * @since 9
24 * @syscap SystemCapability.DistributedDataManager.DataShare.Core
25 * @systemapi
26 * @StageModelOnly
27 */
28declare namespace dataSharePredicates {
29    /**
30     * Manages relational database configurations.
31     *
32     * @since 9
33     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
34     * @systemapi
35     * @StageModelOnly
36     */
37    class DataSharePredicates {
38    /**
39     * Configure the DataSharePredicates to match the field whose data type is ValueType and value is equal
40     * to a specified value.
41     * This method is similar to = of the SQL statement.
42     *
43     * @since 9
44     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
45     * @systemapi
46     * @StageModelOnly
47     * @param field Indicates the column name in the database table.
48     * @param value Indicates the value to match with the DataSharePredicates.
49     * @returns Returns the DataSharePredicates that match the specified field.
50     */
51    equalTo(field: string, value: ValueType): DataSharePredicates;
52
53    /**
54     * Configure the DataSharePredicates to match the field whose data type is ValueType and value is unequal to
55     * a specified value.
56     * This method is similar to != of the SQL statement.
57     *
58     * @since 9
59     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
60     * @systemapi
61     * @StageModelOnly
62     * @param field Indicates the column name in the database table.
63     * @param value Indicates the value to match with the DataSharePredicates.
64     * @returns Returns the DataSharePredicates that match the specified field.
65     */
66    notEqualTo(field: string, value: ValueType): DataSharePredicates;
67
68    /**
69     * Adds a left parenthesis to the DataSharePredicates.
70     * This method is similar to ( of the SQL statement and needs to be used together with endWrap().
71     *
72     * @since 9
73     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
74     * @systemapi
75     * @StageModelOnly
76     * @returns Returns the DataSharePredicates with the left parenthesis.
77     */
78    beginWrap(): DataSharePredicates;
79
80    /**
81     * Adds a right parenthesis to the DataSharePredicates.
82     * This method is similar to ) of the SQL statement and needs to be used together
83     *
84     * with beginWrap().
85     * @since 9
86     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
87     * @systemapi
88     * @StageModelOnly
89     * @returns Returns the DataSharePredicates with the right parenthesis.
90     */
91    endWrap(): DataSharePredicates;
92
93    /**
94     * Adds an or condition to the DataSharePredicates.
95     * This method is similar to or of the SQL statement.
96     *
97     * @since 9
98     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
99     * @systemapi
100     * @StageModelOnly
101     * @returns Returns the DataSharePredicates with the or condition.
102     */
103    or(): DataSharePredicates;
104
105    /**
106     * Adds an and condition to the DataSharePredicates.
107     * This method is similar to and of the SQL statement.
108     *
109     * @since 9
110     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
111     * @systemapi
112     * @StageModelOnly
113     * @returns Returns the DataSharePredicates with the and condition.
114     */
115    and(): DataSharePredicates;
116
117    /**
118     * Configure the DataSharePredicates to match the field whose data type is string and value
119     * contains a specified value.
120     * This method is similar to contains of the SQL statement.
121     *
122     * @since 9
123     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
124     * @systemapi
125     * @StageModelOnly
126     * @param field Indicates the column name in the database table.
127     * @param value Indicates the value to match with the DataSharePredicates.
128     * @returns Returns the DataSharePredicates that match the specified field.
129     */
130    contains(field: string, value: string): DataSharePredicates;
131
132    /**
133     * Configure the DataSharePredicates to match the field whose data type is string and value starts
134     * with a specified string.
135     * This method is similar to value% of the SQL statement.
136     *
137     * @since 9
138     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
139     * @systemapi
140     * @StageModelOnly
141     * @param field Indicates the column name in the database table.
142     * @param value Indicates the value to match with the DataSharePredicates.
143     * @returns Returns the DataSharePredicates that match the specified field.
144     */
145    beginsWith(field: string, value: string): DataSharePredicates;
146
147    /**
148     * Configure the DataSharePredicates to match the field whose data type is string and value
149     * ends with a specified string.
150     * This method is similar to %value of the SQL statement.
151     *
152     * @since 9
153     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
154     * @systemapi
155     * @StageModelOnly
156     * @param field Indicates the column name in the database table.
157     * @param value Indicates the value to match with the DataSharePredicates.
158     * @returns Returns the DataSharePredicates that match the specified field.
159     */
160    endsWith(field: string, value: string): DataSharePredicates;
161
162    /**
163     * Configure the DataSharePredicates to match the fields whose value is null.
164     * This method is similar to is null of the SQL statement.
165     *
166     * @since 9
167     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
168     * @systemapi
169     * @StageModelOnly
170     * @param field Indicates the column name in the database table.
171     * @returns Returns the DataSharePredicates that match the specified field.
172     */
173    isNull(field: string): DataSharePredicates;
174
175    /**
176     * Configure the DataSharePredicates to match the specified fields whose value is not null.
177     * This method is similar to is not null of the SQL statement.
178     *
179     * @since 9
180     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
181     * @systemapi
182     * @StageModelOnly
183     * @param field Indicates the column name in the database table.
184     * @returns Returns the DataSharePredicates that match the specified field.
185     */
186    isNotNull(field: string): DataSharePredicates;
187
188    /**
189     * Configure the DataSharePredicates to match the fields whose data type is string and value is
190     * similar to a specified string.
191     * This method is similar to like of the SQL statement.
192     *
193     * @since 9
194     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
195     * @systemapi
196     * @StageModelOnly
197     * @param field Indicates the column name in the database table.
198     * @param value Indicates the value to match with the DataSharePredicates. The percent sign (%) in the value
199     * is a wildcard (like * in a regular expression).
200     * @returns Returns the DataSharePredicates that match the specified field.
201     */
202    like(field: string, value: string): DataSharePredicates;
203
204    /**
205     * Configure the DataSharePredicates to match the fields whose data type is string and value is
206     * similar to a specified string.
207     * This method is similar to unlike of the SQL statement.
208     *
209     * @since 9
210     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
211     * @systemapi
212     * @StageModelOnly
213     * @param field Indicates the column name in the database table.
214     * @param value Indicates the value to match with the DataSharePredicates. The percent sign (%) in the value
215     * is a wildcard (like * in a regular expression).
216     * @returns Returns the DataSharePredicates that match the specified field.
217     */
218     unlike(field: string, value: string): DataSharePredicates;
219
220    /**
221     * Configure DataSharePredicates to match the specified field whose data type is string and the value contains
222     * a wildcard.
223     * Different from like, the input parameters of this method are case-sensitive.
224     *
225     * @since 9
226     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
227     * @systemapi
228     * @StageModelOnly
229     * @param field Indicates the column name in the database table.
230     * @param value Indicates the value to match with DataSharePredicates.
231     * @returns Returns the SQL statement with the specified DataSharePredicates.
232     */
233    glob(field: string, value: string): DataSharePredicates;
234
235    /**
236     * Restricts the value of the field to the range between low value and high value.
237     *
238     * @since 9
239     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
240     * @systemapi
241     * @StageModelOnly
242     * @param field Indicates the column name.
243     * @param low Indicates the minimum value.
244     * @param high Indicates the maximum value.
245     * @returns Returns the SQL query statement with the specified DataSharePredicates.
246     */
247    between(field: string, low: ValueType, high: ValueType): DataSharePredicates;
248
249    /**
250     * Configure DataSharePredicates to match the specified field whose data type is int and value is
251     * out of a given range.
252     *
253     * @since 9
254     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
255     * @systemapi
256     * @StageModelOnly
257     * @param field Indicates the column name in the database table.
258     * @param low Indicates the minimum value to match with DataSharePredicates.
259     * @param high Indicates the maximum value to match with DataSharePredicates.
260     * @returns Returns the SQL query statement with the specified DataSharePredicates.
261     */
262    notBetween(field: string, low: ValueType, high: ValueType): DataSharePredicates;
263
264    /**
265     * Restricts the value of the field to be greater than the specified value.
266     *
267     * @since 9
268     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
269     * @systemapi
270     * @StageModelOnly
271     * @param field Indicates the column name.
272     * @param value Indicates the String field.
273     * @returns Returns the SQL query statement with the specified DataSharePredicates.
274     */
275    greaterThan(field: string, value: ValueType): DataSharePredicates;
276
277    /**
278     * Restricts the value of the field to be smaller than the specified value.
279     *
280     * @since 9
281     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
282     * @systemapi
283     * @StageModelOnly
284     * @param field Indicates the column name.
285     * @param value Indicates the String field.
286     * @returns Returns the SQL query statement with the specified DataSharePredicates.
287     */
288    lessThan(field: string, value: ValueType): DataSharePredicates;
289
290    /**
291     * Restricts the value of the field to be greater than or equal to the specified value.
292     *
293     * @since 9
294     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
295     * @systemapi
296     * @StageModelOnly
297     * @param field Indicates the column name.
298     * @param value Indicates the String field.
299     * @returns Returns the SQL query statement with the specified DataSharePredicates.
300     */
301    greaterThanOrEqualTo(field: string, value: ValueType): DataSharePredicates;
302
303    /**
304     * Restricts the value of the field to be smaller than or equal to the specified value.
305     *
306     * @since 9
307     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
308     * @systemapi
309     * @StageModelOnly
310     * @param field Indicates the column name.
311     * @param value Indicates the String field.
312     * @returns Returns the SQL query statement with the specified DataSharePredicates.
313     */
314    lessThanOrEqualTo(field: string, value: ValueType): DataSharePredicates;
315
316    /**
317     * Restricts the ascending order of the return list. When there are several orders,
318     * the one close to the head has the highest priority.
319     *
320     * @since 9
321     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
322     * @systemapi
323     * @StageModelOnly
324     * @param field Indicates the column name for sorting the return list.
325     * @returns Returns the SQL query statement with the specified DataSharePredicates.
326     */
327    orderByAsc(field: string): DataSharePredicates;
328
329    /**
330     * Restricts the descending order of the return list. When there are several orders,
331     * the one close to the head has the highest priority.
332     *
333     * @since 9
334     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
335     * @systemapi
336     * @StageModelOnly
337     * @param field Indicates the column name for sorting the return list.
338     * @returns Returns the SQL query statement with the specified DataSharePredicates.
339     */
340    orderByDesc(field: string): DataSharePredicates;
341
342    /**
343     * Restricts each row of the query result to be unique.
344     *
345     * @since 9
346     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
347     * @systemapi
348     * @StageModelOnly
349     * @returns Returns the SQL query statement with the specified DataSharePredicates.
350     */
351    distinct(): DataSharePredicates;
352
353    /**
354     * Construct a query object to specify the number of results and the starting position.
355     *
356     * @since 9
357     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
358     * @systemapi
359     * @StageModelOnly
360     * @param total Represents the specified number of results.
361     * @param offset Indicates the starting position.
362     * @returns Returns the query object.
363     */
364    limit(total: number, offset: number): DataSharePredicates;
365
366    /**
367     * Configure {@code DataSharePredicates} to group query results by specified columns.
368     *
369     * @since 9
370     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
371     * @systemapi
372     * @StageModelOnly
373     * @param fields Indicates the specified columns by which query results are grouped.
374     * @returns Returns the DataSharePredicates with the specified columns by which query results are grouped.
375     */
376    groupBy(fields: Array<string>): DataSharePredicates;
377
378    /**
379     * Configure {@code DataSharePredicates} to specify the index column.
380     * Before using this method, you need to create an index column.
381     *
382     * @since 9
383     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
384     * @systemapi
385     * @StageModelOnly
386     * @param field Indicates the name of the index column.
387     * @returns Returns DataSharePredicates with the specified index column.
388     */
389    indexedBy(field: string): DataSharePredicates;
390
391    /**
392     * Configure {@code DataSharePredicates} to match the specified field whose data type is ValueType array and values
393     * are within a given range.
394     *
395     * @since 9
396     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
397     * @systemapi
398     * @StageModelOnly
399     * @param field Indicates the column name in the database table.
400     * @param values Indicates the values to match with DataSharePredicates.
401     * @returns Returns DataSharePredicates that matches the specified field.
402     */
403    in(field: string, value: Array<ValueType>): DataSharePredicates;
404
405    /**
406     * Configure {@code DataSharePredicates} to match the specified field whose data type is String array and values
407     * are out of a given range.
408     *
409     * @since 9
410     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
411     * @systemapi
412     * @StageModelOnly
413     * @param field Indicates the column name in the database table.
414     * @param values Indicates the values to match with DataSharePredicates.
415     * @returns Returns DataSharePredicates that matches the specified field.
416     */
417    notIn(field: string, value: Array<ValueType>): DataSharePredicates;
418
419    /**
420     * Configure {@code DataSharePredicates} Creates a query condition using the specified key prefix.
421     *
422     * @since 9
423     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
424     * @systemapi
425     * @StageModelOnly
426     * @param prefix Represents the specified key prefix.
427     * @returns Returns the query object.
428     */
429    prefixKey(prefix: string): DataSharePredicates;
430
431    /**
432     * Configure {@code DataSharePredicates} to match the specified value whose key is within a given range.
433     *
434     * @since 9
435     * @syscap SystemCapability.DistributedDataManager.DataShare.Core
436     * @systemapi
437     * @StageModelOnly
438     * @param keys Represents the key names.
439     * @returns Returns the query object.
440     */
441    inKeys(keys: Array<string>): DataSharePredicates;
442    }
443}
444
445export default dataSharePredicates;