{"id":18386045,"url":"https://github.com/catlabinteractive/cursor-pagination","last_synced_at":"2025-04-07T00:32:40.693Z","repository":{"id":62500202,"uuid":"59665642","full_name":"CatLabInteractive/cursor-pagination","owner":"CatLabInteractive","description":"Cursor pagination for REST APIs.","archived":false,"fork":false,"pushed_at":"2022-08-17T14:10:09.000Z","size":27,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-22T09:43:30.081Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CatLabInteractive.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}},"created_at":"2016-05-25T13:31:17.000Z","updated_at":"2022-08-17T14:10:12.000Z","dependencies_parsed_at":"2022-11-02T09:46:06.645Z","dependency_job_id":null,"html_url":"https://github.com/CatLabInteractive/cursor-pagination","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CatLabInteractive%2Fcursor-pagination","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CatLabInteractive%2Fcursor-pagination/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CatLabInteractive%2Fcursor-pagination/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CatLabInteractive%2Fcursor-pagination/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CatLabInteractive","download_url":"https://codeload.github.com/CatLabInteractive/cursor-pagination/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247574088,"owners_count":20960495,"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","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":[],"created_at":"2024-11-06T01:20:02.344Z","updated_at":"2025-04-07T00:32:40.420Z","avatar_url":"https://github.com/CatLabInteractive.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cursor-pagination\n[![Build Status](https://travis-ci.org/CatLabInteractive/cursor-pagination.svg?branch=master)](https://travis-ci.org/CatLabInteractive/cursor-pagination)\n\nCursor pagination for REST APIs.\n\nGoal\n====\nProvide cursor based pagination to APIs or webservices. The library\ncalculates the sql query parameters and the cursors that should be \npassed through the requests.\n\nSo, like LIMIT {offset}, {records}?\n===================================\nCursor based pagination is generally more performant than page based \npagination (using SQL offset) since it filters the records instead \nof limiting the amount of records returned.\n\nFor changing data cursor based pagination is also more correct, since \nadding a row to the beginning of a list might shift all records.\n\nFor more information, head over to this [excellent article](https://www.sitepoint.com/paginating-real-time-data-cursor-based-pagination/).\n\nExample\n=======\n```php\n\u003c?php \n\nuse CatLab\\Base\\Models\\Database\\OrderParameter;\nuse CatLab\\CursorPagination\\CursorPaginationBuilder;\n\nrequire '../vendor/autoload.php';\nrequire 'helpers.php';\n$pdo = require 'mockdata.php';\n\n$builder = new CursorPaginationBuilder();\n\n// Show 5 records on each page\n$builder-\u003elimit(isset($_GET['records']) ? $_GET['records'] : 5);\n\n// Register properties\n$builder-\u003eregisterPropertyName('id', 'public_id');\n$builder-\u003eregisterPropertyName('name', 'public_name');\n$builder-\u003eregisterPropertyName('score', 'public_score');\n\n/**\n * Set select order\n */\n\n// Order by score desc\n$builder-\u003eorderBy(new OrderParameter('score', OrderParameter::DESC));\n\n// Same score? Order by name asc\n$builder-\u003eorderBy(new OrderParameter('name', OrderParameter::ASC));\n\n// Same score and same name? Sort on ID\n$builder-\u003eorderBy(new OrderParameter('id', OrderParameter::ASC));\n\n// Set the request parameters\n$builder-\u003esetRequest($_GET);\n\n/**\n * Select and output data\n */\n// Build the select query\n$query = $builder-\u003ebuild();\n\n// Load the data\n$sql = $query-\u003etoQuery($pdo, 'entries');\n$results = $pdo-\u003equery($sql)-\u003efetchAll();\n\n// Post process results. Very important. Don't forget.\n$results = $builder-\u003eprocessResults($query, $results);\n\n// Display the records\n$table = new Table([ 'id', 'name', 'score' ]);\n$table-\u003eopen();\nforeach ($results as $v) {\n    $table-\u003erow($v);\n}\n$table-\u003eclose();\n\n$table-\u003enavigation($builder-\u003egetNavigation());\n```\n\nThis example is live at https://dev.catlab.eu/cursor-pagination/examples/","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcatlabinteractive%2Fcursor-pagination","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcatlabinteractive%2Fcursor-pagination","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcatlabinteractive%2Fcursor-pagination/lists"}