skills/python/using-peewee-orm/SKILL.md
Design, wire, or test Peewee ORM models with deferred database binding, scoped connections, explicit transactions, and isolated SQLite fixtures. Use for `DatabaseProxy`, model lifecycle, transaction boundaries, or Peewee-backed tests.
npx skillsauth add narumiruna/agent-skills using-peewee-ormInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Bind models at an application or test boundary; keep connection lifetime, transaction lifetime, and schema lifecycle explicit.
from peewee import DatabaseProxy, Model, SqliteDatabase
db_proxy = DatabaseProxy()
class BaseModel(Model):
class Meta:
database = db_proxy
db = SqliteDatabase("app.db", pragmas={"foreign_keys": 1})
db_proxy.initialize(db)
Define one proxy and base model for a connected model graph. Do not bind production credentials or open a production connection at import time.
db.connection_context() when a function owns a scoped open/close boundary.db.atomic() for multiple statements that must commit or roll back as one invariant. A transaction is not a substitute for deciding who owns the connection.with db.connection_context():
rows = list(User.select().limit(100))
with db.connection_context():
with db.atomic():
account.debit(amount)
ledger.record(account, amount)
Keep one deterministic model list and guarantee cleanup:
import pytest
from peewee import SqliteDatabase
MODELS = [User]
@pytest.fixture
def test_db(tmp_path):
db = SqliteDatabase(
str(tmp_path / "test.db"),
pragmas={"foreign_keys": 1},
)
db_proxy.initialize(db)
try:
with db.connection_context():
db.create_tables(MODELS)
yield db
finally:
with db.connection_context():
db.drop_tables(MODELS, safe=True)
A temporary file-backed database preserves its schema when tested code owns and closes scoped connections. Exercise at least two sequential connection_context() blocks—such as a write followed by a read—and test rollback behavior for multi-statement invariants. Do not reuse an application database or depend on table state from another test.
Finish by reporting the binding boundary, connection and transaction ownership, schema-test lifecycle, and checks run.
development
Score or compare one or more agent skills across trigger clarity, workflow actionability, safety boundaries, verification rigor, incremental knowledge value, and leanness. Use only when the user explicitly asks for ratings, numerical quality scores, rubric-based scorecards, or scored comparisons; use creating-agent-skills for unscored reviews or revisions.
development
Assess or improve an existing codebase's architecture when the user asks about module boundaries, coupling, scattered ownership, testability, change locality, deep modules, seams, or behavior-preserving structural refactoring. Use for cross-module design rather than ordinary diff review or a confirmed edge-case bug fix.
development
Perform read-only security audits, vulnerability assessments, or threat-focused reviews of diffs, pull requests, code paths, or explicitly scoped repositories when security is the primary objective or acceptance criterion. Use reviewing-code for ordinary review with baseline security coverage and hardening-code-paths for fixing confirmed findings.
development
Run iterative multi-reviewer panels over a code diff, verify their findings, apply explicitly authorized fixes, and re-review the updated change until it passes or reaches a stopping condition. Use when the user asks for a panel loop, multi-model code-review consensus, or a review-fix-re-review cycle.