SQLBoiler reads your live database schema and generates type-safe Go models and query helpers. It is database-first, not code-first.
Overview
SQLBoiler is a command-line generator that produces a Go object-relational layer matched to tables and relationships already present in a database. You maintain schema with a separate migration tool, point SQLBoiler at the database, and regenerate models when the schema changes.
Generated code emphasizes compile-time type safety, relationship helpers, hooks around create and update operations, eager loading, transactions, and strongly typed query modifiers. It targets PostgreSQL, MySQL, Microsoft SQL Server, and SQLite through separate driver binaries, with hooks to supply other engines out of band.
Configuration uses a TOML file or environment variables for connection details, output package names, table whitelists, and generation switches such as disabling hooks or tests. The tool wipes or replaces output directories on regeneration to avoid stale files from dropped tables.
The project is in maintenance mode: maintainers focus on compatibility and community fixes rather than new features. Documentation positions alternatives such as Bob and sqlc for teams wanting actively developed options.
Key features
- Schema-driven Go model generation
- PostgreSQL, MySQL, MSSQL, SQLite
- Type-safe query modifiers
- Relationship eager loading
- Lifecycle hooks and transactions
- TOML and env configuration
- Compatibility test generation
- Regeneration with wipe support
Use cases
- Go apps on legacy SQL schemas
- Replacing hand-written sql.DB boilerplate
- ActiveRecord-style Go data access