- Published on
TypeORM Pagination
- Authors
- Name
- Yair Mark
- @yairmark
When working with a DB you often may want/need to paginate the results. This is adventageous as:
- You do not have to pull as much from the DB
- The DB does not have to work as hard (pagination adds to the where clause which can improve performance)
- You do not have to transfer as much over the wire
- This can be better if the user generally only looks at a subset of the data anyway. But if there are situations where the user generally needs all data then getting all once over the wire is preferable to multiple round trip calls to the server for each page.
In TypeORM paginating on find is done using the skip
and take
properties.
skip
: Is the offset or first page to start from. This is0
indexed.take
: Is the number of items to have per page.
An example query is:
userRepository.find({
skip: 0,
take: 10,
})
The other possible find options can be found here.