agentsclimarketplace

Using peewee orm

Skill narumiruna/skills/skills/python/using-peewee-orm

Install
npx -y skills add narumiruna/skills --skill using-peewee-orm

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 8 stars8 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

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.

SKILL.md

2.7 KB, as published. Nobody here has run it

Python Peewee

Bind models at an application or test boundary; keep connection lifetime, transaction lifetime, and schema lifecycle explicit.

Model Setup

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.

Lifecycle Rules

  • Use db.connection_context() when a function owns a scoped open/close boundary.
  • Use 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.
  • Pass or retain the initialized database handle at the boundary instead of reaching through private proxy internals.
  • Initialize the proxy before querying. Avoid process-long connections unless the application architecture deliberately owns them.
  • Do not run schema changes, table deletion, migrations, or writes against an external or production database without explicit authorization for that target and operation.
with db.connection_context():
    rows = list(User.select().limit(100))

with db.connection_context():
    with db.atomic():
        account.debit(amount)
        ledger.record(account, amount)

Isolated SQLite Tests

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.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.