{"id":17184043,"url":"https://github.com/raphaelvigee/go-paginate","last_synced_at":"2025-10-07T14:04:03.348Z","repository":{"id":84906387,"uuid":"314269982","full_name":"raphaelvigee/go-paginate","owner":"raphaelvigee","description":"Cursor-based go paginator","archived":false,"fork":false,"pushed_at":"2023-03-26T00:01:34.000Z","size":50,"stargazers_count":78,"open_issues_count":1,"forks_count":7,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-20T18:15:47.958Z","etag":null,"topics":["cursor","golang","gorm","pagination"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/raphaelvigee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-19T14:18:59.000Z","updated_at":"2025-04-20T06:03:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"c671f2e0-078b-4328-af2c-8a196e87ba1c","html_url":"https://github.com/raphaelvigee/go-paginate","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/raphaelvigee/go-paginate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphaelvigee%2Fgo-paginate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphaelvigee%2Fgo-paginate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphaelvigee%2Fgo-paginate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphaelvigee%2Fgo-paginate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raphaelvigee","download_url":"https://codeload.github.com/raphaelvigee/go-paginate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphaelvigee%2Fgo-paginate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278786686,"owners_count":26045591,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cursor","golang","gorm","pagination"],"created_at":"2024-10-15T00:42:15.314Z","updated_at":"2025-10-07T14:04:03.298Z","avatar_url":"https://github.com/raphaelvigee.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-paginate\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/raphaelvigee/go-paginate)](https://pkg.go.dev/github.com/raphaelvigee/go-paginate)\n![Test](https://github.com/raphaelvigee/go-paginate/workflows/Test/badge.svg)\n\nAn efficient go data cursor-based paginator.\n\n- Plug and play\n- Easy to use\n- Fully customizable\n\n```\ngo get github.com/raphaelvigee/go-paginate\n```\n\n## Why?\n\nA lot of articles on the internet summarize very well the benefits of cursor-based pagination, but here are the highlights:\n\n- It scales: Unlike `OFFSET`/`LIMIT`-based pagination doesn't scale well for large datasets\n- Suitable for real-time data: having a fixed point in the flow of data prevents duplicates/missing entries\n\nIt does have an issue, it is hard to implement, that's why `go-paginate` exists :)\n\n## Drivers\n\n- [gorm](https://gorm.io):\n    - Supports multiple columns with different orderings directions (ex: `ORDER BY id ASC, name DESC`)\n\n- Implement your own: See [driver.Driver](driver/driver.go) and [base.Driver](driver/base/driver.go)\n\n\u003e Can't find what you are looking for? [Open an issue!](https://github.com/raphaelvigee/go-paginate/issues/new)\n\n## Usage\n\n### With `gorm`\n\n\u003e Errors omitted for brevity\n\nCreate the paginator, defining the criteria (columns and ordering):\n\n```go\npg := paginator.New(paginator.Options{\n    Driver: gorm.New(gorm.Options{\n        Columns: []gorm.Column{\n            {\n                Name: \"created_at\",\n            },\n        },\n    }),\n})\n```\n\nCreate the cursor instance, most likely from the request (in the initial request, the cursor is an empty string):\n\n```go\nc, err := pg.Cursor(\"\u003ccursor from client\u003e\", cursor.After, 2)\n```\n\nCreate a transaction with appropriate filtering etc and request the pagination info:\n\n```go\ntx := db.Model(\u0026User{}).Where(...)\npage, err := pg.Paginate(c, tx)\n\n// That should be sent back to the client along with the data\nfmt.Println(page.PageInfo.HasPreviousPage)\nfmt.Println(page.PageInfo.HasNextPage)\nfmt.Println(page.PageInfo.StartCursor)\nfmt.Println(page.PageInfo.EndCursor)\n```\n\nRetrieve the underlying data for the page:\n\n```go\nvar users []User\nerr := page.Query(\u0026users)\n```\n\nA full working example can be found in [_examples/gorm](_examples/gorm/main.go).\n\n### Custom cursor\n\nBy default, the cursor will be marshalled through `msgpack` for size concerns, and `base64` for portability.\nOne can choose to do differently (for example encrypting them...), see the implementation of `cursor.MsgPack` and `cursor.Base64`.\n\n```go\npg := paginator.New(paginator.Options{\n    ...\n    CursorMarshaller: cursor.Chain(cursor.MsgPack(), cursor.Base64(base64.StdEncoding))\n})\n```\n\n## Release\n\n    TAG=v0.0.1 make tag\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraphaelvigee%2Fgo-paginate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraphaelvigee%2Fgo-paginate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraphaelvigee%2Fgo-paginate/lists"}