sqlalchemy-postgres

Fix SQLAlchemy 2.x async pattern mistakes in PostgreSQL code.

13|Updated Mar 15, 2019
One-click install
npx skills add https://github.com/WTFox/dotfiles --skill sqlalchemy-postgres-wtfox
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sqlalchemy-postgres
Source: https://github.com/WTFox/dotfiles/tree/main/claude/.claude/skills/sqlalchemy-postgres
Command: npx skills add https://github.com/WTFox/dotfiles --skill sqlalchemy-postgres-wtfox

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Claude frequently writes and reviews SQLAlchemy 2.x code against PostgreSQL, but often mistakes the modern 2.x patterns, leading to bugs, inefficiencies, and migrations gotchas.

Core Features & Use Cases

  • Guided migration for 2.x patterns: helps transition from session.query() to select(), async session usage, and proper transaction handling.
  • N+1 avoidance and relationship loading: demonstrates eager loading strategies to prevent N+1 queries.
  • Alembic and migrations best practices: covers generator defaults and migration checks.

Quick Start

Audit your codebase for SQLAlchemy 2.x patterns in PostgreSQL, focusing on replacing session.query() with select(), ensuring proper async session usage, and enabling eager relationship loading.

Frequently Asked Questions about sqlalchemy-postgres

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix SQLAlchemy 2.x async pattern mistakes in PostgreSQL code?

To fix SQLAlchemy 2.x async pattern mistakes, transition from session.query() to select() statements, ensure proper AsyncSession dependency injection, and apply correct transaction handling for your PostgreSQL codebase.

What's the best way to avoid N+1 queries with SQLAlchemy 2.x async sessions?

Avoid N+1 queries in SQLAlchemy 2.x by implementing proper eager loading strategies for relationship loading. This ensures related data is fetched efficiently within async sessions without triggering individual queries per item.

How do I migrate from session.query() to select() in SQLAlchemy 2.x?

Migrate from session.query() to select() by adopting the modern SQLAlchemy 2.x API patterns. Replace legacy query calls with select() statements and execute them properly through async sessions for PostgreSQL.

Does this cover Alembic migration best practices for PostgreSQL?

Yes, it covers Alembic migration best practices including generator defaults and migration checks. This helps prevent migration gotchas and ensures your database schema transitions correctly with SQLAlchemy 2.x.

Why does my SQLAlchemy 2.x async session drop transaction state?

SQLAlchemy 2.x async sessions drop transaction state when dependency injection for AsyncSession is improperly configured. Ensure proper transaction handling and session management to maintain state during PostgreSQL operations.

Can I use select() style queries for relationship loading in async SQLAlchemy?

Yes, you can use select() style queries for relationship loading in async SQLAlchemy. Apply proper eager loading strategies to efficiently load related objects and prevent N+1 queries in PostgreSQL.