db

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DB     *gorm.DB
	Config = ttviper.ConfigInit("TIKTOK_DB", "dbConfig")
)

Functions

func CreateUser

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

CreateUser create user info

func CreateVideo

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

CreateVideo creates a new video

func DelComment

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

DelComment deletes a comment from the database.

func DisFavorite

func DisFavorite(ctx context.Context, uid int64, vid int64) error

DisFavorite deletes the specified favorite from the database

func DisRelation

func DisRelation(ctx context.Context, uid int64, tid int64) error

DisRelation deletes a relation from the database.

func Favorite

func Favorite(ctx context.Context, uid int64, vid int64) error

Favorite new favorite data.

func Init

func Init()

func InitDB

func InitDB()

Init init DB

func NewComment

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

NewComment creates a new Comment

func NewRelation

func NewRelation(ctx context.Context, uid int64, tid int64) error

NewRelation creates a new Relation

Types

type Comment

type Comment struct {
	gorm.Model
	Video   Video  `gorm:"foreignkey:VideoID"`
	VideoID int    `gorm:"index:idx_videoid;not null"`
	User    User   `gorm:"foreignkey:UserID"`
	UserID  int    `gorm:"index:idx_userid;not null"`
	Content string `gorm:"type:varchar(255);not null"`
}

func GetVideoComments

func GetVideoComments(ctx context.Context, vid int64) ([]*Comment, error)

GetVideoComments returns a list of video comments.

func (Comment) TableName

func (Comment) TableName() string

type Relation

type Relation struct {
	gorm.Model
	User     User `gorm:"foreignkey:UserID;"`
	UserID   int  `gorm:"index:idx_userid,unique;not null"`
	ToUser   User `gorm:"foreignkey:ToUserID;"`
	ToUserID int  `gorm:"index:idx_userid,unique;index:idx_userid_to;not null"`
}

Relation Gorm data structure

func FollowerList

func FollowerList(ctx context.Context, tid int64) ([]*Relation, error)

FollowerList returns the Follower List.

func FollowingList

func FollowingList(ctx context.Context, uid int64) ([]*Relation, error)

FollowingList returns the Following List.

func GetRelation

func GetRelation(ctx context.Context, uid int64, tid int64) (*Relation, error)

GetRelation get relation info

func (Relation) TableName

func (Relation) TableName() string

type User

type User struct {
	gorm.Model
	UserName       string  `gorm:"index:idx_username,unique;type:varchar(40);not null" json:"username"`
	Password       string  `gorm:"type:varchar(256);not null" json:"password"`
	FavoriteVideos []Video `gorm:"many2many:user_favorite_videos" json:"favorite_videos"`
	FollowingCount int     `gorm:"default:0" json:"following_count"`
	FollowerCount  int     `gorm:"default:0" json:"follower_count"`
}

User Gorm Data Structures

func GetUserByID

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

GetUserByID multiple get list of user info

func MGetUsers

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

MGetUsers multiple get list of user info

func QueryUser

func QueryUser(ctx context.Context, userName string) ([]*User, error)

QueryUser query list of user info

func (User) TableName

func (User) TableName() string

type Video

type Video struct {
	gorm.Model
	UpdatedAt     time.Time `gorm:"column:update_time;not null;index:idx_update" `
	Author        User      `gorm:"foreignkey:AuthorID"`
	AuthorID      int       `gorm:"index:idx_authorid;not null"`
	PlayUrl       string    `gorm:"type:varchar(255);not null"`
	CoverUrl      string    `gorm:"type:varchar(255)"`
	FavoriteCount int       `gorm:"default:0"`
	CommentCount  int       `gorm:"default:0"`
	Title         string    `gorm:"type:varchar(50);not null"`
}

Video Gorm Data Structures

func FavoriteList

func FavoriteList(ctx context.Context, uid int64) ([]Video, error)

FavoriteList returns a list of Favorite videos.

func GetFavoriteRelation

func GetFavoriteRelation(ctx context.Context, uid int64, vid int64) (*Video, error)

GetFavoriteRelation get favorite video info

func MGetVideos

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

MGetVideoss multiple get list of videos info

func PublishList

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

PublishList returns a list of videos with AuthorID.

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