Pagination

Teo supports offset pagination, page size based pagination and cursor based pagination.

Offset pagination

Offset pagination uses skip and take to skip a certain number of results and select a limited range. The following query skips the first 2 records and returns records 3 - 5:

Graph
const results = await teo.song.findMany({
  skip: 2,
  take: 3,
})

Take from opposite direction

If a negative take is provided, it takes from the other side.

Graph
const results = await teo.song.findMany({
  skip: 2,
  take: -3,
})

Pagination with pageNumber and pageSize

This query takes records on the 2nd page. numberOfPages is also returned in meta section of the results.

const result = await teo.song.findMany({
  pageSize: 10,
  pageNumber: 2,
})

Cursor based pagination

Cursor based pagination uses cursor and take to return a limited set of results before or after a given cursor. A cursor bookmarks your location in a result set and must be a unique, sequential column.

Graph
const result = await teo.song.findMany({
  cursor: {
    id: 85
  }
})