PHPackages                             setono/doctrine-orm-batcher - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. setono/doctrine-orm-batcher

ActiveLibrary[Database &amp; ORM](/categories/database)

setono/doctrine-orm-batcher
===========================

A library for processing large collections in Doctrine

v0.6.7(1y ago)28631.7k↓15%8[9 PRs](https://github.com/Setono/doctrine-orm-batcher/pulls)6MITPHPPHP &gt;=7.4CI failing

Since Jun 25Pushed 1y ago2 watchersCompare

[ Source](https://github.com/Setono/doctrine-orm-batcher)[ Packagist](https://packagist.org/packages/setono/doctrine-orm-batcher)[ RSS](/packages/setono-doctrine-orm-batcher/feed)WikiDiscussions 0.6.x Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (30)Used By (6)

Doctrine ORM Batcher library
============================

[](#doctrine-orm-batcher-library)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b4a1d4b9f5a260f2cdb4f01032e20de80bdffb156703bff039f04539c3d711bf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7365746f6e6f2f646f637472696e652d6f726d2d626174636865722e737667)](https://packagist.org/packages/setono/doctrine-orm-batcher)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Build Status](https://github.com/Setono/doctrine-orm-batcher/workflows/build/badge.svg)](https://github.com/Setono/doctrine-orm-batcher/actions)

Use this library when you need to process large amounts of entities and maybe in an asynchronous way.

Why do we need this library? Why not just use a paginator library like [Pagerfanta](https://github.com/whiteoctober/Pagerfanta) or normal [batch processing in Doctrine](https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/batch-processing.html)?

Well, because MySQL is [not very good with LIMIT and OFFSET](https://www.eversql.com/faster-pagination-in-mysql-why-order-by-with-limit-and-offset-is-slow/)when the tables become too large. As for Doctrine batch processing capabilities the difference is that this library is very opinionated. It will work very well in a message based architecture where large processing will likely be done in an asynchronous way.

How does it work then? It uses the [seek method](https://www.google.com/search?q=mysql+seek+method) to paginate results instead.

Installation
------------

[](#installation)

```
$ composer require setono/doctrine-orm-batcher
```

Usage
-----

[](#usage)

There are two ways to get results: Getting a range of ids or getting a collection (either of ids or entities).

### Range of ids

[](#range-of-ids)

A range is a lower and upper bound of ids. This is typically intended to be used in an asynchronous environment where you will dispatch a message with the lower and upper bounds so that the consumer of that message will be able to easily fetch the respective entities based on these bounds.

**Example**

You want to process all your `Product` entities. A query builder for that would look like:

```
