relpaginator

package module
v0.0.0-...-3622f96 Latest Latest
Warning

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

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

README

Rel Paginator

With thid package you can create a search with rel ORM by pages. It provides some structs to handler filters.

Examples

At examples directory you can find a postgres example. Just change url, create the database and run it.

You need to know this package works whit all soported rel adapters and engines which support LIMIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockPaginable

type MockPaginable struct {
	mock.Mock
}

MockPaginable is an autogenerated mock type for the Paginable type

func (*MockPaginable) CreatePagination

func (_m *MockPaginable) CreatePagination(ctx context.Context, tableName string, holder interface{}, pageSort *PageSort) (*Page, error)

CreatePagination provides a mock function with given fields: ctx, tableName, holder, pageSort

func (*MockPaginable) CreatePaginator

func (_m *MockPaginable) CreatePaginator(ctx context.Context, tableName string, holder interface{}, pageNumber int, queries ...rel.Querier) (*Page, error)

CreatePaginator provides a mock function with given fields: ctx, tableName, holder, pageNumber, queries

type Page

type Page struct {
	TotalPages   uint        `json:"total_pages,omitempty"`
	CurrentPage  uint        `json:"current_page,omitempty"`
	PreviousPage uint        `json:"previous_page,omitempty"`
	PageSize     uint        `json:"page_size,omitempty"`
	NextPage     uint        `json:"next_page,omitempty"`
	TotalEntries uint        `json:"total_entries,omitempty"`
	Data         interface{} `json:"data,omitempty"`
}

type PageError

type PageError struct {
	PageNumber uint
}

func (PageError) Error

func (c PageError) Error() string

func (PageError) StatusCode

func (c PageError) StatusCode() int

type PageSort

type PageSort struct {
	Page         uint     `json:"page_number,omitempty"`
	ItemsPerPage uint     `json:"itemsPerPage,omitempty"`
	SortBy       []string `json:"sortBy,omitempty"`
	SortDesc     []bool   `json:"sortDesc,omitempty"`
	GroupBy      []string `json:"groupBy,omitempty"`
	GroupDesc    []bool   `json:"groupDesc,omitempty"`
	// TODO: make mustSort and multiSort useful
	MustSort  bool `json:"mustSort,omitempty"`
	MultiSort bool `json:"multiSort,omitempty"`
	// contains filtered or unexported fields
}

func CreatePageSortFromMap

func CreatePageSortFromMap(values map[string]interface{}) *PageSort

func (*PageSort) GetFiltersQueries

func (c *PageSort) GetFiltersQueries() []rel.Querier

func (*PageSort) GetItemsPerPage

func (c *PageSort) GetItemsPerPage() uint

func (*PageSort) GetPage

func (c *PageSort) GetPage() uint

func (*PageSort) GetSortQueries

func (c *PageSort) GetSortQueries() []rel.Querier

func (*PageSort) SetFiltersQueries

func (c *PageSort) SetFiltersQueries(queries ...rel.Querier)

SetFiltersQueries allows to add filters to be consider to the pagination

type Paginable

type Paginable interface {
	CreatePage(
		ctx context.Context,
		tableName string,
		holder interface{},
		pageSort *PageSort,
	) (*Page, error)
}

type Paginator

type Paginator struct {
	// contains filtered or unexported fields
}

func NewPaginator

func NewPaginator(repo rel.Repository, config *RelPaginatorConfig) *Paginator

func (*Paginator) CreatePage

func (c *Paginator) CreatePage(
	ctx context.Context,
	tableName string,
	holder interface{},
	pageSort *PageSort,
) (*Page, error)

type RelPaginatorConfig

type RelPaginatorConfig struct {
	PageSize uint
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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