gen icon indicating copy to clipboard operation
gen copied to clipboard

feat: enhance supports for 'mode' of generations in gentool

Open TremblingV5 opened this issue 7 months ago • 0 comments

  • [x] Do only one thing
  • [x] Non breaking API changes
  • [x] Tested

What did this pull request do?

Enhance the ability of gentool by adding a configuration named mode.

I found that gentool not support the argument named mode. In some scenarios, it may be useful. For example, we can use this argument to generate some code with default queries by using gen.WithDefaultQuery.

User Case Description

Command

gentool -mode="WithDefaultQuery,WithoutContext,WithQueryInterface"

gen.yml

version: "0.1"
database:
  # consult[https://gorm.io/docs/connecting_to_the_database.html]"
  dsn : "user:pass@tcp(127.0.0.1:3306)/dbname?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 : 
  # tables  : 
  #   - orders
  #   - users
  #   - goods
  tables  :
  # only generate models (without query file)
  onlyModel : false
  # 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 with pointer when field has default value
  fieldCoverable : 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
  # generate mode
  mode  :
    - WithDefaultQuery
    - WithoutContext
    - WithQueryInterface

TremblingV5 avatar Jul 20 '24 09:07 TremblingV5