SQLAlchemy 2.0 Async Patterns

•
69
•

Implements high-performance asynchronous database operations using SQLAlchemy 2.0 and FastAPI best practices.

This skill provides production-ready implementation patterns for SQLAlchemy 2.0's asynchronous capabilities, focusing on efficiency and reliability. It covers the setup of AsyncSession factories, FastAPI dependency injection for database sessions, and sophisticated query strategies like eager loading to prevent N+1 issues. By enforcing 'lazy=raise' and providing generic repository patterns, it helps developers build scalable, non-blocking backends while avoiding common pitfalls such as session thread-safety issues, connection leaks, or accidental blocking calls.

主要功能

01Optimized bulk data operations and chunking
02Generic Async Repository pattern implementation
03FastAPI dependency injection integration
04Eager loading strategies to prevent N+1 queries
0569 GitHub stars
06Async engine and session factory configuration

使用场景

01Implementing clean architecture with generic async database repositories
02Building high-concurrency FastAPI backends with PostgreSQL or MySQL
03Refactoring synchronous SQLAlchemy code to modern non-blocking patterns