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: 8 Imported by: 0

Documentation

Index

Constants

View Source
const Delimiter = "&^"

Variables

View Source
var (
	ErrUserDuplicate = errors.New("邮箱冲突")
	ErrUserNotFound  = gorm.ErrRecordNotFound
)
View Source
var ErrCompetitionFailed = errors.New("未抢到记录")

Functions

func InitTable

func InitTable(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, 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) error

type Sms

type Sms struct {
	Id         int64
	Tpl        string
	Args       string
	Numbers    string
	Processing int
	Retry      int
	Ctime      int64
	Utime      int64
}

type SmsDao

type SmsDao interface {
	GetFirst(ctx context.Context) (Sms, error)
	SaveSms(ctx context.Context, sms domain.Sms) (Sms, error)
	UpdateStatusAsProcessed(ctx context.Context, id int64) (int64, error)
	UpdateStatusAsProcessFailed(ctx context.Context, id int64) (int64, error)
}

func NewSmsGormDao

func NewSmsGormDao(db *gorm.DB) SmsDao

type SmsGormDao

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

func (*SmsGormDao) GetFirst

func (dao *SmsGormDao) GetFirst(ctx context.Context) (Sms, error)

GetFirst 用乐观锁拿到记录,同时改掉记录的状态,保证只能被拿到一次

func (*SmsGormDao) SaveSms

func (dao *SmsGormDao) SaveSms(ctx context.Context, sms domain.Sms) (Sms, error)

func (*SmsGormDao) UpdateStatusAsProcessFailed

func (dao *SmsGormDao) UpdateStatusAsProcessFailed(ctx context.Context, id int64) (int64, error)

func (*SmsGormDao) UpdateStatusAsProcessed

func (dao *SmsGormDao) UpdateStatusAsProcessed(ctx context.Context, id int64) (int64, error)

type User

type User struct {
	Id int64 `gorm:"primaryKey,autoIncrement"`
	// 全部用户唯一
	Email    sql.NullString `gorm:"unique"`
	Password string

	// 唯一索引允许有多个空值
	// 但是不能有多个 ""
	Phone sql.NullString `gorm:"unique"`

	// 创建时间,毫秒数
	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) 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