You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

216 lines
6.6 KiB
Markdown

[![Build Status](https://travis-ci.org/xxjwxc/gormt.svg?branch=master)](https://travis-ci.org/xxjwxc/gormt)
[![Go Report Card](https://goreportcard.com/badge/github.com/xxjwxc/gormt)](https://goreportcard.com/report/github.com/xxjwxc/gormt)
5 years ago
[![GoDoc](https://godoc.org/github.com/xxjwxc/gormt?status.svg)](https://godoc.org/github.com/xxjwxc/gormt)
5 years ago
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)
5 years ago
## [中文文档](README_zh_cn.md)
<a href="https://tracking.gitads.io/?repo=gormt">
<img src="https://images.gitads.io/gormt" alt="GitAds"/>
</a>
4 years ago
### mysql database to golang struct conversion tools base on [gorm](https://github.com/jinzhu/gorm)You can automatically generate golang sturct from mysql database. big Camel-Case Name Rule, JSON tag.
## gui support
![show](/image/gormt/ui_en.gif)
5 years ago
```
./gormt -g=true
```
## cmd support
5 years ago
![show](/image/gormt/out.gif)
5 years ago
```
./gormt -g=false
```
4 years ago
## install
```
go get -u github.com/xxjwxc/gormt
```
or: [Dowloading](https://github.com/xxjwxc/gormt/releases)
5 years ago
--------
## 1. Configure default configuration items through the current directory config.yml file
5 years ago
```
out_dir : "." # out dir
url_tag : json # web url tag(json,db(https://github.com/google/go-querystring))
language : # language(English,中 文)
db_tag : gorm # DB tag(gorm,db)
singular_table : true # Table name plural (big Camel-Case):gorm.SingularTable
simple : false #simple output
is_out_sql : false # Whether to output sql
5 years ago
is_out_func : true # Whether to output function
is_url_tag : true # Whether to mark web or not
is_foreign_key : true # Whether to mark foreign key or not
is_gui : false # Whether to operate on gui
is_table_name : false # Whether to out GetTableName function
is_null_to_point : false # database is 'DEFAULT NULL' then set element type as point
mysql_info :
host : "127.0.0.1"
port : 3306
username : "root"
password : "qwer"
database : "oauth_db"
5 years ago
```
## 2. get help
5 years ago
```
./gormt --help
or
./gormt -h
-------------------------------------------------------
base on gorm tools for mysql database to golang struct
Usage:
main [flags]
Flags:
-d, --database string 数据库名
5 years ago
-f, --foreign 是否导出外键关联
-F, --fun 是否导出函数
-g, --gui 是否ui显示模式
5 years ago
-h, --help help for main
-H, --host string 数据库地址.(注意-H为大写)
-o, --outdir string 输出目录
-p, --password string 密码.
--port int 端口号 (default 3306)
-s, --singular 是否禁用表名复数
-l, --url string url标签(json,url)
5 years ago
-u, --user string 用户名.
```
## 3. Can be updated configuration items using command line tools
```
5 years ago
./gormt -H=127.0.0.1 -d=oauth_db -p=qwer -u=root --port=3306 -F=true
```
5 years ago
## 4. Support for gorm attributes
5 years ago
- Database tables, column field annotation support
- singular_table, Table name plural (big Camel-Case)
- json tag json tag output
5 years ago
- gorm.Model [Support export gorm.model>>>](doc/export.md)
- PRIMARY_KEY Specifies column as primary key
- UNIQUE Specifies column as unique
- NOT NULL Specifies column as NOT NULL
- INDEX Create index with or without name, same name creates composite indexes
- UNIQUE_INDEX Like INDEX, create unique index
5 years ago
- Support foreign key related properties [Support export gorm.model>>>](doc/export.md)
5 years ago
- Support function export (foreign key, association, index , unique and more)[Support export function >>>](https://github.com/xxjwxc/gormt/blob/master/data/view/genfunc/genfunc_test.go)
5 years ago
### You can enrich data types in [def](data/view/cnf/def.go)
5 years ago
5 years ago
## 5. Demonstration
5 years ago
- sql:
```
CREATE TABLE `user_account_tbl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`account` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`password` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`account_type` int(11) NOT NULL DEFAULT '0' COMMENT '帐号类型:0手机号1邮件',
`app_key` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT 'authbucket_oauth2_client表的id',
5 years ago
`user_info_tbl_id` int(11) NOT NULL,
5 years ago
`reg_time` datetime DEFAULT NULL,
`reg_ip` varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`bundle_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`describ` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
5 years ago
UNIQUE KEY `account` (`account`) USING BTREE,
KEY `user_info_id` (`user_info_tbl_id`) USING BTREE,
CONSTRAINT `user_account_tbl_ibfk_1` FOREIGN KEY (`user_info_tbl_id`) REFERENCES `user_info_tbl` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='用户账号'
5 years ago
```
###### --->Derived results
5 years ago
```
5 years ago
// UserAccountTbl 用户账号
5 years ago
type UserAccountTbl struct {
5 years ago
ID int `gorm:"primary_key"`
Account string `gorm:"unique"`
Password string
AccountType int // 帐号类型:0手机号1邮件
AppKey string // authbucket_oauth2_client表的id
UserInfoTblID int `gorm:"index"`
UserInfoTbl UserInfoTbl `gorm:"association_foreignkey:user_info_tbl_id;foreignkey:id"` // 用户信息
RegTime time.Time
RegIP string
BundleID string
Describ string
5 years ago
}
```
### [more>>>](doc/export.md)
5 years ago
## 6. support func export
### The exported function is only the auxiliary class function of Gorm, and calls Gorm completely
```
// FetchByPrimaryKey primay or index 获取唯一内容
func (obj *_UserAccountTblMgr) FetchByPrimaryKey(ID int) (result UserAccountTbl, err error) {
err = obj.DB.Table(obj.GetTableName()).Where("id = ?", ID).Find(&result).Error
if err == nil && obj.isRelated {
{
var info UserInfoTbl // 用户信息
err = obj.DB.Table("user_info_tbl").Where("id = ?", result.UserInfoTblID).Find(&info).Error
if err != nil {
return
}
result.UserInfoTbl = info
}
}
return
}
```
5 years ago
### [more>>>](https://github.com/xxjwxc/gormt/tree/master/doc/func.md)
5 years ago
### [how to use call style>>>](https://github.com/xxjwxc/gormt/blob/master/data/view/genfunc/genfunc_test.go)
## 7. build
5 years ago
```
5 years ago
make windows
make linux
make mac
5 years ago
```
5 years ago
or
5 years ago
```
5 years ago
go generate
5 years ago
```
5 years ago
## 8. Next step
- updatedelete support
5 years ago
- revew
5 years ago
5 years ago
## 9. one windows gui tools
5 years ago
![1](/image/gormt/1.png)
![2](/image/gormt/2.jpg)
![3](/image/gormt/3.jpg)
![4](/image/gormt/4.jpg)
5 years ago
[Download](https://github.com/xxjwxc/gormt/releases/download/v1.1.0/v1.0.zip)
5 years ago
5 years ago
5 years ago
- ###### [link](https://xxjwxc.github.io/post/gormtools/)
## Stargazers over time
[![Stargazers over time](https://starchart.cc/xxjwxc/gormt.svg)](https://starchart.cc/xxjwxc/gormt)