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

Add query operators to json api #74

Closed
wants to merge 1 commit into from
Closed

Add query operators to json api #74

wants to merge 1 commit into from

Conversation

sertorsol
Copy link

@sertorsol sertorsol commented Aug 30, 2020

Hi Tomaxx,

I don't know if this can be done already as I didn't go through the code thoroughly.
I want to be able to query stuff based on ranges. For instance if I have a timestamp field and I want to query a range with this patch you can do a GET for instance to http://localhost:5000/?filter[timestamp]=>2020-08-01and<2020-08-03 to retrieve entries between those 2 dates.

This patch allows 2 types of queries:

  • op value
    Where op can be <,<=,>,>=
  • op1 value bop op2 value
    Where op1 and op2 are like op. And bop is one of "and", "or".

Please share your opinion.

@thomaxxl
Copy link
Owner

Hello Sergio,

I can't accept this patch: I don't think it is jsonapi compliant, is it?
If you want to implement this in your code, you can set the jsonapi_filter method of your model, for ex.

class MyClass(SAFRSBase, db.Model):
    ...
    jsonapi_filter = your_jsonapi_filter

There are other ways to implement custom queries:

  • using a SAFRSBase._s_filter override, which will be called with the filter= url query arguments.
  • using a jsonapi_rpc decorator

Can you work with this?

@thomaxxl
Copy link
Owner

wait, I think I misunderstood your code and explanation.
Maybe I can add it, I will test later today.

@sertorsol
Copy link
Author

sertorsol commented Aug 30, 2020 via email

@sertorsol
Copy link
Author

Will come up with better solution

@sertorsol sertorsol closed this Aug 30, 2020
@thomaxxl
Copy link
Owner

Well,

I've been thinking about implementing better filtering but I didn't have the time to implement one. The jsonapi spec is quite liberal regarding filtering strategies https://jsonapi.org/recommendations/#filtering . A bit too liberal imho.

If you manage to implement something generic, I'd be very happy to merge it. There were some ideas here : https://discuss.jsonapi.org/t/share-propose-a-filtering-strategy/257/8 , but no consensus afaik :( .

@sertorsol
Copy link
Author

sertorsol commented Aug 30, 2020 via email

@thomaxxl
Copy link
Owner

I haven't used it, but Drupal seems to have pretty solid jsonapi filtering too: https://www.drupal.org/docs/core-modules-and-themes/core-modules/jsonapi-module/filtering

@sertorsol
Copy link
Author

sertorsol commented Aug 30, 2020 via email

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

Successfully merging this pull request may close these issues.

None yet

2 participants