webit / doctrine-orm-query-builder-iterator
Installs: 47 525
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=8.1
- doctrine/orm: ^2.4.0
Requires (Dev)
- phpspec/prophecy-phpunit: ^v2.0.2
- phpunit/phpunit: ^10.4
- symfony/cache: ^6.3
- symfony/uid: ^6.3
README
Allows to iterate over Query Builder Results in batches
Installation
composer require webit/doctrine-orm-query-builder-iterator=^2.0.0
Usage
QueryIterator implementation
This implementation iterates over given query using limit / offset parameters.
<?php use Webit\DoctrineORM\QueryBuilder\Iterator\QueryIterator; /** @var \Doctrine\ORM\EntityManagerInterface $entityManager */ $queryBuilder = $entityManager->getRepository('MyEntity')->createQueryBuilder(); $queryBuilder->orderBy('a.ble', 'DESC'); $iterator = new QueryIterator( $queryBuilder, 20, // iterates in 50 elements batches (50 by default) ['MyEntity'], // clears entity manager before getting next batch (by default clears the whole entity manager) ); foreach ($iterator as $entity) { // do your stuff with the entity }
IdsIterator implementation
This implementation iterates over given query using pre-fetched list of identifiers.
<?php use Webit\DoctrineORM\QueryBuilder\Iterator\IdsIterator; /** @var \Doctrine\ORM\EntityManagerInterface $entityManager */ $queryBuilder = $entityManager->getRepository('MyEntity')->createQueryBuilder(); $queryBuilder->orderBy('a.ble', 'DESC'); $iterator = new IdsIterator( $queryBuilder, 'a.id', // the ID field 20, // iterates in 20 elements batches (50 by default) ['MyEntity'], // clears entity manager before getting next batch (by default clears the whole entity manager) ); foreach ($iterator as $entity) { // do your stuff with the entity }
Tests
composer install ./vendor/bin/phpunit