-
Notifications
You must be signed in to change notification settings - Fork 142
Open
Labels
Description
I've been exploring nestjs-query for a couple days now and first off, thank you. This is an incredibly well thought out solution. My project requires the use of PostGIS methods like ST_Intersects, for which I've created a custom TypeORM operator. I'd like to extend the functionality of these custom operators to the built in query interface filter but I'm having a hard time understanding how I would go about that.
import { FindOperator, FindOperatorType } from 'typeorm';
type SqlGeneratorType = (aliasPath: string) => string;
class FindOperatorWithExtras<T> extends FindOperator<T> {
constructor(
type: FindOperatorType | 'intersects',
value: FindOperator<T> | T,
useParameter?: boolean,
multipleParameters?: boolean,
getSql?: SqlGeneratorType,
) {
// @ts-ignore
super(type, value, useParameter, multipleParameters, getSql);
}
}
/**
* Find Options Operator.
* Example: { geometry: Intersects({ type: 'Point', coordinates: [1,2]}) }
*/
export function Intersects<T>(
value: T | FindOperator<T>,
): FindOperatorWithExtras<T> {
return new FindOperatorWithExtras(
'intersects',
value,
true,
false,
(aliasPath: string) => `ST_Intersects(${aliasPath}, ST_GeomFromGeoJSON(:${JSON.stringify(value)}))`
);
}
petyunchik, thehappycoder and awHamer