From 7b3a6ce60363c2fb93e9fbe20e59f29df73ca114 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 9 Nov 2023 22:40:30 +1300 Subject: [PATCH 1/4] Fix between query output --- .../android/library/src/main/java/io/appwrite/Query.kt.twig | 6 +++--- templates/dart/lib/query.dart.twig | 3 +-- templates/deno/src/query.ts.twig | 2 +- templates/dotnet/src/Appwrite/Query.cs.twig | 6 +++--- templates/kotlin/src/main/kotlin/io/appwrite/Query.kt.twig | 6 +++--- templates/node/lib/query.js.twig | 2 +- templates/php/src/Query.php.twig | 2 +- templates/python/package/query.py.twig | 2 +- templates/ruby/lib/container/query.rb.twig | 4 ++-- templates/swift/Sources/Query.swift.twig | 6 +++--- templates/web/src/query.ts.twig | 2 +- tests/Base.php | 6 +++--- 12 files changed, 23 insertions(+), 24 deletions(-) diff --git a/templates/android/library/src/main/java/io/appwrite/Query.kt.twig b/templates/android/library/src/main/java/io/appwrite/Query.kt.twig index e9c5a9c88..bb31f9e1b 100644 --- a/templates/android/library/src/main/java/io/appwrite/Query.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/Query.kt.twig @@ -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) diff --git a/templates/dart/lib/query.dart.twig b/templates/dart/lib/query.dart.twig index 249a5f7db..c931b94a1 100644 --- a/templates/dart/lib/query.dart.twig +++ b/templates/dart/lib/query.dart.twig @@ -47,8 +47,7 @@ class Query { static String isNotNull(String attribute) => 'isNotNull("$attribute")'; /// Filter resources where [attribute] is between [start] and [end] (inclusive). - static String between(String attribute, dynamic start, dynamic end) => - _addQuery(attribute, 'between', [start, end]); + static String between(String attribute, dynamic start, dynamic end) => 'between("$attribute", $start, $end)' /// Filter resources where [attribute] starts with [value]. static String startsWith(String attribute, String value) => diff --git a/templates/deno/src/query.ts.twig b/templates/deno/src/query.ts.twig index dd7c7a1cc..1067ced6c 100644 --- a/templates/deno/src/query.ts.twig +++ b/templates/deno/src/query.ts.twig @@ -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}", ${start}, ${end})`; static startsWith = (attribute: string, value: string): string => Query.addQuery(attribute, "startsWith", value); diff --git a/templates/dotnet/src/Appwrite/Query.cs.twig b/templates/dotnet/src/Appwrite/Query.cs.twig index c940f4d6b..8d6522a12 100644 --- a/templates/dotnet/src/Appwrite/Query.cs.twig +++ b/templates/dotnet/src/Appwrite/Query.cs.twig @@ -63,17 +63,17 @@ namespace Appwrite public static string Between(string attribute, string start, string end) { - return AddQuery(attribute, "between", new List { start, end }); + return $"between(\"{attribute}\", {start}, {end})"; } public static string Between(string attribute, int start, int end) { - return AddQuery(attribute, "between", new List { start, end }); + return $"between(\"{attribute}\", {start}, {end})"; } public static string Between(string attribute, double start, double end) { - return AddQuery(attribute, "between", new List { start, end }); + return $"between(\"{attribute}\", {start}, {end})"; } public static string Select(List attributes) diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/Query.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/Query.kt.twig index e9c5a9c88..bb31f9e1b 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/Query.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/Query.kt.twig @@ -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) diff --git a/templates/node/lib/query.js.twig b/templates/node/lib/query.js.twig index 06e0b389d..e091e4c03 100644 --- a/templates/node/lib/query.js.twig +++ b/templates/node/lib/query.js.twig @@ -24,7 +24,7 @@ class Query { `isNotNull("${attribute}")`; static between = (attribute, start, end) => - Query.addQuery(attribute, "between", [start, end]); + `between("${attribute}", ${start}, ${end})` static startsWith = (attribute, value) => Query.addQuery(attribute, "startsWith", value); diff --git a/templates/php/src/Query.php.twig b/templates/php/src/Query.php.twig index 5f4d515fd..1b7a310fc 100644 --- a/templates/php/src/Query.php.twig +++ b/templates/php/src/Query.php.twig @@ -120,7 +120,7 @@ class Query */ public static function between(string $attribute, $start, $end): string { - return self::addQuery($attribute, 'between', [$start, $end]); + return "between(\"{$attribute}\", {$start}, {$end})"; } /** diff --git a/templates/python/package/query.py.twig b/templates/python/package/query.py.twig index da636720e..c52c8b9cd 100644 --- a/templates/python/package/query.py.twig +++ b/templates/python/package/query.py.twig @@ -33,7 +33,7 @@ class Query: @staticmethod def between(attribute, start, end): - return Query.add_query(attribute, "between", [start, end]) + return f'between("{attribute}", {start}, {end})' @staticmethod def starts_with(attribute, value): diff --git a/templates/ruby/lib/container/query.rb.twig b/templates/ruby/lib/container/query.rb.twig index 00806943f..cd6921a77 100644 --- a/templates/ruby/lib/container/query.rb.twig +++ b/templates/ruby/lib/container/query.rb.twig @@ -33,8 +33,8 @@ module {{spec.title | caseUcfirst}} return "isNotNull(\"#{attribute}\")" end - def between(attribute, start, ending) - return add_query(attribute, "between", [start, ending]) + def between(attribute, start, end) + return "between(\"#{attribute}\", #{start}, #{end})" end def starts_with(attribute, value) diff --git a/templates/swift/Sources/Query.swift.twig b/templates/swift/Sources/Query.swift.twig index 9fa9893c7..7d69e7785 100644 --- a/templates/swift/Sources/Query.swift.twig +++ b/templates/swift/Sources/Query.swift.twig @@ -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 { diff --git a/templates/web/src/query.ts.twig b/templates/web/src/query.ts.twig index 51cbb7a9f..750b753d4 100644 --- a/templates/web/src/query.ts.twig +++ b/templates/web/src/query.ts.twig @@ -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}", ${start},${end}])`; static startsWith = (attribute: string, value: string): string => Query.addQuery(attribute, "startsWith", value); diff --git a/tests/Base.php b/tests/Base.php index 464291b45..e0855595b 100644 --- a/tests/Base.php +++ b/tests/Base.php @@ -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"])', From 818125bf4c7983d6b920c5cbdc6c0032ad1a28a9 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 10 Nov 2023 12:53:46 +1300 Subject: [PATCH 2/4] Fix string betweens --- .../library/src/main/java/io/appwrite/Query.kt.twig | 2 +- templates/dart/lib/query.dart.twig | 3 ++- templates/deno/src/query.ts.twig | 2 +- templates/dotnet/src/Appwrite/Query.cs.twig | 2 +- .../kotlin/src/main/kotlin/io/appwrite/Query.kt.twig | 2 +- templates/node/lib/query.js.twig | 2 +- templates/php/src/Query.php.twig | 3 +++ templates/python/package/query.py.twig | 2 +- templates/ruby/lib/container/query.rb.twig | 8 ++++---- templates/swift/Sources/Query.swift.twig | 2 +- templates/web/src/query.ts.twig | 2 +- 11 files changed, 17 insertions(+), 13 deletions(-) diff --git a/templates/android/library/src/main/java/io/appwrite/Query.kt.twig b/templates/android/library/src/main/java/io/appwrite/Query.kt.twig index bb31f9e1b..7f4fbcd81 100644 --- a/templates/android/library/src/main/java/io/appwrite/Query.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/Query.kt.twig @@ -24,7 +24,7 @@ class Query { fun between(attribute: String, start: Double, end: Double) = "between(\"${attribute}\", ${start}, ${end})" - fun between(attribute: String, start: String, end: String) = "between(\"${attribute}\", ${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) diff --git a/templates/dart/lib/query.dart.twig b/templates/dart/lib/query.dart.twig index c931b94a1..a5763d79d 100644 --- a/templates/dart/lib/query.dart.twig +++ b/templates/dart/lib/query.dart.twig @@ -47,7 +47,8 @@ class Query { static String isNotNull(String attribute) => 'isNotNull("$attribute")'; /// Filter resources where [attribute] is between [start] and [end] (inclusive). - static String between(String attribute, dynamic start, dynamic end) => 'between("$attribute", $start, $end)' + static String between(String attribute, dynamic start, dynamic end) => + 'between("$attribute", ${_parseValues(start)}, ${_parseValues(end)})'; /// Filter resources where [attribute] starts with [value]. static String startsWith(String attribute, String value) => diff --git a/templates/deno/src/query.ts.twig b/templates/deno/src/query.ts.twig index 1067ced6c..ce87185fb 100644 --- a/templates/deno/src/query.ts.twig +++ b/templates/deno/src/query.ts.twig @@ -31,7 +31,7 @@ export class Query { `isNotNull("${attribute}")`; static between = (attribute: string, start: string|number, end: string|number): string => - `between("${attribute}", ${start}, ${end})`; + `between("${attribute}", ${Query.parseValues(start)}, ${Query.parseValues(end)})`; static startsWith = (attribute: string, value: string): string => Query.addQuery(attribute, "startsWith", value); diff --git a/templates/dotnet/src/Appwrite/Query.cs.twig b/templates/dotnet/src/Appwrite/Query.cs.twig index 8d6522a12..f10bac28c 100644 --- a/templates/dotnet/src/Appwrite/Query.cs.twig +++ b/templates/dotnet/src/Appwrite/Query.cs.twig @@ -63,7 +63,7 @@ namespace Appwrite public static string Between(string attribute, string start, string end) { - return $"between(\"{attribute}\", {start}, {end})"; + return $"between(\"{attribute}\", \"{start}\", \"{end}\")"; } public static string Between(string attribute, int start, int end) diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/Query.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/Query.kt.twig index bb31f9e1b..7f4fbcd81 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/Query.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/Query.kt.twig @@ -24,7 +24,7 @@ class Query { fun between(attribute: String, start: Double, end: Double) = "between(\"${attribute}\", ${start}, ${end})" - fun between(attribute: String, start: String, end: String) = "between(\"${attribute}\", ${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) diff --git a/templates/node/lib/query.js.twig b/templates/node/lib/query.js.twig index e091e4c03..675b02b49 100644 --- a/templates/node/lib/query.js.twig +++ b/templates/node/lib/query.js.twig @@ -24,7 +24,7 @@ class Query { `isNotNull("${attribute}")`; static between = (attribute, start, end) => - `between("${attribute}", ${start}, ${end})` + `between("${attribute}", ${Query.parseValues(start)}, ${Query.parseValues(end)})` static startsWith = (attribute, value) => Query.addQuery(attribute, "startsWith", value); diff --git a/templates/php/src/Query.php.twig b/templates/php/src/Query.php.twig index 1b7a310fc..e249e8fcc 100644 --- a/templates/php/src/Query.php.twig +++ b/templates/php/src/Query.php.twig @@ -120,6 +120,9 @@ class Query */ public static function between(string $attribute, $start, $end): string { + $start = self::parseValues($start); + $end = self::parseValues($end); + return "between(\"{$attribute}\", {$start}, {$end})"; } diff --git a/templates/python/package/query.py.twig b/templates/python/package/query.py.twig index c52c8b9cd..d970bd8c9 100644 --- a/templates/python/package/query.py.twig +++ b/templates/python/package/query.py.twig @@ -33,7 +33,7 @@ class Query: @staticmethod def between(attribute, start, end): - return f'between("{attribute}", {start}, {end})' + return f'between("{attribute}", {Query.parseValues(start)}, {Query.parseValues(end)})' @staticmethod def starts_with(attribute, value): diff --git a/templates/ruby/lib/container/query.rb.twig b/templates/ruby/lib/container/query.rb.twig index cd6921a77..9f78e878b 100644 --- a/templates/ruby/lib/container/query.rb.twig +++ b/templates/ruby/lib/container/query.rb.twig @@ -34,7 +34,7 @@ module {{spec.title | caseUcfirst}} end def between(attribute, start, end) - return "between(\"#{attribute}\", #{start}, #{end})" + return "between(\"#{attribute}\", #{parse_values(start)}, #{parse_values(end)})" end def starts_with(attribute, value) @@ -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 diff --git a/templates/swift/Sources/Query.swift.twig b/templates/swift/Sources/Query.swift.twig index 7d69e7785..ce1415d75 100644 --- a/templates/swift/Sources/Query.swift.twig +++ b/templates/swift/Sources/Query.swift.twig @@ -41,7 +41,7 @@ public class Query { } public static func between(_ attribute: String, start: String, end: String) -> String { - "between(\"\(attribute)\", \(start), \(end))" + "between(\"\(attribute)\", \"\(start)\", \"\(end)\")" } public static func startsWith(_ attribute: String, value: String) -> String { diff --git a/templates/web/src/query.ts.twig b/templates/web/src/query.ts.twig index 750b753d4..a8bf38065 100644 --- a/templates/web/src/query.ts.twig +++ b/templates/web/src/query.ts.twig @@ -28,7 +28,7 @@ export class Query { `isNotNull("${attribute}")`; static between = (attribute: string, start: string|number, end: string|number): string => - `between("${attribute}", ${start},${end}])`; + `between("${attribute}", ${Query.parseValues(start)}, ${Query.parseValues(end)}])`; static startsWith = (attribute: string, value: string): string => Query.addQuery(attribute, "startsWith", value); From 5dd5720869069b4e7aec64247ce6ae2f6233f18d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 10 Nov 2023 13:11:42 +1300 Subject: [PATCH 3/4] Fix ruby --- templates/ruby/lib/container/query.rb.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/ruby/lib/container/query.rb.twig b/templates/ruby/lib/container/query.rb.twig index 9f78e878b..e62ee4b92 100644 --- a/templates/ruby/lib/container/query.rb.twig +++ b/templates/ruby/lib/container/query.rb.twig @@ -33,8 +33,8 @@ module {{spec.title | caseUcfirst}} return "isNotNull(\"#{attribute}\")" end - def between(attribute, start, end) - return "between(\"#{attribute}\", #{parse_values(start)}, #{parse_values(end)})" + def between(attribute, start, ending) + return "between(\"#{attribute}\", #{parse_values(start)}, #{parse_values(ending)})" end def starts_with(attribute, value) From 923a2f217bf494398e027d3a56d0c3faf41200b9 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 10 Nov 2023 13:12:17 +1300 Subject: [PATCH 4/4] Fix web --- templates/web/src/query.ts.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/web/src/query.ts.twig b/templates/web/src/query.ts.twig index a8bf38065..1f880cb1c 100644 --- a/templates/web/src/query.ts.twig +++ b/templates/web/src/query.ts.twig @@ -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);