agentleFS
colonyopscolonyops/hive/.agents/skills/sqlc/SKILL.md

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.

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
  1. Very specific:

    After any change to .sql query files or sqlc.yaml:

    line 29
  2. Very specific:

    Always commit the generated *.sql.go and models.go alongside the SQL changes.

    line 37
  3. Very specific:

    Write the annotated query in the appropriate .sql file:

    line 41
  4. Very specific:

    Call it via s.db.Queries().GetHCItem(ctx, id).

    line 62
  5. Very specific:

    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:

    line 66
  6. Very specific:

    Nullable / optional columns: Use sql.NullString, sql.NullInt64, etc.

    line 92

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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 edit

sqlc.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 generate

Always commit the generated *.sql.go and models.go alongside the SQL changes.

Adding a Query

  1. Write the annotated query in the appropriate .sql file:
-- 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).

  1. Run mise run generate.
  2. The generated function appears in queries_hc.sql.go (or queries.sql.go) under the db package.
  3. 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.