python-peewee
Use when working with Peewee ORM patterns, especially DatabaseProxy setup, scoped connection/transaction handling, and SQLite-based tests.
What this skill does
# Python Peewee
## Overview
Use Peewee with `DatabaseProxy`, scoped connection handling, explicit transactions, and isolated SQLite tests. Core principle: initialize the database at the boundary, then keep models and tests deterministic.
## Use When
- Defining Peewee models or a shared `BaseModel`.
- Wiring `DatabaseProxy` for app and test databases.
- Choosing `connection_context()` vs `atomic()`.
- Writing SQLite-backed fixtures for model tests.
## Quick Reference
| Need | Pattern |
| --- | --- |
| Deferred database binding | `DatabaseProxy()` |
| Model base class | `class BaseModel(Model)` with `Meta.database` |
| Scoped connection | `with db.connection_context():` |
| Transactional writes | `with db.atomic():` |
| SQLite tests | temporary `SqliteDatabase` fixture |
## Workflow
1. Define one `DatabaseProxy` and one `BaseModel` for the model graph.
2. Initialize the proxy once at the app/test boundary.
3. Use `connection_context()` to open and close connections for scoped work.
4. Use `atomic()` around write units that must commit or roll back together.
5. In tests, bind the proxy to an isolated SQLite database and create/drop tables inside the fixture.
## Setup
### DatabaseProxy & BaseModel
```python
from peewee import DatabaseProxy, Model
db_proxy = DatabaseProxy()
class BaseModel(Model):
class Meta:
database = db_proxy
```
### Initialize DB
```python
from peewee import SqliteDatabase
db = SqliteDatabase("app.db", pragmas={"foreign_keys": 1})
db_proxy.initialize(db)
```
## Connections and Transactions
### Read (no transaction)
```python
with db_proxy.obj.connection_context():
rows = MyModel.select().limit(100)
```
### Write (atomic)
```python
with db_proxy.obj.atomic():
a.save()
b.save()
```
### Combined
```python
db = db_proxy.obj
with db.connection_context():
with db.atomic():
...
```
Use `connection_context()` for scoped connections (open/close).
Use `atomic()` for atomic writes (BEGIN/COMMIT/ROLLBACK).
## SQLite Test Fixture
```python
import pytest
from peewee import SqliteDatabase
@pytest.fixture
def test_db(tmp_path):
db = SqliteDatabase(str(tmp_path / "test.db"))
db_proxy.initialize(db)
with db.connection_context():
db.create_tables([MyModel])
yield db
with db.connection_context():
db.drop_tables([MyModel])
```
Use in function-based pytest tests:
```python
def test_create_user(test_db):
with test_db.atomic():
user = User.create(name="Ada")
assert User.get_by_id(user.id).name == "Ada"
```
## Common Mistakes
- Querying models before `db_proxy.initialize(db)` has run.
- Holding one global open connection for the whole process when scoped connections would be clearer.
- Using `atomic()` as a substitute for opening a connection in code paths that also need explicit connection lifetime.
- Reusing a persistent app database in tests.
## Red Flags
- Tests that depend on table state from previous tests.
- Peewee models bound directly to a production database in module import code.
- Write operations performed without a transaction boundary.
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.