model

package
v0.0.0-...-5952180 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const ArticleStatusDraft = 1 // 草稿
View Source
const ArticleStatusPublished = 2 // 发布
View Source
const CommentStatusHidden = 2 // 隐藏
View Source
const CommentStatusNormal = 1 // 展示
View Source
const TagStatusHidden = 2 // 禁用
View Source
const TagStatusNormal = 1 // 正常
View Source
const UserTypeAdmin = 1 // 管理员
View Source
const UserTypeUser = 2 // 前台用户

Variables

This section is empty.

Functions

func NewDBEngine

func NewDBEngine(dbSetting *setting.DatabaseSetting) (*gorm.DB, error)

Types

type Article

type Article struct {
	Model
	Title         string `json:"title"`
	Sketch        string `json:"sketch"`
	Content       string `json:"content"`
	TagId         int    `json:"tagId"`
	Weight        int    `json:"weight"`
	ArticleStatus int    `json:"articleStatus"`
	Tag           Tag    `json:"tag" gorm:"foreignKey:TagId"`
}

func (Article) TableName

func (t Article) TableName() string

TableName 会将 的表名重写

type Comment

type Comment struct {
	Model
	ArticleId     int    `json:"articleId"`
	UserId        int    `json:"userId"`
	MentionUserId int    `json:"mentionUserId"`
	Content       string `json:"content"`
	CommentStatus int    `json:"commentStatus"`
	User          User   `json:"user" gorm:"foreignKey:UserId"`
	MentionUser   User   `json:"mentionUser" gorm:"foreignKey:MentionUserId"`
}

func (Comment) TableName

func (t Comment) TableName() string

TableName 会将 的表名重写

type Model

type Model struct {
	Id        int            `json:"id" gorm:"primary_key"`
	CreatedAt util.JSONTime  `json:"createdAt" gorm:"autoCreateTime:milli"` // 创建时间 datetime
	UpdatedAt util.JSONTime  `json:"updatedAt" gorm:"autoUpdateTime:milli"` // 更新时间 datetime
	DeletedAt gorm.DeletedAt `json:"-"`                                     // 软删除字段(可以为NULL)  datetime
}

func (*Model) BeforeCreate

func (model *Model) BeforeCreate(db *gorm.DB) error

func (*Model) BeforeUpdate

func (model *Model) BeforeUpdate(db *gorm.DB) error

type Tag

type Tag struct {
	Model
	TagName   string `json:"tagName"`
	Weight    int    `json:"weight"`
	TagStatus int    `json:"tagStatus"`
}

func (Tag) TableName

func (t Tag) TableName() string

TableName 会将 的表名重写

type User

type User struct {
	Model
	Username string `json:"username"`
	Email    string `json:"email"`
	Pwd      string `json:"-"`
	UserType int    `json:"userType"`
}

func (User) TableName

func (t User) TableName() string

TableName 会将 的表名重写

Jump to

Keyboard shortcuts

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