1
1
part of {{ language .params .packageName }};
2
2
3
+ /// Helper class to generate query strings.
3
4
class Query {
4
- Query._();
5
-
5
+ Query._();
6
+
7
+ /// Filter resources where [attribute] is equal to [value].
8
+ ///
9
+ /// [value] can be a single value or a list. If a list is used
10
+ /// the query will return resources where [attribute] is equal
11
+ /// to any of the values in the list.
6
12
static String equal(String attribute, dynamic value) =>
7
13
_addQuery(attribute, 'equal', value);
8
14
15
+ /// Filter resources where [attribute] is not equal to [value].
16
+ ///
17
+ /// [value] can be a single value or a list. If a list is used
18
+ /// the query will return resources where [attribute] is equal
19
+ /// to any of the values in the list.
9
20
static String notEqual(String attribute, dynamic value) =>
10
21
_addQuery(attribute, 'notEqual', value);
11
22
23
+ /// Filter resources where [attribute] is less than [value].
24
+ ///
25
+ /// [value] can be a single value or a list. If a list is used
26
+ /// the query will return resources where [attribute] is equal
27
+ /// to any of the values in the list.
12
28
static String lessThan(String attribute, dynamic value) =>
13
29
_addQuery(attribute, 'lessThan', value);
14
30
31
+ /// Filter resources where [attribute] is less than or equal to [value].
32
+ ///
33
+ /// [value] can be a single value or a list. If a list is used
34
+ /// the query will return resources where [attribute] is equal
35
+ /// to any of the values in the list.
15
36
static String lessThanEqual(String attribute, dynamic value) =>
16
37
_addQuery(attribute, 'lessThanEqual', value);
17
38
39
+ /// Filter resources where [attribute] is greater than [value].
40
+ ///
41
+ /// [value] can be a single value or a list. If a list is used
42
+ /// the query will return resources where [attribute] is equal
43
+ /// to any of the values in the list.
18
44
static String greaterThan(String attribute, dynamic value) =>
19
45
_addQuery(attribute, 'greaterThan', value);
20
46
47
+ /// Filter resources where [attribute] is greater than or equal to [value].
48
+ ///
49
+ /// [value] can be a single value or a list. If a list is used
50
+ /// the query will return resources where [attribute] is equal
51
+ /// to any of the values in the list.
21
52
static String greaterThanEqual(String attribute, dynamic value) =>
22
53
_addQuery(attribute, 'greaterThanEqual', value);
23
54
55
+ /// Filter resources where by searching [attribute] for [value].
56
+ ///
57
+ /// A fulltext index on [attribute] is required for this query to work.
24
58
static String search(String attribute, String value) =>
25
59
_addQuery(attribute, 'search', value);
26
60
61
+ /// Filter resources where [attribute] is null.
27
62
static String isNull(String attribute) => 'isNull("$attribute")';
28
63
64
+ /// Filter resources where [attribute] is not null.
29
65
static String isNotNull(String attribute) => 'isNotNull("$attribute")';
30
66
67
+ /// Filter resources where [attribute] is between [start] and [end] (inclusive).
31
68
static String between(String attribute, dynamic start, dynamic end) =>
32
69
_addQuery(attribute, 'between', [start, end]);
33
70
71
+ /// Filter resources where [attribute] starts with [value].
34
72
static String startsWith(String attribute, String value) =>
35
73
_addQuery(attribute, 'startsWith', value);
36
74
75
+ /// Filter resources where [attribute] ends with [value].
37
76
static String endsWith(String attribute, String value) =>
38
77
_addQuery(attribute, 'endsWith', value);
39
78
40
- static String select(List<String > attributes) => 'select([${attributes.map((attr) => "\"$attr\"").join(",")}])';
79
+ /// Specify which attributes should be returned by the API call.
80
+ static String select(List<String > attributes) =>
81
+ 'select([${attributes.map((attr) => "\"$attr\"").join(",")}])';
41
82
83
+ /// Sort results by [attribute] ascending.
42
84
static String orderAsc(String attribute) => 'orderAsc("$attribute")';
43
85
86
+ /// Sort results by [attribute] descending.
44
87
static String orderDesc(String attribute) => 'orderDesc("$attribute")';
45
88
89
+ /// Return results before [id].
90
+ ///
91
+ /// Refer to the [Cursor Based Pagination]({{sdk .url }}/docs/pagination#cursor-pagination)
92
+ /// docs for more information.
46
93
static String cursorBefore(String id) => 'cursorBefore("$id")';
47
94
95
+ /// Return results after [id].
96
+ ///
97
+ /// Refer to the [Cursor Based Pagination]({{sdk .url }}/docs/pagination#cursor-pagination)
98
+ /// docs for more information.
48
99
static String cursorAfter(String id) => 'cursorAfter("$id")';
49
100
101
+ /// Return only [limit] results.
50
102
static String limit(int limit) => 'limit($limit)';
51
103
104
+ /// Return results from [offset].
105
+ ///
106
+ /// Refer to the [Offset Pagination]({{sdk .url }}/docs/pagination#offset-pagination)
107
+ /// docs for more information.
52
108
static String offset(int offset) => 'offset($offset)';
53
109
54
110
static String _addQuery(String attribute, String method, dynamic value) => (value
55
111
is List)
56
- ? '$method("$attribute", [${value.map((item) => parseValues (item)).join(",")}])'
57
- : '$method("$attribute", [${parseValues (value)}])';
112
+ ? '$method("$attribute", [${value.map((item) => _parseValues (item)).join(",")}])'
113
+ : '$method("$attribute", [${_parseValues (value)}])';
58
114
59
- static String parseValues (dynamic value) =>
115
+ static String _parseValues (dynamic value) =>
60
116
(value is String) ? '"$value"' : '$value';
61
- }
117
+ }
0 commit comments