Skip to content

Commit d5a9f1c

Browse files
authored
Merge pull request #1182 from appwrite/feat-time-between
Add time between queries
2 parents f8fbc4b + 11ac73e commit d5a9f1c

File tree

33 files changed

+449
-141
lines changed

33 files changed

+449
-141
lines changed

composer.lock

Lines changed: 216 additions & 140 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function getSSLPage($url) {
3939

4040
// Leave the platform you want uncommented
4141
// $platform = 'client';
42-
$platform = 'console';
42+
$platform = 'server';
4343
// $platform = 'server';
4444

4545
$version = '1.8.x';

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ class Query(
254254
*/
255255
fun createdAfter(value: String) = Query("createdAfter", null, listOf(value)).toJson()
256256

257+
/**
258+
* Filter resources where document was created between start and end dates (inclusive).
259+
*
260+
* @param start The start date value.
261+
* @param end The end date value.
262+
* @returns The query string.
263+
*/
264+
fun createdBetween(start: String, end: String) = Query("createdBetween", null, listOf(start, end)).toJson()
265+
257266
/**
258267
* Filter resources where document was updated before date.
259268
*
@@ -270,6 +279,15 @@ class Query(
270279
*/
271280
fun updatedAfter(value: String) = Query("updatedAfter", null, listOf(value)).toJson()
272281

282+
/**
283+
* Filter resources where document was updated between start and end dates (inclusive).
284+
*
285+
* @param start The start date value.
286+
* @param end The end date value.
287+
* @returns The query string.
288+
*/
289+
fun updatedBetween(start: String, end: String) = Query("updatedBetween", null, listOf(start, end)).toJson()
290+
273291
/**
274292
* Combine multiple queries using logical OR operator.
275293
*

templates/dart/lib/query.dart.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ class Query {
111111
static String createdAfter(String value) =>
112112
Query._('createdAfter', null, value).toString();
113113

114+
/// Filter resources where document was created between [start] and [end] (inclusive).
115+
static String createdBetween(String start, String end) =>
116+
Query._('createdBetween', null, [start, end]).toString();
117+
114118
/// Filter resources where document was updated before [value].
115119
static String updatedBefore(String value) =>
116120
Query._('updatedBefore', null, value).toString();
@@ -119,6 +123,10 @@ class Query {
119123
static String updatedAfter(String value) =>
120124
Query._('updatedAfter', null, value).toString();
121125

126+
/// Filter resources where document was updated between [start] and [end] (inclusive).
127+
static String updatedBetween(String start, String end) =>
128+
Query._('updatedBetween', null, [start, end]).toString();
129+
122130
static String or(List<String> queries) => Query._(
123131
'or',
124132
null,

templates/dart/test/query_test.dart.twig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,13 @@ void main() {
283283
expect(query['method'], 'createdAfter');
284284
});
285285

286+
test('returns createdBetween', () {
287+
final query = jsonDecode(Query.createdBetween('2023-01-01', '2023-12-31'));
288+
expect(query['attribute'], null);
289+
expect(query['values'], ['2023-01-01', '2023-12-31']);
290+
expect(query['method'], 'createdBetween');
291+
});
292+
286293
test('returns updatedBefore', () {
287294
final query = jsonDecode(Query.updatedBefore('2023-01-01'));
288295
expect(query['attribute'], null);
@@ -296,5 +303,12 @@ void main() {
296303
expect(query['values'], ['2023-01-01']);
297304
expect(query['method'], 'updatedAfter');
298305
});
306+
307+
test('returns updatedBetween', () {
308+
final query = jsonDecode(Query.updatedBetween('2023-01-01', '2023-12-31'));
309+
expect(query['attribute'], null);
310+
expect(query['values'], ['2023-01-01', '2023-12-31']);
311+
expect(query['method'], 'updatedBetween');
312+
});
299313
}
300314

templates/deno/src/query.ts.twig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ export class Query {
173173
static createdAfter = (value: string): string =>
174174
new Query("createdAfter", undefined, value).toString();
175175

176+
/**
177+
* Filter resources where document was created between dates.
178+
*
179+
* @param {string} start
180+
* @param {string} end
181+
* @returns {string}
182+
*/
183+
static createdBetween = (start: string, end: string): string =>
184+
new Query("createdBetween", undefined, [start, end] as QueryTypesList).toString();
185+
176186
/**
177187
* Filter resources where document was updated before date.
178188
*
@@ -191,6 +201,16 @@ export class Query {
191201
static updatedAfter = (value: string): string =>
192202
new Query("updatedAfter", undefined, value).toString();
193203

204+
/**
205+
* Filter resources where document was updated between dates.
206+
*
207+
* @param {string} start
208+
* @param {string} end
209+
* @returns {string}
210+
*/
211+
static updatedBetween = (start: string, end: string): string =>
212+
new Query("updatedBetween", undefined, [start, end] as QueryTypesList).toString();
213+
194214
static or = (queries: string[]) =>
195215
new Query("or", undefined, queries.map((query) => JSON.parse(query))).toString();
196216

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ describe('Query', () => {
218218
`{"method":"createdAfter","values":["2023-01-01"]}`,
219219
));
220220

221+
test('createdBetween', () => assertEquals(
222+
Query.createdBetween('2023-01-01', '2023-12-31').toString(),
223+
`{"method":"createdBetween","values":["2023-01-01","2023-12-31"]}`,
224+
));
225+
221226
test('updatedBefore', () => assertEquals(
222227
Query.updatedBefore('2023-01-01').toString(),
223228
`{"method":"updatedBefore","values":["2023-01-01"]}`,
@@ -227,4 +232,9 @@ describe('Query', () => {
227232
Query.updatedAfter('2023-01-01').toString(),
228233
`{"method":"updatedAfter","values":["2023-01-01"]}`,
229234
));
235+
236+
test('updatedBetween', () => assertEquals(
237+
Query.updatedBetween('2023-01-01', '2023-12-31').toString(),
238+
`{"method":"updatedBetween","values":["2023-01-01","2023-12-31"]}`,
239+
));
230240
})

templates/dotnet/Package/Query.cs.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ namespace {{ spec.title | caseUcfirst }}
186186
return new Query("createdAfter", null, value).ToString();
187187
}
188188

189+
public static string CreatedBetween(string start, string end) {
190+
return new Query("createdBetween", null, new List<string> { start, end }).ToString();
191+
}
192+
189193
public static string UpdatedBefore(string value) {
190194
return new Query("updatedBefore", null, value).ToString();
191195
}
@@ -194,6 +198,10 @@ namespace {{ spec.title | caseUcfirst }}
194198
return new Query("updatedAfter", null, value).ToString();
195199
}
196200

201+
public static string UpdatedBetween(string start, string end) {
202+
return new Query("updatedBetween", null, new List<string> { start, end }).ToString();
203+
}
204+
197205
public static string Or(List<string> queries) {
198206
return new Query("or", null, queries.Select(q => JsonSerializer.Deserialize<Query>(q, Client.DeserializerOptions)).ToList()).ToString();
199207
}

templates/go/query.go.twig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ func CreatedAfter(value interface{}) string {
217217
})
218218
}
219219

220+
func CreatedBetween(start, end interface{}) string {
221+
values := []interface{}{start, end}
222+
return parseQuery(queryOptions{
223+
Method: "createdBetween",
224+
Values: &values,
225+
})
226+
}
227+
220228
func UpdatedBefore(value interface{}) string {
221229
values := toArray(value)
222230
return parseQuery(queryOptions{
@@ -233,6 +241,14 @@ func UpdatedAfter(value interface{}) string {
233241
})
234242
}
235243

244+
func UpdatedBetween(start, end interface{}) string {
245+
values := []interface{}{start, end}
246+
return parseQuery(queryOptions{
247+
Method: "updatedBetween",
248+
Values: &values,
249+
})
250+
}
251+
236252
func Select(attributes interface{}) string {
237253
values := toArray(attributes)
238254
return parseQuery(queryOptions{

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,14 @@ class Query(
6565

6666
fun createdAfter(value: String) = Query("createdAfter", null, listOf(value)).toJson()
6767

68+
fun createdBetween(start: String, end: String) = Query("createdBetween", null, listOf(start, end)).toJson()
69+
6870
fun updatedBefore(value: String) = Query("updatedBefore", null, listOf(value)).toJson()
6971

7072
fun updatedAfter(value: String) = Query("updatedAfter", null, listOf(value)).toJson()
7173

74+
fun updatedBetween(start: String, end: String) = Query("updatedBetween", null, listOf(start, end)).toJson()
75+
7276
fun or(queries: List<String>) = Query("or", null, queries.map { it.fromJson<Query>() }).toJson()
7377

7478
fun and(queries: List<String>) = Query("and", null, queries.map { it.fromJson<Query>() }).toJson()

0 commit comments

Comments
 (0)