db

package
v0.0.0-...-dfc68d5 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

Functions

func AddMessage

func AddMessage(ctx context.Context, currentId int64, toUserId int64, content string) error

AddMessage 添加一条消息记录

func AddRelation

func AddRelation(ctx context.Context, currentId int64, toUserId int64) error

AddRelation 添加一条关注记录,表示currentId关注了toUserId

func CreateComment

func CreateComment(ctx context.Context, comment *CommentRaw) error

CreateComment 通过一条评论创建一条评论记录并增加视频评论数

func CreateFavorite

func CreateFavorite(ctx context.Context, favorite *FavoriteRaw, videoId int64) error

CreateFavorite add a record to the favorite table through a transaction, and add the number of video likes

func CreateUserInfo

func CreateUserInfo(ctx context.Context, username string, password string) (int64, error)

func DeleteFavorite

func DeleteFavorite(ctx context.Context, currentId int64, videoId int64) error

DeleteFavorite Delete a record in the favorite table and reduce the number of video likes

func DeleteRelation

func DeleteRelation(ctx context.Context, currentId int64, toUserId int64) error

DeleteRelation 删除由currentId到toUserId的关注记录

func Init

func Init()

Init init DB

func PublishVideoData

func PublishVideoData(ctx context.Context, videoData *VideoRaw) error

PublishVideoData 向video表添加一条记录

func QueryCommentCountByVideoId

func QueryCommentCountByVideoId(videoId int64) int64

func QueryFavoriteByIds

func QueryFavoriteByIds(ctx context.Context, currentId int64, videoIds []int64) (map[int64]*FavoriteRaw, error)

QueryFavoriteByIds 根据当前用户id和视频id获取点赞信息

func QueryFollowCount

func QueryFollowCount(userId int64) int64

QueryFollowCount 根据用户id,查询该用户关注其他用户的总数

func QueryFollowerCount

func QueryFollowerCount(userId int64) int64

QueryFollowerCount 根据用户id,查询该用户粉丝的总数

func QueryFriendById

func QueryFriendById(ctx context.Context, currentId int64, toUserId int64) ([]int64, error)

QueryFriendById 通过用户id,查询与之互相关注的用户Id

func QueryRelationByIds

func QueryRelationByIds(ctx context.Context, currentId int64, toUserIds []int64) (map[int64]*RelationRaw, error)

QueryRelationByIds 根据当前用户id和目标用户id获取关注信息

func QueryUserFavoritedById

func QueryUserFavoritedById(ctx context.Context, userId int64) (int64, error)

QueryUserFavoritedById 查询用户喜欢的视频总数

func QueryUserTotalFavorited

func QueryUserTotalFavorited(ctx context.Context, userId int64) int64

QueryUserTotalFavorited 查询用户被点赞的总数量

func QueryVideoCountByUserId

func QueryVideoCountByUserId(userId int64) int64

Types

type CommentRaw

type CommentRaw struct {
	gorm.Model
	UserId  int64  `gorm:"column:user_id;not null;index:idx_userid"`
	VideoId int64  `gorm:"column:video_id;not null;index:idx_videoid"`
	Content string `gorm:"column:content;type:varchar(255);not null"`
}

CommentRaw Comment Gorm Data Structures

func DeleteComment

func DeleteComment(ctx context.Context, commentId int64) (*CommentRaw, error)

DeleteComment 通过评论id号删除一条评论并减少视频评论数,返回该评论

func QueryCommentByCommentIds

func QueryCommentByCommentIds(ctx context.Context, commentIds []int64) ([]*CommentRaw, error)

QueryCommentByCommentIds 通过评论id查询一组评论信息

func QueryCommentByVideoId

func QueryCommentByVideoId(ctx context.Context, videoId int64) ([]*CommentRaw, error)

QueryCommentByVideoId 通过视频id号倒序返回一组评论信息

func (CommentRaw) TableName

func (CommentRaw) TableName() string

type FavoriteRaw

type FavoriteRaw struct {
	gorm.Model
	UserId  int64 `gorm:"column:user_id;not null;index:idx_userid"`
	VideoId int64 `gorm:"column:video_id;not null;index:idx_videoid"`
}

