mysql

package
v0.0.0-...-f9b5f64 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DB *gorm.DB
)

Functions

func CreateComment

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

func CreateMessagesByList

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

func CreateRelation

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

func CreateUser

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

func CreateVideo

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

func CreateVideoFavorite

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

func DelCommentByID

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

func DelFavoriteByUserVideoID

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

func DelRelationByUserIDs

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

func DelVideoByID

func DelVideoByID(ctx context.Context, videoID int64, authorID int64) 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"`
}

func GetCommentByCommentID

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

func GetVideoCommentListByVideoID

func GetVideoCommentListByVideoID(ctx context.Context, videoID int64) ([]*Comment, 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"`
}

func GetFavoriteCommentRelationByUserCommentID

func GetFavoriteCommentRelationByUserCommentID(ctx context.Context, userID int64, commentID int64) (*FavoriteCommentRelation, 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"`
}

func GetAllFavoriteList

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

func GetFavoriteListByUserID

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

func GetFavoriteVideoRelationByUserVideoID

func GetFavoriteVideoRelationByUserVideoID(ctx context.Context, userID int64, videoID int64) (*FavoriteVideoRelation, 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"`
}

func GetFollowerListByUserID

func GetFollowerListByUserID(ctx context.Context, toUserID int64) ([]*FollowRelation, 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)

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"`
}

func GetFriendLatestMessage

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

func GetMessageByID

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

func GetMessageIDsByUserIDs

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

func GetMessagesByUserIDs

func GetMessagesByUserIDs(ctx context.Context, userID int64, toUserID int64, lastTimestamp int64) ([]*Message, 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"`                                                               // 个人简介
}

func GetUserByID

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

func GetUserByUserName

func GetUserByUserName(ctx context.Context, username string) (*User, error)

func GetUsersByIDs

func GetUsersByIDs(ctx context.Context, userIDs []int64) ([]*User, 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"`
}

func GetVideoById

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

func GetVideoListByIDs

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

func GetVideosByUserID

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

func MGetVideos

func MGetVideos(ctx context.Context, limit int, latestTime *int64) ([]*Video, 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