query

package
v0.2.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2022 License: MIT Imports: 8 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       int64 `json:"page,omitempty"`      // the json name must match currentPageKey, defined above
	PageSize   int64 `json:"page_size,omitempty"` // the json name must match perPageKey, defined above
	Total      int64 `json:"total,omitempty"`
	TotalPages int64 `json:"total_pages,omitempty"`

	FirstPage    string `json:"first_page,omitempty"`
	PreviousPage string `json:"previous_page,omitempty"`
	NextPage     string `json:"next_page,omitempty"`
	LastPage     string `json:"last_page,omitempty"`
}

func NewPaginationFromGin added in v0.1.29

func NewPaginationFromGin(c *gin.Context) Pagination

func NewPaginationFromValues added in v0.1.29

func NewPaginationFromValues(page, size, total int64) Pagination

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) ApplyPaginationTotals added in v0.1.29

func (q *Query) ApplyPaginationTotals(totalRecordCount int64)

ApplyPaginationTotals updates the Pagination Total and TotalPages values using the provided new totalRecordCount.

func (*Query) ApplyToGorm

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

func (*Query) GetGormPageQuery added in v0.1.29

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

GetGormPageQuery copies the query, removing the pagination and applies it to the provided Gorm instance. Can be used to get the un-paginated total count of rows for use in pagination. DOES NOT MODIFY THE QUERY INSTANCE

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