model

package
v0.0.0-...-830fbbb Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SharedDB *gorm.DB

SharedDB - Shared gorm connection instance

Functions

func InitDB

func InitDB() *gorm.DB

InitDB - Initializing SharedDB instance

func PostOrder

func PostOrder(db *gorm.DB) *gorm.DB

PostOrder - scope for post order.

func ReplyOrder

func ReplyOrder(db *gorm.DB) *gorm.DB

ReplyOrder - scope for reply order.

Types

type Media

type Media struct {
	PublicModel

	Type MediaType
	// Image or video source URL
	RawSrc *string `gorm:"type:text"`

	UUID     uuid.UUID `gorm:"type:char(36);unique_index;not null"`
	FileType string
	Height   uint
	Width    uint

	Posts []Post `gorm:"many2many:post_media_map"`
}

Media - the model of image/video

type MediaType

type MediaType int

MediaType - the Media type deinifition

const (
	// MediaTypeImage - Post is image
	MediaTypeImage MediaType = 0
	// MediaTypeVideo - Post is video
	MediaTypeVideo MediaType = 1
)

type Post

type Post struct {
	PublicModel

	UUID     uuid.UUID `gorm:"type:char(36);unique_index;not null"`
	TopicID  uint      `json:"-"`
	Topic    Topic     `json:"-"`
	ParentID *uint     `json:"-"`
	Parent   *Post
	Message  *string `gorm:"type:mediumtext"`

	Medias  []Media `gorm:"many2many:post_media_map"`
	Replies []Post  `gorm:"foreignkey:parent_id"`
}

Post under the topic

type PublicModel

type PublicModel struct {
	ID        uint `gorm:"primary_key" json:"-"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time `sql:"index" json:"-"`
}

PublicModel base model definition but not output to JSON

type Topic

type Topic struct {
	PublicModel

	Order uint   `gorm:"not null"`
	Name  string `gorm:"not null"`
	Code  string `gorm:"unique_index;not null"`
}

Topic of chats

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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