Pagination¶
Formal is optimized to be memory efficient so you can do this without running out of memory:
But if you're building a HTTP API you don't want to return all the aggregates from your storage in the response. The go-to approach is to use pagination and return a fixed amount of aggregates.
This is very simple with Formal:
This also works with ->repository()->matching()
.
The sort allows the pagination to be stable (the same query will return the same results).
Warning
The order of drop
and take
is important.
The repository is treated as a virtual Sequence
for design consistency. If you take 100
aggregates and then drop 1_000
then the result is necessarily empty.
This allows these 2 examples to be equivalent: