nestjs-query icon indicating copy to clipboard operation
nestjs-query copied to clipboard

Question: Custom filter operators

Open joeybenenati opened this issue 4 years ago • 7 comments

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)}))`
  );
}

joeybenenati avatar Nov 18 '20 19:11 joeybenenati

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

danielkv avatar Nov 24 '20 22:11 danielkv

I've got a similar need -- need to be able to use tsqueries https://www.postgresql.org/docs/12/datatype-textsearch.html

thehappycoder avatar Dec 29 '20 01:12 thehappycoder

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.

doug-martin avatar Dec 29 '20 19:12 doug-martin

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!

luca-nardelli avatar Jan 29 '21 07:01 luca-nardelli

Hi @doug-martin is there any progress on this? How can I help?

jakubnavratil avatar Apr 20 '21 14:04 jakubnavratil

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

Zippersk avatar May 25 '21 13:05 Zippersk

Hello I just came across your wonderful repository. Still no way to customize filters?

hamidrezaborghei avatar May 26 '23 19:05 hamidrezaborghei