@@ -34,19 +34,20 @@ const (
3434
3535// CmdParams is command line parameters
3636type CmdParams struct {
37- DSN string `yaml:"dsn"` // consult[https://gorm.io/docs/connecting_to_the_database.html]"
38- DB string `yaml:"db"` // input mysql or postgres or sqlite or sqlserver. consult[https://gorm.io/docs/connecting_to_the_database.html]
39- Tables []string `yaml:"tables"` // enter the required data table or leave it blank
40- OnlyModel bool `yaml:"onlyModel"` // only generate model
41- OutPath string `yaml:"outPath"` // specify a directory for output
42- OutFile string `yaml:"outFile"` // query code file name, default: gen.go
43- WithUnitTest bool `yaml:"withUnitTest"` // generate unit test for query code
44- ModelPkgName string `yaml:"modelPkgName"` // generated model code's package name
45- FieldNullable bool `yaml:"fieldNullable"` // generate with pointer when field is nullable
46- FieldCoverable bool `yaml:"fieldCoverable"` // generate with pointer when field has default value
47- FieldWithIndexTag bool `yaml:"fieldWithIndexTag"` // generate field with gorm index tag
48- FieldWithTypeTag bool `yaml:"fieldWithTypeTag"` // generate field with gorm column type tag
49- FieldSignable bool `yaml:"fieldSignable"` // detect integer field's unsigned type, adjust generated data type
37+ DSN string `yaml:"dsn"` // consult[https://gorm.io/docs/connecting_to_the_database.html]"
38+ DB string `yaml:"db"` // input mysql or postgres or sqlite or sqlserver. consult[https://gorm.io/docs/connecting_to_the_database.html]
39+ Tables []string `yaml:"tables"` // enter the required data table or leave it blank
40+ OnlyModel bool `yaml:"onlyModel"` // only generate model
41+ OutPath string `yaml:"outPath"` // specify a directory for output
42+ OutFile string `yaml:"outFile"` // query code file name, default: gen.go
43+ WithUnitTest bool `yaml:"withUnitTest"` // generate unit test for query code
44+ ModelPkgName string `yaml:"modelPkgName"` // generated model code's package name
45+ FieldNullable bool `yaml:"fieldNullable"` // generate with pointer when field is nullable
46+ FieldCoverable bool `yaml:"fieldCoverable"` // generate with pointer when field has default value
47+ FieldWithIndexTag bool `yaml:"fieldWithIndexTag"` // generate field with gorm index tag
48+ FieldWithTypeTag bool `yaml:"fieldWithTypeTag"` // generate field with gorm column type tag
49+ FieldWithDefaultTag bool `yaml:"fieldWithDefaultTag"` // generate field with gorm default tag
50+ FieldSignable bool `yaml:"fieldSignable"` // detect integer field's unsigned type, adjust generated data type
5051}
5152
5253func (c * CmdParams ) revise () * CmdParams {
@@ -153,6 +154,7 @@ func argParse() *CmdParams {
153154 fieldCoverable := flag .Bool ("fieldCoverable" , false , "generate with pointer when field has default value" )
154155 fieldWithIndexTag := flag .Bool ("fieldWithIndexTag" , false , "generate field with gorm index tag" )
155156 fieldWithTypeTag := flag .Bool ("fieldWithTypeTag" , false , "generate field with gorm column type tag" )
157+ fieldWithDefaultTag := flag .Bool ("fieldWithDefaultTag" , false , "generate field with gorm default tag" )
156158 fieldSignable := flag .Bool ("fieldSignable" , false , "detect integer field's unsigned type, adjust generated data type" )
157159 flag .Parse ()
158160
@@ -198,6 +200,9 @@ func argParse() *CmdParams {
198200 if * fieldWithTypeTag {
199201 cmdParse .FieldWithTypeTag = * fieldWithTypeTag
200202 }
203+ if * fieldWithDefaultTag {
204+ cmdParse .FieldWithDefaultTag = * fieldWithDefaultTag
205+ }
201206 if * fieldSignable {
202207 cmdParse .FieldSignable = * fieldSignable
203208 }
@@ -217,15 +222,16 @@ func main() {
217222 }
218223
219224 g := gen .NewGenerator (gen.Config {
220- OutPath : config .OutPath ,
221- OutFile : config .OutFile ,
222- ModelPkgPath : config .ModelPkgName ,
223- WithUnitTest : config .WithUnitTest ,
224- FieldNullable : config .FieldNullable ,
225- FieldCoverable : config .FieldCoverable ,
226- FieldWithIndexTag : config .FieldWithIndexTag ,
227- FieldWithTypeTag : config .FieldWithTypeTag ,
228- FieldSignable : config .FieldSignable ,
225+ OutPath : config .OutPath ,
226+ OutFile : config .OutFile ,
227+ ModelPkgPath : config .ModelPkgName ,
228+ WithUnitTest : config .WithUnitTest ,
229+ FieldNullable : config .FieldNullable ,
230+ FieldCoverable : config .FieldCoverable ,
231+ FieldWithIndexTag : config .FieldWithIndexTag ,
232+ FieldWithTypeTag : config .FieldWithTypeTag ,
233+ FieldWithDefaultTag : config .FieldWithDefaultTag ,
234+ FieldSignable : config .FieldSignable ,
229235 })
230236
231237 g .UseDB (db )
0 commit comments