pagination

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count

func Count(resultCount, limit int) int

Count calculates the page count with the given resultCount of a pagination query and a page limit.

func Offset

func Offset(page, limit int) int

Offset calculates the offset with the page and limit params

func Query

func Query(args *fasthttp.Args, allowedColumns map[string]bool) func(*gorm.DB) *gorm.DB

Query builds a pagination query with the provided values and checks the input columns against the allowedColumns list. Returns a gorm query to be used in the function or an error.

func Sort added in v0.0.3

func Sort(args *fasthttp.Args, allowedColumns map[string]bool) func(*gorm.DB) *gorm.DB

Sort builds a sort query with the provided values and checks the input columns against the allowedColumns list. Returns a gorm query to be used in the function or an error.

Types

type Model

type Model struct {
	Limit     int         `json:"limit"`
	Page      int         `json:"page"`
	PageCount int         `json:"pageCount"`
	Total     int         `json:"total"`
	Result    interface{} `json:"result"`
}

Model struct is used to return paginated data.

func CreatePaginationModel

func CreatePaginationModel(limit, page, pageCount, total int, result interface{}) Model

CreatePaginationModel is a helper to be able to return a pagination model in a single line

Jump to

Keyboard shortcuts

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