@@ -34,13 +34,14 @@ 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
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+ UnitTestTemplate string `yaml:"unitTestTemplate"`
4445 ModelPkgName string `yaml:"modelPkgName"` // generated model code's package name
4546 FieldNullable bool `yaml:"fieldNullable"` // generate with pointer when field is nullable
4647 FieldCoverable bool `yaml:"fieldCoverable"` // generate with pointer when field has default value
@@ -149,6 +150,7 @@ func argParse() *CmdParams {
149150 outPath := flag .String ("outPath" , defaultQueryPath , "specify a directory for output" )
150151 outFile := flag .String ("outFile" , "" , "query code file name, default: gen.go" )
151152 withUnitTest := flag .Bool ("withUnitTest" , false , "generate unit test for query code" )
153+ unitTestTemplate := flag .String ("unitTestTemplate" , "" , "custom unit test template file path for query code" )
152154 modelPkgName := flag .String ("modelPkgName" , "" , "generated model code's package name" )
153155 fieldNullable := flag .Bool ("fieldNullable" , false , "generate with pointer when field is nullable" )
154156 fieldCoverable := flag .Bool ("fieldCoverable" , false , "generate with pointer when field has default value" )
@@ -185,6 +187,9 @@ func argParse() *CmdParams {
185187 if * withUnitTest {
186188 cmdParse .WithUnitTest = * withUnitTest
187189 }
190+ if * unitTestTemplate != "" {
191+ cmdParse .UnitTestTemplate = * unitTestTemplate
192+ }
188193 if * modelPkgName != "" {
189194 cmdParse .ModelPkgName = * modelPkgName
190195 }
@@ -226,6 +231,7 @@ func main() {
226231 OutFile : config .OutFile ,
227232 ModelPkgPath : config .ModelPkgName ,
228233 WithUnitTest : config .WithUnitTest ,
234+ UnitTestTemplate : config .UnitTestTemplate ,
229235 FieldNullable : config .FieldNullable ,
230236 FieldCoverable : config .FieldCoverable ,
231237 FieldWithIndexTag : config .FieldWithIndexTag ,
0 commit comments