Skip to content

Latest commit

 

History

History
104 lines (71 loc) · 3.19 KB

README.md

File metadata and controls

104 lines (71 loc) · 3.19 KB

DBML-Gen

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.

Unsupported DBML features list

  • Enums at all (first in TODO list)
  • Composite foreign keys

Features

  • Parse DBML files and generate corresponding Go struct models
  • Support for GORM tags and functionality
  • Customizable output directory
  • Module name specification for generated files

Installation

To install DBML-Gen, make sure you have Go installed on your system, then run:

go install github.com/vloldik/[email protected]

Usage

The basic command to generate models is:

dbml-gen generate -i <input_file> -o <output_directory> -m <module_name> -g <backend>

Flags

  • -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)

Example

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

Project Structure

The project is organized as follows:

  • cmd/: Contains the command-line interface code
  • internal/: Houses the core functionality of the generator
    • dbparse/: DBML parsing logic
    • generator/: Model generation logic
    • utils/: Utility functions and helpers
  • test/: Contains test files and sample output
    • test.dbml: Sample DBML file for testing
    • output/: Generated output from the sample DBML file

Development

To run the project locally for development:

  1. Clone the repository:

    git clone https://github.com/vloldik/dbml-gen.git
    cd dbml-gen
  2. Install dependencies:

    go mod download
  3. Build the project:

    go build
  4. Run the generator with a sample DBML file:

    ./dbml-gen generate -i test/test.dbml -o ./output -m github.com/example/module -g gorm

Contributing

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.

License

MIT

Acknowledgements

This project uses the following open-source packages: