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 support for filter operators #105

Closed
AbegaM opened this issue Jul 17, 2023 · 12 comments · Fixed by #107
Closed

Add support for filter operators #105

AbegaM opened this issue Jul 17, 2023 · 12 comments · Fixed by #107

Comments

@AbegaM
Copy link
Collaborator

AbegaM commented Jul 17, 2023

Purpose of the Issue

I would like to add support for filtering operators in Soul. Currently, Soul filters table fields with the _filters field, which works fine, but I am unable to filter items using the operators <, >, <=, >=, and !=. For example, I can fetch an invoice from Soul using the following URL, which works fine:

   localhost:8000/api/tables/invoices/rows?_filters=Total:1.98

However, I might want to fetch invoices where the total value is less than 2 or greater than 2, and I cannot achieve this with Soul's current functionality.

Proposed Solution

There could be several options to add this feature, but I propose passing double underscores after the column name. Here are some examples:

Greater than (>):

localhost:8000/api/tables/invoices/rows?_filters=Total__gt:3

Less than (<):

localhost:8000/api/tables/invoices/rows?_filters=Total__lt:3

Greater than or equal to (>=):

localhost:8000/api/tables/invoices/rows?_filters=Total__gte:3

Less than or equal to (<=):

localhost:8000/api/tables/invoices/rows?_filters=Total__lte:3

Not equal to (!=):

localhost:8000/api/tables/invoices/rows?_filters=Total__neq:3

This proposal would allow users to filter table rows using the operators listed above, making Soul's functionality more flexible and powerful.

@AbegaM
Copy link
Collaborator Author

AbegaM commented Jul 17, 2023

Hello @thevahidal

Could you please review my feature request issue and let me know what you think? I'm planning to start working on a pull request soon. Thank you!"

@IanMayo
Copy link
Collaborator

IanMayo commented Jul 17, 2023

Note: this strategy for providing filter operators appears to match the one used in react-admin:
https://marmelab.com/react-admin/FilteringTutorial.html#filter-operators

@thevahidal
Copy link
Owner

Thanks for the feature request @AbegaM. This is for sure a must have feature for Soul and I think the way your proposal works is really great!
Please start your PR and let me know if there's anything I can help with it.

@AbegaM
Copy link
Collaborator Author

AbegaM commented Jul 17, 2023

Thank you @thevahidal, i will start working on the PR 👍

@IanMayo
Copy link
Collaborator

IanMayo commented Jul 20, 2023

BTW - @thevahidal - you can use the repo settings to delete branches once the PR is merged. It's a house-keeping chore that helps out just a little.

@thevahidal
Copy link
Owner

Hey @IanMayo, I'll do it for sure.

@IanMayo
Copy link
Collaborator

IanMayo commented Jul 22, 2023

Hello @thevahidal - any chance of a new release? I have a PR in another project that is blocked, waiting on this feature.

@IanMayo
Copy link
Collaborator

IanMayo commented Jul 25, 2023

It appears that the existing filters to not match for null. When we provide _filters=batch:null, I suspect Soul is doing a string comparison.

So, I believe we need a filter attribute for the SQLite value of null. Maybe a new __null operator?

@thevahidal
Copy link
Owner

Hey @IanMayo sorry I wasn't available for the past couple of days, I'm ok to do the release, but do you think we should fix the null thing and then proceed with the release?

@IanMayo
Copy link
Collaborator

IanMayo commented Jul 25, 2023

Good plan, let's defer release until we can filter for null.

@thevahidal
Copy link
Owner

It seems that @AbegaM started a new PR for the matter https://github.com/thevahidal/soul/pull/117/files, let's release these two together.

@IanMayo
Copy link
Collaborator

IanMayo commented Aug 8, 2023

Closed in #117

@IanMayo IanMayo closed this as completed Aug 8, 2023
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 a pull request may close this issue.

3 participants