PHPackages                             vaskevicius/lib-pagination - 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. vaskevicius/lib-pagination

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

vaskevicius/lib-pagination
==========================

Paginates Doctrine QueryBuilder using cursor based or offset based pagination

0.0.1(2y ago)03MITPHPPHP &gt;=8.0

Since Oct 5Pushed 2y agoCompare

[ Source](https://github.com/vaskevicius/lib-pagination)[ Packagist](https://packagist.org/packages/vaskevicius/lib-pagination)[ RSS](/packages/vaskevicius-lib-pagination/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

Paysera Pagination component
============================

[](#paysera-pagination-component)

[![Latest Version on Packagist](https://camo.githubusercontent.com/320c3cb2df09c35e14f5775a4a77c4a99d742257aa142e2b241467eaa2c1109c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706179736572612f6c69622d706167696e6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/paysera/lib-pagination)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/8bd785631dbc7ad08d1ed198e69c522bf6222c99d2277a0acc55a8ea5e7b4844/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f706179736572612f6c69622d706167696e6174696f6e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/paysera/lib-pagination)[![Coverage Status](https://camo.githubusercontent.com/1750c47c63e386a2b61781559e1471029666f8fa315d06ec4761a7edaa40a9e1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f706179736572612f6c69622d706167696e6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/paysera/lib-pagination/code-structure)[![Quality Score](https://camo.githubusercontent.com/214899cb701bfb3e1129cb50cfbce70061e9e71674d352e5ca44da277ca3eed9/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f706179736572612f6c69622d706167696e6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/paysera/lib-pagination)[![Total Downloads](https://camo.githubusercontent.com/9040f5927d0d6977b88ce2ca40c628deba3d7c5f73923a81e092af6b82351679/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706179736572612f6c69622d706167696e6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/paysera/lib-pagination)

This component allows to paginate Doctrine `QueryBuilder` instances using cursor-based pagination. Offset is also supported.

Why?
----

[](#why)

### Performance

[](#performance)

Cursor pagination can be much more efficient under large data-sets.

For example, to take 3000th page, consisting of 100 items, using offset you would need to execute such query:

```
SELECT *
FROM items
WHERE field = 'some value'
ORDER BY created_at DESC
LIMIT 100 OFFSET 29900
```

This type of query, even if you have indexes on the fields you are querying by (and the fields you order by), would need to iterate over 29900 items first, before giving you the requested result.

If using cursor based pagination, the resulting query can look like this:

```
SELECT *
FROM items
WHERE field = 'some value'
AND created_at
