Gen Tool is a single binary without dependencies can be used to generate structs from database
Install
go install gorm.io/gen/tools/gentool@latest |
Usage
gentool -h |
c
Configuration file name, default value “”, command line options have higher priority than configuration file.
db
Specify dirver dialector, default value “mysql”, refer: https://gorm.io/docs/connecting_to_the_database.html
dsn
DSN that used to connect database, refer: https://gorm.io/docs/connecting_to_the_database.html
fieldNullable
Generate with pointer when field is nullable
fieldWithIndexTag
Generate field with gorm index tag
fieldWithTypeTag
Generate field with gorm column type tag
modelPkgName
Generated model code’s package name.
outFile
Genrated query code file name, default: gen.go
outPath
Specify a directory for output (default “./dao/query”)
tables
Specify tables want to genrated from, default all tables.
eg :
--tables="orders" # generate from `orders`
--tables="orders,users" # generate from `orders` and `users`
--tables="" # generate from all tables
Generate some tables code.
withUnitTest
Generate unit test, default value false
, options: false
/ true
fieldSignable
Use signable datatype as field type, default value false
, options: false
/ true
Example
gentool -dsn "user:pwd@tcp(localhost:3306)/database?charset=utf8mb4&parseTime=True&loc=Local" -tables "orders,doctor" |
version: "0.1" |