Skip to content

Commit af96e57

Browse files
Merge pull request #632 from appwrite/feat-new-queries
2 parents 670619b + b096989 commit af96e57

File tree

25 files changed

+497
-133
lines changed

25 files changed

+497
-133
lines changed

composer.lock

Lines changed: 80 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/android/library/src/main/java/io/appwrite/Query.kt.twig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ class Query {
1616

1717
fun search(attribute: String, value: String) = Query.addQuery(attribute, "search", value)
1818

19+
fun isNull(attribute: String) = "isNull(\"${attribute}\")"
20+
21+
fun isNotNull(attribute: String) = "isNotNull(\"${attribute}\")"
22+
23+
fun between(attribute: String, start: Int, end: Int) = Query.addQuery(attribute, "between", listOf(start, end))
24+
25+
fun between(attribute: String, start: Double, end: Double) = Query.addQuery(attribute, "between", listOf(start, end))
26+
27+
fun between(attribute: String, start: String, end: String) = Query.addQuery(attribute, "between", listOf(start, end))
28+
29+
fun startsWith(attribute: String, value: String) = Query.addQuery(attribute, "startsWith", value)
30+
31+
fun endsWith(attribute: String, value: String) = Query.addQuery(attribute, "endsWith", value)
32+
33+
fun select(attributes: List<String>) = "select([${attributes.joinToString(",") { "\"$it\"" }}])"
34+
1935
fun orderAsc(attribute: String) = "orderAsc(\"${attribute}\")"
2036

2137
fun orderDesc(attribute: String) = "orderDesc(\"${attribute}\")"

templates/dart/lib/query.dart.twig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ class Query {
2424
static search(String attribute, String value) =>
2525
_addQuery(attribute, 'search', value);
2626

27+
static isNull(String attribute) => 'isNull("$attribute")';
28+
29+
static isNotNull(String attribute) => 'isNotNull("$attribute")';
30+
31+
static between(String attribute, dynamic start, dynamic end) =>
32+
_addQuery(attribute, 'between', [start, end]);
33+
34+
static startsWith(String attribute, String value) =>
35+
_addQuery(attribute, 'startsWith', value);
36+
37+
static endsWith(String attribute, String value) =>
38+
_addQuery(attribute, 'endsWith', value);
39+
40+
static select(List<String> attributes) => 'select([${attributes.map((attr) => "\"$attr\"").join(",")}])';
41+
2742
static String orderAsc(String attribute) => 'orderAsc("$attribute")';
2843

2944
static String orderDesc(String attribute) => 'orderDesc("$attribute")';

templates/deno/src/query.ts.twig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ export class Query {
2424
static search = (attribute: string, value: string): string =>
2525
Query.addQuery(attribute, "search", value);
2626

27+
static isNull = (attribute: string): string =>
28+
`isNull("${attribute}")`;
29+
30+
static isNotNull = (attribute: string): string =>
31+
`isNotNull("${attribute}")`;
32+
33+
static between = (attribute: string, start: string|number, end: string|number): string =>
34+
`between("${attribute}", [${Query.parseValues(start)},${Query.parseValues(end)}])`;
35+
36+
static startsWith = (attribute: string, value: string): string =>
37+
Query.addQuery(attribute, "startsWith", value);
38+
39+
static endsWith = (attribute: string, value: string): string =>
40+
Query.addQuery(attribute, "endsWith", value);
41+
42+
static select = (attributes: string[]): string =>
43+
`select([${attributes.map((attr: string) => `"${attr}"`).join(",")}])`;
44+
2745
static orderDesc = (attribute: string): string =>
2846
`orderDesc("${attribute}")`;
2947

templates/kotlin/src/main/kotlin/io/appwrite/Query.kt.twig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ class Query {
1616

1717
fun search(attribute: String, value: String) = Query.addQuery(attribute, "search", value)
1818

19+
fun isNull(attribute: String) = "isNull(\"${attribute}\")"
20+
21+
fun isNotNull(attribute: String) = "isNotNull(\"${attribute}\")"
22+
23+
fun between(attribute: String, start: Int, end: Int) = Query.addQuery(attribute, "between", listOf(start, end))
24+
25+
fun between(attribute: String, start: Double, end: Double) = Query.addQuery(attribute, "between", listOf(start, end))
26+
27+
fun between(attribute: String, start: String, end: String) = Query.addQuery(attribute, "between", listOf(start, end))
28+
29+
fun startsWith(attribute: String, value: String) = Query.addQuery(attribute, "startsWith", value)
30+
31+
fun endsWith(attribute: String, value: String) = Query.addQuery(attribute, "endsWith", value)
32+
33+
fun select(attributes: List<String>) = "select([${attributes.joinToString(",") { "\"$it\"" }}])"
34+
1935
fun orderAsc(attribute: String) = "orderAsc(\"${attribute}\")"
2036

