db

package
v0.0.0-...-13a9a9d Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: Apache-2.0 Imports: 7 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

Functions

func AddNewComment

func AddNewComment(comment *Comment) error

AddNewComment add a comment

func AddNewFavorite

func AddNewFavorite(favorite *Favorites) (bool, error)

AddNewFavorite add favorite relation

func AddNewFollow

func AddNewFollow(follow *Follows) (bool, error)

func AddNewMessage

func AddNewMessage(message *Messages) (bool, error)

AddNewMessage add a message and check if the id exists

func CheckCommentExist

func CheckCommentExist(comment_id int64) (bool, error)

func CheckUserExistById

func CheckUserExistById(user_id int64) (bool, error)

CheckUserExistById find if user exists

func CheckVideoExistById

func CheckVideoExistById(video_id int64) (bool, error)

CheckVideoExistById query if video exist

func CreateUser

func CreateUser(user *User) (int64, error)

CreateUser create user info

func CreateVideo

func CreateVideo(video *Video) (Video_id int64, err error)

func DeleteCommentById

func DeleteCommentById(comment_id int64) error

DeleteCommentById delete comment by comment id

func DeleteFavorite

func DeleteFavorite(favorite *Favorites) (bool, error)

DeleteFavorite delete favorite relation

func DeleteFollow

func DeleteFollow(follow *Follows) (bool, error)

DeleteFollow delete follow relation in db and update redis

func GetCommentCountByVideoID

func GetCommentCountByVideoID(video_id int64) (int64, error)

func GetFavoriteCount

func GetFavoriteCount(video_id int64) (int64, error)

GetFavoriteCount count the favorite of video

func GetFavoriteCountByUserID

func GetFavoriteCountByUserID(user_id int64) (int64, error)

GetFavoriteCountByUserID get the num of the video liked by user

func GetFavoriteIdList

func GetFavoriteIdList(user_id int64) ([]int64, error)

GetFavoriteIdList get the id list of video liked by the user

func GetFavoriterIdList

func GetFavoriterIdList(video_id int64) ([]int64, error)

GetFavoriterIdList get the id list of liker of video

func GetFollowCount

func GetFollowCount(follower_id int64) (int64, error)

GetFollowCount query the number of users following

func GetFollowIdList

func GetFollowIdList(follower_id int64) ([]int64, error)

GetFollowIdList find user_id follow id list in db or rdb

func GetFollowerCount

func GetFollowerCount(user_id int64) (int64, error)

GetFollowerCount query the number of followers of a user

func GetFollowerIdList

func GetFollowerIdList(user_id int64) ([]int64, error)

GetFollowerIdList get follower id list in db or rdb

func GetFriendIdList

func GetFriendIdList(user_id int64) ([]int64, error)

func GetWorkCount

func GetWorkCount(user_id int64) (int64, error)

GetWorkCount get the num of video published by the user

func Init

func Init()

Init init DB

func QueryFavoriteExist

func QueryFavoriteExist(user_id, video_id int64) (bool, error)

QueryFavoriteExist query the like record by video_id and user_id

func QueryFollowExist

func QueryFollowExist(user_id, follower_id int64) (bool, error)

QueryFollowExist check the relation of user and follower

func QueryTotalFavoritedByAuthorID

func QueryTotalFavoritedByAuthorID(author_id int64) (int64, error)

QueryTotalFavoritedByAuthorID query the like num of all the video published by the user

func VerifyUser

func VerifyUser(userName, password string) (int64, error)

VerifyUser verify username and password in the db

Types

type Comment

type Comment struct {
	ID          int64          `json:"id"`
	UserId      int64          `json:"user_id"`
	VideoId     int64          `json:"video_id"`
	CommentText string         `json:"comment_text"`
	CreatedAt   time.Time      `json:"created_at"`
	DeletedAt   gorm.DeletedAt `gorm:"index" json:"deleted_at"`
}

func GetCommentListByVideoID

func GetCommentListByVideoID(video_id int64) ([]*Comment, error)

func (Comment) TableName

func (Comment) TableName() string

TableName set table name to make gorm can correctly identify

type Favorites

type Favorites struct {
	ID        int64          `json:"id"`
	UserId    int64          `json:"user_id"`
	VideoId   int64          `json:"video_id"`
	CreatedAt time.Time      `json:"create_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"delete_at"`
}

func (Favorites) TableName

func (Favorites) TableName() string

TableName set table name to make gorm can correctly identify

type Follows

type Follows struct {
	ID         int64          `json:"id"`
	UserId     int64          `json:"user_id"`
	FollowerId int64          `json:"follower_id"`
	CreatedAt  time.Time      `json:"create_at"`
	DeletedAt  gorm.DeletedAt `gorm:"index" json:"delete_at"`
}

Follows follower is fan of user

func (Follows) TableName

func (Follows) TableName() string

TableName set table name to make gorm can correctly identify

type Messages

type Messages struct {
	ID         int64     `json:"id"`
	ToUserId   int64     `json:"to_user_id"`
	FromUserId int64     `json:"from_user_id"`
	Content    string    `json:"content"`
	CreatedAt  time.Time `json:"created_at"`
}

func GetLatestMessageByIdPair

func GetLatestMessageByIdPair(user_id1, user_id2 int64) (*Messages, error)

GetLatestMessageByIdPair query the last message user1 and user2 in the database

func GetMessageByIdPair

func GetMessageByIdPair(user_id1, user_id2 int64, pre_msg_time time.Time) ([]Messages, error)

GetMessageByIdPair get the chat history after a certain time

func (Messages) TableName

func (Messages) TableName() string

type User

type User struct {
	ID              int64  `json:"id"`
	UserName        string `json:"user_name"`
	Password        string `json:"password"`
	Avatar          string `json:"avatar"`
	BackgroundImage string `json:"background_image"`
	Signature       string `json:"signature"`
}

func QueryUser

func QueryUser(userName string) (*User, error)

QueryUser query User by user_name

func QueryUserById

func QueryUserById(user_id int64) (*User, error)

QueryUserById get user in the database by user id

func (User) TableName

func (User) TableName() string

type Video

type Video struct {
	ID          int64
	AuthorID    int64
	PlayURL     string
	CoverURL    string
	PublishTime time.Time
	Title       string
}

func GetVideoByUserID

func GetVideoByUserID(user_id int64) ([]*Video, error)

func GetVideoListByVideoIDList

func GetVideoListByVideoIDList(video_id_list []int64) ([]*Video, error)

func GetVideosByLastTime

func GetVideosByLastTime(lastTime time.Time) ([]*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