dao

package
v0.0.0-...-24b49fa Latest Latest
Warning

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

Go to latest
Published: May 22, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PatternSrcOnly  = "src_only"
	PatternSrcFirst = "src_first"
	PatternDstFirst = "dst_first"
	PatternDstOnly  = "dst_only"
)

Variables

View Source
var ErrRecordNotFound = gorm.ErrRecordNotFound

Functions

func InitTable

func InitTable(db *gorm.DB) error

Types

type DoubleWriteDAO

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

func (*DoubleWriteDAO) BatchIncrReadCnt

func (d *DoubleWriteDAO) BatchIncrReadCnt(
	ctx context.Context,
	bizs []string,
	bizIDs []int64,
) error

BatchIncrReadCnt implements InteractiveDAO.

func (*DoubleWriteDAO) DeleteCollectionBiz

func (d *DoubleWriteDAO) DeleteCollectionBiz(ctx context.Context, cb UserCollectionBiz) error

DeleteCollectionBiz implements InteractiveDAO.

func (*DoubleWriteDAO) DeleteLikeInfo

func (d *DoubleWriteDAO) DeleteLikeInfo(
	ctx context.Context,
	biz string,
	bizID int64,
	uid int64,
) error

DeleteLikeInfo implements InteractiveDAO.

func (*DoubleWriteDAO) Get

func (d *DoubleWriteDAO) Get(ctx context.Context, biz string, bizID int64) (Interactive, error)

func (*DoubleWriteDAO) GetAll

func (d *DoubleWriteDAO) GetAll(
	ctx context.Context,
	biz string,
	limit int,
	offset int,
) ([]Interactive, error)

GetAll implements InteractiveDAO.

func (*DoubleWriteDAO) GetByIDs

func (d *DoubleWriteDAO) GetByIDs(
	ctx context.Context,
	biz string,
	ids []int64,
) ([]Interactive, error)

GetByIDs implements InteractiveDAO.

func (*DoubleWriteDAO) GetCollectInfo

func (d *DoubleWriteDAO) GetCollectInfo(
	ctx context.Context,
	biz string,
	bizID int64,
	uid int64,
) (UserCollectionBiz, error)

GetCollectInfo implements InteractiveDAO.

func (*DoubleWriteDAO) GetLikeInfo

func (d *DoubleWriteDAO) GetLikeInfo(
	ctx context.Context,
	biz string,
	bizID int64,
	uid int64,
) (UserLikeBiz, error)

GetLikeInfo implements InteractiveDAO.

func (*DoubleWriteDAO) GetV1

func (d *DoubleWriteDAO) GetV1(ctx context.Context, biz string, bizID int64) (Interactive, error)

NOTE: validate at the same time (not recommended, coupling)

func (*DoubleWriteDAO) IncrReadCnt

func (d *DoubleWriteDAO) IncrReadCnt(ctx context.Context, biz string, bizID int64) error

IncrReadCnt implements InteractiveDAO.

func (*DoubleWriteDAO) InsertCollectionBiz

func (d *DoubleWriteDAO) InsertCollectionBiz(ctx context.Context, cb UserCollectionBiz) error

InsertCollectionBiz implements InteractiveDAO.

func (*DoubleWriteDAO) InsertLikeInfo

func (d *DoubleWriteDAO) InsertLikeInfo(
	ctx context.Context,
	biz string,
	bizID int64,
	uid int64,
) error

InsertLikeInfo implements InteractiveDAO.

func (*DoubleWriteDAO) MustBatchGet

func (d *DoubleWriteDAO) MustBatchGet(
	ctx context.Context,
	biz string,
	bizIDs []int64,
) ([]Interactive, error)

MustBatchGet implements InteractiveDAO.

func (*DoubleWriteDAO) UpdatePattern

func (d *DoubleWriteDAO) UpdatePattern(pattern string)

type GORMInteractiveDAO

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

func (*GORMInteractiveDAO) BatchIncrReadCnt

func (g *GORMInteractiveDAO) BatchIncrReadCnt(
	ctx context.Context,
	bizs []string,
	bizIDs []int64,
) error

BatchIncrReadCnt implements InteractiveDAO.

func (*GORMInteractiveDAO) DeleteCollectionBiz

func (g *GORMInteractiveDAO) DeleteCollectionBiz(ctx context.Context, cb UserCollectionBiz) error

DeleteCollectionBiz implements InteractiveDAO.

func (*GORMInteractiveDAO) DeleteLikeInfo

func (g *GORMInteractiveDAO) DeleteLikeInfo(
	ctx context.Context,
	biz string,
	bizID int64,
	uid int64,
) error

DeleteLikeInfo implements InteractiveDAO.

func (*GORMInteractiveDAO) Get

func (g *GORMInteractiveDAO) Get(
	ctx context.Context,
	biz string,
	bizID int64,
) (Interactive, error)

Get implements InteractiveDAO.

func (*GORMInteractiveDAO) GetAll

