Install GEN as a binary tool
go install gorm.io/gen/tools/gentool@latestgentool -h
Usage of gentool:
-c string
is path for gen.yml
-db string
input mysql|postgres|sqlite|sqlserver|clickhouse. consult[https://gorm.io/docs/connecting_to_the_database.html] (default "mysql")
-dsn string
consult[https://gorm.io/docs/connecting_to_the_database.html]
-fieldCoverable
generate with pointer when field has default value
-fieldNullable
generate with pointer when field is nullable
-fieldSignable
detect integer field's unsigned type, adjust generated data type
-fieldWithIndexTag
generate field with gorm index tag
-fieldWithTypeTag
generate field with gorm column type tag
-fieldWithDefaultTag
generate field with gorm default tag
-modelPkgName string
generated model code's package name
-onlyModel
only generate models (without query file)
-outFile string
query code file name, default: gen.go
-outPath string
specify a directory for output (default "./dao/query")
-tables string
enter the required data table or leave it blank
-withDefaultQuery
create default query in generated code
-withGeneric
generate code with generic
-withQueryInterface
generate code with exported interface object
-withUnitTest
generate unit test for query code
-unitTestTemplate string
custom unit test template file path for query code
-withoutContext
generate code without context constraindefault "" Is path for gen.yml Replace the command line with a configuration file The command line is the highest priority
default:mysql
input mysql or postgres or sqlite or sqlserver.
consult : https://gorm.io/docs/connecting_to_the_database.html
You can use all gorm's dsn.
consult : https://gorm.io/docs/connecting_to_the_database.html
generate with pointer when field is nullable
generate with pointer when field has default value
generate field with gorm index tag
generate field with gorm column type tag
generate field with gorm default tag
defalut table name.
generated model code's package name.
query code file name, default: gen.go
specify a directory for output (default "./dao/query")
Value : enter the required data table or leave it blank.
eg :
--tables="orders" #orders table
--tables="orders,users" #orders table and users table
--tables="" # All data tables in the database.
Generate some tables code.
Value : False / True
Generate unit test.
custom unit test template file path for query code
Value : False / True
detect integer field's unsigned type, adjust generated data type
Default: false
create default query in generated code
Default: false
generate code with generic
Default: false
generate code with exported interface object
Default: false
generate code without context constrain
gentool -dsn "user:pwd@tcp(127.0.0.1:3306)/database?charset=utf8mb4&parseTime=True&loc=Local" -tables "orders,doctor"