@@ -71,10 +71,11 @@ Generate grom configuration file like this:
71
71
" enable_guregu_null" : false,
72
72
" enable_json_tag" : true,
73
73
" enable_xml_tag" : false,
74
- " enable_gorm_tag" : true ,
74
+ " enable_gorm_tag" : false ,
75
75
" enable_xorm_tag" : false,
76
76
" enable_beego_tag" : false,
77
- " enable_gorose_tag" : false
77
+ " enable_gorose_tag" : false,
78
+ " enable_gorm_v2_tag" : true
78
79
}
79
80
80
81
Usage:
@@ -95,11 +96,11 @@ Usage:
95
96
96
97
Examples:
97
98
grom convert -n ./grom.json
98
- grom convert -H localhost -P 3306 -u user -p password -d database -t table -e INITIALISM,FIELD_COMMENT,JSON_TAG,GORM_TAG --package PACKAGE_NAME --struct STRUCT_NAME
99
+ grom convert -H localhost -P 3306 -u user -p password -d database -t table -e INITIALISM,FIELD_COMMENT,JSON_TAG,GORM_V2_TAG --package PACKAGE_NAME --struct STRUCT_NAME
99
100
100
101
Flags:
101
102
-d, --database string the database of mysql
102
- -e, --enable strings enable services (must in [INITIALISM,FIELD_COMMENT,SQL_NULL,GUREGU_NULL,JSON_TAG,XML_TAG,GORM_TAG,XORM_TAG,BEEGO_TAG,GOROSE_TAG])
103
+ -e, --enable strings enable services (must in [INITIALISM,FIELD_COMMENT,SQL_NULL,GUREGU_NULL,JSON_TAG,XML_TAG,GORM_TAG,XORM_TAG,BEEGO_TAG,GOROSE_TAG,GORM_V2_TAG ])
103
104
-h, --help help for convert
104
105
-H, --host string the host of mysql
105
106
-n, --name string the name of the grom configuration file
@@ -131,32 +132,35 @@ Tags:
131
132
132
133
- [x] json
133
134
- [x] xml
134
- - [x] [ gorm] ( https://gorm.io/docs/models.html )
135
+ - [x] [ gorm v1 ] ( https://v1. gorm.io/docs/models.html )
135
136
- [x] [ xorm] ( https://gobook.io/read/gitea.com/xorm/manual-en-US/chapter-02/4.columns.html )
136
137
- [x] [ beego orm] ( https://beego.me/docs/mvc/model/models.md )
137
138
- [x] [ gorose] ( https://www.kancloud.cn/fizz/gorose-2/1135839 )
139
+ - [x] [ gorm v2] ( https://gorm.io/docs/models.html )
138
140
139
141
## Supported Tag Generation Rules
140
142
141
- | Tag | PrimaryKey | AutoIncrement | ColumnName | Type | IsNullable | Indexes | Uniques | Default | Comment | ForeignKey |
143
+ | Tag | PrimaryKey | AutoIncrement | ColumnName | Type | IsNullable | Indexes | Uniques | Default | Comment | ForeignKey |
142
144
| -----------| ------------| ---------------| ------------| ------| ------------| ---------| ---------| ---------| ---------| ------------|
143
- | json | × | × | √ | × | × | × | × | × | × | × |
144
- | xml | × | × | √ | × | × | × | × | × | × | × |
145
- | gorm | √ | √ | √ | √ | √ | √ | √ | √ | √ | × |
146
- | xorm | √ | √ | √ | √ | √ | √ | √ | √ | √ | × |
147
- | beego orm | √ | √ | √ | √ | √ | × | × | √ | √ | × |
148
- | gorose | × | × | √ | × | × | × | × | × | × | × |
145
+ | json | × | × | √ | × | × | × | × | × | × | × |
146
+ | xml | × | × | √ | × | × | × | × | × | × | × |
147
+ | gorm v1 | √ | √ | √ | √ | √ | √ | √ | √ | √ | × |
148
+ | xorm | √ | √ | √ | √ | √ | √ | √ | √ | √ | × |
149
+ | beego orm | √ | √ | √ | √ | √ | × | × | √ | √ | × |
150
+ | gorose | × | × | √ | × | × | × | × | × | × | × |
151
+ | gorm v2 | √ | √ | √ | √ | √ | √ | √ | √ | √ | × |
149
152
150
153
## Supported Function Generation Rules
151
154
152
- | Tag | TableName | TableIndex | TableUnique |
155
+ | Tag | TableName | TableIndex | TableUnique |
153
156
| -----------| -----------| ------------| -------------|
154
- | json | × | × | × |
155
- | xml | × | × | × |
156
- | gorm | √ | × | × |
157
- | xorm | √ | × | × |
158
- | beego orm | √ | √ | √ |
159
- | gorose | √ | × | × |
157
+ | json | × | × | × |
158
+ | xml | × | × | × |
159
+ | gorm v1 | √ | × | × |
160
+ | xorm | √ | × | × |
161
+ | beego orm | √ | √ | √ |
162
+ | gorose | √ | × | × |
163
+ | gorm v2 | √ | × | × |
160
164
161
165
## Usage Example
162
166
@@ -197,18 +201,19 @@ $ vim grom.json
197
201
" enable_guregu_null" : false,
198
202
" enable_json_tag" : true,
199
203
" enable_xml_tag" : false,
200
- " enable_gorm_tag" : true ,
204
+ " enable_gorm_tag" : false ,
201
205
" enable_xorm_tag" : false,
202
206
" enable_beego_tag" : false,
203
- " enable_gorose_tag" : false
207
+ " enable_gorose_tag" : false,
208
+ " enable_gorm_v2_tag" : true
204
209
}
205
210
$ grom convert -n grom.json
206
211
```
207
212
208
213
You can also fill in the parameters on the command line without generating a configuration file:
209
214
210
215
``` shell script
211
- $ grom convert -H localhost -P 3306 -u user -p password -d database -t api -e INITIALISM,FIELD_COMMENT,JSON_TAG,GORM_TAG
216
+ $ grom convert -H localhost -P 3306 -u user -p password -d database -t api -e INITIALISM,FIELD_COMMENT,JSON_TAG,GORM_V2_TAG
212
217
```
213
218
214
219
Then you will get the generated code:
@@ -217,13 +222,13 @@ Then you will get the generated code:
217
222
package model
218
223
219
224
type API struct {
220
- ID int ` json:"id" gorm:"primary_key ;column:id;type:int(11) auto_increment;comment:' 接口id' "` // 接口id
221
- Path string ` json:"path" gorm:"column:path;type:varchar(255);unique_index :path_method;comment:' 接口路径'" ` // 接口路径
222
- Description string ` json:"description" gorm:"column:description;type:varchar(255);comment:' 接口描述'" ` // 接口描述
223
- Group string ` json:"group" gorm:"column:group;type:varchar(255);index:group;comment:' 接口属组'" ` // 接口属组
224
- Method string ` json:"method" gorm:"column:method;type:varchar(255);unique_index :path_method;default:' POST' ;comment:' 接口方法' "` // 接口方法
225
- CreateTime int64 ` json:"create_time" gorm:"column:create_time;type:bigint(20);comment:' 创建时间'" ` // 创建时间
226
- UpdateTime int64 ` json:"update_time" gorm:"column:update_time;type:bigint(20);comment:' 更新时间'" ` // 更新时间
225
+ ID int ` json:"id" gorm:"primaryKey ;column:id;type:int(11) auto_increment;comment:接口id"` // 接口id
226
+ Path string ` json:"path" gorm:"column:path;type:varchar(255);uniqueIndex :path_method;comment:接口路径" ` // 接口路径
227
+ Description string ` json:"description" gorm:"column:description;type:varchar(255);comment:接口描述" ` // 接口描述
228
+ Group string ` json:"group" gorm:"column:group;type:varchar(255);index:group;comment:接口属组" ` // 接口属组
229
+ Method string ` json:"method" gorm:"column:method;type:varchar(255);uniqueIndex :path_method;default:POST;comment:接口方法"` // 接口方法
230
+ CreateTime int64 ` json:"create_time" gorm:"column:create_time;type:bigint(20);comment:创建时间" ` // 创建时间
231
+ UpdateTime int64 ` json:"update_time" gorm:"column:update_time;type:bigint(20);comment:更新时间" ` // 更新时间
227
232
}
228
233
229
234
// TableName returns the table name of the API model
0 commit comments