dao

package
v0.0.0-...-c234f5e Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDataNotFound  = gorm.ErrRecordNotFound
	ErrUserDuplicate = errors.New("user email duplicate")
)

Functions

func InitTables

func InitTables(db *gorm.DB) error

Types

type GormUserDAO

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

func (*GormUserDAO) FindByEmail

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

func (*GormUserDAO) FindById

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

func (*GormUserDAO) FindByPhone

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

func (*GormUserDAO) Insert

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

type User

type User struct {
	Id    int64          `gorm:"primaryKey;autoIncrement"`
	Email sql.NullString `gorm:"unique"`

	// 由于密码不需要设置成 unique(唯一索引), 因此他为""(空字符串)也没关系
	Password string
	Nickname string `gorm:"type=varchar(128)"`

	Birthday int64  // YYYY-MM-DD
	AboutMe  string `gorm:"type=varchar(4096)"`

	// 代表这是一个可以为 NULL 的列
	// 唯一索引允许有多个 NULL, 但是不允许多个 ""
	Phone     sql.NullString `gorm:"unique"`
	CreatedAt int64          // 统一 UTC +0, 涉及到时间的时候, 再处理时区(转换)
	UpdatedAt int64
}

type UserDAO

type UserDAO interface {
	Insert(ctx context.Context, u User) error
	FindById(ctx context.Context, id int64) (User, error)
	FindByEmail(ctx context.Context, email string) (User, error)
	FindByPhone(ctx context.Context, phone string) (User, error)
}

func NewUserDAO

func NewUserDAO(db *gorm.DB) UserDAO

Directories

Path Synopsis
Package daomocks is a generated GoMock package.
Package daomocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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