11part of {{ language .params .packageName }};
22
3+ /// Helper class to generate query strings.
34class 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.
612 static String equal(String attribute, dynamic value) =>
713 _addQuery(attribute, 'equal', value);
814
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.
920 static String notEqual(String attribute, dynamic value) =>
1021 _addQuery(attribute, 'notEqual', value);
1122
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.
1228 static String lessThan(String attribute, dynamic value) =>
1329 _addQuery(attribute, 'lessThan', value);
1430
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.
1536 static String lessThanEqual(String attribute, dynamic value) =>
1637 _addQuery(attribute, 'lessThanEqual', value);
1738
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.
1844 static String greaterThan(String attribute, dynamic value) =>
1945 _addQuery(attribute, 'greaterThan', value);
2046
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.
2152 static String greaterThanEqual(String attribute, dynamic value) =>
2253 _addQuery(attribute, 'greaterThanEqual', value);
2354
55+ /// Filter resources where by searching [attribute] for [value].
56+ ///
57+ /// A fulltext index on [attribute] is required for this query to work.
2458 static String search(String attribute, String value) =>
2559 _addQuery(attribute, 'search', value);
2660
61+ /// Filter resources where [attribute] is null.
2762 static String isNull(String attribute) => 'isNull("$attribute")';
2863
64+ /// Filter resources where [attribute] is not null.
2965 static String isNotNull(String attribute) => 'isNotNull("$attribute")';
3066
67+ /// Filter resources where [attribute] is between [start] and [end] (inclusive).
3168 static String between(String attribute, dynamic start, dynamic end) =>
3269 _addQuery(attribute, 'between', [start, end]);
3370
71+ /// Filter resources where [attribute] starts with [value].
3472 static String startsWith(String attribute, String value) =>
3573 _addQuery(attribute, 'startsWith', value);
3674
75+ /// Filter resources where [attribute] ends with [value].
3776 static String endsWith(String attribute, String value) =>
3877 _addQuery(attribute, 'endsWith', value);
3978
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(",")}])';
4182
83+ /// Sort results by [attribute] ascending.
4284 static String orderAsc(String attribute) => 'orderAsc("$attribute")';
4385
86+ /// Sort results by [attribute] descending.
4487 static String orderDesc(String attribute) => 'orderDesc("$attribute")';
4588
89+ /// Return results before [id].
90+ ///
91+ /// Refer to the [Cursor Based Pagination]({{sdk .url }}/docs/pagination#cursor-pagination)
92+ /// docs for more information.
4693 static String cursorBefore(String id) => 'cursorBefore("$id")';
4794
95+ /// Return results after [id].
96+ ///
97+ /// Refer to the [Cursor Based Pagination]({{sdk .url }}/docs/pagination#cursor-pagination)
98+ /// docs for more information.
4899 static String cursorAfter(String id) => 'cursorAfter("$id")';
49100
101+ /// Return only [limit] results.
50102 static String limit(int limit) => 'limit($limit)';
51103
104+ /// Return results from [offset].
105+ ///
106+ /// Refer to the [Offset Pagination]({{sdk .url }}/docs/pagination#offset-pagination)
107+ /// docs for more information.
52108 static String offset(int offset) => 'offset($offset)';
53109
54110 static String _addQuery(String attribute, String method, dynamic value) => (value
55111 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)}])';
58114
59- static String parseValues (dynamic value) =>
115+ static String _parseValues (dynamic value) =>
60116 (value is String) ? '"$value"' : '$value';
61- }
117+ }
0 commit comments