Documentation ¶
Index ¶
- Variables
- func InitTable(db *gorm.DB) error
- type GORMProfileDAO
- type GORMUserWithProfileDAO
- type GormUserDAO
- func (dao *GormUserDAO) FindByEmail(ctx context.Context, email string) (User, error)
- func (dao *GormUserDAO) FindById(ctx context.Context, id int64) (User, error)
- func (dao *GormUserDAO) FindByPhone(ctx context.Context, phone string) (User, error)
- func (dao *GormUserDAO) Insert(ctx context.Context, u User) (User, error)
- type Profile
- type ProfileDAO
- type User
- type UserDAO
- type UserWithProfileDAO
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrUserDuplicateEmail = errors.New("邮箱冲突") ErrUserDuplicate = errors.New("用户冲突") ErrUserNotFound = gorm.ErrRecordNotFound )
Functions ¶
Types ¶
type GORMProfileDAO ¶
type GORMProfileDAO struct {
// contains filtered or unexported fields
}
func (*GORMProfileDAO) FindByUserId ¶
type GORMUserWithProfileDAO ¶
type GORMUserWithProfileDAO struct {
// contains filtered or unexported fields
}
func (*GORMUserWithProfileDAO) Create ¶
func (dao *GORMUserWithProfileDAO) Create(ctx context.Context, u User) error
func (*GORMUserWithProfileDAO) FindProfileByEmail ¶
type GormUserDAO ¶
type GormUserDAO struct {
// contains filtered or unexported fields
}
func (*GormUserDAO) FindByEmail ¶
func (*GormUserDAO) FindByPhone ¶
type ProfileDAO ¶
type ProfileDAO interface { FindByUserId(ctx context.Context, id int64) (Profile, error) Insert(ctx context.Context, p Profile) error Update(ctx context.Context, p Profile) error }
func NewProfileDAO ¶
func NewProfileDAO(db *gorm.DB) ProfileDAO
type User ¶
type User struct { Id int64 `gorm:"primaryKey, autoIncrement"` Email sql.NullString `gorm:"unique"` Phone sql.NullString `gorm:"unique"` Password string Ctime int64 Utime int64 }
User 直接对应数据库表结构 有些人叫做 entity,有些人叫做 model,有些人叫做 PO(persistent object)
type UserDAO ¶
type UserDAO interface { FindByEmail(ctx context.Context, email string) (User, error) FindById(ctx context.Context, id int64) (User, error) FindByPhone(ctx context.Context, phone string) (User, error) Insert(ctx context.Context, u User) (User, error) }
func NewUserDAO ¶
type UserWithProfileDAO ¶
type UserWithProfileDAO interface { Create(ctx context.Context, u User) error FindProfileByEmail(ctx context.Context, email string) (User, Profile, error) }
func NewUserWithProfileDAO ¶
func NewUserWithProfileDAO(db *gorm.DB, userDAO UserDAO, profileDAO ProfileDAO) UserWithProfileDAO
Click to show internal directories.
Click to hide internal directories.