์Šคํ‚ฌ python-database-patterns
๐Ÿ—„๏ธ

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.

์ง€์›: Claude Codex Code(CC)
๐Ÿฅ‰ 73 ๋ธŒ๋ก ์ฆˆ
1

์Šคํ‚ฌ ZIP ๋‹ค์šด๋กœ๋“œ

2

Claude์—์„œ ์—…๋กœ๋“œ

์„ค์ • โ†’ ๊ธฐ๋Šฅ โ†’ ์Šคํ‚ฌ โ†’ ์Šคํ‚ฌ ์—…๋กœ๋“œ๋กœ ์ด๋™

3

ํ† ๊ธ€์„ ์ผœ๊ณ  ์‚ฌ์šฉ ์‹œ์ž‘

ํ…Œ์ŠคํŠธํ•ด ๋ณด๊ธฐ

"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

๋ณด์•ˆ ๊ฐ์‚ฌ

์•ˆ์ „
v3 โ€ข 1/10/2026

Documentation-only skill containing educational SQLAlchemy patterns. No executable code, no network calls, no credential access, no malicious patterns detected.

6
์Šค์บ”๋œ ํŒŒ์ผ
1,473
๋ถ„์„๋œ ์ค„ ์ˆ˜
0
๋ฐœ๊ฒฌ ์‚ฌํ•ญ
3
์ด ๊ฐ์‚ฌ ์ˆ˜
๋ณด์•ˆ ๋ฌธ์ œ๋ฅผ ์ฐพ์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค

ํ’ˆ์งˆ ์ ์ˆ˜

59
์•„ํ‚คํ…์ฒ˜
100
์œ ์ง€๋ณด์ˆ˜์„ฑ
81
์ฝ˜ํ…์ธ 
31
์ปค๋ฎค๋‹ˆํ‹ฐ
100
๋ณด์•ˆ
70
์‚ฌ์–‘ ์ค€์ˆ˜

๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ๊ฒƒ

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

์ด ํ”„๋กฌํ”„ํŠธ๋ฅผ ์‚ฌ์šฉํ•ด ๋ณด์„ธ์š”

Define a model
Create a SQLAlchemy 2.0 model called Product with id, name, price, and category relationship
Write async query
Write an async function to fetch a user by email with their posts eagerly loaded
Handle transaction
Implement a transfer_funds function with pessimistic locking to prevent race conditions
Configure pool
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?
SQLAlchemy 2.0+ with Python 3.10+. Async requires asyncpg for PostgreSQL or aiosqlite for SQLite.
Can I use this with FastAPI?
Yes. The skill includes FastAPI dependency injection patterns for async database sessions.
How do I size the connection pool?
Start with pool_size=5 and max_overflow=10. Adjust based on concurrent users and query patterns.
Is my data safe with these patterns?
Yes. Patterns include transaction safety, optimistic locking, and proper session lifecycle management.
Why are my async queries failing?
Common causes include lazy loading without eager loading, uncommitted transactions, or connection pool exhaustion.
How does this compare to raw SQL?
SQLAlchemy provides type safety and abstraction while generating optimized SQL. Use text() for raw queries when needed.

๊ฐœ๋ฐœ์ž ์„ธ๋ถ€ ์ •๋ณด

์ž‘์„ฑ์ž

0xDarkMatter

๋ผ์ด์„ ์Šค

MIT

์ฐธ์กฐ

main

ํŒŒ์ผ ๊ตฌ์กฐ

๐Ÿ“ assets/

๐Ÿ“„ alembic.ini.template

๐Ÿ“ references/

๐Ÿ“„ connection-pooling.md

๐Ÿ“„ migrations.md

๐Ÿ“„ sqlalchemy-async.md

๐Ÿ“„ transactions.md

๐Ÿ“„ SKILL.md