Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions templates/android/library/src/main/java/io/package/Query.kt.twig
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ class Query(
fun max(attribute: String, alias: String = "") = Query("max", attribute, if (alias.isNotEmpty()) listOf(alias) else null).toJson()

/**
* Standard deviation of [attribute], optionally aliased.
* Population standard deviation of [attribute] (the same as stddevPop), optionally aliased.
*
* @param attribute The attribute to inspect.
* @param alias Optional result alias.
Expand All @@ -611,7 +611,7 @@ class Query(
fun stddevSamp(attribute: String, alias: String = "") = Query("stddevSamp", attribute, if (alias.isNotEmpty()) listOf(alias) else null).toJson()

/**
* Variance of [attribute], optionally aliased.
* Population variance of [attribute] (the same as varPop), optionally aliased.
*
* @param attribute The attribute to inspect.
* @param alias Optional result alias.
Expand Down Expand Up @@ -698,19 +698,19 @@ class Query(
fun on(left: String, right: String, operator: String = "=") = Query("on", values = listOf(left, operator, right)).toJson()

/**
* Inner join. [table] is the joined collection/table ID.
* Inner join. [table] is the joined collection/table ID; without an alias the server names the join after it, if the ID is a valid alias, and otherwise rejects the query.
*
* @param table Joined table ID.
* @param left Left-hand join column.
* @param right Right-hand join column.
* @param operator Comparison operator. Defaults to `=`.
* @param alias Optional table alias.
* @param alias Optional table alias. Defaults to the table ID when that is a valid alias.
* @returns The query string.
*/
fun join(table: String, left: String, right: String, operator: String = "=", alias: String = "") = joinQuery("join", table, left, right, operator, alias)

/**
* Inner join with nested ON queries and no alias.
* Inner join with nested ON queries, named after the table ID when that is a valid alias.
*
* @param table Joined table ID.
* @param on Nested ON queries, including [on].
Expand All @@ -729,19 +729,19 @@ class Query(
fun join(table: String, alias: String, on: List<String>) = nestedJoin("join", table, alias, on)

/**
* Left join. [table] is the joined collection/table ID.
* Left join. [table] is the joined collection/table ID; without an alias the server names the join after it, if the ID is a valid alias, and otherwise rejects the query.
*
* @param table Joined table ID.
* @param left Left-hand join column.
* @param right Right-hand join column.
* @param operator Comparison operator. Defaults to `=`.
* @param alias Optional table alias.
* @param alias Optional table alias. Defaults to the table ID when that is a valid alias.
* @returns The query string.
*/
fun leftJoin(table: String, left: String, right: String, operator: String = "=", alias: String = "") = joinQuery("leftJoin", table, left, right, operator, alias)

/**
* Left join with nested ON queries and no alias.
* Left join with nested ON queries, named after the table ID when that is a valid alias.
*
* @param table Joined table ID.
* @param on Nested ON queries, including [on].
Expand All @@ -760,19 +760,19 @@ class Query(
fun leftJoin(table: String, alias: String, on: List<String>) = nestedJoin("leftJoin", table, alias, on)

/**
* Right join. [table] is the joined collection/table ID.
* Right join. [table] is the joined collection/table ID; without an alias the server names the join after it, if the ID is a valid alias, and otherwise rejects the query.
*
* @param table Joined table ID.
* @param left Left-hand join column.
* @param right Right-hand join column.
* @param operator Comparison operator. Defaults to `=`.
* @param alias Optional table alias.
* @param alias Optional table alias. Defaults to the table ID when that is a valid alias.
* @returns The query string.
*/
fun rightJoin(table: String, left: String, right: String, operator: String = "=", alias: String = "") = joinQuery("rightJoin", table, left, right, operator, alias)

/**
* Right join with nested ON queries and no alias.
* Right join with nested ON queries, named after the table ID when that is a valid alias.
*
* @param table Joined table ID.
* @param on Nested ON queries, including [on].
Expand All @@ -791,19 +791,19 @@ class Query(
fun rightJoin(table: String, alias: String, on: List<String>) = nestedJoin("rightJoin", table, alias, on)

/**
* Full outer join. [table] is the joined collection/table ID.
* Full outer join. [table] is the joined collection/table ID; without an alias the server names the join after it, if the ID is a valid alias, and otherwise rejects the query.
*
* @param table Joined table ID.
* @param left Left-hand join column.
* @param right Right-hand join column.
* @param operator Comparison operator. Defaults to `=`.
* @param alias Optional table alias.
* @param alias Optional table alias. Defaults to the table ID when that is a valid alias.
* @returns The query string.
*/
fun fullOuterJoin(table: String, left: String, right: String, operator: String = "=", alias: String = "") = joinQuery("fullOuterJoin", table, left, right, operator, alias)

/**
* Full outer join with nested ON queries and no alias.
* Full outer join with nested ON queries, named after the table ID when that is a valid alias.
*
* @param table Joined table ID.
* @param on Nested ON queries, including [on].
Expand All @@ -822,10 +822,10 @@ class Query(
fun fullOuterJoin(table: String, alias: String, on: List<String>) = nestedJoin("fullOuterJoin", table, alias, on)

/**
* Cross join. [table] is the joined collection/table ID.
* Cross join. [table] is the joined collection/table ID; without an alias the server names the join after it, if the ID is a valid alias, and otherwise rejects the query.
*
* @param table Joined table ID.
* @param alias Optional table alias.
* @param alias Optional table alias. Defaults to the table ID when that is a valid alias.
* @returns The query string.
*/
fun crossJoin(table: String, alias: String = "") = Query("crossJoin", table, if (alias.isNotEmpty()) listOf(alias) else null).toJson()
Expand Down
14 changes: 7 additions & 7 deletions templates/dart/lib/query.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class Query {
static String max(String attribute, [String alias = '']) =>
Query._('max', attribute, alias.isNotEmpty ? alias : null).toString();

/// Standard deviation of [attribute], optionally aliased.
/// Population standard deviation of [attribute] (the same as stddevPop), optionally aliased.
static String stddev(String attribute, [String alias = '']) =>
Query._('stddev', attribute, alias.isNotEmpty ? alias : null).toString();

Expand All @@ -367,7 +367,7 @@ class Query {
Query._('stddevSamp', attribute, alias.isNotEmpty ? alias : null)
.toString();

/// Variance of [attribute], optionally aliased.
/// Population variance of [attribute] (the same as varPop), optionally aliased.
static String variance(String attribute, [String alias = '']) =>
Query._('variance', attribute, alias.isNotEmpty ? alias : null)
.toString();
Expand Down Expand Up @@ -410,7 +410,7 @@ class Query {
static String on(String left, String right, [String operator = '=']) =>
Query._('on', null, [left, operator, right]).toString();

/// Inner join. [table] is the joined collection/table ID.
/// Inner join. [table] is the joined collection/table ID; without an alias the server names the join after it, if the ID is a valid alias, and otherwise rejects the query.
static String join(
String table,
Object leftOrAliasOrOn, [
Expand All @@ -420,7 +420,7 @@ class Query {
]) =>
Query._createJoin('join', table, leftOrAliasOrOn, rightOrOn, operator, alias);

/// Left join. [table] is the joined collection/table ID.
/// Left join. [table] is the joined collection/table ID; without an alias the server names the join after it, if the ID is a valid alias, and otherwise rejects the query.
static String leftJoin(
String table,
Object leftOrAliasOrOn, [
Expand All @@ -430,7 +430,7 @@ class Query {
]) =>
Query._createJoin('leftJoin', table, leftOrAliasOrOn, rightOrOn, operator, alias);

/// Right join. [table] is the joined collection/table ID.
/// Right join. [table] is the joined collection/table ID; without an alias the server names the join after it, if the ID is a valid alias, and otherwise rejects the query.
static String rightJoin(
String table,
Object leftOrAliasOrOn, [
Expand All @@ -440,7 +440,7 @@ class Query {
]) =>
Query._createJoin('rightJoin', table, leftOrAliasOrOn, rightOrOn, operator, alias);

/// Full outer join. [table] is the joined collection/table ID.
/// Full outer join. [table] is the joined collection/table ID; without an alias the server names the join after it, if the ID is a valid alias, and otherwise rejects the query.
static String fullOuterJoin(
String table,
Object leftOrAliasOrOn, [
Expand All @@ -450,7 +450,7 @@ class Query {
]) =>
Query._createJoin('fullOuterJoin', table, leftOrAliasOrOn, rightOrOn, operator, alias);

/// Cross join. [table] is the joined collection/table ID.
/// Cross join. [table] is the joined collection/table ID; without an alias the server names the join after it, if the ID is a valid alias, and otherwise rejects the query.
static String crossJoin(String table, [String alias = '']) =>
Query._('crossJoin', table, alias.isNotEmpty ? alias : null).toString();

Expand Down
17 changes: 17 additions & 0 deletions templates/dart/test/query_test.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,23 @@ void main() {
expect(query['values'], ['ord']);
});

test('returns nested join without alias, leaving the alias to the server',
() {
final query =
jsonDecode(Query.join('orders', [Query.on('\$id', 'customerId')]));
expect(query['method'], 'join');
expect(query['attribute'], 'orders');
expect(query['values'].length, 1);
expect(query['values'][0]['method'], 'on');
});

test('returns crossJoin without alias, leaving the alias to the server', () {
final query = jsonDecode(Query.crossJoin('orders'));
expect(query['method'], 'crossJoin');
expect(query['attribute'], 'orders');
expect(query['values'] ?? [], isEmpty);
});

test('returns vectorDot', () {
final query = jsonDecode(Query.vectorDot('embedding', [0.1, 0.2]));
expect(query['method'], 'vectorDot');
Expand Down
32 changes: 32 additions & 0 deletions templates/go/query_test.go.twig
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,38 @@ func TestCrossJoin(t *testing.T) {
}
}

func TestNestedJoinWithoutAliasLeavesTheAliasToTheServer(t *testing.T) {
q := JoinOn("orders", "", []string{On("$id", "customerId", "")})
var data map[string]interface{}
if err := json.Unmarshal([]byte(q), &data); err != nil {
t.Fatal(err)
}
if data["method"] != "join" {
t.Errorf("Expected join, got %v", data["method"])
}
values := data["values"].([]interface{})
if len(values) != 1 {
t.Fatalf("Expected only the ON condition, got %v", values)
}
if values[0].(map[string]interface{})["method"] != "on" {
t.Errorf("Expected on, got %v", values[0])
}
}

func TestCrossJoinWithoutAliasLeavesTheAliasToTheServer(t *testing.T) {
q := CrossJoin("orders", "")
var data map[string]interface{}
if err := json.Unmarshal([]byte(q), &data); err != nil {
t.Fatal(err)
}
if data["method"] != "crossJoin" {
t.Errorf("Expected crossJoin, got %v", data["method"])
}
if values, ok := data["values"].([]interface{}); ok && len(values) != 0 {
t.Errorf("Expected no alias, got %v", values)
}
}

func TestVectorDot(t *testing.T) {
q := VectorDot("embedding", []float64{0.1, 0.2})
var data map[string]interface{}
Expand Down
32 changes: 16 additions & 16 deletions templates/kotlin/src/main/kotlin/io/appwrite/Query.kt.twig
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class Query(
fun max(attribute: String, alias: String = "") = Query("max", attribute, if (alias.isNotEmpty()) listOf(alias) else null).toJson()

/**
* Standard deviation of [attribute], optionally aliased.
* Population standard deviation of [attribute] (the same as stddevPop), optionally aliased.
*
* @param attribute The attribute to inspect.
* @param alias Optional result alias.
Expand All @@ -311,7 +311,7 @@ class Query(
fun stddevSamp(attribute: String, alias: String = "") = Query("stddevSamp", attribute, if (alias.isNotEmpty()) listOf(alias) else null).toJson()

/**
* Variance of [attribute], optionally aliased.
* Population variance of [attribute] (the same as varPop), optionally aliased.
*
* @param attribute The attribute to inspect.
* @param alias Optional result alias.
Expand Down Expand Up @@ -398,19 +398,19 @@ class Query(
fun on(left: String, right: String, operator: String = "=") = Query("on", values = listOf(left, operator, right)).toJson()

/**
* Inner join. [table] is the joined collection/table ID.
* Inner join. [table] is the joined collection/table ID; without an alias the server names the join after it, if the ID is a valid alias, and otherwise rejects the query.
*
* @param table Joined table ID.
* @param left Left-hand join column.
* @param right Right-hand join column.
* @param operator Comparison operator. Defaults to `=`.
* @param alias Optional table alias.
* @param alias Optional table alias. Defaults to the table ID when that is a valid alias.
* @returns The query string.
*/
fun join(table: String, left: String, right: String, operator: String = "=", alias: String = "") = joinQuery("join", table, left, right, operator, alias)

/**
* Inner join with nested ON queries and no alias.
* Inner join with nested ON queries, named after the table ID when that is a valid alias.
*
* @param table Joined table ID.
* @param on Nested ON queries, including [on].
Expand All @@ -429,19 +429,19 @@ class Query(
fun join(table: String, alias: String, on: List<String>) = nestedJoin("join", table, alias, on)

/**
* Left join. [table] is the joined collection/table ID.
* Left join. [table] is the joined collection/table ID; without an alias the server names the join after it, if the ID is a valid alias, and otherwise rejects the query.
*
* @param table Joined table ID.
* @param left Left-hand join column.
* @param right Right-hand join column.
* @param operator Comparison operator. Defaults to `=`.
* @param alias Optional table alias.
* @param alias Optional table alias. Defaults to the table ID when that is a valid alias.
* @returns The query string.
*/
fun leftJoin(table: String, left: String, right: String, operator: String = "=", alias: String = "") = joinQuery("leftJoin", table, left, right, operator, alias)

/**
* Left join with nested ON queries and no alias.
* Left join with nested ON queries, named after the table ID when that is a valid alias.
*
* @param table Joined table ID.
* @param on Nested ON queries, including [on].
Expand All @@ -460,19 +460,19 @@ class Query(
fun leftJoin(table: String, alias: String, on: List<String>) = nestedJoin("leftJoin", table, alias, on)

/**
* Right join. [table] is the joined collection/table ID.
* Right join. [table] is the joined collection/table ID; without an alias the server names the join after it, if the ID is a valid alias, and otherwise rejects the query.
*
* @param table Joined table ID.
* @param left Left-hand join column.
* @param right Right-hand join column.
* @param operator Comparison operator. Defaults to `=`.
* @param alias Optional table alias.
* @param alias Optional table alias. Defaults to the table ID when that is a valid alias.
* @returns The query string.
*/
fun rightJoin(table: String, left: String, right: String, operator: String = "=", alias: String = "") = joinQuery("rightJoin", table, left, right, operator, alias)

/**
* Right join with nested ON queries and no alias.
* Right join with nested ON queries, named after the table ID when that is a valid alias.
*
* @param table Joined table ID.
* @param on Nested ON queries, including [on].
Expand All @@ -491,19 +491,19 @@ class Query(
fun rightJoin(table: String, alias: String, on: List<String>) = nestedJoin("rightJoin", table, alias, on)

/**
* Full outer join. [table] is the joined collection/table ID.
* Full outer join. [table] is the joined collection/table ID; without an alias the server names the join after it, if the ID is a valid alias, and otherwise rejects the query.
*
* @param table Joined table ID.
* @param left Left-hand join column.
* @param right Right-hand join column.
* @param operator Comparison operator. Defaults to `=`.
* @param alias Optional table alias.
* @param alias Optional table alias. Defaults to the table ID when that is a valid alias.
* @returns The query string.
*/
fun fullOuterJoin(table: String, left: String, right: String, operator: String = "=", alias: String = "") = joinQuery("fullOuterJoin", table, left, right, operator, alias)

/**
* Full outer join with nested ON queries and no alias.
* Full outer join with nested ON queries, named after the table ID when that is a valid alias.
*
* @param table Joined table ID.
* @param on Nested ON queries, including [on].
Expand All @@ -522,10 +522,10 @@ class Query(
fun fullOuterJoin(table: String, alias: String, on: List<String>) = nestedJoin("fullOuterJoin", table, alias, on)

/**
* Cross join. [table] is the joined collection/table ID.
* Cross join. [table] is the joined collection/table ID; without an alias the server names the join after it, if the ID is a valid alias, and otherwise rejects the query.
*
* @param table Joined table ID.
* @param alias Optional table alias.
* @param alias Optional table alias. Defaults to the table ID when that is a valid alias.
* @returns The query string.
*/
fun crossJoin(table: String, alias: String = "") = Query("crossJoin", table, if (alias.isNotEmpty()) listOf(alias) else null).toJson()
Expand Down
Loading
Loading