Applies when building or reviewing SQLAlchemy data layers. Covers session lifecycle, eager loading, connection pooling, 2.0 style, and Alembic migrations.
select(), Session.execute(), Session.scalars(). Legacy Query is deprecated.Mapped[] type annotations with mapped_column().relationship with back_populates, not backref. Explicit, type-checkable.expire_on_commit=False when reading after commit. Default expires attributes, causing extra SELECTs.joinedload few parents/few children. selectinload many parents. subqueryload complex filters.pool_size, max_overflow, pool_pre_ping=True, pool_recycle=1800.create_async_engine("postgresql+asyncpg://...").session.execute(insert(User), [{...}]) not looped session.add().server_default for DB-level defaults, not default (Python-side, skipped in bulk).metadata.create_all() in production.