go install gorm.io/gen/tools/gentool@latest
- gentool -dsn "user:pwd@tcp(localhost:3306)/database?charset=utf8mb4&parseTime=True&loc=Local" -tables "orders,doctor"
-
- gentool -c "./gen.yml"
gen.yml文件:
- version: "0.1"
- database:
- # consult[https://gorm.io/docs/connecting_to_the_database.html]"
- dsn : "username:password@tcp(address:port)/db?charset=utf8mb4&parseTime=true&loc=Local"
- # input mysql or postgres or sqlite or sqlserver. consult[https://gorm.io/docs/connecting_to_the_database.html]
- db : "mysql"
- # enter the required data table or leave it blank.You can input : orders,users,goods
- tables : "user"
- # specify a directory for output
- outPath : "./dao/query"
- # query code file name, default: gen.go
- outFile : ""
- # generate unit test for query code
- withUnitTest : false
- # generated model code's package name
- modelPkgName : ""
- # generate with pointer when field is nullable
- fieldNullable : false
- # generate field with gorm index tag
- fieldWithIndexTag : false
- # generate field with gorm column type tag
- fieldWithTypeTag : false
- onlyModel: true