No More Raw SQL: SQLAlchemy & ORMs
summary
A Marketplace microservice with five tables (customers, addresses, orders, order_items, items) moves from raw sqlite3 SQL to SQLAlchemy core and then declarative ORM models; multi-join queries become a two-line select, inserts become session.add + session.commit, and migrations use alembic. The demo logs SQL via echo, contrasts connection.commit vs engine.begin, exposes the N+1 problem (loading three customers issues four queries and would blow up with hundreds or thousands), and shows eager loading and func.sum optimisations that actually reduce queries and commit successfully.
AI-written summary Β· about
chapters (16)
- 0:00SQLAlchemy & ORMs intro
- 1:04From raw SQL to core
- 7:07Sample microservice
- 8:56Raw SQL queries
- 11:07SQLAlchemy engine
- 12:54SELECT with SQLAlchemy
- 14:42Committing data
- 16:30Adding ORMs
- 19:17Tables to Python classes
- 21:03Querying data with ORMs
- 23:50Complex ORM queries
- 24:33Inserting with ORMs
- 27:00Lazy loading
- 29:04N+1 problem fix
- 30:09SQL functions
- 30:53Summary
related talks
37mNo More Raw SQL with SQLAlchemy and ORMs
01h 28mSQLAlchemy and You - Making SQL the Best Thing Since Sliced Bread
30mThe magic of SQLAlchemy
30mLeave Your Inhibitions at the Database Connection
34mLet's talk Databases in Python: SQLAlchemy and Alembic
23mBuilding a multi-purpose platform for bulk data using sqlalchemy
29mDatabase Sorcery 101 Ditch the Ancient SQL Scrolls for SQLModel
01h 44mTUTORIAL: SQLAlchemy 2.0
