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

feat(sqlalchemy): allow repository functions to be filter by expressions #2265

Merged
merged 19 commits into from
Sep 7, 2023

Conversation

cofin
Copy link
Member

@cofin cofin commented Aug 30, 2023

Pull Request Checklist

  • New code has 100% test coverage
  • (If applicable) The prose documentation has been updated to reflect the changes introduced by this PR
  • (If applicable) The reference documentation has been updated to reflect the changes introduced by this PR

Description

  • This PR enhances the repository so that you can more easily pass in complex where expressions into the repository functions.

Without this, you have to override the statement parameter and it separates the where conditions from the filters and the kwargs.

Allows usage of this syntax:

locations, total_count = await model_service.list_and_count(ST_DWithin(UniqueLocation.location, geog, 1000), account_id=str(account_id))

instead of the previous method of overriding the statement:

locations, total_count = await model_service.list_and_count(statement=select(Model).where(ST_DWithin(UniqueLocation.location, geog, 1000)), account_id=str(account_id))

Close Issue(s)

@sonarcloud
Copy link

sonarcloud bot commented Aug 30, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

66.7% 66.7% Coverage
0.0% 0.0% Duplication

@github-actions
Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/2265

@cofin
Copy link
Member Author

cofin commented Aug 30, 2023

@Alc-Alc nice work on this one!

@cofin cofin marked this pull request as ready for review August 30, 2023 17:52
@cofin cofin requested review from a team as code owners August 30, 2023 17:52
@cofin cofin changed the title feat(sqlalchemy-repo): allow repository functions to be filter by expressions feat(sqlalchemy): allow repository functions to be filter by expressions Aug 30, 2023
@TheGreatAlgo
Copy link

works like a charm, thanks for the quick turnaround on this! Using this syntax locations, total_count = await model_service.list_and_count(ST_DWithin(UniqueLocation.location, geog, 1000), account_id=str(account_id)) it worked as expected on the new branch. And too double check with prior version, it failed as expected with Unexpected filter error

@TheGreatAlgo
Copy link

and no issues with my mypy setup for me. but im not getting any errors using the new syntax with the old branch so probably something on my side that i should resolve

Copy link
Member

@provinzkraut provinzkraut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff!

@Goldziher Goldziher merged commit 7badaf5 into main Sep 7, 2023
10 of 12 checks passed
@Goldziher Goldziher deleted the enhanced-repo-filters branch September 7, 2023 06:17
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

4 participants