silarhi / cursor-pagination
A doctrine ORM cursor based pagination library for faster batch operations.
Installs: 3 272
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=8.0
- doctrine/orm: ^2.5|^3.0
Requires (Dev)
- doctrine/data-fixtures: ^1.7
- friendsofphp/php-cs-fixer: ^3.58
- phpstan/phpstan: ^1.11.3
- phpunit/phpunit: ^9.6.15|^10.5.20|^11.1.3
- rector/rector: ^1.1
- symfony/cache: ^6.0|^7.0
- vimeo/psalm: ^5.24
README
Installation
composer require silarhi/cursor-pagination
Usage
use Silarhi\CursorPagination\Pagination\CursorPagination; $queryBuilder = $entityManager ->createQueryBuilder('u') ->from(User::class, 'u') ->where('u.foo = true'); $configurations = new OrderConfigurations( new OrderConfiguration('u.createdAt', fn (User $user) => $user->getCreatedAt()), new OrderConfiguration('u.id', fn (User $user) => $user->getId()), ); /** @var CursorPagination<User> $pagination */ $pagination = new CursorPagination($queryBuilder, $configurations, 100); // Method 1: get results as chunk (recommended) foreach($pagination->getChunkResults() as $results) { foreach($results as $user) { // do something with user } $entityManager->flush(); $entityManager->clear(); } // Method 2: get single result as iterator foreach($pagination->getResults() as $user) { // do something with user } ``