CLI tool
xxjwxc/gormt avatar
xxjwxc/gormt

gormt: Turning MySQL Schemas into GORM Structs, with Caveats

Project brief: database to golang struct. mysql database to golang struct conversion tools base on gorm(v1/v2) You can automatically generate golang sturct from mysql database.

2,422 stars362 forksGoMIT

At a glance

What is it?
gormt generates Go structs and helper functions from MySQL tables, targeting GORM v1/v2. It is useful for rapid scaffolding, but its last release dates to 2021 and some features carry sharp edges.
Who is it for?
Adopt gormt if you work with MySQL and GORM, need quick struct generation from an existing schema, and accept a tool that has not seen a release since mid-2021. It is the wrong choice for teams on Postgres or SQLite, for those who want active maintenance, or for projects that require complex type customization beyond the built-in def.go mappings.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 67 days ago.
What is it written in?
Mainly Go, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.

DEEP OPEN-SOURCE ANALYSIS

What gormt Solves and Who It Targets

gormt addresses a repetitive chore: turning a MySQL database schema into Go structs that work with the GORM ORM. Without such a tool, developers hand-write structs for every table, matching column names, types, tags, and associations. gormt automates this for GORM v1 and v2, producing structs with big Camel-Case names and JSON tags. The primary audience is Go developers who use GORM against MySQL and want to scaffold models quickly, especially when dealing with many tables or legacy schemas. The README shows a one-command flow: point the tool at a database, and it emits a model directory. It is a code generator, not a runtime library, so it fits into a build-time or development-time workflow.

How gormt Works: From SQL to Struct

The core mechanism is straightforward: gormt reads the MySQL information schema through a database connection, then maps each table to a Go struct. The README demonstrates a sample table `user_account_tbl` and its derived struct `UserAccountTbl`. The mapping includes column types (e.g., `int` to `int`, `datetime` to `time.Time`), and it applies GORM tags like `gorm:"primary_key"` for primary keys and `gorm:"unique"` for unique columns. It also detects foreign keys from column naming conventions or explicit comments, as shown by the `UserInfoTbl` field with `association_foreignkey` and `foreignkey` tags. Beyond structs, gormt can generate helper functions, such as `FetchByPrimaryKey`, which wrap GORM queries. This function export is optional, controlled by the `is_out_func` config flag. The data flow is: connect to MySQL, read table metadata, apply type mappings from a configurable definition file (`data/view/cnf/def.go`), then write structs and functions to an output directory. The tool supports both a GUI mode (`-g=true`) and a command-line mode, making it usable in scripts.

Getting gormt Running: Install and Configuration

Installation is a standard Go command: `go get -u -v github.com/xxjwxc/gormt@latest`. Alternatively, pre-built binaries are available from the releases page. The tool reads a `config.yml` file in the current directory for defaults. Key configuration keys include `out_dir` for the output directory, `url_tag` for JSON or db tags, `db_tag` for GORM or db tags, and `simple` for simplified output. Other flags control whether to output SQL, functions, foreign keys, or table name functions. For example, `is_null_to_point` makes columns with `DEFAULT NULL` map to pointer types. Command-line flags override the config file. A typical invocation is `./gormt -H=127.0.0.1 -d=oauth_db -p=qwer -u=root --port=3306 -F=true`, which connects to a MySQL instance and generates code. The README also notes that Windows users may need to switch the console encoding with `CHCP 65001` to handle UTF-8 output. This setup is simple enough for a one-off use, but the reliance on a `config.yml` file means you must keep that file in sync with your project's conventions.

Feature Depth: Tags, Functions, and Custom Types

gormt goes beyond basic struct generation. It supports GORM attributes like `PRIMARY_KEY`, `UNIQUE`, `NOT NULL`, and `INDEX`, mapping them to struct tags. It can also export functions that provide GORM query helpers, such as `FetchByPrimaryKey`, which the README shows with a related table load. This is a significant feature: it generates not just data structures but also common data-access methods, which can speed up initial CRUD scaffolding. The tool also supports foreign key relationships, either detected automatically or specified via column comments like `[@fk tableName.columnName]`. For custom data type mappings, developers can edit `data/view/cnf/def.go` to enrich type conversions. This is a practical extension point, but it requires recompiling the tool if you use a pre-built binary. The config option `is_foreign_key` controls whether foreign key markers are added, and `is_out_func` toggles function generation. These options give teams control over the verbosity of the output.

Limitations and Failure Modes

The most obvious limitation is maintenance: the last release, v2.1.gorm, is dated 2021-06-27, and the repository's last push is the same date. This means the tool may not support newer GORM versions or MySQL features that have appeared since. The README itself notes that the config format may change, directing users to check `/data/config/MyIni.go` for the latest, which suggests internal instability. Another limitation is MySQL-only support; the tool does not handle Postgres or SQLite, so it is not a general database-to-Go solution. The generated structs are opinionated: they use big Camel-Case names and specific tag formats, which may not match a team's style guide. The foreign key detection relies on naming conventions or explicit comments, so schemas without clear conventions may produce incorrect associations. The README also mentions that Windows does not support UTF-8 style in the default mode, requiring an encoding switch, which is a friction point for Windows users. Finally, the function export generates code that calls GORM directly, so if your project uses a different ORM or a custom query layer, those generated functions are not useful.

Alternatives and How They Differ

A direct alternative is `gorm.io/gen`, which is part of the GORM ecosystem and provides code generation from database schemas. The key difference is that `gorm.io/gen` is actively maintained and integrates more deeply with GORM's current APIs, offering dynamic query building and type-safe operations. In contrast, gormt is a standalone tool that generates static structs and helper functions, and it has not been updated since 2021. Another alternative is `sqlboiler`, which generates Go structs and query helpers for multiple databases, but it is not GORM-specific; it produces its own ORM layer. For teams already using GORM, `gorm.io/gen` is a more future-proof choice because it tracks GORM releases. gormt's advantage is simplicity: it produces plain GORM structs with tags, which can be easier to understand than the more complex generated code from `gorm.io/gen`. However, the lack of maintenance is a significant risk for production use.

Maintenance, License, and Upgrade Cost

The project is licensed under MIT, which allows free use and modification, but the maintenance status is a concern. With no commits since June 2021, there is no active development to fix bugs or add features. The repository is not archived, so it is possible someone could fork it, but the original author appears inactive. The upgrade cost is low if you use gormt as a one-time scaffolding tool: you run it, get your models, and move on. However, if you need to regenerate models after schema changes, you are relying on a tool that may not support your current GORM version. The README mentions building from source with `make windows`, `make linux`, or `make mac`, which implies you can customize the tool, but that requires Go development skills. The license is permissive, so you can fork and maintain your own version, but that adds a long-term maintenance burden. Before adopting, check the release date and test the generated code against your GORM version to avoid surprises.

Editorial conclusion

Adopt gormt if you work with MySQL and GORM, need quick struct generation from an existing schema, and accept a tool that has not seen a release since mid-2021. It is the wrong choice for teams on Postgres or SQLite, for those who want active maintenance, or for projects that require complex type customization beyond the built-in def.go mappings. Before adopting, verify that the generated code matches your GORM version (v1 or v2), test the foreign key and function export features on a non-production schema, and check the output for any column comments that use the special @gorm or @fk prefixes, as these alter generated tags and associations.

Official sources

  1. Official documentation
  2. Official README
  3. Project repository
  4. Release notes
Community notes

Community notes