dao

package
v0.0.0-...-7efebb4 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func InitTables

func InitTables(db *gorm.DB) error

initialize tables

Types

type Article

type Article struct {
	Id int64 `gorm:"primaryKey,autoIncrement"`
	// create an index for frequently queried column
	AuthorId int64  `gorm:"index"`
	Topic    string `gorm:"type=varchar(4096)"`
	Content  string `gorm:"type=BLOB"`
	// why use int64 here
	// bson doesn't support time.Time?
	Status uint8
	Ctime  int64
	Utime  int64
}

type ArticleDAO

type ArticleDAO interface {
	GetById(context.Context, int64) (Article, error)
	GetByPublishedId(context.Context, int64) (PublishedArticle, error)
	Insert(context.Context, Article) (int64, error)
	GetByAuthorId(context.Context, int64, int, int) ([]Article, error)
	Sync(context.Context, Article) (int64, error)
	UpdateById(context.Context, Article) error
	SyncStatus(ctx context.Context, userId int64, artId int64, status domain.ArticleStatus) error
	ListPub(context.Context, time.Time, int, int) ([]PublishedArticle, error)
}

func NewArticleGormDAO

func NewArticleGormDAO(db *gorm.DB) ArticleDAO

type ArticleGormDAO

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

func (*ArticleGormDAO) GetByAuthorId

func (d *ArticleGormDAO) GetByAuthorId(ctx context.Context, authorId int64, limit int, offset int) ([]Article, error)

func (*ArticleGormDAO) GetById

func (d *ArticleGormDAO) GetById(ctx context.Context, id int64) (Article, error)

func (*ArticleGormDAO) GetByPublishedId

func (d *ArticleGormDAO) GetByPublishedId(ctx context.Context, id int64) (PublishedArticle, error)

func (*ArticleGormDAO) Insert

func (d *ArticleGormDAO) Insert(ctx context.Context, article Article) (int64, error)

func (*ArticleGormDAO) ListPub

func (d *ArticleGormDAO) ListPub(ctx context.Context, start time.Time, offset int, batchSize int) ([]PublishedArticle, error)

func (*ArticleGormDAO) Sync

func (d *ArticleGormDAO) Sync(ctx context.Context, art Article) (int64, error)

func (*ArticleGormDAO) SyncStatus

func (d *ArticleGormDAO) SyncStatus(ctx context.Context, userId int64, artId int64, status domain.ArticleStatus) error

func (*ArticleGormDAO) UpdateById

func (d *ArticleGormDAO) UpdateById(ctx context.Context, art Article) error

type AsyncGormSmsDAO

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

func (*AsyncGormSmsDAO) GetPreemptiveSms

func (a *AsyncGormSmsDAO) GetPreemptiveSms(ctx context.Context) (AsyncSms, error)

func (*AsyncGormSmsDAO) Insert

func (a *AsyncGormSmsDAO) Insert(ctx context.Context, sms AsyncSms) error

func (*AsyncGormSmsDAO) MarkFailure

func (a *AsyncGormSmsDAO) MarkFailure(ctx context.Context, smsId int64) error

func (*AsyncGormSmsDAO) MarkSuccess

func (a *AsyncGormSmsDAO) MarkSuccess(ctx context.Context, smsId int64) error

type AsyncSms

type AsyncSms struct {
	Id       int64  `gorm:"primaryKey, autoIncrement"`
	Config   []byte `gorm:"type:json"`
	Status   uint8
	RetryCnt int
	RetryMax int
	Utime    int64 `gorm:"index"`
	Ctime    int64
}

type AsyncSmsDAO

type AsyncSmsDAO interface {
	Insert(ctx context.Context, sms AsyncSms) error
	GetPreemptiveSms(ctx context.Context) (AsyncSms, error)
	MarkSuccess(ctx context.Context, smsId int64) error
	MarkFailure(ctx context.Context, smsId int64) error
}

func NewAsyncSmsDao

func NewAsyncSmsDao(db *gorm.DB) AsyncSmsDAO

type PublishedArticle

type PublishedArticle struct {
	Article
}

type SmsConfig

type SmsConfig struct {
	TplId     string
	Args      []string
	PhoneNums []string
}

type User

type User struct {
	Id       int64          `gorm:"primaryKey, autoIncrement"`
	Email    sql.NullString `gorm:"unique"`
	Password string
	Phone    sql.NullString `gorm:"unique"`

	Nickname string `gorm:"type=varchar(128)"`

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

	// 数据库溯源
	Ctime int64
	Utime int64
}

type UserActivity

type UserActivity struct {
	// 联合唯一索引:防止并发写入问题
	// 保证任何时刻这两个列都是一致的
	Id          int64  `gorm:"primaryKey,autoIncrement"`
	Biz         string `gorm:"type:varchar(128);uniqueIndex:biz_type_id"`
	BizId       int64  `gorm:"uniqueIndex:biz_type_id"`
	ReadCnt     int64
	LikeCnt     int64
	BookmarkCnt int64
	Utime       int64
	Ctime       int64
}

type UserActivityDAO

type UserActivityDAO interface {
	IncrReadCntIfPresent(ctx context.Context, biz string, bizId int64) error
	BatchIncrReadCntIfPresent(ctx context.Context, bizs []string, bizIds []int64) error
	GetReadByIds(ctx context.Context, biz string, bizIds []int64) ([]UserActivity, error)
}

func NewUserActivityDAO

func NewUserActivityDAO(db *gorm.DB) UserActivityDAO

type UserDAO

type UserDAO interface {
	Insert(context.Context, User) error
	Create(context.Context, User) error
	FindByEmail(context.Context, string) (User, error)
	FindByPhone(context.Context, string) (User, error)
	FindById(context.Context, int64) (User, error)
	UpdateById(context.Context, User) error
}

func NewUserDAO

func NewUserDAO(db *gorm.DB) UserDAO

type UserGormDAO

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

func (*UserGormDAO) Create

func (dao *UserGormDAO) Create(ctx context.Context, user User) error

func (*UserGormDAO) FindByEmail

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

func (*UserGormDAO) FindById

func (dao *UserGormDAO) FindById(ctx context.Context, uid int64) (User, error)

func (*UserGormDAO) FindByPhone

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

func (*UserGormDAO) Insert

func (dao *UserGormDAO) Insert(ctx context.Context, user User) error

func (*UserGormDAO) UpdateById

func (dao *UserGormDAO) UpdateById(ctx context.Context, user User) error

Jump to

Keyboard shortcuts

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