Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Custom filter operators #702

Open
joeybenenati opened this issue Nov 18, 2020 · 7 comments
Open

Question: Custom filter operators #702

joeybenenati opened this issue Nov 18, 2020 · 7 comments
Labels

Comments

@joeybenenati
Copy link

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)}))`
  );
}
@danielkv
Copy link

danielkv commented Nov 24, 2020

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: #720

I opened the issue to take a look on it. This lib is great, but without it would really be a problem

@thehappycoder
Copy link
Contributor

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

@doug-martin
Copy link
Owner

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.

@luca-nardelli
Copy link

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!

@jakubnavratil
Copy link

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

@Zippersk
Copy link

For my needs, it would be enough if there was a way to expand this map.

const filterComparisonMap = new Map<string, () => Class<FilterFieldComparison<unknown>>>();

@hamidrezaborghei
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants