What it looks like¶
Mutate a model
What it adds¶
- Active Record–style models. Generated over sqlc queries — not a dynamic ORM, every terminal operation resolves to a statically declared query.
- Sessions and collections. APIs for model construction, lookup, persistence, and transactions.
- Dirty tracking and validation. Original snapshots, lifecycle state, and validation errors on every model.
- Typed relations. Lazy loading, eager loading, scopes, cache inspection, and explicit terminal operations.
- Value-object conversion hooks. Map database columns to real domain types at the field level.
- Deterministic generation. Golden snapshot coverage keeps generated output stable across runs.
Install¶
Install the sqlc process plugin:
Add it to sqlc.yaml:
plugins:
- name: richmodel
process:
cmd: sqlc-model
sql:
- schema: schema.sql
queries: query.sql
engine: postgresql
codegen:
- plugin: richmodel
out: internal/models
options:
version: 1
sqlc:
package: sqlcdb
import: example.com/project/internal/database/sqlc
driver: pgx/v5
contexts:
- name: content
package: content
directory: content
models: {}
See the configuration reference for the complete options contract.
Documentation¶
- Tutorials teach the system through complete, guided examples.
- How-to guides solve specific implementation and application tasks.
- Reference defines exact configuration, API, lifecycle, query, and compatibility contracts.
- Explanation records the architectural reasoning and rejected alternatives.
- Project implementation defines the delivery plan, release boundary, and definition of done.
Start with the documentation index.