Skip to content

Commit 16a4ec3

Browse files
committed
Add spatial queries
1 parent 4636f9c commit 16a4ec3

File tree

2 files changed

+134
-6
lines changed

2 files changed

+134
-6
lines changed

src/models.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,15 @@ export namespace Models {
223223
/**
224224
* Row automatically incrementing ID.
225225
*/
226-
readonly $sequence: number;
226+
$sequence: number;
227227
/**
228228
* Table ID.
229229
*/
230-
readonly $tableId: string;
230+
$tableId: string;
231231
/**
232232
* Database ID.
233233
*/
234-
readonly $databaseId: string;
234+
$databaseId: string;
235235
/**
236236
* Row creation date in ISO 8601 format.
237237
*/
@@ -262,15 +262,15 @@ export namespace Models {
262262
/**
263263
* Document automatically incrementing ID.
264264
*/
265-
readonly $sequence: number;
265+
$sequence: number;
266266
/**
267267
* Collection ID.
268268
*/
269-
readonly $collectionId: string;
269+
$collectionId: string;
270270
/**
271271
* Database ID.
272272
*/
273-
readonly $databaseId: string;
273+
$databaseId: string;
274274
/**
275275
* Document creation date in ISO 8601 format.
276276
*/

src/query.ts

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

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

0 commit comments

Comments
 (0)