dao

package
v0.0.0-...-d13da26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserDuplicateEmail = errors.New("邮箱冲突")
	ErrUserDuplicate      = errors.New("用户冲突")
	ErrUserNotFound       = gorm.ErrRecordNotFound
)

Functions

func InitTable

func InitTable(db *gorm.DB) error

Types

type GORMProfileDAO

type GORMProfileDAO struct {
	// contains filtered or unexported fields
}

func (*GORMProfileDAO) FindByUserId

func (dao *GORMProfileDAO) FindByUserId(ctx context.Context, id int64) (Profile, error)

func (*GORMProfileDAO) Insert

func (dao *GORMProfileDAO) Insert(ctx context.Context, p Profile) error

func (*GORMProfileDAO) Update

func (dao *GORMProfileDAO) Update(ctx context.Context, p Profile) error

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

func (dao *GORMUserWithProfileDAO) FindProfileByEmail(ctx context.Context, email string) (User, Profile, error)

type GormUserDAO

type GormUserDAO struct {
	// contains filtered or unexported fields
}

func (*GormUserDAO) FindByEmail

func (dao *GormUserDAO) FindByEmail(ctx context.Context, email string) (User, error)

func (*GormUserDAO) FindById

func (dao *GormUserDAO) FindById(ctx context.Context, id int64) (User, error)

func (*GormUserDAO) FindByPhone

func (dao *GormUserDAO) FindByPhone(ctx context.Context, phone string) (User, error)

func (*GormUserDAO) Insert

func (dao *GormUserDAO) Insert(ctx context.Context, u User) (User, error)

type Profile

type Profile struct {
	Id       int64 `gorm:"primaryKey, autoIncrement"`
	UserId   int64
	Nickname string
	Biology  string
	Birthday int64
	Ctime    int64
	Utime    int64
}

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

func NewUserDAO(db *gorm.DB) UserDAO

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL