Skip to content

Latest commit

 

History

History
49 lines (40 loc) · 1.26 KB

README.md

File metadata and controls

49 lines (40 loc) · 1.26 KB

gmodeltool

the tools of gmodel, you can automatically generate codes from go:generate, or commands. If your data table fields chanaged, you only need to rerun the command.

Installaion

    go install github.com/lingdor/gmodeltool@latest

Configuation

write configuration to your project root (gmodel.yml):

gmodel:
  connection:
    default:
      dsn: mysql://bobby:abc123@tcp(localhost:3306)/dbname
    user:
      dsn: mysql://bobby:abc123@tcp(localhost:3306)/dbnameb

Generate gmodel schema code to a code file:

//go:generate gomodeltool gen schema --tables tb_user
//or
//go:generate gomodeltool gen schema --tables tb_%

Generate entity from database table

//go:generate gmodeltool gen entity --tables tb_%

//or generate a entity for gorm 
//go:generate gmodeltool gen entity --tables tb_% --gorm

Generate codes in shell easily

    gmodeltool gen entity --tables "tb_%" --to-files ./
    #or
    gmodeltool gen schema --tables "%" --to-files ./
    #or
    gmodeltool gen schema --tables tb_user,tb_school --to-files ./
    #or
    gmodeltool gen schema --tables "tb_user" --dry-run --verbose
    #or
    gmodeltool gen schema --tables "tb_user" --dsn "mysql://user:pass@tcp(localhost:3306)/db1" --to-files ./