- 在 model/user.go 中添加 Querier 接口,定义了 GetByEmail 方法- 在 query/users.gen.go 中实现 Querier 接口的 GetByEmail 方法 - 修改 gen.go以使用新的 Querier 接口和 User 模型生成代码 - 将 users.gen.go 中的 ID 类型从 Int64 改为 Uint
25 lines
419 B
Go
25 lines
419 B
Go
package main
|
|
|
|
import (
|
|
"github.com/suyiiyii/hertz101/app/user/biz/model"
|
|
"gorm.io/gen"
|
|
)
|
|
|
|
func main() {
|
|
//mysql.Init()
|
|
|
|
//db := mysql.DB
|
|
|
|
g := gen.NewGenerator(gen.Config{
|
|
OutPath: "biz/dal/query",
|
|
Mode: gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface,
|
|
})
|
|
|
|
//g.UseDB(db)
|
|
|
|
//g.ApplyBasic(g.GenerateModel("users"))
|
|
g.ApplyInterface(func(model.Querier) {}, model.User{})
|
|
|
|
g.Execute()
|
|
}
|