What problem does it solve?
Provide clear, actionable guidance to design, review, and troubleshoot SQLAlchemy 2.x ORM and Core code, reducing runtime errors, N+1 queries, session/transaction misuse, and async/sync pitfalls.
Core Features & Use Cases
- ORM and Core patterns: Recommend idiomatic SQLAlchemy 2.x usage including DeclarativeBase, Mapped, mapped_column, and when to use Core for bulk or tuned SQL.
- Query and loading strategies: Identify N+1 problems and propose loader strategies such as selectinload and joinedload to optimize performance.
- Async and pooling guidance: Advise on async engine/session creation, async_sessionmaker usage, run_sync bridging, and connection pool tuning for production workloads.
- Debugging and best practices: Diagnose session lifecycle, transaction boundaries, and pooling/exhaustion issues with stepwise remediation suggestions.
Quick Start
Review this SQLAlchemy code for N+1 issues, incorrect transaction/session usage, and async/sync mixing, then provide corrected examples and recommended loader strategies.