Skip to content

Commit

Permalink
Merge pull request #632 from appwrite/feat-new-queries
Browse files Browse the repository at this point in the history
  • Loading branch information
lohanidamodar authored Apr 4, 2023
2 parents 670619b + b096989 commit af96e57
Show file tree
Hide file tree
Showing 25 changed files with 497 additions and 133 deletions.
159 changes: 80 additions & 79 deletions composer.lock

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions templates/android/library/src/main/java/io/appwrite/Query.kt.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ class Query {

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

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

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: Double, end: Double) = Query.addQuery(attribute, "between", listOf(start, end))

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

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

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

fun select(attributes: List<String>) = "select([${attributes.joinToString(",") { "\"$it\"" }}])"

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

fun orderDesc(attribute: String) = "orderDesc(\"${attribute}\")"
Expand Down
15 changes: 15 additions & 0 deletions templates/dart/lib/query.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ class Query {
static search(String attribute, String value) =>
_addQuery(attribute, 'search', value);

static isNull(String attribute) => 'isNull("$attribute")';

static isNotNull(String attribute) => 'isNotNull("$attribute")';

static between(String attribute, dynamic start, dynamic end) =>
_addQuery(attribute, 'between', [start, end]);

static startsWith(String attribute, String value) =>
_addQuery(attribute, 'startsWith', value);

static endsWith(String attribute, String value) =>
_addQuery(attribute, 'endsWith', value);

static select(List<String> attributes) => 'select([${attributes.map((attr) => "\"$attr\"").join(",")}])';

static String orderAsc(String attribute) => 'orderAsc("$attribute")';

static String orderDesc(String attribute) => 'orderDesc("$attribute")';
Expand Down
18 changes: 18 additions & 0 deletions templates/deno/src/query.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ export class Query {
static search = (attribute: string, value: string): string =>
Query.addQuery(attribute, "search", value);

static isNull = (attribute: string): string =>
`isNull("${attribute}")`;

static isNotNull = (attribute: string): string =>
`isNotNull("${attribute}")`;

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

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

static endsWith = (attribute: string, value: string): string =>
Query.addQuery(attribute, "endsWith", value);

static select = (attributes: string[]): string =>
`select([${attributes.map((attr: string) => `"${attr}"`).join(",")}])`;

static orderDesc = (attribute: string): string =>
`orderDesc("${attribute}")`;

Expand Down
16 changes: 16 additions & 0 deletions templates/kotlin/src/main/kotlin/io/appwrite/Query.kt.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ class Query {

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

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

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: Double, end: Double) = Query.addQuery(attribute, "between", listOf(start, end))

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

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

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

fun select(attributes: List<String>) = "select([${attributes.joinToString(",") { "\"$it\"" }}])"

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

