query

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Eq equal
	Eq = "eq"
	// Neq not equal
	Neq = "neq"
	// Gt greater than
	Gt = "gt"
	// Gte greater than or equal
	Gte = "gte"
	// Lt less than
	Lt = "lt"
	// Lte less than or equal
	Lte = "lte"
	// Like like
	Like = "like"

	// AND logic and
	AND string = "and"
	// OR logic or
	OR string = "or"
)

Variables

View Source
var (
	// ErrNotFound 空记录
	ErrNotFound = gorm.ErrRecordNotFound
)

Functions

func SetMaxSize

func SetMaxSize(max int)

SetMaxSize 修改默认每页数量最大值

Types

type Column

type Column struct {
	Name  string      `json:"name"`  // 列名
	Exp   string      `json:"exp"`   // 表达式,值为空时默认为=,有=、!=、>、>=、<、<=、like七种类型
	Value interface{} `json:"value"` // 列值
	Logic string      `json:"logic"` // 逻辑类型,值为空时默认为and,有&(and)、||(or)两种类型
}

Column 表的列查询信息

type Page

type Page struct {
	// contains filtered or unexported fields
}

Page 页

func DefaultPage

func DefaultPage(page int) *Page

DefaultPage 默认page,每页数量20,按id倒叙排序

func NewPage

func NewPage(page int, size int, columnNames string) *Page

NewPage 自定义page,从第0页开始, 参数columnNames表示排序字段,如果为空表示id降序,如果有多个列名,用逗号分隔, 每一个列名称前面有'-'号,表示降序,否则升序

func (*Page) Offset

func (p *Page) Offset() int

Offset 偏移量

func (*Page) Page

func (p *Page) Page() int

Page 页码

func (*Page) Size

func (p *Page) Size() int

Size 每一页数量

func (*Page) Sort

func (p *Page) Sort() string

Sort 排序

type Params

type Params struct {
	Page int    `form:"page" binding:"gte=0" json:"page"`
	Size int    `form:"size" binding:"gt=0" json:"size"`
	Sort string `form:"sort" binding:"" json:"sort,omitempty"`

	Columns []Column `json:"columns,omitempty"` // 非必须
}

Params 查询原始参数

func (*Params) ConvertToGormConditions

func (p *Params) ConvertToGormConditions() (string, []interface{}, error)

ConvertToGormConditions 根据参数Columns转换成符合gorm规则参数 无论是一列还是多列查询,忽略最后一列的逻辑类型

func (*Params) ConvertToPage

func (p *Params) ConvertToPage() (order string, limit int, offset int)

ConvertToPage 根据参数page size sort转换成符合gorm规则参数

Jump to

Keyboard shortcuts

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