paginator

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: MIT Imports: 4 Imported by: 0

README

gorm-paginator

Usage

go get github.com/Leukocyte-Lab/gorm-paginator
pgntr := paginator.New(page, orders, map[string]string{})

var models []*Model
result := pgntr.GenGormTransaction(dao.DB).Find(&models)
if result.Error != nil {
    // TODO: handle error
}

err := pgntr.CountPageTotal(result)
if result.Error != nil {
    // TODO: handle error
}

// return models, pgntr.Page

License

MIT

Documentation

Index

Constants

View Source
const (
	MaxPageSize     = 100
	DefaultPageSize = 20
)
View Source
const (
	MinPageNumber = 1
	MinPageSize   = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Direction

type Direction int

Direction is sort direction when ordering

const (
	SortASC Direction
	SortDESC
)

func (Direction) String

func (enum Direction) String() string

type Order

type Order struct {
	Column    string
	Direction Direction
}

Order contains sort direction and sort field

type Page

type Page struct {
	Number int
	Size   int
	Total  int
}

page contains page number, page size, and total number of items

func GenPage

func GenPage(pageNo int, pageSize int) Page

GenPage is helper function to generate page with default page number and page size

type Paginator

type Paginator struct {
	Page   Page
	Order  []Order
	Filter map[string]string
}

Paginator is basic struct contains pagination information

func New

func New(page Page, orders []Order, filter map[string]string) *Paginator

New is helper function for create Paginator instance

func (*Paginator) CountPageTotal

func (pgntr *Paginator) CountPageTotal(tx *gorm.DB) error

CountPageTotal is setter of Paginator.Page.Total by counting total page number

func (Paginator) GenGormTransaction

func (pgntr Paginator) GenGormTransaction(tx *gorm.DB) *gorm.DB

GenGormTransaction generate GORMv2 sql Transaction (gorm.DB) for paging

func (*Paginator) LimitPageTotal

func (pgntr *Paginator) LimitPageTotal()

func (Paginator) Paging

func (pgntr Paginator) Paging(tx *gorm.DB, dest interface{}) (*Page, error)

Paging is wrapper for doing paging easily

Jump to

Keyboard shortcuts

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