sqlc
docs.sqlc.dev
4
Leaving SiteNav
External Link Disclaimer
You are about to visit docs.sqlc.dev. This website is not operated by us. We are not responsible for its content or privacy practices.
About this website
sqlc is a compiler that generates fully type-safe idiomatic Go (or Python, Kotlin, TypeScript) code from SQL queries. Instead of using an ORM that abstracts away SQL, sqlc takes a different approach: developers write standard SQL queries in .sql files with annotations (-- name: QueryName :one, :many, or :exec), and sqlc parses the SQL, understands the database schema, and generates Go structs, query functions, and interface implementations that are fully type-safe. This eliminates entire categories of runtime errors: SQL syntax errors, type mismatches between Go and database columns, null handling issues, and column name typos. Key features include: schema-aware code generation (sqlc reads CREATE TABLE statements or introspects a live PostgreSQL/MySQL/SQLite database to understand column types, nullability, foreign keys, and constraints), four query annotation modes (:one returns a single struct, :many returns a slice, :exec returns no rows, :copyfrom for COPY FROM bulk insert), PostgreSQL pgx driver support with native array and UUID types, nullable type handling (Go pointers or sql.Null* types), database migration integration (embedding migrations via Go embed), query annotation for struct generation (-- name: CreateAuthor :one), view generation, enum support, JSON column support, and multiple database engines (PostgreSQL, MySQL, SQLite, and experimental support for SQL Server). The generated code includes query constants, scan functions, and optional dbtx interface for easy testing with mocks. As of 2026, sqlc has over 14,200 stars.
Statistics
4
Views
0
Clicks
0
Like
0
Dislike