Skip to content

Commit aea747c

Browse files
authored
Merge pull request #1177 from appwrite/spatial-type-queries
added spatial type queries
2 parents db229fa + f8cdda6 commit aea747c

File tree

28 files changed

+1457
-4
lines changed

28 files changed

+1457
-4
lines changed

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

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,122 @@ class Query(
304304
*/
305305
fun and(queries: List<String>) = Query("and", null, queries.map { it.fromJson<Query>() }).toJson()
306306

307+
/**
308+
* Filter resources where attribute is at a specific distance from the given coordinates.
309+
*
310+
* @param attribute The attribute to filter on.
311+
* @param values The coordinate values.
312+
* @param distance The distance value.
313+
* @param meters Whether the distance is in meters.
314+
* @returns The query string.
315+
*/
316+
fun distanceEqual(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceEqual", attribute, listOf(values, distance, meters)).toJson()
317+
318+
/**
319+
* Filter resources where attribute is not at a specific distance from the given coordinates.
320+
*
321+
* @param attribute The attribute to filter on.
322+
* @param values The coordinate values.
323+
* @param distance The distance value.
324+
* @param meters Whether the distance is in meters.
325+
* @returns The query string.
326+
*/
327+
fun distanceNotEqual(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceNotEqual", attribute, listOf(values, distance, meters)).toJson()
328+
329+
/**
330+
* Filter resources where attribute is at a distance greater than the specified value from the given coordinates.
331+
*
332+
* @param attribute The attribute to filter on.
333+
* @param values The coordinate values.
334+
* @param distance The distance value.
335+
* @param meters Whether the distance is in meters.
336+
* @returns The query string.
337+
*/
338+
fun distanceGreaterThan(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceGreaterThan", attribute, listOf(values, distance, meters)).toJson()
339+
340+
/**
341+
* Filter resources where attribute is at a distance less than the specified value from the given coordinates.
342+
*
343+
* @param attribute The attribute to filter on.
344+
* @param values The coordinate values.
345+
* @param distance The distance value.
346+
* @param meters Whether the distance is in meters.
347+
* @returns The query string.
348+
*/
349+
fun distanceLessThan(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceLessThan", attribute, listOf(values, distance, meters)).toJson()
350+
351+
/**
352+
* Filter resources where attribute intersects with the given geometry.
353+
*
354+
* @param attribute The attribute to filter on.
355+
* @param values The coordinate values.
356+
* @returns The query string.
357+
*/
358+
fun intersects(attribute: String, values: List<Any>) = Query("intersects", attribute, values).toJson()
359+
360+
/**
361+
* Filter resources where attribute does not intersect with the given geometry.
362+
*
363+
* @param attribute The attribute to filter on.
364+
* @param values The coordinate values.
365+
* @returns The query string.
366+
*/
367+
fun notIntersects(attribute: String, values: List<Any>) = Query("notIntersects", attribute, values).toJson()
368+
369+
/**
370+
* Filter resources where attribute crosses the given geometry.
371+
*
372+
* @param attribute The attribute to filter on.
373+
* @param values The coordinate values.
374+
* @returns The query string.
375+
*/
376+
fun crosses(attribute: String, values: List<Any>) = Query("crosses", attribute, values).toJson()
377+
378+
/**
379+
* Filter resources where attribute does not cross the given geometry.
380+
*
381+
* @param attribute The attribute to filter on.
382+
* @param values The coordinate values.
383+
* @returns The query string.
384+
*/
385+
fun notCrosses(attribute: String, values: List<Any>) = Query("notCrosses", attribute, values).toJson()
386+
387+
/**
388+
* Filter resources where attribute overlaps with the given geometry.
389+
*
390+
* @param attribute The attribute to filter on.
391+
* @param values The coordinate values.
392+
* @returns The query string.
393+
*/
394+
fun overlaps(attribute: String, values: List<Any>) = Query("overlaps", attribute, values).toJson()
395+
396+
/**
397+
* Filter resources where attribute does not overlap with the given geometry.
398+
*
399+
* @param attribute The attribute to filter on.
400+
* @param values The coordinate values.
401+
* @returns The query string.
402+
*/
403+
fun notOverlaps(attribute: String, values: List<Any>) = Query("notOverlaps", attribute, values).toJson()
404+
405+
/**
406+
* Filter resources where attribute touches the given geometry.
407+
*
408+
* @param attribute The attribute to filter on.
409+
* @param values The coordinate values.
410+
* @returns The query string.
411+
*/
412+
fun touches(attribute: String, values: List<Any>) = Query("touches", attribute, values).toJson()
413+
414+
/**
415+
* Filter resources where attribute does not touch the given geometry.
416+
*
417+
* @param attribute The attribute to filter on.
418+
* @param values The coordinate values.
419+
* @returns The query string.
420+
*/
421+
fun notTouches(attribute: String, values: List<Any>) = Query("notTouches", attribute, values).toJson()
422+
307423
/**
308424
* Parse the value to a list of values.
309425
*

templates/dart/lib/query.dart.twig

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,52 @@ class Query {
174174
/// docs for more information.
175175
static String offset(int offset) =>
176176
Query._('offset', null, offset).toString();
177+
178+
/// 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+
182+
/// 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+
186+
/// 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+
190+
/// 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+
194+
/// Filter resources where [attribute] intersects with the given geometry.
195+
static String intersects(String attribute, List<dynamic> values) =>
196+
Query._('intersects', attribute, values).toString();
197+
198+
/// Filter resources where [attribute] does not intersect with the given geometry.
199+
static String notIntersects(String attribute, List<dynamic> values) =>
200+
Query._('notIntersects', attribute, values).toString();
201+
202+
/// Filter resources where [attribute] crosses the given geometry.
203+
static String crosses(String attribute, List<dynamic> values) =>
204+
Query._('crosses', attribute, values).toString();
205+
206+
/// Filter resources where [attribute] does not cross the given geometry.
207+
static String notCrosses(String attribute, List<dynamic> values) =>
208+
Query._('notCrosses', attribute, values).toString();
209+
210+
/// Filter resources where [attribute] overlaps with the given geometry.
211+
static String overlaps(String attribute, List<dynamic> values) =>
212+
Query._('overlaps', attribute, values).toString();
213+
214+
/// Filter resources where [attribute] does not overlap with the given geometry.
215+
static String notOverlaps(String attribute, List<dynamic> values) =>
216+
Query._('notOverlaps', attribute, values).toString();
217+
218+
/// Filter resources where [attribute] touches the given geometry.
219+
static String touches(String attribute, List<dynamic> values) =>
220+
Query._('touches', attribute, values).toString();
221+
222+
/// Filter resources where [attribute] does not touch the given geometry.
223+
static String notTouches(String attribute, List<dynamic> values) =>
224+
Query._('notTouches', attribute, values).toString();
177225
}

templates/deno/src/query.ts.twig

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,132 @@ export class Query {
216216

217217
static and = (queries: string[]) =>
218218
new Query("and", undefined, queries.map((query) => JSON.parse(query))).toString();
219+
220+
/**
221+
* Filter resources where attribute is at a specific distance from the given coordinates.
222+
*
223+
* @param {string} attribute
224+
* @param {any[]} values
225+
* @param {number} distance
226+
* @param {boolean} meters
227+
* @returns {string}
228+
*/
229+
static distanceEqual = (attribute: string, values: any[], distance: number, meters: boolean = true): string =>
230+
new Query("distanceEqual", attribute, [values, distance, meters] as QueryTypesList).toString();
231+
232+
/**
233+
* Filter resources where attribute is not at a specific distance from the given coordinates.
234+
*
235+
* @param {string} attribute
236+
* @param {any[]} values
237+
* @param {number} distance
238+
* @param {boolean} meters
239+
* @returns {string}
240+
*/
241+
static distanceNotEqual = (attribute: string, values: any[], distance: number, meters: boolean = true): string =>
242+
new Query("distanceNotEqual", attribute, [values, distance, meters] as QueryTypesList).toString();
243+
244+
/**
245+
* Filter resources where attribute is at a distance greater than the specified value from the given coordinates.
246+
*
247+
* @param {string} attribute
248+
* @param {any[]} values
249+
* @param {number} distance
250+
* @param {boolean} meters
251+
* @returns {string}
252+
*/
253+
static distanceGreaterThan = (attribute: string, values: any[], distance: number, meters: boolean = true): string =>
254+
new Query("distanceGreaterThan", attribute, [values, distance, meters] as QueryTypesList).toString();
255+
256+
/**
257+
* Filter resources where attribute is at a distance less than the specified value from the given coordinates.
258+
*
259+
* @param {string} attribute
260+
* @param {any[]} values
261+
* @param {number} distance
262+
* @param {boolean} meters
263+
* @returns {string}
264+
*/
265+
static distanceLessThan = (attribute: string, values: any[], distance: number, meters: boolean = true): string =>
266+
new Query("distanceLessThan", attribute, [values, distance, meters] as QueryTypesList).toString();
267+
268+
/**
269+
* Filter resources where attribute intersects with the given geometry.
270+
*
271+
* @param {string} attribute
272+
* @param {any[]} values
273+
* @returns {string}
274+
*/
275+
static intersects = (attribute: string, values: any[]): string =>
276+
new Query("intersects", attribute, values).toString();
277+
278+
/**
279+
* Filter resources where attribute does not intersect with the given geometry.
280+
*
281+
* @param {string} attribute
282+
* @param {any[]} values
283+
* @returns {string}
284+
*/
285+
static notIntersects = (attribute: string, values: any[]): string =>
286+
new Query("notIntersects", attribute, values).toString();
287+
288+
/**
289+
* Filter resources where attribute crosses the given geometry.
290+
*
291+
* @param {string} attribute
292+
* @param {any[]} values
293+
* @returns {string}
294+
*/
295+
static crosses = (attribute: string, values: any[]): string =>
296+
new Query("crosses", attribute, values).toString();
297+
298+
/**
299+
* Filter resources where attribute does not cross the given geometry.
300+
*
301+
* @param {string} attribute
302+
* @param {any[]} values
303+
* @returns {string}
304+
*/
305+
static notCrosses = (attribute: string, values: any[]): string =>
306+
new Query("notCrosses", attribute, values).toString();
307+
308+
/**
309+
* Filter resources where attribute overlaps with the given geometry.
310+
*
311+
* @param {string} attribute
312+
* @param {any[]} values
313+
* @returns {string}
314+
*/
315+
static overlaps = (attribute: string, values: any[]): string =>
316+
new Query("overlaps", attribute, values).toString();
317+
318+
/**
319+
* Filter resources where attribute does not overlap with the given geometry.
320+
*
321+
* @param {string} attribute
322+
* @param {any[]} values
323+
* @returns {string}
324+
*/
325+
static notOverlaps = (attribute: string, values: any[]): string =>
326+
new Query("notOverlaps", attribute, values).toString();
327+
328+
/**
329+
* Filter resources where attribute touches the given geometry.
330+
*
331+
* @param {string} attribute
332+
* @param {any[]} values
333+
* @returns {string}
334+
*/
335+
static touches = (attribute: string, values: any[]): string =>
336+
new Query("touches", attribute, values).toString();
337+
338+
/**
339+
* Filter resources where attribute does not touch the given geometry.
340+
*
341+
* @param {string} attribute
342+
* @param {any[]} values
343+
* @returns {string}
344+
*/
345+
static notTouches = (attribute: string, values: any[]): string =>
346+
new Query("notTouches", attribute, values).toString();
219347
}

templates/dotnet/Package/Query.cs.twig

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,65 @@ namespace {{ spec.title | caseUcfirst }}
209209
public static string And(List<string> queries) {
210210
return new Query("and", null, queries.Select(q => JsonSerializer.Deserialize<Query>(q, Client.DeserializerOptions)).ToList()).ToString();
211211
}
212+
213+
public static string DistanceEqual(string attribute, object values, double distance, bool meters = true)
214+
{
215+
return new Query("distanceEqual", attribute, new List<object> { values, distance, meters }).ToString();
216+
}
217+
218+
public static string DistanceNotEqual(string attribute, object values, double distance, bool meters = true)
219+
{
220+
return new Query("distanceNotEqual", attribute, new List<object> { values, distance, meters }).ToString();
221+
}
222+
223+
public static string DistanceGreaterThan(string attribute, object values, double distance, bool meters = true)
224+
{
225+
return new Query("distanceGreaterThan", attribute, new List<object> { values, distance, meters }).ToString();
226+
}
227+
228+
public static string DistanceLessThan(string attribute, object values, double distance, bool meters = true)
229+
{
230+
return new Query("distanceLessThan", attribute, new List<object> { values, distance, meters }).ToString();
231+
}
232+
233+
public static string Intersects(string attribute, object values)
234+
{
235+
return new Query("intersects", attribute, values).ToString();
236+
}
237+
238+
public static string NotIntersects(string attribute, object values)
239+
{
240+
return new Query("notIntersects", attribute, values).ToString();
241+
}
242+
243+
public static string Crosses(string attribute, object values)
244+
{
245+
return new Query("crosses", attribute, values).ToString();
246+
}
247+
248+
public static string NotCrosses(string attribute, object values)
249+
{
250+
return new Query("notCrosses", attribute, values).ToString();
251+
}
252+
253+
public static string Overlaps(string attribute, object values)
254+
{
255+
return new Query("overlaps", attribute, values).ToString();
256+
}
257+
258+
public static string NotOverlaps(string attribute, object values)
259+
{
260+
return new Query("notOverlaps", attribute, values).ToString();
261+
}
262+
263+
public static string Touches(string attribute, object values)
264+
{
265+
return new Query("touches", attribute, values).ToString();
266+
}
267+
268+
public static string NotTouches(string attribute, object values)
269+
{
270+
return new Query("notTouches", attribute, values).ToString();
271+
}
212272
}
213273
}

0 commit comments

Comments
 (0)