func (g *GORMInteractiveDAO) GetAll(
	ctx context.Context,
	biz string,
	limit int,
	offset int,
) ([]Interactive, error)

GetAll implements InteractiveDAO.

func (*GORMInteractiveDAO) GetByIDs

func (g *GORMInteractiveDAO) GetByIDs(
	ctx context.Context,
	biz string,
	ids []int64,
) ([]Interactive, error)

GetByIDs implements InteractiveDAO.

func (*GORMInteractiveDAO) GetCollectInfo

func (g *GORMInteractiveDAO) GetCollectInfo(
	ctx context.Context,
	biz string,
	bizID int64,
	uid int64,
) (UserCollectionBiz, error)

func (*GORMInteractiveDAO) GetLikeInfo

func (g *GORMInteractiveDAO) GetLikeInfo(
	ctx context.Context,
	biz string,
	bizID int64,
	uid int64,
) (UserLikeBiz, error)

GetLikeInfo implements InteractiveDAO.

func (*GORMInteractiveDAO) IncrReadCnt

func (g *GORMInteractiveDAO) IncrReadCnt(ctx context.Context, biz string, bizID int64) error

IncrReadCnt implements InteractiveDAO.

func (*GORMInteractiveDAO) InsertCollectionBiz

func (g *GORMInteractiveDAO) InsertCollectionBiz(ctx context.Context, cb UserCollectionBiz) error

InsertCollectionBiz implements InteractiveDAO.

func (*GORMInteractiveDAO) InsertLikeInfo

func (g *GORMInteractiveDAO) InsertLikeInfo(
	ctx context.Context,
	biz string,
	bizID int64,
	uid int64,
) error

InsertLikeInfo implements InteractiveDAO.

func (*GORMInteractiveDAO) MustBatchGet

func (g *GORMInteractiveDAO) MustBatchGet(
	ctx context.Context,
	biz string,
	bizIDs []int64,
) ([]Interactive, error)

BatchGet implements InteractiveDAO.

type Interactive

type Interactive struct {
	ID int64 `gorm:"primaryKey,autoIncrement"`

	// <biz_id, biz>
	BizID      int64  `gorm:"uniqueIndex:biz_type_id"`
	Biz        string `gorm:"uniqueIndex:biz_type_id,length:128"`
	ReadCnt    int64
	LikeCnt    int64
	CollectCnt int64
	Utime      int64
	Ctime      int64
}

type InteractiveDAO

type InteractiveDAO interface {
	IncrReadCnt(ctx context.Context, biz string, bizID int64) error
	BatchIncrReadCnt(ctx context.Context, bizs []string, bizIDs []int64) error
	InsertLikeInfo(ctx context.Context, biz string, bizID int64, uid int64) error
	DeleteLikeInfo(ctx context.Context, biz string, bizID int64, uid int64) error
	InsertCollectionBiz(ctx context.Context, cb UserCollectionBiz) error
	DeleteCollectionBiz(ctx context.Context, cb UserCollectionBiz) error
	Get(ctx context.Context, biz string, bizID int64) (Interactive, error)
	GetAll(ctx context.Context, biz string, limit int, offset int) ([]Interactive, error)
	MustBatchGet(ctx context.Context, biz string, bizIDs []int64) ([]Interactive, error)
	GetLikeInfo(ctx context.Context, biz string, bizID int64, uid int64) (UserLikeBiz, error)
	GetCollectInfo(
		ctx context.Context,
		biz string,
		bizID int64,
		uid int64,
	) (UserCollectionBiz, error)
	GetByIDs(ctx context.Context, biz string, ids []int64) ([]Interactive, error)
}

func NewDoubleWriteDAO

func NewDoubleWriteDAO(src InteractiveDAO, dst InteractiveDAO, l logger.Logger) InteractiveDAO

func NewGORMInteractiveDAO

func NewGORMInteractiveDAO(db *gorm.DB) InteractiveDAO

type UserCollectionBiz

type UserCollectionBiz struct {
	ID int64 `gorm:"primaryKey,autoIncrement"`
	// One ressource can only be put into one collection.
	// Otherwise the composite index should include CID too
	UID   int64  `gorm:"uniqueIndex:uid_biz_type_id"`
	BizID int64  `gorm:"uniqueIndex:uid_biz_type_id"`
	Biz   string `gorm:"uniqueIndex:uid_biz_type_id,length:128"`
	// collection ID
	CID   int64 `gorm:"index"`
	Utime int64
	Ctime int64
}

type UserLikeBiz

type UserLikeBiz struct {
	ID     int64  `gorm:"primaryKey,autoIncrement"`
	UID    int64  `gorm:"uniqueIndex:uid_biz_type_id"`
	BizID  int64  `gorm:"uniqueIndex:uid_biz_type_id"`
	Biz    string `gorm:"uniqueIndex:uid_biz_type_id,length:128"`
	Status int
	Utime  int64
	Ctime  int64
}

Directories

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

Jump to

Keyboard shortcuts

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