model

package
v0.0.0-...-f1d9293 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Db *gorm.DB

Functions

func CheckUser

func CheckUser(username string) bool

func GetDB

func GetDB() *gorm.DB

GetDB:返回db

func InitDB

func InitDB() *gorm.DB

TODO:支持redis

Types

type Comment

type Comment struct {
	ID      int64  `gorm:"column:id;primary_key;AUTO_INCREMENT;not null"`
	Content string `gorm:"not null"`
	UserID  int64  `gorm:"not null"` //评论者的id
	VideoID int64  `gorm:"not null"` //被评论视频的id
}

Comment:视频评论

type User

type User struct {
	ID            int64 `gorm:"column:id;primary_key;AUTO_INCREMENT;not null"`
	Username      string
	Password_Hash string // 加密后的密码
	//用户关注列表,多对多,gorm自动生成一个中间表
	Follows []*User `gorm:"many2many:user_follows;association_jointable_foreignkey:follow_id"` //该用户的关注
	//粉丝列表,多对多,同样自动生成一个中间表
	Followers []*User `gorm:"many2many:user_followers;association_jointable_foreignkey:follower_id"` //该用户的粉丝
	//用户发布的视频,通过视频表的作者id作为外键关联
	Videos []Video `gorm:"foreignkey:AuthorID"` //该用户发布的作品
	//用户点赞过的视频,多对多,生成一个中间表,
	FavoriteVideos []Video `gorm:"many2many:user_favorite;association_jointable_foreignkey:favorite_id"` //用户点赞过的作品
}

User_info:用户信息

func SaveUser

func SaveUser(username, password_hash string) (*User, error)

type Video

type Video struct {
	ID             int64 `gorm:"column:id;primary_key;AUTO_INCREMENT;not null"`
	Title          string
	AuthorID       int64  //作者id
	UpdateTime     int64  //发布、更新时间
	Location       string //储存位置
	Cover_location string //封面储存位置
	// PlayLocation   string //视频播放地址
	//视频评论,通过评论表的用户id作为外键关联
	Comments []Comment `gorm:"foreignkey:UserID"` //视频的评论
}

Video:视频信息

Jump to

Keyboard shortcuts

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