python-database-patterns
Implement Python database patterns with SQLAlchemy
๋ํ ๋ค์์์ ์ฌ์ฉํ ์ ์์ต๋๋ค: 0xDarkMatter
Writing database code is complex and error-prone. This skill provides battle-tested SQLAlchemy 2.0 patterns for models, queries, async sessions, transactions, and migrations.
์คํฌ ZIP ๋ค์ด๋ก๋
Claude์์ ์ ๋ก๋
์ค์ โ ๊ธฐ๋ฅ โ ์คํฌ โ ์คํฌ ์ ๋ก๋๋ก ์ด๋
ํ ๊ธ์ ์ผ๊ณ ์ฌ์ฉ ์์
ํ ์คํธํด ๋ณด๊ธฐ
"python-database-patterns" ์ฌ์ฉ ์ค์ ๋๋ค. Create a User model with email unique constraint and a relationship to Post
์์ ๊ฒฐ๊ณผ:
- - Define User class with mapped columns
- - Add unique constraint on email field
- - Create one-to-many relationship to Post model
- - Use back_populates for bidirectional navigation
๋ณด์ ๊ฐ์ฌ
์์ Documentation-only skill containing educational SQLAlchemy patterns. No executable code, no network calls, no credential access, no malicious patterns detected.
ํ์ง ์ ์
๋ง๋ค ์ ์๋ ๊ฒ
Learn SQLAlchemy 2.0
Get started with modern SQLAlchemy patterns for declarative models and type-safe queries
Build async API backends
Implement FastAPI endpoints with async database sessions and transaction management
Manage database schemas
Set up Alembic migrations and configure connection pools for production databases
์ด ํ๋กฌํํธ๋ฅผ ์ฌ์ฉํด ๋ณด์ธ์
Create a SQLAlchemy 2.0 model called Product with id, name, price, and category relationship
Write an async function to fetch a user by email with their posts eagerly loaded
Implement a transfer_funds function with pessimistic locking to prevent race conditions
Show me how to configure connection pool size, overflow, and pre-ping for a production PostgreSQL async engine
๋ชจ๋ฒ ์ฌ๋ก
- Use SQLAlchemy 2.0 declarative style with Mapped and mapped_column for type safety
- Prefer session.execute with select() over legacy session.query() method
- Configure pool_pre_ping=True to catch stale connections before queries
- Use eager loading (selectinload/joinedload) to avoid N+1 queries in async contexts
ํผํ๊ธฐ
- Using lazy loading in async sessions causes MissingGreenlet errors
- Calling session.commit() inside session.begin() creates nested transaction issues
- Hardcoding database URLs instead of using environment configuration
- Skipping pool_recycle causing connections to timeout after long queries
์์ฃผ ๋ฌป๋ ์ง๋ฌธ
What SQLAlchemy versions are supported?
Can I use this with FastAPI?
How do I size the connection pool?
Is my data safe with these patterns?
Why are my async queries failing?
How does this compare to raw SQL?
๊ฐ๋ฐ์ ์ธ๋ถ ์ ๋ณด
์์ฑ์
0xDarkMatter๋ผ์ด์ ์ค
MIT
๋ฆฌํฌ์งํ ๋ฆฌ
https://github.com/0xDarkMatter/claude-mods/tree/main/skills/python-database-patterns์ฐธ์กฐ
main
ํ์ผ ๊ตฌ์กฐ
๐ assets/
๐ alembic.ini.template
๐ references/
๐ migrations.md
๐ sqlalchemy-async.md
๐ transactions.md
๐ SKILL.md