Skip to content

0.3.0

Choose a tag to compare

@igorbenav igorbenav released this 02 Nov 21:05
· 292 commits to main since this release
10d1e07

Summary

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)

Warning
What's retrieved from the get is no longer an ORM model, it's a sqlalchemy.engine.row.Row, so update your code accordingly

What's Changed

Full Changelog: v0.2.1...v0.3.0