model

package
v0.0.0-...-c6f1323 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckUserExist

func CheckUserExist(username string) (bool, error)

CheckUserExist 判断用户是否存在 如果存在返回true,不存在返回false

func GetIdByUsername

func GetIdByUsername(username string) uint

GetIdByUsername 通过username获取userid

func NewDBEngine

func NewDBEngine(databaseSetting *setting.DatabaseSettingS) (*gorm.DB, error)

func TimeStampForUpdateCallback

func TimeStampForUpdateCallback(db *gorm.DB)

修改内容时回调

func UpTimestampForCreateCallback

func UpTimestampForCreateCallback(db *gorm.DB)

新建时自动添加时间 回调

Types

type Articles

type Articles struct {
	BaseModel
	Title   string `json:"title"`   // 文章标题
	Author  string `json:"author"`  // 作者
	Content string `json:"content"` // 文章内容
	//MarkdownUrl string `json:"markdown_url"`                                // markdown上传后得到的url
	Tags     *[]Tag    `gorm:"many2many:articles_tags" json:"tags,omitempty"` // 标签
	Category *Category `json:"category,omitempty"`                            // 分类
	UserID   uint      `json:"user_id,omitempty"`
	Comments []Comment `json:"comments,omitempty"` // 评论
}

func NewArticles

func NewArticles() Articles

func (*Articles) Count

func (a *Articles) Count() int64

文章数量计数

func (*Articles) Create

func (a *Articles) Create() bool

新建文章 必须传递指针参数才能改变原值

func (*Articles) Delete

func (a *Articles) Delete()

删除文章

func (*Articles) GetTag

func (a *Articles) GetTag() *[]Tag

GetTag 获取文章拥有的标签列表

func (*Articles) Info

func (a *Articles) Info() (err error)

获取文章信息

func (*Articles) List

func (a *Articles) List(pageOffset, pageSize int) []*Articles

批量文章查询

func (*Articles) MarkdownToHtml

func (a *Articles) MarkdownToHtml()

Markdown渲染为Html

func (*Articles) NewCreate

func (a *Articles) NewCreate(token string) error

new 新建文章 必须传递指针才能改变原值

func (Articles) TableName

func (a Articles) TableName() string

func (*Articles) Update

func (a *Articles) Update()

更新文章

type Auth

type Auth struct {
	BaseModel
	Username string `json:"username"`
	Password string `json:"password"`
}

func (Auth) Create

func (a Auth) Create(u User)

对数据库进行写入

func (Auth) Get

func (a Auth) Get() (Auth, error)

对数据库进行查询,返回结构体和查询情况

func (Auth) TableName

func (receiver Auth) TableName() string

type BaseModel

type BaseModel struct {
	*gorm.DB  `gorm:"-" json:"-"`
	ID        uint           `gorm:"primary_key" json:"id,omitempty"`
	CreatedAt time.Time      `json:"created_at,omitempty"` // 时间日期直接按照字符串处理即可
	UpdatedAt time.Time      `json:"updated_at,omitempty"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
}

BaseModel 创建基本类型

type Category

type Category struct {
	BaseModel
	CategoryName string `json:"category_name,omitempty"`
	ArticlesID   uint   `json:"articles_id,omitempty"`
}

type Comment

type Comment struct {
	*BaseModel
	UserID     uint   `json:"user_id"` // 发布评论的用户id
	Content    string `json:"content"` // 评论内容
	Root       int    `json:"root"`    // 根评论id,不为0即是回复评论
	Parent     uint   `json:"parent"`  // 父评论id 为0 是root评论
	ArticlesID uint   `json:"articles_id"`
}

func (*Comment) Create

func (c *Comment) Create() error

func (*Comment) List

func (c *Comment) List()

查询文章下的所有评论

func (*Comment) ListParent

func (c *Comment) ListParent()

只查询父评论

func (*Comment) ListSon

func (c *Comment) ListSon()

查询指定父评论下的子评论

type Profile

type Profile struct {
	BaseModel
	Desc   string `gorm:"default:;" json:"desc"`
	Img    string `gorm:"default:;" json:"img"`
	UserId uint   `json:"user_id"`
}

func (Profile) TableName

func (p Profile) TableName() string

type Tag

type Tag struct {
	BaseModel
	TagName string `json:"tag_name,omitempty"`
}

type User

type User struct {
	BaseModel
	RoleId      string `json:"role_id"`
	Password    string `json:"password"  binding:"required"`
	Signature   string `json:"signature"`
	Username    string `gorm:"unique" json:"username"  binding:"required"`
	SnowFlakeId int64
	Profile     Profile    `json:"profile"`
	Articles    []Articles // 文章
}

func (User) Login

func (u User) Login() (User, error)

func (User) Register

func (u User) Register() (User, error)

func (User) TableName

func (u User) TableName() string

Jump to

Keyboard shortcuts

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