Skip to content

使用 text/template 生成dao代码。每次写sql都去看表结构、字段名、复制字段名啥的太麻烦了,这个项目封装了curd,把字段包装成了方法。

Notifications You must be signed in to change notification settings

ghoulhyk/dao-gen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

使用

go install github.com/ghoulhyk/dao-gen

安装命令。

调用之后,能将如数据表定义转换成简单的dao

  • 数据表定义:
package _db1

import (
	"time"
)

// User
// @database db_1_test
// @tableName user
// @comment 用户信息表
type User struct {
	Id         *uint32    `json:"id" colAttr:"'id' pk autoincr"`
	Name       *string    `json:"name" colAttr:"'name'"` // 姓名
	Gender     *uint8     `json:"gender" colAttr:"'gender'"`
	CreateTime *time.Time `json:"createTime" colAttr:"'create_time'"`
}
  • 生成后的代码的调用示例
dao.NewClient().Inserter().User().SetName("用户001").SetGender(1).Insert()

dao.NewClient().Selector().User().
    Where(func(cond *whereCond.User) {
        cond.And().Name().Equ("用户001")
    }).Single()

dao.NewClient().Updater().User().
    Where(func(cond *whereCond.User) {
        cond.And().Name().Equ("用户001")
    }).
    SetGender(1).
    Update()

dao.NewClient().Deleter().User().
    Where(func(cond *whereCond.User) {
        cond.And().Name().Equ("用户001")
    }).
    Delete()

更多示例详见 https://github.com/ghoulhyk/dao-gen-demo

About

使用 text/template 生成dao代码。每次写sql都去看表结构、字段名、复制字段名啥的太麻烦了,这个项目封装了curd,把字段包装成了方法。

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages