dbtpl
dbtpl is a command-line code generator for Go that introspects SQL database schemas and generates type-safe, idiomatic Go code. It supports PostgreSQL, MySQL, SQLite, Oracle, and MSSQL, and can produce models, schema scripts, JSON/YAML definitions, and Graphviz diagrams.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | xo/dbtpl |
| Owner | xo |
| Primary language | Go |
| License | MIT — OSI-approved |
| Stars | 3.9k |
| Forks | 334 |
| Open issues | 67 |
| Latest release | v1.0.2 (2024-05-24) |
| Last updated | 2026-03-30 |
| Source | https://github.com/xo/dbtpl |
What dbtpl is
dbtpl connects to databases via DSN, extracts schema metadata using SQL introspection queries, and applies Go templates to generate type definitions for tables, enums, stored procedures, and custom queries. It supports both schema-wide generation and query-specific code generation with optional type safety verification.
Get the dbtpl source
Clone the repository and explore it locally.
git clone https://github.com/xo/dbtpl.gitcd dbtpl# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- Generated code is claimed to be production-quality but requires manual review and integration; regeneration workflow must be documented and tested.
- Schema introspection requires live database connectivity during code generation; secure credential management (DSN handling) is developer responsibility.
- Enum and custom type support varies by database (PostgreSQL has best coverage; Oracle and MSSQL lack enum support)—verify feature matrix against your schema.
- Customizable templates via `--src` flag allow branching from defaults, but maintaining parallel template versions across updates adds maintenance overhead.
- Command-line flag complexity is high (60+ options for schema/query generation); pipeline integration requires careful parameter validation and testing.
When to avoid it — and what to weigh
- Need non-Go language support — dbtpl explicitly supports Go only. Other languages are not currently planned, making this unsuitable for polyglot teams or non-Go backends.
- Require a full ORM with runtime query builder — dbtpl generates types and schemas only; it does not provide query execution, relationship management, or migration tooling. You must write or integrate SQL and query logic separately.
- Expect zero post-generation customization — README notes that dbtpl-generated code is not a 'silver bullet'—manual authoring of SQL and Go is still expected. Heavy schema changes require regeneration.
- Working with unsupported databases — If your primary database is not PostgreSQL, MySQL, SQLite, Oracle, or MSSQL, dbtpl cannot introspect your schema.
License & commercial use
dbtpl is licensed under the MIT License, a permissive open-source license that permits commercial use, modification, and distribution with minimal restrictions (requires attribution and license notice).
MIT License permits commercial use without restriction. You may use dbtpl in proprietary projects, modify the source, and sell software built with generated code. No commercial licensing or fees required. Recommended practice: include MIT license notice in distributions.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Adequate |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Good |
| Assessment confidence | High |
dbtpl requires database credentials (DSN) for schema introspection; DSN handling is developer responsibility—secure storage, rotation, and access control must be enforced externally. Generated Go code contains no security-related features or protections; security of resulting application depends on developer-written SQL and business logic. No security audit, CVE history, or hardened-by-default settings documented.
Alternatives to consider
sqlc
Query-first code generator; type-safe query results from explicit SQL; narrower scope but tighter type safety; supports more databases and languages; active maintenance.
gorm
Full-featured ORM with code generation; includes query builder, hooks, migrations; heavier runtime footprint; different philosophy (ORM abstraction vs. code generation).
ent
Graph-based ORM with schema-first code generation; provides query builder and migrations; more opinionated; tighter coupling to ent ecosystem.
Build on dbtpl with DEV.co software developers
Evaluate dbtpl for your project by testing schema generation against your database. Review generated code quality, template customization options, and integration requirements before adopting into your CI/CD pipeline.
Talk to DEV.coRelated on DEV.co
Explore the category and the services that help you build with it.
dbtpl FAQ
Can dbtpl generate code for databases without an internet connection?
Does dbtpl support migration generation?
Can I use dbtpl with an existing codebase that already has Go models?
Is dbtpl production-ready?
Work with a software development agency
From first prototype to production, DEV.co delivers software development services around tools like dbtpl. Our software development agency staffs experienced software developers and web developers for custom software development, web development, integrations, and ongoing support across open-source databases and beyond.
Ready to streamline Go database development?
Evaluate dbtpl for your project by testing schema generation against your database. Review generated code quality, template customization options, and integration requirements before adopting into your CI/CD pipeline.