FavoriteRaw Gorm Data Structures

func (FavoriteRaw) TableName

func (FavoriteRaw) TableName() string

type MessageRaw

type MessageRaw struct {
	gorm.Model
	UserId     int64  `gorm:"column:user_id;not null;index:idx_userid"`
	ToUserId   int64  `gorm:"column:to_user_id;not null;index:idx_touserid"`
	Content    string `gorm:"column:content;not null;index:idx_content"`
	CreateTime int64  `gorm:"column:create_time;not null;index:idx_createtime;autoCreateTime"` // 使用时间戳秒数填充创建时间
}

MessageRaw Message Gorm Data Structures

func QueryFriendLastMessage

func QueryFriendLastMessage(ctx context.Context, userId int64, toUserId int64) (*MessageRaw, error)

QueryFriendLastMessage 根据用户id和目标用户id,查询最新的消息记录

func QueryMessageById

func QueryMessageById(ctx context.Context, userId int64, toUserId int64) ([]*MessageRaw, error)

QueryMessageById 根据用户id和目标用户id,查询对应的消息记录

func (MessageRaw) TableName

func (MessageRaw) TableName() string

type RelationRaw

type RelationRaw struct {
	gorm.Model
	UserId   int64 `gorm:"column:user_id;not null;index:idx_userid"`
	ToUserId int64 `gorm:"column:to_user_id;not null;index:idx_touserid"`
}

RelationRaw Relation Gorm Data Structures

func QueryFollowById

func QueryFollowById(ctx context.Context, userId int64) ([]*RelationRaw, error)

QueryFollowById 通过用户id,查询该用户关注的用户,返回两者之间的关注记录

func QueryFollowerById

func QueryFollowerById(ctx context.Context, userId int64) ([]*RelationRaw, error)

QueryFollowerById 通过用户id,查询该用户的粉丝,返回两者之间的关注记录

func (RelationRaw) TableName

func (RelationRaw) TableName() string

type UserRaw

type UserRaw struct {
	gorm.Model
	Name            string `gorm:"column:name;index:idx_username,unique;type:varchar(32);not null"`
	Password        string `gorm:"column:password;type:varchar(32);not null"`
	Avatar          string `gorm:"column:avatar;type:varchar(128);not null"`
	BackgroundImage string `gorm:"column:backGround;type:varchar(128);not null"`
	Signature       string `gorm:"column:signature;type:varchar(128);not null"`
}

UserRaw User Gorm Data structures

func QueryUserByIds

func QueryUserByIds(ctx context.Context, userIds []int64) ([]*UserRaw, error)

QueryUserByIds 根据用户id获取用户信息

func QueryUserByName

func QueryUserByName(ctx context.Context, name string) (*UserRaw, error)

func (UserRaw) TableName

func (UserRaw) TableName() string

type VideoRaw

type VideoRaw struct {
	gorm.Model
	UserId    int64     `gorm:"column:user_id;not null;index:idx_userid"`
	Title     string    `gorm:"column:title;type:varchar(128);not null"`
	PlayUrl   string    `gorm:"column:play_url;varchar(128);not null"`
	CoverUrl  string    `gorm:"column:cover_url;varchar(128);not null"`
	UpdatedAt time.Time `gorm:"column:update_time;not null;index:idx_update"`
}

VideoRaw Video Gorm Data Structures

func QueryVideoByLatestTime

func QueryVideoByLatestTime(ctx context.Context, latestTime int64) ([]*VideoRaw, error)

QueryVideoByLatestTime query video info by latest create Time

func QueryVideoByUserId

func QueryVideoByUserId(ctx context.Context, userId int64) ([]*VideoRaw, error)

QueryVideoByUserId 新增通过用户id获取视频数据的功能

func QueryVideoByVideoIds

func QueryVideoByVideoIds(ctx context.Context, videoIds []int64) ([]*VideoRaw, error)

QueryVideoByVideoIds query video info by video ids

func (*VideoRaw) TableName

func (v *VideoRaw) TableName() string

Jump to

Keyboard shortcuts

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