How sqlc-dev/sqlc works
sqlc is a SQL compiler: users provide SQL queries, schema and configuration, then invoke the CLI to produce type-safe application code. The principal workflow parses and analyzes SQL against a database dialect/catalog, then passes compiled query metadata to a language generator. The tree also exposes analysis, vetting, formatting, diff/verification, and database-management commands, plus plugin support. The compiler excerpt confirms dialect-specific setup and a core analysis path; wiring for several command and plugin branches is inferred only at the documented capability level.
Main entry points: cmd Command Handlers · engine.go Compiler · cli.go CLI · gen.go Go Generator
Components 21
CLI and Config
- CLI
pkg/cli/cli.go - Command Handlers
internal/cmd - Configuration
internal/config/config.go
SQL Compilation
- SQL Parsing
internal/compiler/parse.go - Dialect Engines
internal/engine - Compiler
internal/compiler/engine.go - Schema Catalog
internal/core/catalog.go - Query Catalog
internal/compiler/query_catalog.go - Query Analysis
internal/compiler/analyze.go
Code Generation
- Go Generator
internal/codegen/golang/gen.go - JSON Generator
internal/codegen/json/gen.go - Plugin Protocol
internal/plugin/codegen.pb.go - Plugin Runtime
internal/ext/handler.go
Validation and Services
- Analyze and Vet
internal/cmd/analyze.go - Format and Diff
internal/cmd/fmt.go - Verify Queries
internal/cmd/verify.go - Managed Databases
internal/dbmanager/client.go
Other components
- Developer
- SQL and Config
- Generated Files
- SQL Database
Connections 24
- Developer → CLI: invokes
- SQL and Config → Command Handlers: supplies inputs
- CLI → Command Handlers: dispatches
- Command Handlers → Configuration: loads settings
- Command Handlers → Compiler: compiles queries
- Compiler → SQL Parsing: parses SQL
- Compiler → Dialect Engines: selects dialect
- Compiler → Schema Catalog: builds catalog
- Compiler → Query Catalog: resolves relations
- Compiler → Query Analysis: analyzes queries
- Command Handlers → Go Generator: generates Go
- Command Handlers → Plugin Protocol: requests generation
- Plugin Protocol → Plugin Runtime: dispatches plugin
- Plugin Runtime → JSON Generator: invokes JSON
- Go Generator → Generated Files: writes code
- JSON Generator → Generated Files: returns files
- Command Handlers → Analyze and Vet: runs analysis
- Command Handlers → Format and Diff: runs formatting
- Command Handlers → Verify Queries: runs verification
- Command Handlers → Managed Databases: creates database
- Managed Databases → SQL Database: creates and migrates
- Analyze and Vet → Compiler: analyzes SQL
- Verify Queries → Compiler: checks queries
- Developer → Generated Files: uses generated code