feat(user): 生成用户查询接口并优化模型
- 在 model/user.go 中添加 Querier 接口,定义了 GetByEmail 方法- 在 query/users.gen.go 中实现 Querier 接口的 GetByEmail 方法 - 修改 gen.go以使用新的 Querier 接口和 User 模型生成代码 - 将 users.gen.go 中的 ID 类型从 Int64 改为 Uint
This commit is contained in:
@@ -1,23 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/suyiiyii/hertz101/app/user/biz/dal/mysql"
|
||||
"github.com/suyiiyii/hertz101/app/user/biz/model"
|
||||
"gorm.io/gen"
|
||||
)
|
||||
|
||||
func main() {
|
||||
mysql.Init()
|
||||
//mysql.Init()
|
||||
|
||||
db := mysql.DB
|
||||
//db := mysql.DB
|
||||
|
||||
g := gen.NewGenerator(gen.Config{
|
||||
OutPath: "biz/dal/query",
|
||||
Mode: gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface,
|
||||
})
|
||||
|
||||
g.UseDB(db)
|
||||
//g.UseDB(db)
|
||||
|
||||
g.ApplyBasic(g.GenerateModel("users"))
|
||||
//g.ApplyBasic(g.GenerateModel("users"))
|
||||
g.ApplyInterface(func(model.Querier) {}, model.User{})
|
||||
|
||||
g.Execute()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user