Skip to content

Commit 5d2d520

Browse files
committed
Add spatial queries
1 parent d4f9bb5 commit 5d2d520

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
@@ -1976,15 +1976,15 @@ export namespace Models {
19761976
/**
19771977
* Row automatically incrementing ID.
19781978
*/
1979-
readonly $sequence: number;
1979+
$sequence: number;
19801980
/**
19811981
* Table ID.
19821982
*/
1983-
readonly $tableId: string;
1983+
$tableId: string;
19841984
/**
19851985
* Database ID.
19861986
*/
1987-
readonly $databaseId: string;
1987+
$databaseId: string;
19881988
/**
19891989
* Row creation date in ISO 8601 format.
19901990
*/
@@ -2015,15 +2015,15 @@ export namespace Models {
20152015
/**
20162016
* Document automatically incrementing ID.
20172017
*/
2018-
readonly $sequence: number;
2018+
$sequence: number;
20192019
/**
20202020
* Collection ID.
20212021
*/
2022-
readonly $collectionId: string;
2022+
$collectionId: string;
20232023
/**
20242024
* Database ID.
20252025
*/
2026-
readonly $databaseId: string;
2026+
$databaseId: string;
20272027
/**
20282028
* Document creation date in ISO 8601 format.
20292029
*/

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)