Commands
sqlc init
Create an empty sqlc.yaml (v2 format)
sqlc generate
Generate code from schema and queries
sqlc compile
Check SQL for syntax and type errors
Parses and type-checks only; writes no files.
sqlc vet
Run lint rules over the queries
sqlc diff
Show how output differs from files on disk
sqlc -f <file> generate
Use another config file
sqlc init --v1
Create a version 1 config instead
sqlc parse
Print the SQL AST as JSON
sqlc createdb
Create an ephemeral database
sqlc verify --against <tag>
Compare to a tagged push
sqlc push -t <tag>
Upload project to sqlc cloud
sqlc push --dry-run
Dump the push request only
sqlc --no-remote generate
Disable remote execution
sqlc version
Print installed version
Query annotations
-- name: <Name> :one
Return a single row
-- name: <Name> :many
Return a slice of rows
-- name: <Name> :exec
Run it, return only an error
-- name: <Name> :execrows
Return affected row count
-- name: <Name> :execresult
Return the driver's sql.Result
-- name: <Name> :execlastid
Return the generated ID
-- name: <Name> :batchexec
Batch executions (pgx, Go only)
-- name: <Name> :batchone
Batch of single-row queries
-- name: <Name> :batchmany
Batch of multi-row queries
-- name: <Name> :copyfrom
Bulk insert, driver specific
sqlc.yaml
version: "2"
Config format version
engine: postgresql
postgresql, mysql or sqlite
schema: "<path>"
Schema file, dir or migrations
queries: "<path>"
Query file or directory
gen.go.package: <name>
Go package name of the output
gen.go.out: <dir>
Output directory
sql_package: pgx/v5
Pick driver (default database/sql)
emit_json_tags: true
Add json tags to structs
emit_interface: true
Generate a Querier interface
emit_empty_slices: true
Return [] instead of nil for :many
emit_pointers_for_null_types
Use *T for nullable columns
overrides:
Map db types or columns to Go types
rules: [<name>]
Enable vet rules for this package
database.uri: ${DB_URL}
Live database for vet; env vars expand
database.managed: true
Use a managed database (needs cloud)
analyzer.database: false
Skip database-backed analysis
strict_function_checks: true
Error on unknown functions
codegen: / plugins:
Plugin based output (process, wasm)