Documentation
¶
Overview ¶
Package query data access layer
Index ¶
- Constants
- Variables
- func GenRedisKey(table string, id int64) string
- func NewGormDB(config *config.Config, logger *zap.Logger) (*gorm.DB, error)
- type CommentCommand
- type CommentQuery
- type HashField
- type LikeCommand
- type LikeQuery
- func (c *LikeQuery) FindByVideoIDAndUserID(ctx context.Context, vid, uid int64) (*dal.Like, error)
- func (c *LikeQuery) FindVideoIDsByUserID(ctx context.Context, uid int64, limit, offset int) ([]int64, error)
- func (c *LikeQuery) FindWhetherLiked(ctx context.Context, userid int64, videoID []int64) ([]int64, error)
- type RDB
- type RelationCommand
- type RelationQuery
- func (c *RelationQuery) FindFollowerFrom(ctx context.Context, followTo int64, limit, offset int) ([]int64, error)
- func (c *RelationQuery) FindFollowerTo(ctx context.Context, userid int64, limit, offset int) ([]int64, error)
- func (c *RelationQuery) FindWhetherFollowedList(ctx context.Context, userid int64, followTo []int64) ([]int64, error)
- type UniqueID
- type UserCommand
- type UserQuery
- func (c *UserQuery) FindByUsername(ctx context.Context, username string) (*dal.User, error)
- func (c *UserQuery) FindMany(ctx context.Context, ids []int64) ([]*dal.User, error)
- func (c *UserQuery) FindManyStat(ctx context.Context, users []*dal.User) ([]*dal.User, error)
- func (c *UserQuery) FindOne(ctx context.Context, id int64) (*dal.User, error)
- func (c *UserQuery) FindOneStat(ctx context.Context, user *dal.User) (*dal.User, error)
- type VideoCommand
- type VideoQuery
- func (c *VideoQuery) FindByUserID(ctx context.Context, userID int64, limit, offset int) ([]*dal.Video, error)
- func (c *VideoQuery) FindLatest(ctx context.Context, timestamp int64, limit int64) ([]*dal.Video, error)
- func (c *VideoQuery) FindMany(ctx context.Context, ids []int64) ([]*dal.Video, error)
- func (c *VideoQuery) FindManyStat(ctx context.Context, videos []*dal.Video) ([]*dal.Video, error)
- func (c *VideoQuery) FindOne(ctx context.Context, id int64) (*dal.Video, error)
- func (c *VideoQuery) FindOneStat(ctx context.Context, video *dal.Video) (*dal.Video, error)
Constants ¶
const ( TableUser = "user" TableVideo = "video" )
各个表的枚举
const ( CountLike = "like_count" CountVideo = "video_count" CountComment = "comment_count" CountFans = "fans_count" CountFollow = "follow_count" )
统计量的枚举
Variables ¶
var Module = fx.Module("data access layer", fx.Provide( fx.Annotate(NewGormDB, fx.OnStop(gormClose)), fx.Annotate(NewRedisUniversalClient, fx.OnStop(closeRedis)), fx.Annotate(NewUserQuery, fx.As(new(dal.UserQuery))), fx.Annotate(NewUserCommand, fx.As(new(dal.UserCommand))), fx.Annotate(NewCommentQuery, fx.As(new(dal.CommentQuery))), fx.Annotate(NewCommentCommand, fx.As(new(dal.CommentCommand))), fx.Annotate(NewVideoQuery, fx.As(new(dal.VideoQuery))), fx.Annotate(NewVideoCommand, fx.As(new(dal.VideoCommand))), fx.Annotate(NewLikeQuery, fx.As(new(dal.LikeQuery))), fx.Annotate(NewLikeCommand, fx.As(new(dal.LikeCommand))), fx.Annotate(NewRelationQuery, fx.As(new(dal.RelationQuery))), ), fx.Decorate(RedisOtel, withPlugins), )
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 ¶
GenRedisKey generate redis key table: enum of table id: id of the table
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
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 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
type LikeQuery ¶
type LikeQuery struct {
// contains filtered or unexported fields
}
LikeQuery is the implementation of dal.LikeQuery
func NewLikeQuery ¶
NewLikeQuery creates a new comment like model
func (*LikeQuery) FindByVideoIDAndUserID ¶
FindByVideoIDAndUserID finds a like by video id and user id
type RDB ¶
type RDB struct { redis.UniversalClient // contains filtered or unexported fields }
RDB is the database of redis
func NewRedisUniversalClient ¶
NewRedisUniversalClient returns a redis client extended with zap logger on incr error
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
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
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
type UserQuery ¶
type UserQuery struct {
// contains filtered or unexported fields
}
UserQuery is the implementation of dal.UserQuery
func NewUserQuery ¶
NewUserQuery returns a *UserQuery
func (*UserQuery) FindByUsername ¶
FindByUsername find one user by username
func (*UserQuery) FindMany ¶
FindMany find many users by ids Even if there is no any user matched, it will return an empty slice
func (*UserQuery) FindManyStat ¶
FindManyStat find many user stats by ids 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
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) FindManyStat ¶
FindManyStat find many video stats by ids
func (*VideoQuery) FindOneStat ¶
FindOneStat find one video stat by id