← ClaudeAtlas

sqlmodellisted

Use when writing or reviewing Python code with SQLModel, especially models, sessions, queries, FastAPI integration, relationships, link models, creates, updates, and deletes.
zaffnet/whetstone · ★ 1 · AI & Automation · score 74
Install: claude install-skill zaffnet/whetstone
# SQLModel Patterns Use SQLModel's API first. Do not default to raw SQLAlchemy patterns unless the task explicitly needs a SQLAlchemy-only feature. ## Imports Prefer imports from `sqlmodel`: ```python from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select ``` Do not use SQLAlchemy declarative defaults such as `declarative_base()`, `Mapped[...]`, `mapped_column()`, `relationship()`, or `sessionmaker()` for normal SQLModel code. ## Models Define table models with `SQLModel, table=True` and `Field()`: ```python class Hero(SQLModel, table=True): id: int | None = Field(default=None, primary_key=True) name: str = Field(index=True) team_id: int | None = Field(default=None, foreign_key="team.id") ``` Use `Field(default_factory=...)` for generated values: ```python id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True) ``` Use non-table `SQLModel` classes for create/update/public API schemas instead of mixing request/response-only fields into table models. ## Sessions and Queries Open sessions directly with the engine: ```python with Session(engine) as session: heroes = session.exec(select(Hero)).all() ``` Do not create a `sessionmaker()` for typical SQLModel examples. Use `session.exec(select(...))`, not `session.execute(...)` and not `session.query(...)`. SQLModel's `exec()` handles scalar results so agents should not add `.scalars()` after selects of models. Use `session.get(Model, id)` for primary-key lookup