Skip to content

Commit 4c431d5

Browse files
Merge pull request #740 from appwrite/fix-between-serialization
2 parents 792eb3d + 923a2f2 commit 4c431d5

File tree

12 files changed

+28
-25
lines changed

12 files changed

+28
-25
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ class Query {
2020

2121
fun isNotNull(attribute: String) = "isNotNull(\"${attribute}\")"
2222

23-
fun between(attribute: String, start: Int, end: Int) = Query.addQuery(attribute, "between", listOf(start, end))
23+
fun between(attribute: String, start: Int, end: Int) = "between(\"${attribute}\", ${start}, ${end})"
2424

25-
fun between(attribute: String, start: Double, end: Double) = Query.addQuery(attribute, "between", listOf(start, end))
25+
fun between(attribute: String, start: Double, end: Double) = "between(\"${attribute}\", ${start}, ${end})"
2626

27-
fun between(attribute: String, start: String, end: String) = Query.addQuery(attribute, "between", listOf(start, end))
27+
fun between(attribute: String, start: String, end: String) = "between(\"${attribute}\", \"${start}\", \"${end}\")"
2828

2929
fun startsWith(attribute: String, value: String) = Query.addQuery(attribute, "startsWith", value)
3030

templates/dart/lib/query.dart.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Query {
4848

4949
/// Filter resources where [attribute] is between [start] and [end] (inclusive).
5050
static String between(String attribute, dynamic start, dynamic end) =>
51-
_addQuery(attribute, 'between', [start, end]);
51+
'between("$attribute", ${_parseValues(start)}, ${_parseValues(end)})';
5252

5353
/// Filter resources where [attribute] starts with [value].
5454
static String startsWith(String attribute, String value) =>

templates/deno/src/query.ts.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class Query {
3131
`isNotNull("${attribute}")`;
3232

3333
static between = (attribute: string, start: string|number, end: string|number): string =>
34-
`between("${attribute}", [${Query.parseValues(start)},${Query.parseValues(end)}])`;
34+
`between("${attribute}", ${Query.parseValues(start)}, ${Query.parseValues(end)})`;
3535

3636
static startsWith = (attribute: string, value: string): string =>
3737
Query.addQuery(attribute, "startsWith", value);

templates/dotnet/src/Appwrite/Query.cs.twig

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ namespace Appwrite
6363

6464
public static string Between(string attribute, string start, string end)
6565
{
66-
return AddQuery(attribute, "between", new List<string> { start, end });
66+
return $"between(\"{attribute}\", \"{start}\", \"{end}\")";
6767
}
6868

6969
public static string Between(string attribute, int start, int end)
7070
{
71-
return AddQuery(attribute, "between", new List<int> { start, end });
71+
return $"between(\"{attribute}\", {start}, {end})";
7272
}
7373

7474
public static string Between(string attribute, double start, double end)
7575
{
76-
return AddQuery(attribute, "between", new List<double> { start, end });
76+
return $"between(\"{attribute}\", {start}, {end})";
7777
}
7878

7979
public static string Select(List<string> attributes)

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ class Query {
2020

2121
fun isNotNull(attribute: String) = "isNotNull(\"${attribute}\")"
2222

23-
fun between(attribute: String, start: Int, end: Int) = Query.addQuery(attribute, "between", listOf(start, end))
23+
fun between(attribute: String, start: Int, end: Int) = "between(\"${attribute}\", ${start}, ${end})"
2424

25-
fun between(attribute: String, start: Double, end: Double) = Query.addQuery(attribute, "between", listOf(start, end))
25+
fun between(attribute: String, start: Double, end: Double) = "between(\"${attribute}\", ${start}, ${end})"
2626

27-
fun between(attribute: String, start: String, end: String) = Query.addQuery(attribute, "between", listOf(start, end))
27+
fun between(attribute: String, start: String, end: String) = "between(\"${attribute}\", \"${start}\", \"${end}\")"
2828

2929
fun startsWith(attribute: String, value: String) = Query.addQuery(attribute, "startsWith", value)
3030

templates/node/lib/query.js.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Query {
2424
`isNotNull("${attribute}")`;
2525

2626
static between = (attribute, start, end) =>
27-
Query.addQuery(attribute, "between", [start, end]);
27+
`between("${attribute}", ${Query.parseValues(start)}, ${Query.parseValues(end)})`
2828

2929
static startsWith = (attribute, value) =>
3030
Query.addQuery(attribute, "startsWith", value);

templates/php/src/Query.php.twig

+4-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ class Query
120120
*/
121121
public static function between(string $attribute, $start, $end): string
122122
{
123-
return self::addQuery($attribute, 'between', [$start, $end]);
123+
$start = self::parseValues($start);
124+
$end = self::parseValues($end);
125+
126+
return "between(\"{$attribute}\", {$start}, {$end})";
124127
}
125128
126129
/**

templates/python/package/query.py.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Query:
3333

3434
@staticmethod
3535
def between(attribute, start, end):
36-
return Query.add_query(attribute, "between", [start, end])
36+
return f'between("{attribute}", {Query.parseValues(start)}, {Query.parseValues(end)})'
3737

3838
@staticmethod
3939
def starts_with(attribute, value):

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module {{spec.title | caseUcfirst}}
3434
end
3535

3636
def between(attribute, start, ending)
37-
return add_query(attribute, "between", [start, ending])
37+
return "between(\"#{attribute}\", #{parse_values(start)}, #{parse_values(ending)})"
3838
end
3939

4040
def starts_with(attribute, value)
@@ -81,13 +81,13 @@ module {{spec.title | caseUcfirst}}
8181

8282
def add_query(attribute, method, value)
8383
if value.is_a?(Array)
84-
"#{method}(\"#{attribute}\", [#{value.map {|item| parseValues(item)}.join(',')}])"
84+
"#{method}(\"#{attribute}\", [#{value.map {|item| parse_values(item)}.join(',')}])"
8585
else
86-
return "#{method}(\"#{attribute}\", [#{parseValues(value)}])"
86+
return "#{method}(\"#{attribute}\", [#{parse_values(value)}])"
8787
end
8888
end
8989

90-
def parseValues(value)
90+
def parse_values(value)
9191
return value.is_a?(String) ? "\"#{value}\"" : value
9292
end
9393
end

templates/swift/Sources/Query.swift.twig

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public class Query {
3333
}
3434

3535
public static func between(_ attribute: String, start: Int, end: Int) -> String {
36-
buildQueryWhere(attribute, is: "between", to: [start, end])
36+
"between(\"\(attribute)\", \(start), \(end))"
3737
}
3838

3939
public static func between(_ attribute: String, start: Double, end: Double) -> String {
40-
buildQueryWhere(attribute, is: "between", to: [start, end])
40+
"between(\"\(attribute)\", \(start), \(end))"
4141
}
4242

4343
public static func between(_ attribute: String, start: String, end: String) -> String {
44-
buildQueryWhere(attribute, is: "between", to: [start, end])
44+
"between(\"\(attribute)\", \"\(start)\", \"\(end)\")"
4545
}
4646

4747
public static func startsWith(_ attribute: String, value: String) -> String {

templates/web/src/query.ts.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class Query {
2828
`isNotNull("${attribute}")`;
2929

3030
static between = (attribute: string, start: string|number, end: string|number): string =>
31-
`between("${attribute}", [${Query.parseValues(start)},${Query.parseValues(end)}])`;
31+
`between("${attribute}", ${Query.parseValues(start)}, ${Query.parseValues(end)})`;
3232

3333
static startsWith = (attribute: string, value: string): string =>
3434
Query.addQuery(attribute, "startsWith", value);

tests/Base.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ abstract class Base extends TestCase
6969
'search("name", ["john"])',
7070
'isNull("name")',
7171
'isNotNull("name")',
72-
'between("age", [50,100])',
73-
'between("age", [50.5,100.5])',
74-
'between("name", ["Anna","Brad"])',
72+
'between("age", 50, 100)',
73+
'between("age", 50.5, 100.5)',
74+
'between("name", "Anna", "Brad")',
7575
'startsWith("name", ["Ann"])',
7676
'endsWith("name", ["nne"])',
7777
'select(["name","age"])',

0 commit comments

Comments
 (0)