https://github.com/ittus/cursor-paginator
Golang's two way cursor with GORM
https://github.com/ittus/cursor-paginator
cursor golang gorm pagination
Last synced: 3 months ago
JSON representation
Golang's two way cursor with GORM
- Host: GitHub
- URL: https://github.com/ittus/cursor-paginator
- Owner: ittus
- Created: 2019-08-02T10:17:08.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-08-05T05:45:27.000Z (over 6 years ago)
- Last Synced: 2025-02-01T18:45:32.153Z (11 months ago)
- Topics: cursor, golang, gorm, pagination
- Language: Go
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Cursor paginator
Two-way cursor pagination with Golang and GORM (bidirections cursor)
## Install
```go
go get -u github.com/ittus/cursor-paginator
```
## How to use
Support we have gorm model
```go
type item struct {
ID int `gorm:"primary_key"`
CreatedAt time.Time `gorm:"type:timestamp;not null"`
}
```
then we can use
```go
import paginator "https://github.com/ittus/cursor-paginator"
var itemResults []item
var cursor *int64
p := paginator.NewCursorPaginator(
baseQuery,
perPage,
paginator.OrderDirections.Desc,
paginator.PaginatorDirections.Next,
"id",
"ID",
cursor,
paginator.IDModeCursor)
p.Paginate(&itemResults)
// p.NextCursor
// p.PreviousCursor
```
## Test
```go
go test -v -covermode=count -coverprofile=c.out
```
## License
Released under the [MIT License](/LICENSE)