• gentool gen go自动生成表结构


    第一步:安装

    go install gorm.io/gen/tools/gentool@latest

    第二步:运行

    样例1通过配置文件:

    gentool -c "hack/gen.yml"

    样例2通过 字段获取

    gentool -dsn "user:pwd@tcp(127.0.0.1:3306)/database?charset=utf8mb4&parseTime=True&loc=Local" -tables "kk_product"

    gen.yml文件内容

    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

    问题:

    goland 报错,提示 cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in %PATH%

    1.缺乏编译软件导致的,软件下载地址

    https://sourceforge.net/projects/mingw-w64/files/

    2.下载之后,进行离线软件包安装

    2.1 将下载文件解压在想要安装的地方即可

    2.2 系统环境变量添加MinGW64 bin路径

    2.3 测试在cmd命令里面输入 

    gcc -v

  • 相关阅读:
    PyQt中QFrame窗口中的组件不显示的原因
    Nautilus Chain 联合香港数码港举办 BIG DEMO DAY活动,释放何信号?
    【学习笔记03】node.js搭建一个简易的服务器
    使用Python进行可视化
    SpringBoot中HttpClient的使用
    前端周刊第十六期
    预训练模型的多任务主动学习
    unity变体收集工具
    U2Net网络简介
    如何在filters中使用data中数据?
  • 原文地址:https://blog.csdn.net/nishihong/article/details/126360705