Skip to content

Commit a5678c9

Browse files
committed
Add spatial queries
1 parent 2a0246d commit a5678c9

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
@@ -226,15 +226,15 @@ export namespace Models {
226226
/**
227227
* Row automatically incrementing ID.
228228
*/
229-
readonly $sequence: number;
229+
$sequence: number;
230230
/**
231231
* Table ID.
232232
*/
233-
readonly $tableId: string;
233+
$tableId: string;
234234
/**
235235
* Database ID.
236236
*/
237-
readonly $databaseId: string;
237+
$databaseId: string;
238238
/**
239239
* Row creation date in ISO 8601 format.
240240
*/
@@ -265,15 +265,15 @@ export namespace Models {
265265
/**
266266
* Document automatically incrementing ID.
267267
*/
268-
readonly $sequence: number;
268+
$sequence: number;
269269
/**
270270
* Collection ID.
271271
*/
272-
readonly $collectionId: string;
272+
$collectionId: string;
273273
/**
274274
* Database ID.
275275
*/
276-
readonly $databaseId: string;
276+
$databaseId: string;
277277
/**
278278
* Document creation date in ISO 8601 format.
279279
*/

src/query.ts

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,132 @@ export class Query {
366366
*/
367367
static and = (queries: string[]) =>
368368
new Query("and", undefined, queries.map((query) => JSON.parse(query))).toString();
369+
370+
/**
371+
* Filter resources where attribute is at a specific distance from the given coordinates.
372+
*
373+
* @param {string} attribute
374+
* @param {any[]} values
375+
* @param {number} distance
376+
* @param {boolean} meters
377+
* @returns {string}
378+
*/
379+
static distanceEqual = (attribute: string, values: any[], distance: number, meters: boolean = true): string =>
380+
new Query("distanceEqual", attribute, [values, distance, meters] as QueryTypesList).toString();
381+
382+
/**
383+
* Filter resources where attribute is not at a specific distance from the given coordinates.
384+
*
385+
* @param {string} attribute
386+
* @param {any[]} values
387+
* @param {number} distance
388+
* @param {boolean} meters
389+
* @returns {string}
390+
*/
391+
static distanceNotEqual = (attribute: string, values: any[], distance: number, meters: boolean = true): string =>
392+
new Query("distanceNotEqual", attribute, [values, distance, meters] as QueryTypesList).toString();
393+
394+
/**
395+
* Filter resources where attribute is at a distance greater than the specified value from the given coordinates.
396+
*
397+
* @param {string} attribute
398+
* @param {any[]} values
399+
* @param {number} distance
400+
* @param {boolean} meters
401+
* @returns {string}
402+
*/
403+
static distanceGreaterThan = (attribute: string, values: any[], distance: number, meters: boolean = true): string =>
404+
new Query("distanceGreaterThan", attribute, [values, distance, meters] as QueryTypesList).toString();
405+
406+
/**
407+
* Filter resources where attribute is at a distance less than the specified value from the given coordinates.
408+
*
409+
* @param {string} attribute
410+
* @param {any[]} values
411+
* @param {number} distance
412+
* @param {boolean} meters
413+
* @returns {string}
414+
*/
415+
static distanceLessThan = (attribute: string, values: any[], distance: number, meters: boolean = true): string =>
416+
new Query("distanceLessThan", attribute, [values, distance, meters] as QueryTypesList).toString();
417+
418+
/**
419+
* Filter resources where attribute intersects with the given geometry.
420+
*
421+
* @param {string} attribute
422+
* @param {any[]} values
423+
* @returns {string}
424+
*/
425+
static intersects = (attribute: string, values: any[]): string =>
426+
new Query("intersects", attribute, values).toString();
427+
428+
/**
429+
* Filter resources where attribute does not intersect with the given geometry.
430+
*
431+
* @param {string} attribute
432+
* @param {any[]} values
433+
* @returns {string}
434+
*/
435+
static notIntersects = (attribute: string, values: any[]): string =>
436+
new Query("notIntersects", attribute, values).toString();
437+
438+
/**
439+
* Filter resources where attribute crosses the given geometry.
440+
*
441+
* @param {string} attribute
442+
* @param {any[]} values
443+
* @returns {string}
444+
*/
445+
static crosses = (attribute: string, values: any[]): string =>
446+
new Query("crosses", attribute, values).toString();
447+
448+
/**
449+
* Filter resources where attribute does not cross the given geometry.
450+
*
451+
* @param {string} attribute
452+
* @param {any[]} values
453+
* @returns {string}
454+
*/
455+
static notCrosses = (attribute: string, values: any[]): string =>
456+
new Query("notCrosses", attribute, values).toString();
457+
458+
/**
459+
* Filter resources where attribute overlaps with the given geometry.
460+
*
461+
* @param {string} attribute
462+
* @param {any[]} values
463+
* @returns {string}
464+
*/
465+
static overlaps = (attribute: string, values: any[]): string =>
466+
new Query("overlaps", attribute, values).toString();
467+
468+
/**
469+
* Filter resources where attribute does not overlap with the given geometry.
470+
*
471+
* @param {string} attribute
472+
* @param {any[]} values
473+
* @returns {string}
474+
*/
475+
static notOverlaps = (attribute: string, values: any[]): string =>
476+
new Query("notOverlaps", attribute, values).toString();
477+
478+
/**
479+
* Filter resources where attribute touches the given geometry.
480+
*
481+
* @param {string} attribute
482+
* @param {any[]} values
483+
* @returns {string}
484+
*/
485+
static touches = (attribute: string, values: any[]): string =>
486+
new Query("touches", attribute, values).toString();
487+
488+
/**
489+
* Filter resources where attribute does not touch the given geometry.
490+
*
491+
* @param {string} attribute
492+
* @param {any[]} values
493+
* @returns {string}
494+
*/
495+
static notTouches = (attribute: string, values: any[]): string =>
496+
new Query("notTouches", attribute, values).toString();
369497
}

0 commit comments

Comments
 (0)