pagination

package module
v1.0.1-0...-201ca54 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2021 License: MIT Imports: 6 Imported by: 0

README

gorm-paginator

Usage

go get github.com/jeffmingup/gorm-paginator
type User struct {
	ID       int
	UserName string `gorm:"not null;size:100;unique"`
}

var users []User
db = db.Where("id > ?", 0)

pagination.Pagging(&pagination.Param{
    DB:      db,
    Page:    1,
    Limit:   3,
    OrderBy: []string{"id desc"},
}, &users)

With Gin

r := gin.Default()
r.GET("/", func(c *gin.Context) {
    page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
    limit, _ := strconv.Atoi(c.DefaultQuery("page_size", "3"))
    var users []User

    paginator := pagination.Pagging(&pagination.Param{
        DB:      db,
        Page:    page,
        Limit:   limit,
        OrderBy: []string{"id desc"},
        ShowSQL: true,
    }, &users)
    c.JSON(200, paginator)
})

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Paginator

type Paginator struct {
	TotalRecord int64       `json:"total_record"`
	TotalPage   int         `json:"total_page"`
	Records     interface{} `json:"records"`
	Offset      int         `json:"offset"`
	PageSize    int         `json:"page_size"`
	Page        int         `json:"page"`
	PrevPage    int         `json:"prev_page"`
	NextPage    int         `json:"next_page"`
}

Paginator 分页返回

func Paging

func Paging(p *Param, res interface{}) (*Paginator, error)

Paging 分页

type Param

type Param struct {
	DB         *gorm.DB
	C          *gin.Context
	ExistModel bool
	OrderBy    []string
}

Param 分页参数

Directories

Path Synopsis
pagination module

Jump to

Keyboard shortcuts

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