1 Star 0 Fork 0

sun/common_pkg

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

sql2code

Generate code for different purposes according to sql, support generating json, gorm model, update parameter, request parameter code, sql can be obtained from parameter, file, db three ways, priority from high to low.


Example of use

Main setting parameters.

type Args struct {
	SQL string // DDL sql

	DDLFile string // DDL file

	DBDsn   string // connecting to mysql's dsn
	DBTable string // table name

	Package        string // specify the package name (only valid for model types)
	GormType       bool   // gorm type
	JSONTag        bool   // does it include a json tag
	JSONNamedType  int    // json naming type, 0: consistent with the column name, other values indicate a hump
	IsEmbed        bool   // is gorm.Model embedded
	CodeType       string // specify the different types of code to be generated, namely model (default), json, dao, handler, proto
}

Generated code example.

    import "gitee.com/jianguosun_admin/common_pkg/sql2code"

    // generate gorm model code
    code, err := sql2code.GenerateOne(&sql2code.Args{
        SQL: sqlData,  // source from sql text
        // DDLFile: "user.sql", // source from sql file
        // DBDsn: "root:123456@(127.0.0.1:3306)/account"
        // DBTable "user"
        GormType: true,
        JSONTag: true,
        IsEmbed: true,
        CodeType: "model"
    })

      // generate json, model, dao, handler code
      codes, err := sql2code.Generate(&sql2code.Args{
          SQL: sqlData,  // source from sql text
          // DDLFile: "user.sql", // source from sql file
          // DBDsn: "root:123456@(127.0.0.1:3306)/account"
          // DBTable "user"
          GormType: true,
          JSONTag: true,
          IsEmbed: true,
          CodeType: "dao"
      })
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jianguosun_admin/common_pkg.git
git@gitee.com:jianguosun_admin/common_pkg.git
jianguosun_admin
common_pkg
common_pkg
master

搜索帮助