https://github.com/wonli/gormt
golang database to struct
https://github.com/wonli/gormt
Last synced: 10 months ago
JSON representation
golang database to struct
- Host: GitHub
- URL: https://github.com/wonli/gormt
- Owner: wonli
- License: apache-2.0
- Created: 2024-05-13T05:43:40.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-17T09:50:25.000Z (about 2 years ago)
- Last Synced: 2025-07-28T20:49:36.909Z (11 months ago)
- Language: Go
- Size: 36.1 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Golang Database to Struct
### MySQL Database to Golang Struct Conversion Tool Based on GORM v2
This tool allows you to automatically generate Golang structs from a MySQL database using GORM (version 2). It supports the big Camel-Case naming convention and JSON tags.
### Improvements
This project is derived and improved from `https://github.com/xxjwxc/gormt`. Changes include:
- Removal of the GUI for a simpler command-line interface.
- Addition of table prefix configuration options.
- Added support for `GEOMETRY` data type.
- Removal of some unnecessary code for a more streamlined experience.
## Support for GORM Attributes
- **Database Tables and Column Field Annotation**: Support for detailed annotations in generated structs.
- **JSON Tag**: Automatic JSON tag output in structs.
- **GORM.Model**: Inclusion of GORM's built-in model features.
- **PRIMARY_KEY**: Specifies a column as the primary key.
- **UNIQUE**: Marks a column as unique.
- **NOT NULL**: Marks a column as NOT NULL.
- **INDEX**: Allows the creation of indexes, with or without a name; using the same name creates composite indexes.
- **UNIQUE_INDEX**: Similar to INDEX, but creates a unique index.
- **GEOMETRY**: Support for geometry data type.
### Installation
Install the tool using the following Go command:
`go get github.com/wonli/gormt@latest`
### Usage
```go
package main
import (
"github.com/wonli/gormt"
"github.com/wonli/gormt/config"
)
func main() {
dbInfo := config.DBInfo{
Host: "127.0.0.1",
Port: 3306,
Username: "root",
Password: "123456",
Database: "test",
Type: 0,
}
conf := config.Config{
DBInfo: dbInfo,
PkgName: "schema",
OutDir: "./examples/model",
DbTag: "gorm",
IsJsonTag: true,
IsNullToSqlNull: true,
TablePrefix: "q_",
StripTablePrefix: true,
OutFileName: "schema",
}
gormt.ExecuteConfig(&conf)
}
```