models

package
v0.0.0-...-56c8062 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STATE_OPEN  = 1
	STATE_CLOSE = 0
)

资源启用标志

Variables

This section is empty.

Functions

func NewDBEngine

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

Types

type Article

type Article struct {
	*Model
	Title         string `json:"title"`
	Description   string `json:"description"`
	Content       string `json:"content"`
	CoverImageUrl string `json:"cover_image_url"`
	State         uint8  `json:"state"`
}

func (Article) CountByTagID

func (a Article) CountByTagID(db *gorm.DB, tagID uint32) (int, error)

根据 TagID 统计文章数量

func (Article) Create

func (a Article) Create(db *gorm.DB) (*Article, error)

func (Article) Delete

func (a Article) Delete(db *gorm.DB) error

func (Article) Get

func (a Article) Get(db *gorm.DB) (Article, error)

func (Article) ListByTagID

func (a Article) ListByTagID(db *gorm.DB, tagID uint32, pageOffset, pageSize int) ([]*ArticleRow, error)

根据 TagID 获取文章列表 利用 Gorm 调用 Pg/MySql 注意两者 SQL 语法差异

func (Article) TableName

func (a Article) TableName() string

func (Article) Update

func (a Article) Update(db *gorm.DB, values interface{}) error

type ArticleRow

type ArticleRow struct {
	ArticleID          uint32
	TagID              uint32
	TagName            string
	ArticleTitle       string
	ArticleDescription string
	CoverImageUrl      string
	Content            string
}

type ArticleSwagger

type ArticleSwagger struct {
	List  []*Article
	Pager *app.Pager
}

type ArticleTag

type ArticleTag struct {
	*Model
	ArticleID uint32 `json:"article_id"`
	TagID     uint32 `json:"tag_id"`
}

func (ArticleTag) Create

func (a ArticleTag) Create(db *gorm.DB) error

func (ArticleTag) Delete

func (a ArticleTag) Delete(db *gorm.DB) error

func (ArticleTag) DeleteOne

func (a ArticleTag) DeleteOne(db *gorm.DB) error

func (ArticleTag) GetByArticleID

func (a ArticleTag) GetByArticleID(db *gorm.DB) (ArticleTag, error)

func (ArticleTag) ListByArticleIDs

func (a ArticleTag) ListByArticleIDs(db *gorm.DB, articleIDs []uint32) ([]*ArticleTag, error)

根据文章ID列表获取文章标签列表

func (ArticleTag) ListByTagID

func (a ArticleTag) ListByTagID(db *gorm.DB) ([]*ArticleTag, error)

func (ArticleTag) TableName

func (a ArticleTag) TableName() string

func (ArticleTag) UpdateOne

func (a ArticleTag) UpdateOne(db *gorm.DB, values interface{}) error

type Auth

type Auth struct {
	*Model
	AppKey    string `json:"app_key"`
	AppSecret string `json:"app_secret"`
}

func (Auth) Get

func (a Auth) Get(db *gorm.DB) (Auth, error)

验证传入的认证信息

func (Auth) TableName

func (a Auth) TableName() string

type Model

type Model struct {
	ID         uint32         `gorm:"primary_key" json:"id"`
	CreatedBy  string         `json:"created_by"`
	ModifiedBy string         `json:"modified_by"`
	CreatedAt  time.Time      `json:"created_at"`
	UpdatedAt  time.Time      `json:"updated_at"`
	DeletedAt  gorm.DeletedAt `gorm:"index" json:"deleted_at"`
	IsDel      uint8          `json:"is_del"`
}

公共字段设置为 CreatedAt, ModifiedAt, DeletedAt 时 Gorm 可以自动更新 IsDel 软删除标记, ID 主键, State 状态标记, 表示是否启用资源

type Tag

type Tag struct {
	*Model
	Name  string `json:"name"`
	State uint8  `json:"state"`
}

func (Tag) Count

func (t Tag) Count(db *gorm.DB) (int, error)

统计符合条件的 Tag 数量

func (Tag) Create

func (t Tag) Create(db *gorm.DB) error

func (Tag) Delete

func (t Tag) Delete(db *gorm.DB) error

func (Tag) Get

func (t Tag) Get(db *gorm.DB) (Tag, error)

根据 ID 获取 Tag

func (Tag) List

func (t Tag) List(db *gorm.DB, pageOffset, pageSize int) ([]*Tag, error)

获取 Tag 列表

func (Tag) ListByIDs

func (t Tag) ListByIDs(db *gorm.DB, ids []uint32) ([]*Tag, error)

根据 ID 列表获取对应 Tag 列表

func (Tag) TableName

func (t Tag) TableName() string

实现 Gorm 的接口,指定 Tag 对应的 pg 表名

func (Tag) Update

func (t Tag) Update(db *gorm.DB, values interface{}) error

type TagSwagger

type TagSwagger struct {
	List  []*Tag
	Pager *app.Pager
}

Swagger 文档生成

Jump to

Keyboard shortcuts

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