raphaelvigee/go-paginate

[Feature Request] Number of pages

Closed this issue · 4 comments

Hi there. First of all, great library, really simple to use and effective.
One feature I would like to request, if you have time of course, is ability to have the number of total pages available for given query, perhaps adding it to PageInfo struct?

I have not seen any other similar library supporting that, cause it doesnt really make sense I would say, can you provide examples of how that would work ?

For example, if you request a query that has in total 200 results, and you fetch 20 results per page, just to have a key in pageinfo that there are total 10 pages, or 200 results. It would be useful if you're showing your data in a table (showing 1-20 of 200 rows)

I agree it would be useful, but because of the way cursor work, there is no way to correlate your current position to the total number of pages in a consistent manner, hence why this seems out of scope for this library.
If you use the gorm driver, you can do something like:

// tx is your gorm query
pages := tx.Count() / perPages

That will work too, thanks. Great library :)