nestjs-query
nestjs-query copied to clipboard
Question: Custom filter operators
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)}))`
);
}
I'm also trying to figure it out. I don't think it's possible. Some problems happen because we can't define how each filter would work. It also happens in sorting: https://github.com/doug-martin/nestjs-query/issues/720
I opened the issue to take a look on it. This lib is great, but without it would really be a problem
I've got a similar need -- need to be able to use tsqueries https://www.postgresql.org/docs/12/datatype-textsearch.html
I'm working on this right now, there are quite a few pieces to it from the core library to graphql and how to use it properly within the persistence library. Its taking me a while but I think it should be out in the next week or so.
Hi @doug-martin! First of all, this library is awesome, I love how it is structured and declarative, so thank you! I am also in need of custom sorting/filtering and I am working on some workaround for typeorm in these days. If you want, I could try and help you with this feature. Let me know your thoughts, thank you!
Hi @doug-martin is there any progress on this? How can I help?
For my needs, it would be enough if there was a way to expand this map. https://github.com/doug-martin/nestjs-query/blob/3ceb56fb7c452b9c6f96fdddef1c324296fdbf2c/packages/query-graphql/src/types/query/field-comparison/field-comparison.factory.ts#L29
Hello I just came across your wonderful repository. Still no way to customize filters?