go install gorm.io/gen/tools/gentool@latest
gentool -c "hack/gen.yml"
gentool -dsn "user:pwd@tcp(127.0.0.1:3306)/database?charset=utf8mb4&parseTime=True&loc=Local" -tables "kk_product"
version: "0.1" database: # consult[https://gorm.io/docs/connecting_to_the_database.html]" dsn : "root:root@tcp(127.0.0.1:3306)/gotest?charset=utf8&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 : tables : # - kk_product # tables : # specify a directory for output outPath : "app/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 : "app/model/internal" # 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 # detect integer field's unsigned type, adjust generated data type fieldSignable : false
gentool -h
Usage of gentool:
-c string 是gen.yml的路径
is path for gen.yml
-db string 输入mysql或postgres或sqlite或sqlserver 数据库类型
input mysql or postgres or sqlite or sqlserver. consult[https://gorm.io/docs/connecting_to_the_database.html] (default "mysql")
-dsn string 数据库配置信息
consult[https://gorm.io/docs/connecting_to_the_database.html]
-fieldNullable 生成的模型代码的包名 当字段为空时使用指针生成
generate with pointer when field is nullable
-fieldSignable 要检测整型字段的无符号类型,请调整生成的数据类型
detect integer field's unsigned type, adjust generated data type
-fieldWithIndexTag 使用gorm索引标记生成字段
generate field with gorm index tag
-fieldWithTypeTag 使用gorm列类型标记生成字段
generate field with gorm column type tag
-modelPkgName string 表结构生成的对应目录
generated model code's package name
-onlyModel 仅生成模型(无查询文件)
only generate models (without query file)
-outFile string 查询代码文件名,默认值:gen.go outPath底下的基础文件 建议用默认的gen.go
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
-withUnitTest 为查询代码生成单元测试
generate unit test for query code
1.缺乏编译软件导致的,软件下载地址
https://sourceforge.net/projects/mingw-w64/files/
2.下载之后,进行离线软件包安装
2.1 将下载文件解压在想要安装的地方即可
2.2 系统环境变量添加MinGW64 bin路径
2.3 测试在cmd命令里面输入
gcc -v