-
-
Notifications
You must be signed in to change notification settings - Fork 30
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 between as a usable operator #551
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for fastapi-filter ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #551 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 6 6
Lines 193 196 +3
=========================================
+ Hits 193 196 +3
|
@@ -39,6 +39,7 @@ def _backward_compatible_value_for_like_and_ilike(value: str): | |||
"isnull": lambda value: ("is_", None) if value is True else ("is_not", None), | |||
"lt": lambda value: ("__lt__", value), | |||
"lte": lambda value: ("__le__", value), | |||
"between": lambda value: ("between", (value[0], value[1])), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be beneficial to enhance protection against IndexError
. For instance, if a client passes __between=21
, instead of between=21,33
.
@@ -274,6 +274,7 @@ class UserFilter(Filter): # type: ignore[misc, valid-type] | |||
age__gt: Optional[int] = None | |||
age__gte: Optional[int] = None | |||
age__in: Optional[List[int]] = None | |||
age__between: Optional[List[int]] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type annotation here and in examples/fastapi_filter_sqlalchemy.py:105 (List[List[int]]
) differs. Is this a mistake?
This PR aims to expose the between() operator present in SQLAlchemy.
While the conjunction of
lte
andgte
operators can suffice when dealing with numerical columns this opens the possibility of using the operator also on textual and date columns with a single operator.The proposed implementation asks the user to input a list, the first two element are considered the right and left sides of the queried interval. If more than two elements are present they are simply ignored.