Compile SQL queries to type-safe Go code with sqlc. Use this skill whenever working with sqlc configuration (sqlc.yaml, sqlc.json), writing SQL query files with sqlc annotations (:one, :many, :exec, :execrows, :execresult, :execlastid, :copyfrom, :batchone, :batchmany, :batchexec), configuring type overrides, setting up vet/lint rules, managing sqlc plugins (WASM or process), or troubleshooting sqlc code generation. Also triggers when code imports generated sqlc packages, when the user mentions "sqlc generate", "sqlc init", "sqlc vet", "sqlc diff", "sqlc compile", or asks about SQL-to-Go code generation, query compilation, database schema parsing, or Go struct generation from SQL tables. Applies to PostgreSQL, MySQL, and SQLite engines.
sqlc generates fully type-safe Go code from SQL queries. The workflow is:
sqlc generatesqlc parses SQL at compile time — no reflection, no runtime query building. This catches SQL errors before the code runs and produces Go code that reads like hand-written database access.
sqlc init
This creates an empty sqlc.yaml with version 2 format. See references/config.md
for the full configuration reference.
-- schema.sql
CREATE TABLE authors (
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL,
bio TEXT
);
Schema can be a single file, a directory of files, or a list of paths. sqlc also supports migration files from golang-migrate, goose, atlas, dbmate, sql-migrate, and tern — it automatically ignores down migrations.
-- query.sql
-- name: GetAuthor :one
SELECT * FROM authors
WHERE id = $1 LIMIT 1;
-- name: ListAuthors :many
SELECT * FROM authors
ORDER BY name;
-- name: CreateAuthor :one
INSERT INTO authors (name, bio)
VALUES ($1, $2)
RETURNING *;
-- name: DeleteAuthor :exec
DELETE FROM authors WHERE id = $1;
Each query needs a -- name: <Name> :<command> comment. See references/queries.md
for all annotation types and macros.