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

filter param generator helper #53

Closed
Bnaya opened this issue Mar 29, 2019 · 7 comments
Closed

filter param generator helper #53

Bnaya opened this issue Mar 29, 2019 · 7 comments

Comments

@Bnaya
Copy link

Bnaya commented Mar 29, 2019

Is there any ready-made lib that will take query object, in a syntax similar to, say mongo query,
And will give the appropriate filter for it?
Screen Shot 2019-03-29 at 18 22 25
The syntax is very hard to write

@michaelyali
Copy link
Member

Why do we need any such library if we can create a query builder for current implementation? And there will not be any breaking changes.

@Bnaya
Copy link
Author

Bnaya commented Mar 29, 2019

To clarify:
I'm writing the client side, (react-admin dataProvider to be more specific)
And my input is javascript object, and i need to build complex query param filter from it.

If i had mongo-like query api that would much simpler for me

@esistgut
Copy link

esistgut commented May 18, 2019

@Bnaya did you make any progress on the react-admin data provider?
edit: nevermind, found this one https://github.com/FusionWorks/react-admin-nestjsx-crud-dataprovider

@Bnaya
Copy link
Author

Bnaya commented May 20, 2019

I wrote something sketchy,
That im using since then,
But 2 days ago i also found that new provider
I will maybe refactor to use it.
I will be happy to hear how it was for you

@michaelyali
Copy link
Member

@Bnaya @esistgut
I've made a package @nestjsx/request-query (haven't published it yet though). It's framework agnostic and can be used on both - frontend and backend. It will be used in our RestfulQueryInterceptor on GET requests as well. The usage example (frontend):

import { RequestQueryBuilder } from '@nestjsx/request-query';

const qb = new RequestQueryBuilder();

const queryString = qb
  .select(['id', 'name', 'email'])
  .setFilter({ field: 'name', operator: 'eq', value: 'John' })
  .setOr({ field: 'email', operator: 'cont', value: 'john' })
  .setJoin({ field: 'company', select: ['name'] })
  .setJoin({ field: 'profile' })
  .sortBy({ field: 'id', order: 'DESC' })
  .setLimit(20)
  .setPage(3)
  .resetCache()
  .query();

Also, it will be possible to set names map to each of existing query param, .e.g:

import { RequestQueryBuilder } from '@nestjsx/request-query';

RequestQueryBuilder.setOptions({
  delim: '||',
  delimStr: ',',
  paramNamesMap: {
    fields: ['fields', 'select'],
    filter: ['filter[]', 'filter'],
    or: ['or[]', 'or'],
    join: ['join[]', 'join'],
    sort: ['sort[]', 'sort'],
    limit: ['per_page', 'limit'],
    offset: ['offset'],
    page: ['page'],
    cache: ['cache'],
  },
})

...and to change to whatever you want. And of coucre this must be done on the backend side as well. I'll provide more details on that in the future.
Also, there won't be a need in class-validator to validate query param anymore, because I've added all validation needed and it's reusable on both - frontend and backend.

So guys, please let me know what you think about that. It's 100% done, 100% covered by tests, but not published yet.

Cheers!

@Bnaya
Copy link
Author

Bnaya commented May 28, 2019

Amazing, thank you!!

@michaelyali
Copy link
Member

@Bnaya please see the docs

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

No branches or pull requests

3 participants