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

add SQLAlchemy 2.0 #74

Open
grillazz opened this issue Feb 17, 2023 · 1 comment · Fixed by #80
Open

add SQLAlchemy 2.0 #74

grillazz opened this issue Feb 17, 2023 · 1 comment · Fixed by #80
Assignees

Comments

@grillazz
Copy link
Owner

No description provided.

@grillazz grillazz self-assigned this Feb 17, 2023
@grillazz grillazz linked a pull request Mar 22, 2023 that will close this issue
@grillazz grillazz reopened this Mar 22, 2023
@grillazz
Copy link
Owner Author

grillazz commented Jun 21, 2023

Doing performance improvements is the best way to learn how a tool actually works. I've used SQLAlchemy with Postgres and FastAPI for the last few months and I've learned that:

  1. Postgres does not automatically add indexes on foreign key and neither SQLAlchemy (Django, the other ORM I've used before did that by default). So add index=True on your foreign keys if necessary.

  2. You can define column properties with scalar subqueries outside the model definition: https://docs.sqlalchemy.org/en/20/orm/mapped_sql_expr.html#adding-column-property-to-an-existing-declarative-mapped-class

  3. I've also discovered query expressions, they are a saver for complex queries: https://docs.sqlalchemy.org/en/20/orm/queryguide/columns.html#loading-arbitrary-sql-expressions-onto-objects

  4. Extremely important for heavy queries how the relationship loading is done: https://docs.sqlalchemy.org/en/20/orm/queryguide/relationships.html

  5. If you are migration to 2.0, this is the holy bible: https://docs.sqlalchemy.org/en/14/changelog/migration_20.html#migration-orm-usage

I wonder why there was a need to create tools with yaml and adopt configuration engineering, when SQLAlchemy has a great choice of database drivers, it offers not only schema validation - but it enforces good data modeling practices and it provides a nice ORM to work with.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant