query

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder interface {
	String() string
	Order(field string, dir SortDir)
	ApplyToGorm(g *gorm.DB) (*gorm.DB, error)
	ApplyToGormCount(g *gorm.DB) (*gorm.DB, error)

	WhereEq(field string, value interface{})
	WhereLike(field string, value interface{})
	WhereIn(field string, value interface{})
	WhereLt(field string, value interface{})
	WhereLtEq(field string, value interface{})
	WhereGt(field string, value interface{})
	WhereGtEq(field string, value interface{})
	WhereNotEq(field string, value interface{})

	OrWhereEq(field string, value interface{})
	OrWhereLike(field string, value interface{})
	OrWhereIn(field string, value interface{})
	OrWhereLt(field string, value interface{})
	OrWhereLtEq(field string, value interface{})
	OrWhereGt(field string, value interface{})
	OrWhereGtEq(field string, value interface{})
	OrWhereNotEq(field string, value interface{})
}

type Pagination

type Pagination struct {
	Page     uint `json:"page"`
	PageSize uint `json:"page_size"`
	Total    uint `json:"total"`
}

func NewPagination

func NewPagination(c *gin.Context) Pagination

func (Pagination) Paginate

func (p Pagination) Paginate(page, size, total uint)

func (Pagination) String

func (p Pagination) String() string

type Query

type Query struct {
	Pagination Pagination
	Filter     filter.Filter
	Sort       []Sort
	Preload    []string
}

func NewQueryBuilder

func NewQueryBuilder(c *gin.Context) *Query

func (*Query) ApplyToGorm

func (q *Query) ApplyToGorm(g *gorm.DB) (*gorm.DB, error)

func (*Query) ApplyToGormCount

func (q *Query) ApplyToGormCount(g *gorm.DB) (*gorm.DB, error)

Copies the query, removing the pagination and applies it to the provided Gorm instance. Can be used to get the unpaginated total count of rows for use in pagination.

func (*Query) OrWhereEq

func (q *Query) OrWhereEq(field string, value interface{})

func (*Query) OrWhereGt

func (q *Query) OrWhereGt(field string, value interface{})

func (*Query) OrWhereGtEq

func (q *Query) OrWhereGtEq(field string, value interface{})

func (*Query) OrWhereIn

func (q *Query) OrWhereIn(field string, value interface{})

func (*Query) OrWhereLike

func (q *Query) OrWhereLike(field string, value interface{})

func (*Query) OrWhereLt

func (q *Query) OrWhereLt(field string, value interface{})

func (*Query) OrWhereLtEq

func (q *Query) OrWhereLtEq(field string, value interface{})

func (*Query) OrWhereNotEq

func (q *Query) OrWhereNotEq(field string, value interface{})

func (*Query) Order

func (q *Query) Order(field string, dir SortDir)

func (*Query) String

func (q *Query) String() string

func (*Query) WhereEq

func (q *Query) WhereEq(field string, value interface{})

func (*Query) WhereGt

func (q *Query) WhereGt(field string, value interface{})

func (*Query) WhereGtEq

func (q *Query) WhereGtEq(field string, value interface{})

func (*Query) WhereIn

func (q *Query) WhereIn(field string, value interface{})

func (*Query) WhereLike

func (q *Query) WhereLike(field string, value interface{})

func (*Query) WhereLt

func (q *Query) WhereLt(field string, value interface{})

func (*Query) WhereLtEq

func (q *Query) WhereLtEq(field string, value interface{})

func (*Query) WhereNotEq

func (q *Query) WhereNotEq(field string, value interface{})

type Sort

type Sort struct {
	Field string
	Dir   SortDir
}

func NewSort

func NewSort(c *gin.Context) []Sort

func (Sort) String

func (s Sort) String() string

type SortDir

type SortDir string
const (
	SortAsc  SortDir = "asc"
	SortDesc SortDir = "desc"
)

func SortDirFromString

func SortDirFromString(s string) (SortDir, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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