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 between as a usable operator #551

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

Kastakin
Copy link

This PR aims to expose the between() operator present in SQLAlchemy.

While the conjunction of lte and gte 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.

Copy link

netlify bot commented Jan 30, 2024

Deploy Preview for fastapi-filter ready!

Name Link
🔨 Latest commit a2e98b9
🔍 Latest deploy log https://app.netlify.com/sites/fastapi-filter/deploys/6613e71a6673e00008eeef0f
😎 Deploy Preview https://deploy-preview-551--fastapi-filter.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Jan 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (e0f2fa8) to head (a2e98b9).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #551   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          193       196    +3     
=========================================
+ Hits           193       196    +3     
Files Coverage Δ
fastapi_filter/contrib/sqlalchemy/filter.py 100.00% <100.00%> (ø)

@@ -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])),
Copy link

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
Copy link

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?

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.

2 participants