query

package
v0.0.0-...-611b6d6 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package query data access layer

Index

Constants

View Source
const (
	TableUser  = "user"
	TableVideo = "video"
)

各个表的枚举

View Source
const (
	CountLike    = "like_count"
	CountVideo   = "video_count"
	CountComment = "comment_count"
	CountFans    = "fans_count"
	CountFollow  = "follow_count"
)

统计量的枚举

Variables

Module is the module for dal. It provides the data access layer for the application. fx.Annotate is used to wrap the struct with an interface.

Functions

func GenRedisKey

func GenRedisKey(table string, id int64) string

GenRedisKey generate redis key table: enum of table id: id of the table

func NewGormDB

func NewGormDB(config *config.Config, logger *zap.Logger) (*gorm.DB, error)

NewGormDB returns a new gorm db instance

Types

type CommentCommand

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

CommentCommand is the implementation of dal.CommentCommand

func NewCommentCommand

func NewCommentCommand(db *gorm.DB, rdb *RDB) *CommentCommand

NewCommentCommand is the constructor of CommentCommand

func (*CommentCommand) Delete

func (c *CommentCommand) Delete(ctx context.Context, id int64, uid int64, vid int64) error

Delete deletes a comment by id and user id

func (*CommentCommand) Insert

func (c *CommentCommand) Insert(ctx context.Context, comment *dal.Comment) error

Insert inserts a comment

type CommentQuery

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

CommentQuery is the implementation of dal.CommentQuery

func NewCommentQuery

func NewCommentQuery(db *gorm.DB, rdb *RDB) *CommentQuery

NewCommentQuery is the constructor of CommentQuery

func (*CommentQuery) FindByVideoID

func (c *CommentQuery) FindByVideoID(ctx context.Context, videoID int64, limit, offset int) ([]*dal.Comment, error)

FindByVideoID finds comments by video id

type HashField

type HashField struct {
	Key   string
	Field string
}

HashField is the struct for specifying field of redis hash structure

type LikeCommand

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

LikeCommand is the implementation of dal.LikeCommand

func NewLikeCommand

func NewLikeCommand(db *gorm.DB, rdb *RDB) *LikeCommand

NewLikeCommand creates a new comment like model

func (*LikeCommand) Delete

func (c *LikeCommand) Delete(ctx context.Context, vid, uid int64) error

Delete deletes a like by video id and user id

func (*LikeCommand) Insert

func (c *LikeCommand) Insert(ctx context.Context, like *dal.Like) error

Insert inserts a like

type LikeQuery

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

LikeQuery is the implementation of dal.LikeQuery

func NewLikeQuery

func NewLikeQuery(db *gorm.DB, rdb *RDB) *LikeQuery

NewLikeQuery creates a new comment like model

func (*LikeQuery) FindByVideoIDAndUserID

func (c *LikeQuery) FindByVideoIDAndUserID(ctx context.Context, vid, uid int64) (*dal.Like, error)

FindByVideoIDAndUserID finds a like by video id and user id

func (*LikeQuery) FindVideoIDsByUserID

func (c *LikeQuery) FindVideoIDsByUserID(ctx context.Context, uid int64, limit, offset int) ([]int64, error)

FindVideoIDsByUserID finds liked video ids by user id

func (*LikeQuery) FindWhetherLiked

func (c *LikeQuery) FindWhetherLiked(ctx context.Context, userid int64, videoID []int64) ([]int64, error)

FindWhetherLiked finds a like record by video ids and user id return a list of video id that liked by userid

type RDB

type RDB struct {
	redis.UniversalClient
	// contains filtered or unexported fields
}

RDB is the database of redis

func NewRedisUniversalClient

func NewRedisUniversalClient(config *config.Config, logger *zap.Logger) *RDB

NewRedisUniversalClient returns a redis client extended with zap logger on incr error

func RedisOtel

func RedisOtel(rdb *RDB) (*RDB, error)

RedisOtel extends redis client with open telemetry tracing

func (*RDB) HIncrBy

func (r *RDB) HIncrBy(ctx context.Context, key, field string, value int64)

HIncrBy for given key and field, increment the value

func (*RDB) HKeyFieldsIncrBy

func (r *RDB) HKeyFieldsIncrBy(ctx context.Context, keyFields []HashField, value int64)

HKeyFieldsIncrBy for given keys and fields, increment the value

type RelationCommand

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

RelationCommand is the implementation of dal.RelationCommand

func NewRelationCommand

func NewRelationCommand(db *gorm.DB, rdb *RDB) *RelationCommand

NewRelationCommand creates a new comment relation model

func (*RelationCommand) Delete

func (c *RelationCommand) Delete(ctx context.Context, userid, followTo int64) error

Delete a relation record by userid and followTo

func (*RelationCommand) Insert

func (c *RelationCommand) Insert(ctx context.Context, rel *dal.Relation) error

Insert create a relation record

type RelationQuery

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

RelationQuery is the implementation of dal.RelationQuery

func NewRelationQuery

func NewRelationQuery(db *gorm.DB, rdb *RDB) *RelationQuery

NewRelationQuery creates a new comment relation model

func (*RelationQuery) FindFollowerFrom

func (c *RelationQuery) FindFollowerFrom(ctx context.Context, followTo int64, limit, offset int) ([]int64, error)

FindFollowerFrom query the user's follower return the follower ids that the user is followed by

func (*RelationQuery) FindFollowerTo

func (c *RelationQuery) FindFollowerTo(ctx context.Context, userid int64, limit, offset int) ([]int64, error)

FindFollowerTo query the user's followTo return the followTo ids that the user follow

func (*RelationQuery) FindWhetherFollowedList

func (c *RelationQuery) FindWhetherFollowedList(ctx context.Context, userid int64, followTo []int64) ([]int64, error)

FindWhetherFollowedList query whether the user follow the followTo ids return the followTo ids that the user follow

type UniqueID

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

UniqueID provides unique id generation

func NewUniqueID

func NewUniqueID() *UniqueID

NewUniqueID creates a new unique id generator

func (*UniqueID) NextID

func (u *UniqueID) NextID() (int64, error)

NextID generates a new unique id according to the generator's algorithm

type UserCommand

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

UserCommand is the implementation of dal.UserCommand

func NewUserCommand

func NewUserCommand(db *gorm.DB, rdb *RDB) *UserCommand

NewUserCommand returns a *UserCommand

func (*UserCommand) Insert

func (c *UserCommand) Insert(ctx context.Context, u *dal.User) error

Insert insert a user

func (*UserCommand) Update

func (*UserCommand) Update(context.Context, *dal.User) error

Update update a user

type UserQuery

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

UserQuery is the implementation of dal.UserQuery

func NewUserQuery

func NewUserQuery(db *gorm.DB, rdb *RDB) *UserQuery

NewUserQuery returns a *UserQuery

func (*UserQuery) FindByUsername

func (c *UserQuery) FindByUsername(ctx context.Context, username string) (*dal.User, error)

FindByUsername find one user by username

func (*UserQuery) FindMany

func (c *UserQuery) FindMany(ctx context.Context, ids []int64) ([]*dal.User, error)

FindMany find many users by ids Even if there is no any user matched, it will return an empty slice

func (*UserQuery) FindManyStat

func (c *UserQuery) FindManyStat(ctx context.Context, users []*dal.User) ([]*dal.User, error)

FindManyStat find many user stats by ids from redis

func (*UserQuery) FindOne

func (c *UserQuery) FindOne(ctx context.Context, id int64) (*dal.User, error)

FindOne find one user by id

func (*UserQuery) FindOneStat

func (c *UserQuery) FindOneStat(ctx context.Context, user *dal.User) (*dal.User, error)

FindOneStat find one user stat by id from redis

type VideoCommand

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

VideoCommand is the implementation of dal.VideoQuery

func NewVideoCommand

func NewVideoCommand(db *gorm.DB, rdb *RDB) *VideoCommand

NewVideoCommand returns a *VideoCommand

func (*VideoCommand) Delete

func (c *VideoCommand) Delete(ctx context.Context, id int64, uid int64) error

Delete a video by its id and correct user id

func (*VideoCommand) Insert

func (c *VideoCommand) Insert(ctx context.Context, video *dal.Video) error

Insert insert a video

func (*VideoCommand) Update

Update update a video

type VideoQuery

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

VideoQuery is the implementation of dal.VideoQuery

func NewVideoQuery

func NewVideoQuery(db *gorm.DB, rdb *RDB) *VideoQuery

NewVideoQuery returns a *VideoQuery

func (*VideoQuery) FindByUserID

func (c *VideoQuery) FindByUserID(ctx context.Context, userID int64, limit, offset int) ([]*dal.Video, error)

FindByUserID find videos by user id

func (*VideoQuery) FindLatest

func (c *VideoQuery) FindLatest(ctx context.Context, timestamp int64, limit int64) ([]*dal.Video, error)

FindLatest find the latest videos timestamp is the millisecond timestamp

func (*VideoQuery) FindMany

func (c *VideoQuery) FindMany(ctx context.Context, ids []int64) ([]*dal.Video, error)

FindMany find many videos by ids

func (*VideoQuery) FindManyStat

func (c *VideoQuery) FindManyStat(ctx context.Context, videos []*dal.Video) ([]*dal.Video, error)

FindManyStat find many video stats by ids

func (*VideoQuery) FindOne

func (c *VideoQuery) FindOne(ctx context.Context, id int64) (*dal.Video, error)

FindOne find one video by id

func (*VideoQuery) FindOneStat

func (c *VideoQuery) FindOneStat(ctx context.Context, video *dal.Video) (*dal.Video, error)

FindOneStat find one video stat by id

Jump to

Keyboard shortcuts

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