https://github.com/hellokaton/gorm-paginator
gorm pagination extension
https://github.com/hellokaton/gorm-paginator
gorm pagination
Last synced: 11 months ago
JSON representation
gorm pagination extension
- Host: GitHub
- URL: https://github.com/hellokaton/gorm-paginator
- Owner: hellokaton
- License: mit
- Created: 2018-05-15T06:42:06.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2025-02-19T02:27:00.000Z (about 1 year ago)
- Last Synced: 2025-03-28T18:14:56.316Z (11 months ago)
- Topics: gorm, pagination
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 157
- Watchers: 5
- Forks: 52
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gorm-paginator
## Usage
```bash
go get github.com/hellokaton/gorm-paginator/pagination
```
```go
type User struct {
ID int
UserName string `gorm:"not null;size:100;unique"`
}
var users []User
db = db.Where("id > ?", 0)
pagination.Paging(&pagination.Param{
DB: db,
Page: 1,
Limit: 3,
OrderBy: []string{"id desc"},
}, &users)
```
## With Gin
```go
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.Paging(&pagination.Param{
DB: db,
Page: page,
Limit: limit,
OrderBy: []string{"id desc"},
ShowSQL: true,
}, &users)
c.JSON(200, paginator)
})
```
## License
[MIT](LICENSE)