fastapi-pagination icon indicating copy to clipboard operation
fastapi-pagination copied to clipboard

Option to return both Page and Offset

Open dhait opened this issue 2 years ago • 3 comments

I would like to have the page number as well as the offset returned in the response. Currently I can either choose Page or LimitOffsetPage but not both.

dhait avatar Aug 23 '23 14:08 dhait

Hi @dhait,

Could you please provide examples of what you want to achieve?

uriyyo avatar Aug 24 '23 07:08 uriyyo

For response_model "Page", we get:

  "items": [ ... ],
  "page": 2,
  "size": 3,
  "pages": 34,
  "total": 100
}

For response_mode "LimitOffsetPage", we get:

{
  "items": [ ... ],
  "limit": 3,
  "offset": 2,
  "total": 100
}

I would like to see:

{
  "items": [ ... ],
  "page": 2,
  "size": 3,
  "offset": 3
  "pages": 34,
  "total": 100
}


Meaning, the first item displayed is "n" offset from the beginning.

I know I could figure it out by multiplying "size" by "page" but it seems like an extra unnecessary step.

Also, it would be a more flexible solution if we could supply EITHER "page" or "offset" as a parameter, depending on the need (notice that "limit" and "size" appear to be the same value).

dhait avatar Aug 29 '23 17:08 dhait