github.com/unionj-cloud/go-doudou/v2@v2.3.5/toolkit/gormgen/tools/gentool/README.ZH_CN.md (about) 1 # GenTool 2 3 将Gen作为二进制的方式进行安装 4 5 6 7 ## 安装 8 9 ```shell 10 go install gorm.io/gen/tools/gentool@latest 11 ``` 12 13 ## 使用方式 14 15 ```shell 16 17 gentool -h 18 19 Usage of gentool: 20 -db string 21 input mysql or postgres or sqlite or sqlserver. consult[https://gorm.io/docs/connecting_to_the_database.html] (default "mysql") 22 -dsn string 23 consult[https://gorm.io/docs/connecting_to_the_database.html] 24 -fieldNullable 25 generate with pointer when field is nullable 26 -fieldWithIndexTag 27 generate field with gorm index tag 28 -fieldWithTypeTag 29 generate field with gorm column type tag 30 -modelPkgName string 31 generated model code's package name 32 -outFile string 33 query code file name, default: gen.go 34 -outPath string 35 specify a directory for output (default "./dao/query") 36 -tables string 37 enter the required data table or leave it blank 38 -onlyModel 39 only generate models (without query file) 40 -withUnitTest 41 generate unit test for query code 42 -fieldSignable 43 detect integer field's unsigned type, adjust generated data type 44 45 ``` 46 47 #### c 48 default "" 49 可以指定配置文件gen.yml的路径。 50 用配置文件来代替命令行。 51 命令行是最高优先级。 52 53 #### db 54 55 默认值:mysql 56 57 可以输入: mysql、 postgres、 sqlite 、 sqlserve 58 59 参考:https://gorm.io/docs/connecting_to_the_database.html 60 61 #### dsn 62 63 你可以使用GORM所有的连接。 64 65 参考:https://gorm.io/docs/connecting_to_the_database.html 66 67 #### fieldNullable 68 69 字段可为空时使用指针生成 70 71 #### fieldWithIndexTag 72 73 使用GROM索引标记生成字段 74 75 #### fieldWithTypeTag 76 77 使用gorm列类型标记生成字段 78 79 #### modelPkgName 80 81 默认值是数据表名称。 82 83 生成的model代码的包名称。 84 85 #### outFile 86 87 默认为:gen.go 88 89 查询代码文件名。 90 91 #### outPath 92 93 默认为:/dao/query 94 95 指定输出目录 96 97 #### tables 98 99 值为 : 输入所需的数据表或将其留空 100 101 eg : 102 103 --tables="orders" #orders 数据表 104 105 --tables="orders,users" #orders 数据表和 users数据表 106 107 --tables="" # 数据库中所有的数据表 108 109 基于数据表生成对应的代码。 110 111 #### withUnitTest 112 113 值为 : False / True 114 115 生成单元测试。 116 117 #### fieldSignable 118 119 Value : False / True 120 121 基于数据表定义的数据类型,生成对应的数据类型 122 123 124 ### 使用示例 125 126 ```shell 127 gentool -dsn "user:pwd@tcp(127.0.0.1:3306)/database?charset=utf8mb4&parseTime=True&loc=Local" -tables "orders,doctor" 128 ```