db

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2022 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

Functions

func Create

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

增加当前用户的关注总数,增加其他用户的粉丝总数,创建关注记录

func CreateComment

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

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

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 Delete

func Delete(ctx context.Context, currentId int64, toUserId 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 Init

func Init()

Init init DB

func PublishVideoData

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

向video表添加一条记录

func QueryFavoriteById

func QueryFavoriteById(ctx context.Context, userId int64) ([]int64, error)

QueryFavoriteById 通过一个用户id查询出该用户点赞的所有视频id号

func QueryFavoriteByIds

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

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

func QueryRelationByIds

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

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

func UploadUserData

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

上传用户信息到数据库

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"`
	Contents string `grom:"column:contents;type:varchar(255);not null"`
}

Comment Gorm Data Structures

func DeleteComment

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

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

func QueryCommentByCommentIds

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

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

func QueryCommentByVideoId

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

通过视频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"`
}

Favorite Gorm Data Structures

func (FavoriteRaw) TableName

func (FavoriteRaw) 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"`
}

Relation Gorm Data Structures

func QueryFollowById

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

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

func QueryFollowerById

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

通过用户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"`
	FollowCount   int64  `gorm:"column:follow_count;default:0"`
	FollowerCount int64  `gorm:"column:follower_count;default:0"`
}

User Gorm Data structures

func QueryUserByIds

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

根据用户id获取用户信息

func QueryUserByName

func QueryUserByName(ctx context.Context, userName 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"`
	FavoriteCount int64     `gorm:"column:favorite_count;default:0"`
	CommentCount  int64     `gorm:"column:comment_count;default:0"`
	UpdatedAt     time.Time `gorm:"column:update_time;not null;index:idx_update"`
}

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)

新增通过用户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