Skip to content

manuelarte/pagorminator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

28 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Go coverage Go Report Card

๐Ÿ“ƒ PaGORMinator

Gorm plugin to add Pagination to your select queries

โฌ‡๏ธ How to install it

go get -u -v github.com/manuelarte/pagorminator

๐ŸŽฏ How to use it

var DB *gorm.DB
DB.Use(pagorminator.PaGormMinator{})
var products []*Products
pageRequest, err := pagorminator.PageRequest(0, 10)
DB.Clauses(pageRequest).First(&products)

The pagination struct contains the following data:

  • page: page number, e.g. 0
  • size: page size, e.g. 10
  • sort: to apply sorting, e.g. id,asc

The plugin will calculate the total amount of elements, and then the pagination instance provides a GetTotalElements() and GetTotalPages() methods to be used. The pagination starts at index 0. So if the total pages is 6, then the pagination index goes from 0 to 5.

๐ŸŽ“ Examples

Simple query with no filters (no WHERE clause)

Simple query with sorting and no filters (no WHERE clause)

Simple query with no filters (no WHERE clause), many pages

Using WHERE to filter

Unpaged query (pagination with no pagination)

Example using Preload

๐Ÿ”— Contact