No More Raw SQL with SQLAlchemy and ORMs
summary
Claim: stop writing raw SQL and let SQLAlchemy replace it with programmatic queries that are shorter, safer, and easier to maintain. Uses engine and session (core vs ORM), prepared statements to prevent injection, explicit commit vs begin ones, and relationship loading strategies. Builds a small Marketplace microservice with five tables and converts raw inserts/selects into ORM objects; an N+1 example with three customers emits four queries but eager loading collapses that to one. Also shows hybrid properties for SQL expressions and clearer aggregation.
AI-written summary · about
chapters (13)
- 0:00SQLAlchemy and ORMs intro
- 2:55What is SQLAlchemy
- 8:19Marketplace app overview
- 9:22Raw SQL without ORM
- 11:52Database engine setup
- 13:39SQLAlchemy core queries
- 17:21SQLAlchemy ORM intro
- 24:00ORM querying data
- 26:51ORM inserting data
- 28:40Optimizing ORM queries
- 31:53SQL functions in ORM
- 32:36Hybrid properties for calc
- 35:27SQLAlchemy benefits
related talks
32mNo More Raw SQL: SQLAlchemy & ORMs
30mLeave Your Inhibitions at the Database Connection
30mThe magic of SQLAlchemy
01h 28mSQLAlchemy and You - Making SQL the Best Thing Since Sliced Bread
01h 04mInside the ORM
52mThe SQL inside the ORM/Builder box | Claudio Zizza
39mLet's Build an ORM
28mThe Ultimate Python Database Toolkit: SQLAlchemy
