sqlc
Skill41 starsChanged 7 days agoMITView on GitHub
Add SQL queries, run code generation, and configure type overrides for the hive SQLite data layer. Use when writing new queries, adding tables, or mapping domain types to generated code.
In this repository17 other files it gives its agents.
- AGENTS.mdAGENTS.md
- docs/AGENTS.mdAGENTS.md
- cli-autocalibrateSkill
- cli-smokeSkill
- cli-tuiSkill
- desktop-apiSkill
- desktop-commands-auditSkill
- desktop-devserverSkill
- desktop-shipped-skillsSkill
- desktop-ui-auditSkill
- desktop-ui-perfSkill
- docs-auditSkill
- docs-pageSkill
- go-enumSkill
- release-notesSkill
- release-prepSkill
- releaseSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 0 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 29
After any change to .sql query files or sqlc.yaml:
- Very specific: line 37
Always commit the generated *.sql.go and models.go alongside the SQL changes.
- Very specific: line 41
Write the annotated query in the appropriate .sql file:
- Very specific: line 62
Call it via s.db.Queries().GetHCItem(ctx, id).
- Very specific: line 66
When a column stores a domain enum, add an override in sqlc.yaml so the generated params/returns use the Go type directly instead of string:
- Very specific: line 92
Nullable / optional columns: Use sql.NullString, sql.NullInt64, etc.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
sqlc in Hive
Hive uses sqlc to generate type-safe Go from SQL queries. The generated files are committed to the repo — never edit them manually.
File Layout
internal/store/db/
├── queries/
│ ├── queries.sql # Core session/message queries
│ └── queries_hc.sql # Honeycomb queries (separate file)
├── migrations/
│ └── NNNN_name.up.sql # Schema migrations (source of truth for sqlc)
├── queries.sql.go # Generated — do not edit
├── queries_hc.sql.go # Generated — do not edit
└── models.go # Generated — do not editsqlc.yaml at the repo root lists both query files under sql[0].queries.
Running Code Generation
After any change to .sql query files or sqlc.yaml:
mise run generate # runs sqlc generate + go-enum generation
# or directly:
sqlc generateAlways commit the generated *.sql.go and models.go alongside the SQL changes.
Adding a Query
- Write the annotated query in the appropriate
.sqlfile:
-- name: GetHCItem :one
SELECT id, repo_key, epic_id, parent_id, session_id, title, "desc",
type, status, depth, created_at, updated_at
FROM hc_items WHERE id = ?;
-- name: ListHCItems :many
SELECT ... FROM hc_items WHERE repo_key = ? ORDER BY created_at DESC;
-- name: InsertHCItem :exec
INSERT INTO hc_items (...) VALUES (...);Annotations: :one (returns single row), :many (returns slice), :exec (no rows returned).
- Run
mise run generate. - The generated function appears in
queries_hc.sql.go(orqueries.sql.go) under thedbpackage. - Call it via
s.db.Queries().GetHCItem(ctx, id).
Type Overrides (Domain Types in Generated Code)
When a column stores a domain enum, add an override in sqlc.yaml so the generated params/returns use the Go type directly instead of string:
overrides:
- column: "hc_items.status"
go_type:
import: "github.com/colonyops/hive/internal/domain/hc"
type: "Status"
- column: "hc_items.type"
go_type:
import: "github.com/colonyops/hive/internal/domain/hc"
type: "ItemType"The domain type must implement driver.Valuer and sql.Scanner (or use text marshaling). go-enum generated types satisfy this via MarshalText/UnmarshalText, which SQLite handles as text.
Schema Source of Truth
sqlc derives the schema from internal/store/db/migrations/*.up.sql. When you add a migration, run mise run generate to regenerate models. The generated models.go is always overwritten — do not add hand-written code there.
Separate Query Files
HC queries live in queries_hc.sql to keep the diff surface small. Add new feature query files by listing them under sql[0].queries in sqlc.yaml. All query files share the same gen.go output directory and package.
Common Patterns
Nullable / optional columns: Use sql.NullString, sql.NullInt64, etc. Override with nullable: true in sqlc.yaml if needed.
Timestamps: Stored as INTEGER NOT NULL (Unix seconds). The generated code uses int64. Conversion to/from time.Time happens in the store layer, not in generated code.
Transactions: Store methods call queries through s.db.Ctx(ctx), which joins an ambient transaction when the context carries one. Open a unit of work with s.db.WithinTx(ctx, func(ctx context.Context, q *db.DB) error { ... }); a nested call joins the outer transaction and only the outermost call commits or rolls back.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

