# xo/dbtpl

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/xo-dbtpl).**

3,892 stars · 334 forks · Go · MIT

## Links

- GitHub: https://github.com/xo/dbtpl
- awesome-repositories: https://awesome-repositories.com/repository/xo-dbtpl.md

## Topics

`code-generator` `golang` `microsoft-sql-server` `mysql` `oracle` `orm` `postgresql` `sql` `sqlite`

## Description

dbtpl is a database model generator and schema introspector that produces type-safe source code and data models from SQL database schemas. It functions as a command line tool that maps SQL types to Go structs and execution functions, while providing a template-based system for creating custom source code and schema definitions.

The tool supports multiple database engines, including PostgreSQL, MySQL, SQLite, Oracle, and SQL Server. It distinguishes itself by allowing users to define custom output formats through text templates and the ability to generate compatible model definitions for the Django web framework.

Its capabilities extend to producing SQL scripts for database migration and mirroring, as well as exporting schema representations in JSON or YAML formats. Additionally, it can generate dot files to visualize database relationships and structural diagrams.

## Tags

### Programming Languages & Runtimes

- [Go Code Generators](https://awesome-repositories.com/f/programming-languages-runtimes/go-code-generators.md) — Automatically generates idiomatic Go source code and type-safe data models from SQL database schemas.
- [Source Code Generators](https://awesome-repositories.com/f/programming-languages-runtimes/source-code-generators.md) — Programmatically generates valid source code files and schema scripts from database representations. ([source](https://github.com/xo/dbtpl/blob/main/main.go))

### Software Engineering & Architecture

- [Typesafe SQL Code Generators](https://awesome-repositories.com/f/software-engineering-architecture/schema-generators/procedural-macro-generators/sql-schema-generators/typesafe-sql-code-generators.md) — Generates type-safe Go source code and data models from SQL database schemas and queries.
- [Database Accessor Generators](https://awesome-repositories.com/f/software-engineering-architecture/interface-definition-languages/type-safe-code-generators/database-accessor-generators.md) — Creates type-safe data models and accessor functions for tables, enums, and stored procedures. ([source](https://github.com/xo/dbtpl/blob/main/README.md))

### Data & Databases

- [Output Format Definitions](https://awesome-repositories.com/f/data-databases/custom-data-types/custom-data-type-providers/code-generators/template-based-code-customizers/custom-metadata-templates/output-format-definitions.md) — The tool allows defining custom output formats by authoring or modifying base templates to match specific organizational requirements. ([source](https://github.com/xo/dbtpl#readme))
- [Database Introspection Tools](https://awesome-repositories.com/f/data-databases/database-introspection-tools.md) — Provides utilities for reverse-engineering schema definitions from live databases across multiple SQL dialects.
- [Typesafe Query Generations](https://awesome-repositories.com/f/data-databases/sql-query-generation/typesafe-query-generations.md) — Generates type-safe query functions and result models from labeled SQL statements. ([source](https://github.com/xo/dbtpl/blob/main/README.md))
- [Access Layer Templates](https://awesome-repositories.com/f/data-databases/custom-data-types/custom-data-type-providers/code-generators/template-based-code-customizers/custom-metadata-templates/access-layer-templates.md) — Allows defining specific code output formats using text templates to match organizational standards.
- [Django Model Definitions](https://awesome-repositories.com/f/data-databases/data-model-generation/django-model-generation/django-model-definitions.md) — Produces compatible model definitions for the Django web framework based on database schemas or SQL queries. ([source](https://github.com/xo/dbtpl/blob/main/_examples/django))
- [Platform-Specific Type Mappings](https://awesome-repositories.com/f/data-databases/data-type-definitions/abstract-type-systems/platform-specific-type-mappings.md) — Maps vendor-specific database types into a common internal representation for consistent source code output.
- [Schema Documentation Generators](https://awesome-repositories.com/f/data-databases/schema-documentation-generators.md) — Produces structured reports, visual diagrams, and JSON/YAML representations of relational database schemas.
- [DDL Script Generators](https://awesome-repositories.com/f/data-databases/schema-generators/ddl-script-generators.md) — Produces DDL scripts to recreate or mirror database schemas based on live introspection. ([source](https://github.com/xo/dbtpl/blob/main/README.md))
- [Migration Script Generators](https://awesome-repositories.com/f/data-databases/sql-migration-frameworks/migration-script-generators.md) — Produces SQL migration scripts by introspecting a live database to recreate its schema.
- [SQL Statement Parsing](https://awesome-repositories.com/f/data-databases/sql-statement-parsing.md) — Parses custom SQL statements to automatically derive the necessary data types and execution functions.

### Development Tools & Productivity

- [Database Schema Analyzers](https://awesome-repositories.com/f/development-tools-productivity/database-schema-analyzers.md) — Analyzes database catalogs across multiple SQL dialects to export structural definitions for development.
- [SQL-to-Go Struct Generators](https://awesome-repositories.com/f/development-tools-productivity/go-type-generators/sql-to-go-struct-generators.md) — Parses custom SQL queries to automatically create corresponding type-safe Go structs and execution functions.
- [Template-Based Code Generators](https://awesome-repositories.com/f/development-tools-productivity/template-based-code-generators.md) — Uses dynamic text templates to automate the creation of source code and scripts from schema metadata.
- [Model Generators](https://awesome-repositories.com/f/development-tools-productivity/type-generators/database-schema/model-generators.md) — Generates language-specific model structures, including Go structs, from database schemas.

### Graphics & Multimedia

- [Database Relationship Diagrams](https://awesome-repositories.com/f/graphics-multimedia/graph-visualization-scripts/database-relationship-diagrams.md) — Produces dot files that visualize database relationships and structural diagrams using graph visualization tools.

### User Interface & Experience

- [Generation Templates](https://awesome-repositories.com/f/user-interface-experience/layout-utilities/presentation-engines/template-engines/configuration-and-integration/custom-template-integrations/generation-templates.md) — Uses custom text templates to modify the structure, logic, and content of generated files. ([source](https://github.com/xo/dbtpl/blob/main/README.md))

### Part of an Awesome List

- [Database Tools](https://awesome-repositories.com/f/awesome-lists/data/database-tools.md) — Listed in the “Database Tools” section of the Awesome Go awesome list.