fun orderDesc(attribute: String) = "orderDesc(\"${attribute}\")"
Expand Down
18 changes: 18 additions & 0 deletions templates/node/lib/query.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ class Query {
static greaterThanEqual = (attribute, value) =>
Query.addQuery(attribute, "greaterThanEqual", value);

static isNull = (attribute) =>
`isNull("${attribute}")`;

static isNotNull = (attribute) =>
`isNotNull("${attribute}")`;

static between = (attribute, start, end) =>
Query.addQuery(attribute, "between", [start, end]);

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

static endsWith = (attribute, value) =>
Query.addQuery(attribute, "endsWith", value);

static select = (attributes) =>
`select([${attributes.map((attr) => `"${attr}"`).join(",")}])`;

static search = (attribute, value) =>
Query.addQuery(attribute, "search", value);

Expand Down
70 changes: 70 additions & 0 deletions templates/php/src/Query.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,76 @@ class Query
return self::addQuery($attribute, 'search', $value);
}
/**
* Is Null
*
* @param string $attribute
* @return string
*/
public static function isNull(string $attribute): string
{
return 'isNull("' . $attribute . '")';
}
/**
* Is Not Null
*
* @param string $attribute
* @return string
*/
public static function isNotNull(string $attribute): string
{
return 'isNotNull("' . $attribute . '")';
}
/**
* Between
*
* @param string $attribute
* @param string|int|float $start
* @param string|int|float $end
* @return string
*/
public static function between(string $attribute, $start, $end): string
{
return self::addQuery($attribute, 'between', [$start, $end]);
}
/**
* Starts With
*
* @param string $attribute
* @param string $value
* @return string
*/
public static function startsWith(string $attribute, string $value): string
{
return self::addQuery($attribute, 'startsWith', $value);
}
/**
* Ends With
*
* @param string $attribute
* @param string $value
* @return string
*/
public static function endsWith(string $attribute, string $value): string
{
return self::addQuery($attribute, 'endsWith', $value);
}
/**
* Select
*
* @param array<string> $attributes
* @return string
*/
public static function select(array $attributes): string
{
return 'select([' . implode(",", array_map(function ($attr) {return '"' . $attr . '"';}, $attributes)) . '])';
}
/**
* Cursor After
*
Expand Down
58 changes: 41 additions & 17 deletions templates/python/package/query.py.twig
Original file line number Diff line number Diff line change
@@ -1,46 +1,70 @@
class Query:
@staticmethod
def equal(attribute, value):
return Query.addQuery(attribute, "equal", value)
return Query.add_query(attribute, "equal", value)

@staticmethod
def notEqual(attribute, value):
return Query.addQuery(attribute, "notEqual", value)
def not_equal(attribute, value):
return Query.add_query(attribute, "notEqual", value)

@staticmethod
def lessThan(attribute, value):
return Query.addQuery(attribute, "lessThan", value)
def less_than(attribute, value):
return Query.add_query(attribute, "lessThan", value)

@staticmethod
def lessThanEqual(attribute, value):
return Query.addQuery(attribute, "lessThanEqual", value)
def less_than_equal(attribute, value):
return Query.add_query(attribute, "lessThanEqual", value)

@staticmethod
def greaterThan(attribute, value):
return Query.addQuery(attribute, "greaterThan", value)
def greater_than(attribute, value):
return Query.add_query(attribute, "greaterThan", value)

@staticmethod
def greaterThanEqual(attribute, value):
return Query.addQuery(attribute, "greaterThanEqual", value)
def greater_than_equal(attribute, value):
return Query.add_query(attribute, "greaterThanEqual", value)

@staticmethod
def is_null(attribute):
return f'isNull("{attribute}")'

@staticmethod
def is_not_null(attribute):
return f'isNotNull("{attribute}")'

@staticmethod
def between(attribute, start, end):
return Query.add_query(attribute, "between", [start, end])

@staticmethod
def starts_with(attribute, value):
return Query.add_query(attribute, "startsWith", value)

@staticmethod
def ends_with(attribute, value):
return Query.add_query(attribute, "endsWith", value)

@staticmethod
def select(attributes):
return f'select([{",".join(map(Query.parseValues, attributes))}])'

@staticmethod
def search(attribute, value):
return Query.addQuery(attribute, "search", value)
return Query.add_query(attribute, "search", value)

@staticmethod
def orderAsc(attribute):
def order_asc(attribute):
return f'orderAsc("{attribute}")'

@staticmethod
def orderDesc(attribute):
def order_desc(attribute):
return f'orderDesc("{attribute}")'

@staticmethod
def cursorBefore(id):
def cursor_before(id):
return f'cursorBefore("{id}")'

@staticmethod
def cursorAfter(id):
def cursor_after(id):
return f'cursorAfter("{id}")'

@staticmethod
Expand All @@ -52,7 +76,7 @@ class Query:
return f'offset({offset})'

@staticmethod
def addQuery(attribute, method, value):
def add_query(attribute, method, value):
if type(value) == list:
return f'{method}("{attribute}", [{",".join(map(Query.parseValues, value))}])'
else:
Expand Down
58 changes: 41 additions & 17 deletions templates/ruby/lib/container/query.rb.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,70 @@ module {{spec.title | caseUcfirst}}
class Query
class << Query
def equal(attribute, value)
return addQuery(attribute, "equal", value)
return add_query(attribute, "equal", value)
end

def notEqual(attribute, value)
return addQuery(attribute, "notEqual", value)
def not_equal(attribute, value)
return add_query(attribute, "notEqual", value)
end

def lessThan(attribute, value)
return addQuery(attribute, "lessThan", value)
def less_than(attribute, value)
return add_query(attribute, "lessThan", value)
end

def lessThanEqual(attribute, value)
return addQuery(attribute, "lessThanEqual", value)
def less_than_equal(attribute, value)
return add_query(attribute, "lessThanEqual", value)
end

def greaterThan(attribute, value)
return addQuery(attribute, "greaterThan", value)
def greater_than(attribute, value)
return add_query(attribute, "greaterThan", value)
end

def greaterThanEqual(attribute, value)
return addQuery(attribute, "greaterThanEqual", value)
def greater_than_equal(attribute, value)
return add_query(attribute, "greaterThanEqual", value)
end

def is_null(attribute)
return "isNull(\"#{attribute}\")"
end

def is_not_null(attribute)
return "isNotNull(\"#{attribute}\")"
end

def between(attribute, start, ending)
return add_query(attribute, "between", [start, ending])
end

def starts_with(attribute, value)
return add_query(attribute, "startsWith", value)
end

def ends_with(attribute, value)
return add_query(attribute, "endsWith", value)
end

def select(attributes)
return "select([#{attributes.map {|attribute| "\"#{attribute}\""}.join(',')}])"
end

def search(attribute, value)
return addQuery(attribute, "search", value)
return add_query(attribute, "search", value)
end

def orderAsc(attribute)
def order_asc(attribute)
return "orderAsc(\"#{attribute}\")"
end

def orderDesc(attribute)
def order_desc(attribute)
return "orderDesc(\"#{attribute}\")"
end

def cursorBefore(id)
def cursor_before(id)
return "cursorBefore(\"#{id}\")"
end

def cursorAfter(id)
def cursor_after(id)
return "cursorAfter(\"#{id}\")"
end

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

private

def addQuery(attribute, method, value)
def add_query(attribute, method, value)
if value.is_a?(Array)
"#{method}(\"#{attribute}\", [#{value.map {|item| parseValues(item)}.join(',')}])"
else
Expand Down
Loading

0 comments on commit af96e57

Please sign in to comment.