Version: v1.0.27 Latest Latest

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

Go to latest
Published: Apr 27, 2021 License: MIT Imports: 11 Imported by: 0




This section is empty.


This section is empty.


func GetPagingParams

func GetPagingParams(c *gin.Context) (page int, size int)

GetPagingParams 获取分页参数

func GetParamsTryInt

func GetParamsTryInt(val string, defaults int) int

GetParamsTryInt 字符串转数字


type Controller

type Controller interface {
	// add update 验证
	Validator() error
	SetCode() error
	SetUser(c *gin.Context, data interface{}) error

	// 表名
	TableName() string
	// 自身实例 用于found one
	Object() interface{}
	// 自身实例 用于found list
	Objects() interface{}

	// 以下三个方法用于辅助默认方法实现curd,过于复杂的直接override
	// Where 搜索条件
	// Search(db *gorm.DB, key string) *gorm.DB
	// 查询的补充条件
	Joins(db *gorm.DB) *gorm.DB
	// 处理列表返回结果
	Result(data interface{}) interface{}

Controller ModelInterface

type GormDB

type GormDB struct {

GormDB 自定义方法

func (*GormDB) ConnectMysql

func (g *GormDB) ConnectMysql(dsn string) (err error)

ConnectMysql 链接mysql

func (*GormDB) GetObjectOrNotFound

func (g *GormDB) GetObjectOrNotFound(obj interface{}, query map[string]interface{}, midd ...Middleware) (err error)

GetObjectOrNotFound 获取某一条数据 gorm 查询接收空条件,在某些情况下会操作到错误到数据

func (*GormDB) GetObjectsOrEmpty

func (g *GormDB) GetObjectsOrEmpty(obj interface{}, query interface{}, args ...Middleware) *Objects

GetObjectsOrEmpty 获取列表 \n 可选参数 middleware models.middleware 接收一个 *gorm.DB 返回 *gorm.DB

type Middleware

type Middleware func(db *gorm.DB) *gorm.DB

Middleware 查询中间操作

type Model

type Model struct {
	ID        uint           `json:"id" gorm:"primary_key"`
	Code      string         `json:"code" gorm:"primary_key;index;unique;not null"` //
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `json:"deleted_at,omitempty" gorm:"index"`

Model 空方法用户数据模型继承方法

func (*Model) Joins added in v1.0.20

func (m *Model) Joins(db *gorm.DB) *gorm.DB

Joins Joins

func (*Model) Result added in v1.0.20

func (m *Model) Result(data interface{}) interface{}


func (*Model) SetCode added in v1.0.20

func (m *Model) SetCode() (err error)

SetCode SetCode

func (*Model) SetID added in v1.0.20

func (m *Model) SetID(id uint)

func (*Model) SetUser added in v1.0.20

func (m *Model) SetUser(c *gin.Context, data interface{}) error

SetUser SetUser

type ObjResult

type ObjResult struct {
	List interface{} `json:"list"`

ObjResult Result

func (*ObjResult) MarshalJSON

func (o *ObjResult) MarshalJSON() ([]byte, error)

MarshalJSON MarshalJSON

type Objects

type Objects struct {
	Obj        interface{}
	Model      *gorm.DB
	Pagination *Pagination
	Result     *ObjResult

Objects List

func (*Objects) All

func (o *Objects) All() (err error)

All 全部数据

func (*Objects) Paging

func (o *Objects) Paging(page int, size int, args ...Middleware) (err error)

Paging 分页数据

type Page

type Page struct {
	Page int
	URL  string

Page 分页

type Pagination

type Pagination struct {
	Page      int    `json:"page"`
	Size      int    `json:"size"`
	Total     int    `json:"total"`
	URLFormat string `json:"-"`

Pagination 分页数据

func (*Pagination) Pages

func (p *Pagination) Pages() int

Pages 总页数

func (*Pagination) Range

func (p *Pagination) Range() []Page

Range 生成数组

func (*Pagination) SetURLFormat

func (p *Pagination) SetURLFormat(url string) string

SetURLFormat 设置url

func (*Pagination) URL

func (p *Pagination) URL(page int, size int) string

URL 获取url

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL