Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

More efficient select #29

Merged
merged 7 commits into from
Nov 2, 2023
Merged

More efficient select #29

merged 7 commits into from
Nov 2, 2023

Conversation

igorbenav
Copy link
Owner

Now it's possible to select only a few attributes in a query.

For the get and get_multi methods we have the option to define a schema_to_select attribute, which is what actually makes the queries more efficient. When you pass a pydantic schema in schema_to_select to the get or get_multi methods, only the attributes in the schema will be selected.

from app.schemas.user import UserRead
# Here it's selecting all of the user's data
crud_user.get(db=db, username="myusername")

# Now it's only selecting the data that is in UserRead. 
# Since that's my response_model, it's all I need
crud_user.get(db=db, username="myusername", schema_to_select=UserRead)

@igorbenav igorbenav added the enhancement New feature or request label Nov 2, 2023
@igorbenav igorbenav self-assigned this Nov 2, 2023
@igorbenav igorbenav merged commit 10d1e07 into main Nov 2, 2023
@igorbenav igorbenav deleted the more-efficient-query branch November 2, 2023 21:00
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant