Skip to content

Commit a2ccc86

Browse files
committed
Add spatial queries
1 parent 84b4dac commit a2ccc86

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,66 @@ class Query(
7777

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

80+
/**
81+
* Filter resources where attribute is at a specific distance from the given coordinates.
82+
*
83+
* @param attribute The attribute to filter on.
84+
* @param values The coordinate values.
85+
* @param distance The distance value.
86+
* @param meters Whether the distance is in meters.
87+
* @returns The query string.
88+
*/
89+
fun distanceEqual(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceEqual", attribute, listOf(values, distance, meters)).toJson()
90+
91+
/**
92+
* Filter resources where attribute is not at a specific distance from the given coordinates.
93+
*
94+
* @param attribute The attribute to filter on.
95+
* @param values The coordinate values.
96+
* @param distance The distance value.
97+
* @param meters Whether the distance is in meters.
98+
* @returns The query string.
99+
*/
100+
fun distanceNotEqual(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceNotEqual", attribute, listOf(values, distance, meters)).toJson()
101+
102+
/**
103+
* Filter resources where attribute is at a distance greater than the specified value from the given coordinates.
104+
*
105+
* @param attribute The attribute to filter on.
106+
* @param values The coordinate values.
107+
* @param distance The distance value.
108+
* @param meters Whether the distance is in meters.
109+
* @returns The query string.
110+
*/
111+
fun distanceGreaterThan(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceGreaterThan", attribute, listOf(values, distance, meters)).toJson()
112+
113+
/**
114+
* Filter resources where attribute is at a distance less than the specified value from the given coordinates.
115+
*
116+
* @param attribute The attribute to filter on.
117+
* @param values The coordinate values.
118+
* @param distance The distance value.
119+
* @param meters Whether the distance is in meters.
120+
* @returns The query string.
121+
*/
122+
fun distanceLessThan(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceLessThan", attribute, listOf(values, distance, meters)).toJson()
123+
124+
fun intersects(attribute: String, values: List<Any>) = Query("intersects", attribute, values).toJson()
125+
126+
fun notIntersects(attribute: String, values: List<Any>) = Query("notIntersects", attribute, values).toJson()
127+
128+
fun crosses(attribute: String, values: List<Any>) = Query("crosses", attribute, values).toJson()
129+
130+
fun notCrosses(attribute: String, values: List<Any>) = Query("notCrosses", attribute, values).toJson()
131+
132+
fun overlaps(attribute: String, values: List<Any>) = Query("overlaps", attribute, values).toJson()
133+
134+
fun notOverlaps(attribute: String, values: List<Any>) = Query("notOverlaps", attribute, values).toJson()
135+
136+
fun touches(attribute: String, values: List<Any>) = Query("touches", attribute, values).toJson()
137+
138+
fun notTouches(attribute: String, values: List<Any>) = Query("notTouches", attribute, values).toJson()
139+
80140
private fun parseValue(value: Any): List<Any> {
81141
return when (value) {
82142
is List<*> -> value as List<Any>

0 commit comments

Comments
 (0)