Skip to content

Commit

Permalink
Merge pull request #740 from appwrite/fix-between-serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
lohanidamodar authored Nov 12, 2023
2 parents 792eb3d + 923a2f2 commit 4c431d5
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class Query {

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

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

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion templates/dart/lib/query.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Query {

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

/// Filter resources where [attribute] starts with [value].
static String startsWith(String attribute, String value) =>
Expand Down
2 changes: 1 addition & 1 deletion templates/deno/src/query.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class Query {
`isNotNull("${attribute}")`;

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

static startsWith = (attribute: string, value: string): string =>
Query.addQuery(attribute, "startsWith", value);
Expand Down
6 changes: 3 additions & 3 deletions templates/dotnet/src/Appwrite/Query.cs.twig
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ namespace Appwrite

public static string Between(string attribute, string start, string end)
{
return AddQuery(attribute, "between", new List<string> { start, end });
return $"between(\"{attribute}\", \"{start}\", \"{end}\")";
}

public static string Between(string attribute, int start, int end)
{
return AddQuery(attribute, "between", new List<int> { start, end });
return $"between(\"{attribute}\", {start}, {end})";
}

public static string Between(string attribute, double start, double end)
{
return AddQuery(attribute, "between", new List<double> { start, end });
return $"between(\"{attribute}\", {start}, {end})";
}

public static string Select(List<string> attributes)
Expand Down
6 changes: 3 additions & 3 deletions templates/kotlin/src/main/kotlin/io/appwrite/Query.kt.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class Query {

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

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

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion templates/node/lib/query.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Query {
`isNotNull("${attribute}")`;

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

static startsWith = (attribute, value) =>
Query.addQuery(attribute, "startsWith", value);
Expand Down
5 changes: 4 additions & 1 deletion templates/php/src/Query.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ class Query
*/
public static function between(string $attribute, $start, $end): string
{
return self::addQuery($attribute, 'between', [$start, $end]);
$start = self::parseValues($start);
$end = self::parseValues($end);
return "between(\"{$attribute}\", {$start}, {$end})";
}
/**
Expand Down
2 changes: 1 addition & 1 deletion templates/python/package/query.py.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Query:

@staticmethod
def between(attribute, start, end):
return Query.add_query(attribute, "between", [start, end])
return f'between("{attribute}", {Query.parseValues(start)}, {Query.parseValues(end)})'

@staticmethod
def starts_with(attribute, value):
Expand Down
8 changes: 4 additions & 4 deletions templates/ruby/lib/container/query.rb.twig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module {{spec.title | caseUcfirst}}
end

def between(attribute, start, ending)
return add_query(attribute, "between", [start, ending])
return "between(\"#{attribute}\", #{parse_values(start)}, #{parse_values(ending)})"
end

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

def add_query(attribute, method, value)
if value.is_a?(Array)
"#{method}(\"#{attribute}\", [#{value.map {|item| parseValues(item)}.join(',')}])"
"#{method}(\"#{attribute}\", [#{value.map {|item| parse_values(item)}.join(',')}])"
else
return "#{method}(\"#{attribute}\", [#{parseValues(value)}])"
return "#{method}(\"#{attribute}\", [#{parse_values(value)}])"
end
end

def parseValues(value)
def parse_values(value)
return value.is_a?(String) ? "\"#{value}\"" : value
end
end
Expand Down
6 changes: 3 additions & 3 deletions templates/swift/Sources/Query.swift.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public class Query {
}

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

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

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

public static func startsWith(_ attribute: String, value: String) -> String {
Expand Down
2 changes: 1 addition & 1 deletion templates/web/src/query.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Query {
`isNotNull("${attribute}")`;

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

static startsWith = (attribute: string, value: string): string =>
Query.addQuery(attribute, "startsWith", value);
Expand Down
6 changes: 3 additions & 3 deletions tests/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ abstract class Base extends TestCase
'search("name", ["john"])',
'isNull("name")',
'isNotNull("name")',
'between("age", [50,100])',
'between("age", [50.5,100.5])',
'between("name", ["Anna","Brad"])',
'between("age", 50, 100)',
'between("age", 50.5, 100.5)',
'between("name", "Anna", "Brad")',
'startsWith("name", ["Ann"])',
'endsWith("name", ["nne"])',
'select(["name","age"])',
Expand Down

0 comments on commit 4c431d5

Please sign in to comment.