Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vloldik/dbml-gen

GORM model generator from DBML
https://github.com/vloldik/dbml-gen

code-generation dbml dbml-go go gorm-model

Last synced: 15 days ago
JSON representation

GORM model generator from DBML

Awesome Lists containing this project

README

        

# 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:

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

## Usage

The basic command to generate models is:

```bash
dbml-gen generate -i -o -m -g
```

### 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:

```bash
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:
```bash
git clone https://github.com/vloldik/dbml-gen.git
cd dbml-gen
```

2. Install dependencies:
```bash
go mod download
```

3. Build the project:
```bash
go build
```

4. Run the generator with a sample DBML file:
```bash
./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:
- [github.com/spf13/cobra](https://github.com/spf13/cobra) for creating powerful modern CLI applications
- [gorm.io/gorm](https://gorm.io/) for the ORM functionality in generated models