Need help with gorm-paginator?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

biezhi
134 Stars 53 Forks MIT License 11 Commits 11 Opened issues

Description

gorm pagination extension

Services available

!
?

Need anything else?

Contributors list

# 1,068
java8
netty4
mvc-fra...
wechat-...
9 commits

gorm-paginator

Usage

go get github.com/biezhi/gorm-paginator/pagination
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("limit", "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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.