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.

Evaluated Mar 06, 2026 (0d ago) v1.25+
Homepage ↗ Repo ↗ Developer Tools go sql code-generation postgres mysql sqlite type-safe compile-time
⚙ Agent Friendliness
68
/ 100
Can an agent use this?
🔒 Security
86
/ 100
Is it safe for agents?
⚡ Reliability
83
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
85
Error Messages
82
Auth Simplicity
100
Rate Limits
100

🔒 Security

TLS Enforcement
90
Auth Strength
85
Scope Granularity
80
Dep. Hygiene
88
Secret Handling
88

Generated code uses parameterized queries — SQL injection prevention built in. Code generator itself has no network access during generation.

⚡ Reliability

Uptime/SLA
88
Version Stability
82
Breaking Changes
78
Error Recovery
85
AF Security 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

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

Code generator — no auth needed. Database auth configured via connection string in application code.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

MIT licensed open source CLI tool. sqlc Cloud adds team features.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

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.

$99

Scores are editorial opinions as of 2026-03-06.

5208
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered