sqlc
Compile-time SQL to Go code generator. Write SQL queries in .sql files, run sqlc generate, and get type-safe Go functions and struct types. Eliminates reflection-based ORM overhead while providing better type safety than raw database/sql. Supports PostgreSQL, MySQL, and SQLite. Alternative to GORM for teams that prefer writing SQL directly.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Generated code uses parameterized queries — SQL injection prevention built in. Code generator itself has no network access during generation.
⚡ Reliability
Best When
Go teams that want type-safe database access with full SQL control and compile-time validation.
Avoid When
You need dynamic query building or rapid schema iteration — GORM or squirrel are more flexible.
Use Cases
- • Generate type-safe Go database access code from plain SQL queries — no ORM reflection, no runtime type assertions
- • Write complex SQL (CTEs, window functions, joins) that ORMs can't express and get type-safe Go wrappers
- • Enforce SQL correctness at code generation time — sqlc validates SQL against actual schema, catching errors before runtime
- • Build data access layers for Go services with full SQL control and PostgreSQL-specific features
- • Migrate from GORM to raw SQL for performance — sqlc provides structure without ORM overhead
Not For
- • Dynamic query building — sqlc requires static SQL at compile time; use squirrel or bun for dynamic queries
- • Non-SQL databases — sqlc is SQL-only; use Mongo or Redis drivers directly for NoSQL
- • Rapid prototyping where schema changes frequently — sqlc requires regenerating code on every schema change
Interface
Authentication
Code generator — no auth needed. Database auth configured via connection string in application code.
Pricing
MIT licensed open source CLI tool. sqlc Cloud adds team features.
Agent Metadata
Known Gotchas
- ⚠ sqlc requires explicit schema files — define CREATE TABLE statements in schema.sql for sqlc to validate against; it doesn't connect to a live database
- ⚠ Query names must match Go naming conventions — use -- name: GetUser :one comment format; incorrect format silently skips the query
- ⚠ NULL handling requires *string, *int64 nullable types — SQL columns without NOT NULL generate pointer types in Go; handle accordingly
- ⚠ Pagination requires explicit LIMIT/OFFSET in queries — sqlc doesn't add pagination automatically; write the SQL and map it to structs
- ⚠ Schema changes require regeneration — after ALTER TABLE or schema updates, run sqlc generate again and fix any compilation errors
- ⚠ pgtype vs standard types: PostgreSQL-specific types (JSONB, UUID, arrays) map to pgtype package types — import pgtype for these columns
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for sqlc.
Scores are editorial opinions as of 2026-03-06.