model

package
v0.0.0-...-8960dd1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CtxWithTransaction

func CtxWithTransaction(ctx context.Context, tx *gorm.DB) context.Context

func GetDBWithCtx

func GetDBWithCtx(ctx context.Context) *gorm.DB

func NewDBEngine

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

func Transaction

func Transaction(ctx context.Context, fn func(txctx context.Context) error) error

Types

type Article

type Article struct {
	*Model
	Title         string `json:"title"`
	Desc          string `json:"desc"`
	Content       string `json:"content"`
	CoverImageUrl string `json:"cover_image_url"`
	TagID         uint32 `json:"-"`
	Tag           *Tag   `json:"tag" gorm:"-"`
}

func (*Article) Count

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

func (*Article) Create

func (a *Article) Create(db *gorm.DB) 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) List

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

func (*Article) Update

func (a *Article) Update(db *gorm.DB, updateMap map[string]any) error

type Model

type Model struct {
	ID        uint32                `json:"id"`
	CreatedAt uint32                `json:"create_time"`
	UpdatedAt uint32                `json:"update_time"`
	DeletedAt soft_delete.DeletedAt `json:"-"` // gorm查询会自动过滤被软删除的结果,软删除即 deleted_at != 0
	CreatedBy string                `json:"create_by"`
	UpdatedBy string                `json:"update_by"`
	Status    uint8                 `json:"status"` // 1启用,2禁用,99删除

}

type Tag

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

func (*Tag) Count

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

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)

func (*Tag) List

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

func (*Tag) Update

func (t *Tag) Update(db *gorm.DB, updateMap map[string]any) error

Jump to

Keyboard shortcuts

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