Skip to content

Install sqlty for Go

sqlty.SQL[R, P] types a query string with its row struct and parameters, and sqlty-vet checks it against your schema under go vet. No code is generated and no database is needed.

Preview

The Go module works with any release. A prebuilt sqlty-vet ships from the next release on; until then, build it from a checkout as below.

1. Add the module

go get github.com/jirikuncar/sqlty/go

It needs Go 1.26 or newer, and gives sqlty.SQL and pgxq, which runs the queries with pgx v5. Neither links the engine.

2. Point it at your schema

Put a sqlty.toml next to go.mod.

sqlty.toml:

schema = "schema.sql"

The analyzer reads the nearest sqlty.toml, or [tool.sqlty] in a pyproject.toml, above each Go file. See Configuration.

3. Install sqlty-vet

From the next release, on macOS and Linux with glibc 2.35 or newer:

brew install jirikuncar/sqlty/sqlty-vet

A release runs on Go 1.26 up to the newest Go of its day. go vet rejects every package of a newer Go than built the tool, so after a Go release, take the next sqlty release or build it from a checkout.

Until then, build it from a checkout, which needs Go and a Rust toolchain:

git clone https://github.com/jirikuncar/sqlty.git
cd sqlty
make go-vet   # builds rust/target/go/sqlty-vet

4. Check

go vet -vettool=$(which sqlty-vet) ./...

Each finding names its rule, such as [unknown-column] or [nullable-mismatch], and fails go vet. Go (go vet and golangci-lint) lists the rules, the golangci-lint plugin and the jirikuncar/sqlty/go GitHub Action, which installs sqlty-vet and runs it on the pull request from the next release on.

Common questions

Why not go install sqlty-vet?

sqlty-vet links the engine, a Rust static library, through cgo. go install cannot build it, so it ships prebuilt or builds from a checkout.

Does the Go module need cgo?

No. sqlty.SQL and pgxq are plain Go; only sqlty-vet links the engine.

Which databases does the analyzer support?

PostgreSQL with pgx v5. A query run as string(q) through conn.Query, QueryRow, Exec or Batch.Queue is checked too.