adt/bulk-fetcher

v5.0 2024-06-19 08:56 UTC

This package is auto-updated.

Last update: 2024-10-19 09:54:53 UTC


README

\ADT\BulkFetcher\Factory can be used with:

  • \Kdyby\Doctrine\ResultSet
  • \Doctrine\ORM\QueryBuilder
  • \Kdyby\Doctrine\NativeQueryBuilder

Installation

via composer:

composer require adt/bulk-fetcher

Full example

Whole batch is in transaction.

$qb = $entityManager->createQueryBuilder('user');

try {
	$entityManager->beginTransaction();	
	
	$data = \ADT\BulkFetcher\Factory::create($qb, 100);
	$data->onBeforeFetch[] = function() use ($entityManager) {
		$entityManager->commit();
		$entityManager->clear();
		$entityManager->beginTransaction();
	};
	
	foreach ($data as $key => $row) {
		// code
	}
	
	$entityManager->commit();

} catch (\Exception $e) {
	$entityManager->rollback();
	throw $e;
}