2137
fun orderDesc(attribute: String) = "orderDesc(\"${attribute}\")"

templates/node/lib/query.js.twig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ class Query {
1717
static greaterThanEqual = (attribute, value) =>
1818
Query.addQuery(attribute, "greaterThanEqual", value);
1919

20+
static isNull = (attribute) =>
21+
`isNull("${attribute}")`;
22+
23+
static isNotNull = (attribute) =>
24+
`isNotNull("${attribute}")`;
25+
26+
static between = (attribute, start, end) =>
27+
Query.addQuery(attribute, "between", [start, end]);
28+
29+
static startsWith = (attribute, value) =>
30+
Query.addQuery(attribute, "startsWith", value);
31+
32+
static endsWith = (attribute, value) =>
33+
Query.addQuery(attribute, "endsWith", value);
34+
35+
static select = (attributes) =>
36+
`select([${attributes.map((attr) => `"${attr}"`).join(",")}])`;
37+
2038
static search = (attribute, value) =>
2139
Query.addQuery(attribute, "search", value);
2240

templates/php/src/Query.php.twig

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,76 @@ class Query
8888
return self::addQuery($attribute, 'search', $value);
8989
}
9090
91+
/**
92+
* Is Null
93+
*
94+
* @param string $attribute
95+
* @return string
96+
*/
97+
public static function isNull(string $attribute): string
98+
{
99+
return 'isNull("' . $attribute . '")';
100+
}
101+
102+
/**
103+
* Is Not Null
104+
*
105+
* @param string $attribute
106+
* @return string
107+
*/
108+
public static function isNotNull(string $attribute): string
109+
{
110+
return 'isNotNull("' . $attribute . '")';
111+
}
112+
113+
/**
114+
* Between
115+
*
116+
* @param string $attribute
117+
* @param string|int|float $start
118+
* @param string|int|float $end
119+
* @return string
120+
*/
121+
public static function between(string $attribute, $start, $end): string
122+
{
123+
return self::addQuery($attribute, 'between', [$start, $end]);
124+
}
125+
126+
/**
127+
* Starts With
128+
*
129+
* @param string $attribute
130+
* @param string $value
131+
* @return string
132+
*/
133+
public static function startsWith(string $attribute, string $value): string
134+
{
135+
return self::addQuery($attribute, 'startsWith', $value);
136+
}
137+
138+
/**
139+
* Ends With
140+
*
141+
* @param string $attribute
142+
* @param string $value
143+
* @return string
144+
*/
145+
public static function endsWith(string $attribute, string $value): string
146+
{
147+
return self::addQuery($attribute, 'endsWith', $value);
148+
}
149+
150+
/**
151+
* Select
152+
*
153+
* @param array<string> $attributes
154+
* @return string
155+
*/
156+
public static function select(array $attributes): string
157+
{
158+
return 'select([' . implode(",", array_map(function ($attr) {return '"' . $attr . '"';}, $attributes)) . '])';
159+
}
160+
91161
/**
92162
* Cursor After
93163
*

templates/python/package/query.py.twig

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,70 @@
11
class Query:
22
@staticmethod
33
def equal(attribute, value):
4-
return Query.addQuery(attribute, "equal", value)
4+
return Query.add_query(attribute, "equal", value)
55

66
@staticmethod
7-
def notEqual(attribute, value):
8-
return Query.addQuery(attribute, "notEqual", value)
7+
def not_equal(attribute, value):
8+
return Query.add_query(attribute, "notEqual", value)
99

1010
@staticmethod
11-
def lessThan(attribute, value):
12-
return Query.addQuery(attribute, "lessThan", value)
11+
def less_than(attribute, value):
12+
return Query.add_query(attribute, "lessThan", value)
1313

1414
@staticmethod
15-
def lessThanEqual(attribute, value):
16-
return Query.addQuery(attribute, "lessThanEqual", value)
15+
def less_than_equal(attribute, value):
16+
return Query.add_query(attribute, "lessThanEqual", value)
1717

1818
@staticmethod
19-
def greaterThan(attribute, value):
20-
return Query.addQuery(attribute, "greaterThan", value)
19+
def greater_than(attribute, value):
20+
return Query.add_query(attribute, "greaterThan", value)
2121

2222
@staticmethod
23-
def greaterThanEqual(attribute, value):
24-
return Query.addQuery(attribute, "greaterThanEqual", value)
23+
def greater_than_equal(attribute, value):
24+
return Query.add_query(attribute, "greaterThanEqual", value)
25+
26+
@staticmethod
27+
def is_null(attribute):
28+
return f'isNull("{attribute}")'
29+
30+
@staticmethod
31+
def is_not_null(attribute):
32+
return f'isNotNull("{attribute}")'
33+
34+
@staticmethod
35+
def between(attribute, start, end):
36+
return Query.add_query(attribute, "between", [start, end])
37+
38+
@staticmethod
39+
def starts_with(attribute, value):
40+
return Query.add_query(attribute, "startsWith", value)
41+
42+
@staticmethod
43+
def ends_with(attribute, value):
44+
return Query.add_query(attribute, "endsWith", value)
45+
46+
@staticmethod
47+
def select(attributes):
48+
return f'select([{",".join(map(Query.parseValues, attributes))}])'
2549

2650
@staticmethod
2751
def search(attribute, value):
28-
return Query.addQuery(attribute, "search", value)
52+
return Query.add_query(attribute, "search", value)
2953

3054
@staticmethod
31-
def orderAsc(attribute):
55+
def order_asc(attribute):
3256
return f'orderAsc("{attribute}")'
3357

3458
@staticmethod
35-
def orderDesc(attribute):
59+
def order_desc(attribute):
3660
return f'orderDesc("{attribute}")'
3761

3862
@staticmethod
39-
def cursorBefore(id):
63+
def cursor_before(id):
4064
return f'cursorBefore("{id}")'
4165

4266
@staticmethod
43-
def cursorAfter(id):
67+
def cursor_after(id):
4468
return f'cursorAfter("{id}")'
4569

4670
@staticmethod
@@ -52,7 +76,7 @@ class Query:
5276
return f'offset({offset})'
5377

5478
@staticmethod
55-
def addQuery(attribute, method, value):
79+
def add_query(attribute, method, value):
5680
if type(value) == list:
5781
return f'{method}("{attribute}", [{",".join(map(Query.parseValues, value))}])'
5882
else:

templates/ruby/lib/container/query.rb.twig

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,70 @@ module {{spec.title | caseUcfirst}}
22
class Query
33
class << Query
44
def equal(attribute, value)
5-
return addQuery(attribute, "equal", value)
5+
return add_query(attribute, "equal", value)
66
end
77

8-
def notEqual(attribute, value)
9-
return addQuery(attribute, "notEqual", value)
8+
def not_equal(attribute, value)
9+
return add_query(attribute, "notEqual", value)
1010
end
1111

12-
def lessThan(attribute, value)
13-
return addQuery(attribute, "lessThan", value)
12+
def less_than(attribute, value)
13+
return add_query(attribute, "lessThan", value)
1414
end
1515

16-
def lessThanEqual(attribute, value)
17-
return addQuery(attribute, "lessThanEqual", value)
16+
def less_than_equal(attribute, value)
17+
return add_query(attribute, "lessThanEqual", value)
1818
end
1919

20-
def greaterThan(attribute, value)
21-
return addQuery(attribute, "greaterThan", value)
20+
def greater_than(attribute, value)
21+
return add_query(attribute, "greaterThan", value)
2222
end
2323

24-
def greaterThanEqual(attribute, value)
25-
return addQuery(attribute, "greaterThanEqual", value)
24+
def greater_than_equal(attribute, value)
25+
return add_query(attribute, "greaterThanEqual", value)
26+
end
27+
28+
def is_null(attribute)
29+
return "isNull(\"#{attribute}\")"
30+
end
31+
32+
def is_not_null(attribute)
33+
return "isNotNull(\"#{attribute}\")"
34+
end
35+
36+
def between(attribute, start, ending)
37+
return add_query(attribute, "between", [start, ending])
38+
end
39+
40+
def starts_with(attribute, value)
41+
return add_query(attribute, "startsWith", value)
42+
end
43+
44+
def ends_with(attribute, value)
45+
return add_query(attribute, "endsWith", value)
46+
end
47+
48+
def select(attributes)
49+
return "select([#{attributes.map {|attribute| "\"#{attribute}\""}.join(',')}])"
2650
end
2751

2852
def search(attribute, value)
29-
return addQuery(attribute, "search", value)
53+
return add_query(attribute, "search", value)
3054
end
3155

32-
def orderAsc(attribute)
56+
def order_asc(attribute)
3357
return "orderAsc(\"#{attribute}\")"
3458
end
3559

36-
def orderDesc(attribute)
60+
def order_desc(attribute)
3761
return "orderDesc(\"#{attribute}\")"
3862
end
3963

40-
def cursorBefore(id)
64+
def cursor_before(id)
4165
return "cursorBefore(\"#{id}\")"
4266
end
4367

44-
def cursorAfter(id)
68+
def cursor_after(id)
4569
return "cursorAfter(\"#{id}\")"
4670
end
4771

@@ -55,7 +79,7 @@ module {{spec.title | caseUcfirst}}
5579

5680
private
5781

58-
def addQuery(attribute, method, value)
82+
def add_query(attribute, method, value)
5983
if value.is_a?(Array)
6084
"#{method}(\"#{attribute}\", [#{value.map {|item| parseValues(item)}.join(',')}])"
6185
else

0 commit comments

Comments
 (0)