db

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPerPage defines the default value for pagination
	DefaultPerPage uint = 20
)

Variables

View Source
var (
	ErrUnsupportedDriver = errors.New("unsupported driver")
	ErrRecordNotFound    = errors.New("record not found")
	ErrNotImplemented    = errors.New("not implemented")
	ErrInvalidField      = errors.New("invalid field")
	ErrEmptySlice        = errors.New("empty slice")
)
View Source
var (
	ErrNoResult       = errors.New("No result")
	ErrTooManyResults = errors.New("too many results returned")
	ErrNoModification = errors.New("No changes made")
)

Functions

This section is empty.

Types

type Pagination

type Pagination struct {
	Page    uint
	PerPage uint
	// contains filtered or unexported fields
}

Pagination is a pagination calcul handler for database request.

func NewPaginator

func NewPaginator(page, perPage uint) *Pagination

NewPaginator returns a pagination holder

func (*Pagination) CurrentPageCount

func (p *Pagination) CurrentPageCount() uint

CurrentPageCount returns the element count of the current page

func (*Pagination) HasNext

func (p *Pagination) HasNext() bool

HasNext returns the status if current page has a next one

func (*Pagination) HasOtherPages

func (p *Pagination) HasOtherPages() bool

HasOtherPages returns the status of having previous or next pages

func (*Pagination) HasPrev

func (p *Pagination) HasPrev() bool

HasPrev returns the status if current page has a previous one

func (*Pagination) NextPage

func (p *Pagination) NextPage() uint

NextPage returns the page number for the next page. won't go past the end

func (*Pagination) NumPages

func (p *Pagination) NumPages() uint

NumPages returns the total number of pages

func (*Pagination) Offset

func (p *Pagination) Offset() uint

Offset returns the offset of first element

func (*Pagination) PrevPage

func (p *Pagination) PrevPage() uint

PrevPage returns the page number for the page before this bottoms out at the first page

func (*Pagination) SetTotal

func (p *Pagination) SetTotal(total uint)

SetTotal is used to defines the total count of paginated values.

func (*Pagination) Total

func (p *Pagination) Total() uint

Total returns the total number of items

type SortDirection

type SortDirection int

SortDirection is the enumeration for sort

const (
	Ascending SortDirection = iota + 1
	Descending
)

func (SortDirection) String

func (m SortDirection) String() string

type SortParameters

type SortParameters map[string]SortDirection

SortParameters contains a hashmap of field name with sort direction

func SortConverter

func SortConverter(sorts []string) *SortParameters

SortConverter convert a list of string to a SortParameters instance

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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