Skip to content

Commit 561f99f

Browse files
authored
Merge pull request #1192 from appwrite/spatial-type-queries
updated query and tests for the contains and equal
2 parents 375a6c9 + 97a71ea commit 561f99f

File tree

28 files changed

+254
-188
lines changed

28 files changed

+254
-188
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ class Query(
313313
* @param meters Whether the distance is in meters.
314314
* @returns The query string.
315315
*/
316-
fun distanceEqual(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceEqual", attribute, listOf(values, distance, meters)).toJson()
316+
fun distanceEqual(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceEqual", attribute, listOf(listOf(values, distance, meters))).toJson()
317317

318318
/**
319319
* Filter resources where attribute is not at a specific distance from the given coordinates.
@@ -324,7 +324,7 @@ class Query(
324324
* @param meters Whether the distance is in meters.
325325
* @returns The query string.
326326
*/
327-
fun distanceNotEqual(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceNotEqual", attribute, listOf(values, distance, meters)).toJson()
327+
fun distanceNotEqual(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceNotEqual", attribute, listOf(listOf(values, distance, meters))).toJson()
328328

329329
/**
330330
* Filter resources where attribute is at a distance greater than the specified value from the given coordinates.
@@ -335,7 +335,7 @@ class Query(
335335
* @param meters Whether the distance is in meters.
336336
* @returns The query string.
337337
*/
338-
fun distanceGreaterThan(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceGreaterThan", attribute, listOf(values, distance, meters)).toJson()
338+
fun distanceGreaterThan(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceGreaterThan", attribute, listOf(listOf(values, distance, meters))).toJson()
339339

340340
/**
341341
* Filter resources where attribute is at a distance less than the specified value from the given coordinates.
@@ -346,7 +346,7 @@ class Query(
346346
* @param meters Whether the distance is in meters.
347347
* @returns The query string.
348348
*/
349-
fun distanceLessThan(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceLessThan", attribute, listOf(values, distance, meters)).toJson()
349+
fun distanceLessThan(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceLessThan", attribute, listOf(listOf(values, distance, meters))).toJson()
350350

351351
/**
352352
* Filter resources where attribute intersects with the given geometry.
@@ -355,7 +355,7 @@ class Query(
355355
* @param values The coordinate values.
356356
* @returns The query string.
357357
*/
358-
fun intersects(attribute: String, values: List<Any>) = Query("intersects", attribute, values).toJson()
358+
fun intersects(attribute: String, values: List<Any>) = Query("intersects", attribute, listOf(values)).toJson()
359359

360360
/**
361361
* Filter resources where attribute does not intersect with the given geometry.
@@ -364,7 +364,7 @@ class Query(
364364
* @param values The coordinate values.
365365
* @returns The query string.
366366
*/
367-
fun notIntersects(attribute: String, values: List<Any>) = Query("notIntersects", attribute, values).toJson()
367+
fun notIntersects(attribute: String, values: List<Any>) = Query("notIntersects", attribute, listOf(values)).toJson()
368368

369369
/**
370370
* Filter resources where attribute crosses the given geometry.
@@ -373,7 +373,7 @@ class Query(
373373
* @param values The coordinate values.
374374
* @returns The query string.
375375
*/
376-
fun crosses(attribute: String, values: List<Any>) = Query("crosses", attribute, values).toJson()
376+
fun crosses(attribute: String, values: List<Any>) = Query("crosses", attribute, listOf(values)).toJson()
377377

378378
/**
379379
* Filter resources where attribute does not cross the given geometry.
@@ -382,7 +382,7 @@ class Query(
382382
* @param values The coordinate values.
383383
* @returns The query string.
384384
*/
385-
fun notCrosses(attribute: String, values: List<Any>) = Query("notCrosses", attribute, values).toJson()
385+
fun notCrosses(attribute: String, values: List<Any>) = Query("notCrosses", attribute, listOf(values)).toJson()
386386

387387
/**
388388
* Filter resources where attribute overlaps with the given geometry.
@@ -391,7 +391,7 @@ class Query(
391391
* @param values The coordinate values.
392392
* @returns The query string.
393393
*/
394-
fun overlaps(attribute: String, values: List<Any>) = Query("overlaps", attribute, values).toJson()
394+
fun overlaps(attribute: String, values: List<Any>) = Query("overlaps", attribute, listOf(values)).toJson()
395395

396396
/**
397397
* Filter resources where attribute does not overlap with the given geometry.
@@ -400,7 +400,7 @@ class Query(
400400
* @param values The coordinate values.
401401
* @returns The query string.
402402
*/
403-
fun notOverlaps(attribute: String, values: List<Any>) = Query("notOverlaps", attribute, values).toJson()
403+
fun notOverlaps(attribute: String, values: List<Any>) = Query("notOverlaps", attribute, listOf(values)).toJson()
404404

405405
/**
406406
* Filter resources where attribute touches the given geometry.
@@ -409,7 +409,7 @@ class Query(
409409
* @param values The coordinate values.
410410
* @returns The query string.
411411
*/
412-
fun touches(attribute: String, values: List<Any>) = Query("touches", attribute, values).toJson()
412+
fun touches(attribute: String, values: List<Any>) = Query("touches", attribute, listOf(values)).toJson()
413413

414414
/**
415415
* Filter resources where attribute does not touch the given geometry.
@@ -418,7 +418,7 @@ class Query(
418418
* @param values The coordinate values.
419419
* @returns The query string.
420420
*/
421-
fun notTouches(attribute: String, values: List<Any>) = Query("notTouches", attribute, values).toJson()
421+
fun notTouches(attribute: String, values: List<Any>) = Query("notTouches", attribute, listOf(values)).toJson()
422422

423423
/**
424424
* Parse the value to a list of values.

templates/dart/lib/query.dart.twig

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ class Query {
99
Query._(this.method, [this.attribute = null, this.values = null]);
1010

1111
Map<String, dynamic> toJson() {
12-
final map = <String, dynamic>{'method': method};
13-
12+
final result = <String, dynamic>{};
13+
14+
result['method'] = method;
15+
1416
if(attribute != null) {
15-
map['attribute'] = attribute;
17+
result['attribute'] = attribute;
1618
}
1719

1820
if(values != null) {
19-
map['values'] = values is List ? values : [values];
21+
result['values'] = values is List ? values : [values];
2022
}
2123

22-
return map;
24+
return result;
2325
}
2426

2527
@override
@@ -35,7 +37,7 @@ class Query {
3537

3638
/// Filter resources where [attribute] is not equal to [value].
3739
static String notEqual(String attribute, dynamic value) =>
38-
Query._('notEqual', attribute, [value]).toString();
40+
Query._('notEqual', attribute, value).toString();
3941

4042
/// Filter resources where [attribute] is less than [value].
4143
static String lessThan(String attribute, dynamic value) =>
@@ -176,50 +178,50 @@ class Query {
176178
Query._('offset', null, offset).toString();
177179

178180
/// Filter resources where [attribute] is at a specific distance from the given coordinates.
179-
static String distanceEqual(String attribute, List<dynamic> values, double distance, [bool meters = true]) =>
180-
Query._('distanceEqual', attribute, [values, distance, meters]).toString();
181+
static String distanceEqual(String attribute, List<dynamic> values, num distance, [bool meters = true]) =>
182+
Query._('distanceEqual', attribute, [[values, distance, meters]]).toString();
181183

182184
/// Filter resources where [attribute] is not at a specific distance from the given coordinates.
183-
static String distanceNotEqual(String attribute, List<dynamic> values, double distance, [bool meters = true]) =>
184-
Query._('distanceNotEqual', attribute, [values, distance, meters]).toString();
185+
static String distanceNotEqual(String attribute, List<dynamic> values, num distance, [bool meters = true]) =>
186+
Query._('distanceNotEqual', attribute, [[values, distance, meters]]).toString();
185187

186188
/// Filter resources where [attribute] is at a distance greater than the specified value from the given coordinates.
187-
static String distanceGreaterThan(String attribute, List<dynamic> values, double distance, [bool meters = true]) =>
188-
Query._('distanceGreaterThan', attribute, [values, distance, meters]).toString();
189+
static String distanceGreaterThan(String attribute, List<dynamic> values, num distance, [bool meters = true]) =>
190+
Query._('distanceGreaterThan', attribute, [[values, distance, meters]]).toString();
189191

190192
/// Filter resources where [attribute] is at a distance less than the specified value from the given coordinates.
191-
static String distanceLessThan(String attribute, List<dynamic> values, double distance, [bool meters = true]) =>
192-
Query._('distanceLessThan', attribute, [values, distance, meters]).toString();
193+
static String distanceLessThan(String attribute, List<dynamic> values, num distance, [bool meters = true]) =>
194+
Query._('distanceLessThan', attribute, [[values, distance, meters]]).toString();
193195

194196
/// Filter resources where [attribute] intersects with the given geometry.
195197
static String intersects(String attribute, List<dynamic> values) =>
196-
Query._('intersects', attribute, values).toString();
198+
Query._('intersects', attribute, [values]).toString();
197199

198200
/// Filter resources where [attribute] does not intersect with the given geometry.
199201
static String notIntersects(String attribute, List<dynamic> values) =>
200-
Query._('notIntersects', attribute, values).toString();
202+
Query._('notIntersects', attribute, [values]).toString();
201203

202204
/// Filter resources where [attribute] crosses the given geometry.
203205
static String crosses(String attribute, List<dynamic> values) =>
204-
Query._('crosses', attribute, values).toString();
206+
Query._('crosses', attribute, [values]).toString();
205207

206208
/// Filter resources where [attribute] does not cross the given geometry.
207209
static String notCrosses(String attribute, List<dynamic> values) =>
208-
Query._('notCrosses', attribute, values).toString();
210+
Query._('notCrosses', attribute, [values]).toString();
209211

210212
/// Filter resources where [attribute] overlaps with the given geometry.
211213
static String overlaps(String attribute, List<dynamic> values) =>
212-
Query._('overlaps', attribute, values).toString();
214+
Query._('overlaps', attribute, [values]).toString();
213215

214216
/// Filter resources where [attribute] does not overlap with the given geometry.
215217
static String notOverlaps(String attribute, List<dynamic> values) =>
216-
Query._('notOverlaps', attribute, values).toString();
218+
Query._('notOverlaps', attribute, [values]).toString();
217219

218220
/// Filter resources where [attribute] touches the given geometry.
219221
static String touches(String attribute, List<dynamic> values) =>
220-
Query._('touches', attribute, values).toString();
222+
Query._('touches', attribute, [values]).toString();
221223

222224
/// Filter resources where [attribute] does not touch the given geometry.
223225
static String notTouches(String attribute, List<dynamic> values) =>
224-
Query._('notTouches', attribute, values).toString();
226+
Query._('notTouches', attribute, [values]).toString();
225227
}

templates/deno/src/query.ts.twig

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
type QueryTypesSingle = string | number | boolean;
2-
export type QueryTypesList = string[] | number[] | boolean[] | Query[];
2+
export type QueryTypesList = string[] | number[] | boolean[] | Query[] | any[];
33
export type QueryTypes = QueryTypesSingle | QueryTypesList;
44
type AttributesTypes = string | string[];
55

@@ -33,10 +33,10 @@ export class Query {
3333
});
3434
}
3535

36-
static equal = (attribute: string, value: QueryTypes): string =>
36+
static equal = (attribute: string, value: QueryTypes | any[]): string =>
3737
new Query("equal", attribute, value).toString();
3838

39-
static notEqual = (attribute: string, value: QueryTypes): string =>
39+
static notEqual = (attribute: string, value: QueryTypes | any[]): string =>
4040
new Query("notEqual", attribute, value).toString();
4141

4242
static lessThan = (attribute: string, value: QueryTypes): string =>
@@ -100,7 +100,7 @@ export class Query {
100100
* @param {string | string[]} value
101101
* @returns {string}
102102
*/
103-
static contains = (attribute: string, value: string | string[]): string =>
103+
static contains = (attribute: string, value: string | any[]): string =>
104104
new Query("contains", attribute, value).toString();
105105

106106
/**
@@ -110,7 +110,7 @@ export class Query {
110110
* @param {string | string[]} value
111111
* @returns {string}
112112
*/
113-
static notContains = (attribute: string, value: string | string[]): string =>
113+
static notContains = (attribute: string, value: string | any[]): string =>
114114
new Query("notContains", attribute, value).toString();
115115

116116
/**
@@ -227,7 +227,7 @@ export class Query {
227227
* @returns {string}
228228
*/
229229
static distanceEqual = (attribute: string, values: any[], distance: number, meters: boolean = true): string =>
230-
new Query("distanceEqual", attribute, [values, distance, meters] as QueryTypesList).toString();
230+
new Query("distanceEqual", attribute, [[values, distance, meters]]).toString();
231231

232232
/**
233233
* Filter resources where attribute is not at a specific distance from the given coordinates.
@@ -239,7 +239,7 @@ export class Query {
239239
* @returns {string}
240240
*/
241241
static distanceNotEqual = (attribute: string, values: any[], distance: number, meters: boolean = true): string =>
242-
new Query("distanceNotEqual", attribute, [values, distance, meters] as QueryTypesList).toString();
242+
new Query("distanceNotEqual", attribute, [[values, distance, meters]]).toString();
243243

244244
/**
245245
* Filter resources where attribute is at a distance greater than the specified value from the given coordinates.
@@ -251,7 +251,7 @@ export class Query {
251251
* @returns {string}
252252
*/
253253
static distanceGreaterThan = (attribute: string, values: any[], distance: number, meters: boolean = true): string =>
254-
new Query("distanceGreaterThan", attribute, [values, distance, meters] as QueryTypesList).toString();
254+
new Query("distanceGreaterThan", attribute, [[values, distance, meters]]).toString();
255255

256256
/**
257257
* Filter resources where attribute is at a distance less than the specified value from the given coordinates.
@@ -263,7 +263,7 @@ export class Query {
263263
* @returns {string}
264264
*/
265265
static distanceLessThan = (attribute: string, values: any[], distance: number, meters: boolean = true): string =>
266-
new Query("distanceLessThan", attribute, [values, distance, meters] as QueryTypesList).toString();
266+
new Query("distanceLessThan", attribute, [[values, distance, meters]]).toString();
267267

268268
/**
269269
* Filter resources where attribute intersects with the given geometry.
@@ -273,7 +273,7 @@ export class Query {
273273
* @returns {string}
274274
*/
275275
static intersects = (attribute: string, values: any[]): string =>
276-
new Query("intersects", attribute, values).toString();
276+
new Query("intersects", attribute, [values]).toString();
277277

278278
/**
279279
* Filter resources where attribute does not intersect with the given geometry.
@@ -283,7 +283,7 @@ export class Query {
283283
* @returns {string}
284284
*/
285285
static notIntersects = (attribute: string, values: any[]): string =>
286-
new Query("notIntersects", attribute, values).toString();
286+
new Query("notIntersects", attribute, [values]).toString();
287287

288288
/**
289289
* Filter resources where attribute crosses the given geometry.
@@ -293,7 +293,7 @@ export class Query {
293293
* @returns {string}
294294
*/
295295
static crosses = (attribute: string, values: any[]): string =>
296-
new Query("crosses", attribute, values).toString();
296+
new Query("crosses", attribute, [values]).toString();
297297

298298
/**
299299
* Filter resources where attribute does not cross the given geometry.
@@ -303,7 +303,7 @@ export class Query {
303303
* @returns {string}
304304
*/
305305
static notCrosses = (attribute: string, values: any[]): string =>
306-
new Query("notCrosses", attribute, values).toString();
306+
new Query("notCrosses", attribute, [values]).toString();
307307

308308
/**
309309
* Filter resources where attribute overlaps with the given geometry.
@@ -313,7 +313,7 @@ export class Query {
313313
* @returns {string}
314314
*/
315315
static overlaps = (attribute: string, values: any[]): string =>
316-
new Query("overlaps", attribute, values).toString();
316+
new Query("overlaps", attribute, [values]).toString();
317317

318318
/**
319319
* Filter resources where attribute does not overlap with the given geometry.
@@ -323,7 +323,7 @@ export class Query {
323323
* @returns {string}
324324
*/
325325
static notOverlaps = (attribute: string, values: any[]): string =>
326-
new Query("notOverlaps", attribute, values).toString();
326+
new Query("notOverlaps", attribute, [values]).toString();
327327

328328
/**
329329
* Filter resources where attribute touches the given geometry.
@@ -333,7 +333,7 @@ export class Query {
333333
* @returns {string}
334334
*/
335335
static touches = (attribute: string, values: any[]): string =>
336-
new Query("touches", attribute, values).toString();
336+
new Query("touches", attribute, [values]).toString();
337337

338338
/**
339339
* Filter resources where attribute does not touch the given geometry.
@@ -343,5 +343,5 @@ export class Query {
343343
* @returns {string}
344344
*/
345345
static notTouches = (attribute: string, values: any[]): string =>
346-
new Query("notTouches", attribute, values).toString();
346+
new Query("notTouches", attribute, [values]).toString();
347347
}

0 commit comments

Comments
 (0)