Compile SQL to type-safe code
open sourceMITself-hostablefree
sqlc is a SQL compiler: you write your schema and queries in plain SQL, run sqlc generate, and it produces type-safe, idiomatic code with an interface for each query, so you call methods instead of writing querying boilerplate and catch mismatches at build time instead of in production. Go is built in, and plugins generate Kotlin, Python and TypeScript (community plugins add more). PostgreSQL and MySQL support is stable, with SQLite, ClickHouse, DuckDB, Spanner and SQL Server in beta. Other commands lint queries (vet), verify schema changes, format SQL and analyze result types; push and managed databases use the free sqlc Cloud. A single binary for Linux, macOS and Windows, MIT licensed.
Problems it solves
- write raw SQL in Go but get type-safe generated code instead of hand-written scanning
- catch SQL query and schema mismatches at build time instead of at runtime
- a type-safe database layer in Go without an ORM
- generate TypeScript, Python or Kotlin code from SQL queries
- lint SQL queries in CI for unsafe patterns
- check that a schema migration doesn't break existing queries
Features
- type-safe code generated from SQL schema and queries
- built-in Go generator; plugins for Kotlin, Python and TypeScript
- PostgreSQL and MySQL (stable); SQLite, ClickHouse, DuckDB, Spanner and SQL Server (beta)
- vet command for linting queries
- verify command for checking schema changes
- fmt, parse and analyze commands
- query annotations, macros, type overrides and struct configuration
- codegen plugins for more languages
- online playground
- push and managed databases through sqlc Cloud
Capabilities
| Has a command line tool | plan not known |
|---|---|
| Takes plugins | plan not known |
Alternatives
The same job
These do what sqlc does.
- ent An entity framework for Go
- Prisma ORM One schema. Every query type-safe.
- SQLAlchemy The Python SQL toolkit and Object Relational Mapper
- Slick Functional Relational Mapping for Scala
