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.
 
 
 
谢小军 2f94d7dc0b update test file 5 years ago
.github Update go.yml 5 years ago
data add test file 5 years ago
doc foreign key en 5 years ago
image new 5 years ago
.coveralls.yml new 5 years ago
.gitattributes Initial commit 6 years ago
.gitignore Update .gitignore 5 years ago
.travis.yml update test file 5 years ago
FUNDING.yml 1 5 years ago
LICENSE new 5 years ago
Makefile add build style 5 years ago
README.md update test file 5 years ago
README_zh_cn.md add tag to identify the code quality 5 years ago
config.yml re check 5 years ago
go.mod re check 5 years ago
go.sum new 5 years ago
gogenerate.go add build style 5 years ago
main.go new 5 years ago
main_test.go update test file 5 years ago
test.yam support foreign key.添加 外键支持 5 years ago

README.md

Build Status Go Report Card codecov

gormt

中文文档

mysql database to goang struct conversion tools base on gormYou can automatically generate golang sturct from MySQL database.

big Camel-Case Name Rule

JSON tag


1. Configure default configuration items through the current directory config.yml file

out_dir : "."  # out dir
singular_table : false  # Table name plural (big Camel-Case):gorm.SingularTable
simple : false #simple output
is_out_sql : false # Whether to output sql
is_json_tag : true # Whether to mark JSON or not
is_foreign_key : true # Whether to mark foreign key or not
[mysql_info]
    host : "127.0.0.1"
    port : 3306
    username : "root"
    password : "qwer"
    database : "oauth_db"

2. get help

./gormt --help
or
./gormt -h

-------------------------------------------------------
base on gorm tools for mysql database to golang struct

Usage:
  main [flags]

Flags:
  -d, --database string   数据库名
  -f, --foreign           是否导出外键关联
  -h, --help              help for main
  -H, --host string       数据库地址.(注意-H为大写)
  -o, --outdir string     输出目录
  -p, --password string   密码.
      --port int          端口号 (default 3306)
  -s, --singular          是否禁用表名复数
  -u, --user string       用户名.
  

3. Can be updated configuration items using command line tools

./gormt -H=127.0.0.1 -d=oauth_db -p=qwer -u=root --port=3306

4. Support for gorm attributes

  • Database tables, column field annotation support
  • singular_table, Table name plural (big Camel-Case)
  • json tag json tag output
  • gorm.Model Support export gorm.model>>>
  • 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
  • Support foreign key related properties Support export gorm.model>>>

You can enrich data types in def

5. Demonstration

  • 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',
  `user_info_tbl_id` int(11) NOT NULL,
  `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,
  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='用户账号'
--->Derived results
// UserAccountTbl 用户账号
type UserAccountTbl struct {
	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
}

more>>>

6. build

make windows
make linux
make mac

or

go generate

7. Next step

  • Add common function (ormfunc)

8. one windows gui tools

1

2

3

4

Download