gorm tools
gorm export tools
This commit is contained in:
77
README.md
77
README.md
@@ -1,15 +1,20 @@
|
||||
|
||||
# [gorm-tools](https://github.com/xie1xiao1jun/gorm-tools)
|
||||
### gorm mysql数据库转 struct 工具,可以将mysql数据库自动生成golang sturct结构,带大驼峰命名规则。带json标签
|
||||
### mysql database to goang 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
|
||||
|
||||
[中文版](README_zh_cn.md)
|
||||
|
||||
--------
|
||||
|
||||
## 1. 通过当前目录config.toml文件配置默认配置项
|
||||
## 1. Configure default configuration items through the current directory config. toml file
|
||||
```
|
||||
out_dir = "." # 输出目录
|
||||
singular_table = false # 表名复数,是否大驼峰构建 参考:gorm.SingularTable
|
||||
simple = false #简单输出
|
||||
isJsonTag = true #是否打json标记
|
||||
out_dir = "." # out dir
|
||||
singular_table = false # Table name plural (big Camel-Case):gorm.SingularTable
|
||||
simple = false #simple output
|
||||
isJsonTag = true # Whether to mark JSON or not
|
||||
[mysql_info]
|
||||
host = "127.0.0.1"
|
||||
port = 3306
|
||||
@@ -18,11 +23,7 @@ isJsonTag = true #是否打json标记
|
||||
database = "oauth_db"
|
||||
|
||||
```
|
||||
## 2. 可以使用命令行工具更新配置项
|
||||
```
|
||||
./gormt -H=127.0.0.1 -d=oauth_db -p=qwer -u=root --port=3306
|
||||
```
|
||||
## 3. 查看帮助
|
||||
## 2. get help
|
||||
```
|
||||
./gormt --help
|
||||
or
|
||||
@@ -45,20 +46,24 @@ Flags:
|
||||
-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. 支持gorm 相关属性
|
||||
## 4. Support for gorm attributes
|
||||
|
||||
- 数据库表,列字段注释支持
|
||||
- singular_table 表名复数(大驼峰)
|
||||
- json tag json标签输出
|
||||
- gorm.Model 基本模型
|
||||
- PRIMARY_KEY 将列指定为主键
|
||||
- UNIQUE 将列指定为唯一
|
||||
- NOT NULL 将列指定为非 NULL
|
||||
- INDEX 创建具有或不带名称的索引, 如果多个索引同名则创建复合索引
|
||||
- UNIQUE_INDEX 和 INDEX 类似,只不过创建的是唯一索引
|
||||
- Database tables, column field annotation support
|
||||
- singular_table, Table name plural (big Camel-Case)
|
||||
- json tag json tag output
|
||||
- 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
|
||||
|
||||
## 5. 示例展示
|
||||
## 5. Demonstration
|
||||
|
||||
- sql:
|
||||
```
|
||||
@@ -80,12 +85,12 @@ CREATE TABLE `user_account_tbl` (
|
||||
CONSTRAINT `1` FOREIGN KEY (`user_info_id`) REFERENCES `user_info_tbl` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='用户信息'
|
||||
```
|
||||
- 参数:singular_table = false simple = false
|
||||
- param :singular_table = false simple = false
|
||||
|
||||
###### --->导出结果
|
||||
###### --->Derived results
|
||||
|
||||
```
|
||||
// 用户信息
|
||||
// User information
|
||||
type UserAccountTbl struct {
|
||||
ID int `gorm:"primary_key;column:id;type:int(11);not null" json:"-"` //
|
||||
Account string `gorm:"unique;column:account;type:varchar(64);not null" json:"account"` //
|
||||
@@ -100,9 +105,9 @@ type UserAccountTbl struct {
|
||||
}
|
||||
```
|
||||
|
||||
- 参数:singular_table = true simple = false
|
||||
- param :singular_table = true simple = false
|
||||
|
||||
###### --->导出结果
|
||||
###### --->erived results
|
||||
|
||||
```
|
||||
type User_account_tbl struct {
|
||||
@@ -118,9 +123,9 @@ type User_account_tbl struct {
|
||||
Describ string `gorm:"column:describ;type:varchar(255)" json:"describ"` //
|
||||
}
|
||||
```
|
||||
- 参数:singular_table = false simple = true isJsonTag = true
|
||||
- param :singular_table = false simple = true isJsonTag = true
|
||||
|
||||
###### --->导出结果
|
||||
###### --->erived results
|
||||
|
||||
```
|
||||
// 用户信息
|
||||
@@ -138,9 +143,9 @@ type UserAccountTbl struct {
|
||||
}
|
||||
```
|
||||
|
||||
- 参数:singular_table = false simple = true isJsonTag = false
|
||||
- param :singular_table = false simple = true isJsonTag = false
|
||||
|
||||
###### --->导出结果
|
||||
###### --->erived results
|
||||
|
||||
```
|
||||
// 用户信息
|
||||
@@ -171,9 +176,9 @@ CREATE TABLE `user_info_tbl` (
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='用户信息'
|
||||
```
|
||||
|
||||
- 参数:singular_table = false simple = true isJsonTag = false
|
||||
- param :singular_table = false simple = true isJsonTag = false
|
||||
|
||||
###### --->导出结果
|
||||
###### --->erived results
|
||||
|
||||
|
||||
```
|
||||
@@ -185,8 +190,8 @@ type UserInfoTbl struct {
|
||||
}
|
||||
```
|
||||
|
||||
## 6. 下一步计划
|
||||
## 6. Next step
|
||||
|
||||
- 加入外键支持(ForeignKey)
|
||||
- support (ForeignKey)
|
||||
|
||||
- ###### [传送门](https://xie1xiao1jun.github.io/post/gormtools/)
|
||||
- ###### [link](https://xie1xiao1jun.github.io/post/gormtools/)
|
||||
|
||||
Reference in New Issue
Block a user