- 在 model/user.go 中添加 Querier 接口,定义了 GetByEmail 方法- 在 query/users.gen.go 中实现 Querier 接口的 GetByEmail 方法 - 修改 gen.go以使用新的 Querier 接口和 User 模型生成代码 - 将 users.gen.go 中的 ID 类型从 Int64 改为 Uint
20 lines
375 B
Go
20 lines
375 B
Go
package model
|
|
|
|
import (
|
|
"gorm.io/gen"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type User struct {
|
|
gorm.Model
|
|
Email string `gorm:"uniqueIndex;type:varchar(255) not null"`
|
|
PasswordHashed string `gorm:"type:varchar(255) not null"`
|
|
}
|
|
|
|
type Querier interface {
|
|
// GetByEmail get user by email
|
|
//
|
|
// SELECT * FROM @@table WHERE email = @email
|
|
GetByEmail(email string) (*gen.T, error)
|
|
}
|