Documentation ¶
Overview ¶
Package dao 代表对数据库的操作
Index ¶
- Variables
- func InitTables(db *gorm.DB) error
- type GORMUserDAO
- func (dao *GORMUserDAO) FindByEmail(ctx context.Context, email string) (User, error)
- func (dao *GORMUserDAO) FindById(ctx context.Context, uid int64) (User, error)
- func (dao *GORMUserDAO) FindByPhone(ctx context.Context, phone string) (User, error)
- func (dao *GORMUserDAO) Insert(ctx context.Context, u User) error
- func (dao *GORMUserDAO) UpdateById(ctx context.Context, entity User) error
- type User
- type UserDAO
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrDuplicateEmail = errors.New("邮箱冲突") ErrRecordNotFound = gorm.ErrRecordNotFound )
Functions ¶
func InitTables ¶
Types ¶
type GORMUserDAO ¶
type GORMUserDAO struct {
// contains filtered or unexported fields
}
func (*GORMUserDAO) FindByEmail ¶
func (*GORMUserDAO) FindByPhone ¶
func (*GORMUserDAO) UpdateById ¶
func (dao *GORMUserDAO) UpdateById(ctx context.Context, entity User) error
type User ¶
type User struct { Id int64 `gorm:"primaryKey,autoIncrement"` // 代表这是一个可以为 NULL 的列 //Email *string Email sql.NullString `gorm:"unique"` Password string Nickname string `gorm:"type=varchar(128)"` // YYYY-MM-DD Birthday int64 AboutMe string `gorm:"type=varchar(4096)"` // 代表这是一个可以为 NULL 的列 Phone sql.NullString `gorm:"unique"` // 时区,UTC 0 的毫秒数 // 创建时间 Ctime int64 // 更新时间 Utime int64 }
type UserDAO ¶
type UserDAO interface { Insert(ctx context.Context, u User) error FindByEmail(ctx context.Context, email string) (User, error) UpdateById(ctx context.Context, entity User) error FindById(ctx context.Context, uid int64) (User, error) FindByPhone(ctx context.Context, phone string) (User, error) }
func NewUserDAO ¶
Click to show internal directories.
Click to hide internal directories.