dao

package
v0.0.0-...-2f866d2 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package dao 代表对数据库的操作

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicateEmail = errors.New("邮箱冲突")
	ErrRecordNotFound = gorm.ErrRecordNotFound
)

Functions

func InitTables

func InitTables(db *gorm.DB) error

Types

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, uid 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) error

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

func NewUserDAO(db *gorm.DB) UserDAO

Jump to

Keyboard shortcuts

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