Skip to content

Commit d07ab71

Browse files
committed
Add orderRandom query
1 parent 6fda9e5 commit d07ab71

File tree

31 files changed

+95
-1
lines changed

31 files changed

+95
-1
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ class Query(
151151
*/
152152
fun orderDesc(attribute: String) = Query("orderDesc", attribute).toJson()
153153

154+
/**
155+
* Sort results randomly.
156+
*
157+
* @returns The query string.
158+
*/
159+
fun orderRandom() = Query("orderRandom").toJson()
160+
154161
/**
155162
* Return results before documentId.
156163
*

templates/dart/lib/query.dart.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ class Query {
153153
static String orderDesc(String attribute) =>
154154
Query._('orderDesc', attribute).toString();
155155

156+
/// Sort results randomly.
157+
static String orderRandom() =>
158+
Query._('orderRandom').toString();
159+
156160
/// Return results before [id].
157161
///
158162
/// Refer to the [Cursor Based Pagination]({{sdk.url}}/docs/pagination#cursor-pagination)

templates/dart/test/query_test.dart.twig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ void main() {
190190
expect(query['method'], 'orderDesc');
191191
});
192192

193+
test('returns orderRandom', () {
194+
final query = jsonDecode(Query.orderRandom());
195+
expect(query['attribute'], null);
196+
expect(query['values'], null);
197+
expect(query['method'], 'orderRandom');
198+
});
199+
193200
test('returns cursorBefore', () {
194201
final query = jsonDecode(Query.cursorBefore('custom'));
195202
expect(query['attribute'], null);

templates/deno/src/query.ts.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ export class Query {
8181
static orderAsc = (attribute: string): string =>
8282
new Query("orderAsc", attribute).toString();
8383

84+
static orderRandom = (): string =>
85+
new Query("orderRandom").toString();
86+
8487
static cursorAfter = (documentId: string): string =>
8588
new Query("cursorAfter", undefined, documentId).toString();
8689

templates/deno/test/query.test.ts.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ describe('Query', () => {
153153
`{"method":"orderDesc","attribute":"attr"}`,
154154
));
155155

156+
test('orderRandom', () => assertEquals(
157+
Query.orderRandom().toString(),
158+
`{"method":"orderRandom"}`,
159+
));
160+
156161
test('cursorBefore', () => assertEquals(
157162
Query.cursorBefore('attr').toString(),
158163
`{"method":"cursorBefore","attribute":"attr"}`,

templates/dotnet/Package/Query.cs.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ namespace {{ spec.title | caseUcfirst }}
138138
return new Query("orderDesc", attribute, null).ToString();
139139
}
140140

141+
public static string OrderRandom() {
142+
return new Query("orderRandom", null, null).ToString();
143+
}
144+
141145
public static string Limit(int limit) {
142146
return new Query("limit", null, limit).ToString();
143147
}

templates/go/query.go.twig

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,14 @@ func OrderDesc(attribute string) string {
268268
return parseQuery(queryOptions{
269269
Method: "orderDesc",
270270
Attribute: &attribute,
271-
})}
271+
})
272+
}
273+
274+
func OrderRandom() string {
275+
return parseQuery(queryOptions{
276+
Method: "orderRandom",
277+
})
278+
}
272279

273280
func CursorBefore(documentId interface{}) string {
274281
values := toArray(documentId)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class Query(
4141

4242
fun orderDesc(attribute: String) = Query("orderDesc", attribute).toJson()
4343

44+
fun orderRandom() = Query("orderRandom").toJson()
45+
4446
fun cursorBefore(documentId: String) = Query("cursorBefore", null, listOf(documentId)).toJson()
4547

4648
fun cursorAfter(documentId: String) = Query("cursorAfter", null, listOf(documentId)).toJson()

templates/php/src/Query.php.twig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,16 @@ class Query implements \JsonSerializable
233233
return (new Query('orderDesc', $attribute, null))->__toString();
234234
}
235235
236+
/**
237+
* Order Random
238+
*
239+
* @return string
240+
*/
241+
public static function orderRandom(): string
242+
{
243+
return (new Query('orderRandom', null, null))->__toString();
244+
}
245+
236246
/**
237247
* Limit
238248
*

templates/php/tests/QueryTest.php.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ final class QueryTest extends TestCase {
131131
$this->assertSame('orderDesc("attr")', Query::orderDesc('attr'));
132132
}
133133
134+
public function testOrderRandom(): void {
135+
$this->assertSame('orderRandom()', Query::orderRandom());
136+
}
137+
134138
public function testCursorBefore(): void {
135139
$this->assertSame('cursorBefore("attr")', Query::cursorBefore('attr'));
136140
}

0 commit comments

Comments
 (0)