DBML-Gen is a command-line tool that generates Go models from DBML (Database Markup Language) files. It currently supports generating models compatible with GORM, a popular ORM library for Go.
DBML (Database Markup Language) is a simple, readable DSL language designed to define database structures. It allows developers to describe database schemas and relationships in a human-readable format.
- Enums at all (first in TODO list)
- Composite foreign keys
- Parse DBML files and generate corresponding Go struct models
- Support for GORM tags and functionality
- Customizable output directory
- Module name specification for generated files
To install DBML-Gen, make sure you have Go installed on your system, then run:
go install github.com/vloldik/[email protected]
The basic command to generate models is:
dbml-gen generate -i <input_file> -o <output_directory> -m <module_name> -g <backend>
-i, --input
: Path to the input DBML file (required)-o, --output
: Directory for generated files (default: current directory)-m, --module
: Name of the module (e.g., gorm.io/gorm)-g, --backend
: Backend for generated models (currently only "gorm" is supported)
To generate GORM models from a DBML file named schema.dbml
and output them to a directory named models
, use the following command:
dbml-gen generate -i schema.dbml -o ./models -m github.com/your/module -g gorm
The project is organized as follows:
cmd/
: Contains the command-line interface codeinternal/
: Houses the core functionality of the generatordbparse/
: DBML parsing logicgenerator/
: Model generation logicutils/
: Utility functions and helpers
test/
: Contains test files and sample outputtest.dbml
: Sample DBML file for testingoutput/
: Generated output from the sample DBML file
To run the project locally for development:
-
Clone the repository:
git clone https://github.com/vloldik/dbml-gen.git cd dbml-gen
-
Install dependencies:
go mod download
-
Build the project:
go build
-
Run the generator with a sample DBML file:
./dbml-gen generate -i test/test.dbml -o ./output -m github.com/example/module -g gorm
Contributions to DBML-Gen are welcome! Please feel free to submit a Pull Request.
Testing and Contributions Testing is crucial to ensure the reliability and accuracy of the code generated by DBML-Gen. We encourage contributors to write tests for new features, bug fixes, or any changes made to the codebase. To help enhance the project, you can create test cases that validate the generated Go models against their expected structures and behavior.
Contributions to DBML-Gen are welcome! Please feel free to submit a Pull Request.
MIT
This project uses the following open-source packages:
- github.com/spf13/cobra for creating powerful modern CLI applications
- gorm.io/gorm for the ORM functionality in generated models