db

package
v0.0.0-...-966fd63 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package db /*

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateComment

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

CreateComment

@Description: 新增一条评论数据,并对所属视频的评论数+1
@Date 2023-01-21 14:42:49
@param ctx 数据库操作上下文
@param comment 评论数据
@return error

func CreateMessagesByList

func CreateMessagesByList(ctx context.Context, messages []*Message) error

CreateMessagesByList

@Description: 新增多条聊天信息
@Date 2023-01-21 17:13:26
@param ctx 数据库操作上下文
@param users 用户数据列表
@return error

func CreateRelation

func CreateRelation(ctx context.Context, userID int64, toUserID int64) error

CreateRelation

@Description: 新增一条用户之间的关注数据
@Date 2023-01-21 16:56:25
@param ctx 数据库操作上下文
@param userID 关注用户的用户id
@param toUserID 被关注用户的用户id
@return error

func CreateUser

func CreateUser(ctx context.Context, user *User) error

CreateUser

@Description: 新增一条用户数据
@Date 2023-02-22 11:46:43
@param ctx 数据库操作上下文
@param user 用户数据
@return error

func CreateUsers

func CreateUsers(ctx context.Context, users []*User) error

CreateUsers

@Description: 新增多条用户数据
@Date 2023-01-21 17:13:26
@param ctx 数据库操作上下文
@param users 用户数据列表
@return error

func CreateVideo

func CreateVideo(ctx context.Context, video *Video) error

CreateVideo

@Description: 发布一条视频
@Date 2023-01-21 16:26:19
@param ctx 数据库操作上下文
@param video 视频数据
@return error

func CreateVideoFavorite

func CreateVideoFavorite(ctx context.Context, userID int64, videoID int64, authorID int64) error

CreateVideoFavorite

@Description: 创建一条用户点赞数据
@Date 2023-01-21 17:19:20
@param ctx 数据库操作上下文
@param userID 用户id
@param videoID 视频id
@param authorID 视频作者id
@return error

func DelCommentByID

func DelCommentByID(ctx context.Context, commentID int64, vid int64) error

DelCommentByID

@Description: 删除一条评论数据,并对所属视频的评论数-1
@Date 2023-01-21 14:49:43
@param ctx 数据库操作上下文
@param commentID 需要删除的评论的id
@param vid 评论所属视频的id
@return error

func DelFavoriteByUserVideoID

func DelFavoriteByUserVideoID(ctx context.Context, userID int64, videoID int64, authorID int64) error

DelFavoriteByUserVideoID

@Description: 删除用户对视频的点赞信息,并对所属视频的点赞数-1
@Date 2023-01-21 16:05:11
@param ctx 数据库操作上下文
@param userID 用户id
@param videoID 视频id
@param authorID 视频作者id
@return error

func DelRelationByUserIDs

func DelRelationByUserIDs(ctx context.Context, userID int64, toUserID int64) error

DelRelationByUserIDs

@Description: 删除一条关注数据
@Date 2023-01-21 16:57:50
@param ctx 数据库操作上下文
@param userID 关注用户的用户id
@param toUserID 被关注用户的用户id
@return error

func DelVideoByID

func DelVideoByID(ctx context.Context, videoID int64, authorID int64) error

DelVideoByID

@Description: 根据视频id和作者id删除视频
@Date 2023-02-22 23:34:45
@param ctx 数据库操作上下文
@param videoID 视频id
@param authorID 作者id
@return error

func GetDB

func GetDB() *gorm.DB

Types

type Comment

type Comment struct {
	ID         uint      `gorm:"primarykey"`
	CreatedAt  time.Time `gorm:"index;not null" json:"create_date"`
	UpdatedAt  time.Time
	DeletedAt  gorm.DeletedAt `gorm:"index"`
	Video      Video          `gorm:"foreignkey:VideoID" json:"video,omitempty"`
	VideoID    uint           `gorm:"index:idx_videoid;not null" json:"video_id"`
	User       User           `gorm:"foreignkey:UserID" json:"user,omitempty"`
	UserID     uint           `gorm:"index:idx_userid;not null" json:"user_id"`
	Content    string         `gorm:"type:varchar(255);not null" json:"content"`
	LikeCount  uint           `gorm:"column:like_count;default:0;not null" json:"like_count,omitempty"`
	TeaseCount uint           `gorm:"column:tease_count;default:0;not null" json:"tease_count,omitempty"`
}

Comment

@Description: 用户评论数据模型

func GetCommentByCommentID

func GetCommentByCommentID(ctx context.Context, commentID int64) (*Comment, error)

GetCommentByCommentID

@Description: 根据评论ID获取评论
@Date 2023-02-23 10:03:01
@param ctx 数据库操作上下文
@param id 评论id
@return *Comment 评论
@return error

func GetVideoCommentListByVideoID

func GetVideoCommentListByVideoID(ctx context.Context, videoID int64) ([]*Comment, error)

GetVideoCommentListByVideoID

@Description: 根据视频id获取指定视频的全部评论内容
@Date 2023-01-21 15:13:33
@param ctx 数据库操作上下文
@param videoID 视频id
@return []*Comment 评论内容
@return error

func (Comment) TableName

func (Comment) TableName() string

type FavoriteCommentRelation

type FavoriteCommentRelation struct {
	Comment   Comment `gorm:"foreignkey:CommentID;" json:"comment,omitempty"`
	CommentID uint    `gorm:"column:comment_id;index:idx_commentid;not null" json:"video_id"`
	User      User    `gorm:"foreignkey:UserID;" json:"user,omitempty"`
	UserID    uint    `gorm:"column:user_id;index:idx_userid;not null" json:"user_id"`
}

FavoriteCommentRelation

@Description: 用户与评论的点赞关系数据模型

func GetFavoriteCommentRelationByUserCommentID

func GetFavoriteCommentRelationByUserCommentID(ctx context.Context, userID int64, commentID int64) (*FavoriteCommentRelation, error)

GetFavoriteCommentRelationByUserCommentID

@Description: 获取评论的点赞关系
@Date 2023-02-17 21:28:00
@param ctx 数据库操作上下文
@param userID 用户ID
@param commentID 评论ID
@return *FavoriteCommentRelation 评论点赞关系
@return error

func (FavoriteCommentRelation) TableName

func (FavoriteCommentRelation) TableName() string

type FavoriteVideoRelation

type FavoriteVideoRelation struct {
	Video   Video `gorm:"foreignkey:VideoID;" json:"video,omitempty"`
	VideoID uint  `gorm:"index:idx_videoid;not null" json:"video_id"`
	User    User  `gorm:"foreignkey:UserID;" json:"user,omitempty"`
	UserID  uint  `gorm:"index:idx_userid;not null" json:"user_id"`
}

FavoriteVideoRelation

@Description: 用户与视频的点赞关系数据模型

func GetAllFavoriteList

func GetAllFavoriteList(ctx context.Context) ([]*FavoriteVideoRelation, error)

GetAllFavoriteList

@Description: 获取全部的点赞关系列表
@Date 2023-02-17 16:15:00
@param ctx 数据库操作上下文
@return []*FavoriteVideoRelation 所有的点赞关系列表
@return error

func GetFavoriteListByUserID

func GetFavoriteListByUserID(ctx context.Context, userID int64) ([]*FavoriteVideoRelation, error)

GetFavoriteListByUserID

@Description: 根据用户id获取用户的点赞关系列表
@Date 2023-01-21 17:08:52
@param ctx 数据库操作上下文
@param userID 用户id
@return []*FavoriteVideoRelation 点赞关系列表
@return error

func GetFavoriteVideoRelationByUserVideoID

func GetFavoriteVideoRelationByUserVideoID(ctx context.Context, userID int64, videoID int64) (*FavoriteVideoRelation, error)

GetFavoriteVideoRelationByUserVideoID

@Description: 获取用户与视频之间的点赞关系
@Date 2023-01-21 16:49:38
@param ctx 数据库操作上下文
@param userID 用户id
@param videoID 视频id
@return *Video 视频数据
@return error

func (FavoriteVideoRelation) TableName

func (FavoriteVideoRelation) TableName() string

type FollowRelation

type FollowRelation struct {
	gorm.Model
	User     User `gorm:"foreignkey:UserID;" json:"user,omitempty"`
	UserID   uint `gorm:"index:idx_userid;not null" json:"user_id"`
	ToUser   User `gorm:"foreignkey:ToUserID;" json:"to_user,omitempty"`
	ToUserID uint `gorm:"index:idx_userid;index:idx_userid_to;not null" json:"to_user_id"`
}

FollowRelation

@Description: 用户之间的关注关系数据模型

func GetFollowerListByUserID

func GetFollowerListByUserID(ctx context.Context, toUserID int64) ([]*FollowRelation, error)

GetFollowerListByUserID

@Description: 获取指定用户的粉丝关系列表
@Date 2023-01-21 17:01:45
@param ctx 数据库操作上下文
@param toUserID 指定用户的用户id
@return []*Relation 指定用户的粉丝关系列表
@return error

func GetFollowingListByUserID

func GetFollowingListByUserID(ctx context.Context, userID int64) ([]*FollowRelation, error)

GetFollowingListByUserID

@Description: 获取指定用户的关注关系列表
@Date 2023-01-21 17:01:40
@param ctx 数据库操作上下文
@param userID 指定用户的用户id
@return []*Relation 指定用户的关注关系列表
@return error

func GetFriendList

func GetFriendList(ctx context.Context, userID int64) ([]*FollowRelation, error)

func GetRelationByUserIDs

func GetRelationByUserIDs(ctx context.Context, userID int64, toUserID int64) (*FollowRelation, error)

GetRelationByUserIDs

@Description: 获取用户之间的关注关系
@Date 2023-01-21 16:45:47
@param ctx 数据库操作上下文
@param userID 用户id
@param toUserID 被关注用户的用户id
@return *Relation 用户关注关系数据
@return error

func (FollowRelation) TableName

func (FollowRelation) TableName() string

type Message

type Message struct {
	ID         uint      `gorm:"primarykey"`
	CreatedAt  time.Time `gorm:"index;not null" json:"create_time"`
	UpdatedAt  time.Time
	DeletedAt  gorm.DeletedAt `gorm:"index"`
	FromUser   User           `gorm:"foreignkey:FromUserID;" json:"from_user,omitempty"`
	FromUserID uint           `gorm:"index:idx_userid_from;not null" json:"from_user_id"`
	ToUser     User           `gorm:"foreignkey:ToUserID;" json:"to_user,omitempty"`
	ToUserID   uint           `gorm:"index:idx_userid_from;index:idx_userid_to;not null" json:"to_user_id"`
	Content    string         `gorm:"type:varchar(255);not null" json:"content"`
}

Message

@Description: 聊天消息数据模型

func GetFriendLatestMessage

func GetFriendLatestMessage(ctx context.Context, userID int64, toUserID int64) (*Message, error)

func GetMessageByID

func GetMessageByID(ctx context.Context, messageID int64) (*Message, error)

GetMessageByID

@Description: 根据消息ID查询消息
@Date 2023-01-21 17:13:26
@param ctx 数据库操作上下文
@param messageID 消息ID列表
@return error

func GetMessageIDsByUserIDs

func GetMessageIDsByUserIDs(ctx context.Context, userID int64, toUserID int64) ([]*Message, error)

GetMessageIDsByUserIDs

@Description: 查询消息ID
@Date 2023-01-21 17:13:26
@param ctx 数据库操作上下文
@param userID 发送用户
@param toUserID 接收用户
@return error

func GetMessagesByUserIDs

func GetMessagesByUserIDs(ctx context.Context, userID int64, toUserID int64, lastTimestamp int64) ([]*Message, error)

GetMessagesByUserIDs

	@Description: 根据两个用户的用户id获取聊天信息记录
	@Date 2023-01-25 11:37:08
	@param ctx 数据库操作上下文
	@param userID 主用户id
	@param toUserID 对象用户id
 @param lastTimestamp 要查询消息时间的下限
	@return []*Message 聊天信息数据列表
	@return error

func GetMessagesByUserToUser

func GetMessagesByUserToUser(ctx context.Context, userID int64, toUserID int64, lastTimestamp int64) ([]*Message, error)

func (Message) TableName

func (Message) TableName() string

type User

type User struct {
	gorm.Model
	UserName        string  `gorm:"index:idx_username,unique;type:varchar(40);not null" json:"name,omitempty"`
	Password        string  `gorm:"type:varchar(256);not null" json:"password,omitempty"`
	FavoriteVideos  []Video `gorm:"many2many:user_favorite_videos" json:"favorite_videos,omitempty"`
	FollowingCount  uint    `gorm:"default:0;not null" json:"follow_count,omitempty"`                                                           // 关注总数
	FollowerCount   uint    `gorm:"default:0;not null" json:"follower_count,omitempty"`                                                         // 粉丝总数
	Avatar          string  `gorm:"type:varchar(256)" json:"avatar,omitempty"`                                                                  // 用户头像
	BackgroundImage string  `gorm:"column:background_image;type:varchar(256);default:default_background.jpg" json:"background_image,omitempty"` // 用户个人页顶部大图
	WorkCount       uint    `gorm:"default:0;not null" json:"work_count,omitempty"`                                                             // 作品数
	FavoriteCount   uint    `gorm:"default:0;not null" json:"favorite_count,omitempty"`                                                         // 喜欢数
	TotalFavorited  uint    `gorm:"default:0;not null" json:"total_favorited,omitempty"`                                                        // 获赞总量
	Signature       string  `gorm:"type:varchar(256)" json:"signature,omitempty"`                                                               // 个人简介
}

User

@Description: 用户数据模型

func GetPasswordByUsername

func GetPasswordByUsername(ctx context.Context, userName string) (*User, error)

根据用户名获取密码

func GetUserByID

func GetUserByID(ctx context.Context, userID int64) (*User, error)

GetUserByID

@Description: 根据用户id获取用户数据
@Date 2023-01-21 17:12:54
@param ctx 数据库操作上下文
@param userID 用户id
@return *User 用户数据
@return error

func GetUserByName

func GetUserByName(ctx context.Context, userName string) (*User, error)

GetUserByName

@Description: 根据用户名获取用户数据列表
@Date 2023-01-21 17:15:17
@param ctx 数据库操作上下文
@param userName 用户名
@return []*User 用户数据列表
@return error

func GetUsersByIDs

func GetUsersByIDs(ctx context.Context, userIDs []int64) ([]*User, error)

GetUsersByIDs

@Description: 根据用户id列表获取用户列表
@Date 2023-01-21 17:11:13
@param ctx 数据库操作上下文
@param userIDs 用户id列表
@return []*User 用户列表
@return error

func (User) TableName

func (User) TableName() string

type Video

type Video struct {
	ID            uint      `gorm:"primarykey"`
	CreatedAt     time.Time `gorm:"not null;index:idx_create" json:"created_at,omitempty"`
	UpdatedAt     time.Time
	DeletedAt     gorm.DeletedAt `gorm:"index"`
	Author        User           `gorm:"foreignkey:AuthorID" json:"author,omitempty"`
	AuthorID      uint           `gorm:"index:idx_authorid;not null" json:"author_id,omitempty"`
	PlayUrl       string         `gorm:"type:varchar(255);not null" json:"play_url,omitempty"`
	CoverUrl      string         `gorm:"type:varchar(255)" json:"cover_url,omitempty"`
	FavoriteCount uint           `gorm:"default:0;not null" json:"favorite_count,omitempty"`
	CommentCount  uint           `gorm:"default:0;not null" json:"comment_count,omitempty"`
	Title         string         `gorm:"type:varchar(50);not null" json:"title,omitempty"`
}

Video

@Description: 视频数据模型

func GetVideoById

func GetVideoById(ctx context.Context, videoID int64) (*Video, error)

GetVideoById

@Description: 根据视频id获取视频
@Date 2023-01-24 15:58:52
@param ctx 数据库操作上下文
@param videoID 视频id
@return *Video 视频数据
@return error

func GetVideoListByIDs

func GetVideoListByIDs(ctx context.Context, videoIDs []int64) ([]*Video, error)

GetVideoListByIDs

@Description: 根据视频id列表获取视频列表
@Date 2023-01-24 16:00:12
@param ctx 数据库操作上下文
@param videoIDs 视频id列表
@return []*Video 视频数据列表
@return error

func GetVideosByUserID

func GetVideosByUserID(ctx context.Context, authorId int64) ([]*Video, error)

GetVideosByUserID

@Description: 获取用户发布的视频列表
@Date 2023-01-21 16:28:44
@param ctx 数据库操作上下文
@param authorId 作者的用户id
@return []*Video 视频列表
@return error

func MGetVideos

func MGetVideos(ctx context.Context, limit int, latestTime *int64) ([]*Video, error)

MGetVideos

@Description: 获取最近发布的视频
@Date 2023-01-21 16:39:00
@param ctx
@param limit 获取的视频条数
@param latestTime 最早的时间限制
@return []*Video 视频列表
@return error

func (Video) TableName

func (Video) TableName() string

Jump to

Keyboard shortcuts

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