sqlc — Overview#

Identity#

Purpose#

sqlc is a SQL compiler that generates type-safe Go code from SQL queries. Developers write SQL queries annotated with a small naming DSL, run sqlc generate, and receive idiomatic Go functions with fully typed parameters and return structs — no ORM abstraction, no reflection at runtime. It targets developers who prefer writing SQL directly but want compile-time safety and autocompletion over raw database/sql.

Significance#

sqlc occupies a unique “SQL-first” niche in the Go ecosystem, positioned between raw database/sql and full ORMs like GORM. It has broad community adoption, an active Discord, and commercial backing (Riza, Inc., Coder, Mux). Its plugin architecture enables community-contributed code generators for Kotlin, Python, and TypeScript, multiplying its reach beyond Go. The project influenced a wider movement toward generated, type-safe database access layers across multiple languages.

Key metrics#

  • Go files: 3,329 (XL-tier project despite “S” label in the queue entry)
  • Top-level directories: cmd/, docs/, examples/, internal/, pkg/, protos/, scripts/
  • Direct dependencies: 25
  • First commit / age: Repository clone begins 2026-03-20; project originated ~2019 (Kyle Conroy)

Notable characteristics#

  • Compiler pipeline, not an ORM: sqlc implements a genuine multi-stage compiler: parse SQL → analyze AST → type-check against a schema → emit Go code. This is architecturally closer to a language tool (e.g., gofmt) than a database library.
  • Multi-engine SQL parsing: Supports PostgreSQL (via pg_query_go, a CGo wrapper around the real Postgres parser, plus a pure-Go WASM variant), MySQL (via TiDB’s parser), and SQLite (via go-sqlite3). Each engine is isolated under internal/engine/.
  • WASM plugin system: Code generators are decoupled from the core binary via a protobuf-over-WASM plugin protocol, using Wazero as the embedded WASM runtime. This allows language plugins to be distributed and sandboxed independently.
  • Protobuf-defined IR: The internal representation shared between the compiler and code generators is defined in .proto files (protos/plugin/, protos/analysis/, protos/vet/), giving a formal contract between the analysis core and generation plugins.
  • Built-in vet / static analysis: sqlc vet uses Google CEL (Common Expression Language) to evaluate user-defined rules against query metadata — an unusual embedded policy engine for a developer tool.