Sqlc go postgres codegen
Skill kjuhwa/skills-hub/skills/devops/sqlc-go-postgres-codegen
Self-correcting knowledge corpus for Claude Code — 9 stable shape clusters, bias-correction pipeline baked into contribution flow. 47 papers, 45 techniques, 1.1k skills.
npx -y skills add kjuhwa/skills-hub --skill sqlc-go-postgres-codegenAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Generate typed Go database access code from SQL files and migrations using sqlc — one source of truth per query, no ORM runtime overhead.
SKILL.md
2.6 KB, 575 tokens by cl100k_base, as published. Nobody here has run it
When to use
- Go backend with PostgreSQL, medium-complex queries (joins, CTEs, window functions).
- You want compile-time type safety for query results but don't want an ORM.
- You have up/down SQL migrations and hand-written query SQL.
Steps
- Install sqlc (
brew install sqlcor via Go:go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest). - Create
server/sqlc.yaml:version: "2" sql: - engine: "postgresql" queries: "pkg/db/queries/" schema: "migrations/" gen: go: package: "db" out: "pkg/db/generated" sql_package: "pgx/v5" emit_json_tags: true emit_empty_slices: true - Write SQL queries in
pkg/db/queries/<domain>.sqlwith magic comments:-- name: GetWorkspaceBySlug :one SELECT * FROM workspaces WHERE slug = $1; -- name: ListIssuesByWorkspace :many SELECT * FROM issues WHERE workspace_id = $1 ORDER BY created_at DESC LIMIT $2; -- name: CreateWorkspace :one INSERT INTO workspaces (name, slug) VALUES ($1, $2) RETURNING *; - Add a Makefile target:
sqlc: cd server && sqlc generate - Run
make sqlcafter editing any.sqlfile. Generated code appears inpkg/db/generated/(models, queries, interfaces). - Consume generated code:
queries := db.New(pool) ws, err := queries.GetWorkspaceBySlug(ctx, "my-team")
Example
Typical layout:
server/
sqlc.yaml
migrations/
001_init.up.sql
001_init.down.sql
pkg/db/
queries/
workspace.sql
issue.sql
generated/ # gitignored or committed, your call
models.go
workspace.sql.go
issue.sql.go
db.go
Caveats
pgx/v5is the recommended driver;database/sqlmode loses some Postgres types.- Commit the generated code to the repo if you want
go buildto work withoutsqlc generateas a prerequisite; skip it if you run codegen in CI. - sqlc reads the schema from migrations in order. Don't use
IF NOT EXISTSor nondeterministic DDL — sqlc can't infer types if the schema is ambiguous.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.