I'm in the situation where my queries return a lot (potentially over 50.000+) results, but for each page I only want to display 50 results and then make it possible to click a next/previous button..
I was thinking this could be achieved this way:
querySize := 50
total, err := db.client.Count(ctx, query)
numPages := (total % querySize)
if numPages > curPage {
return nil, errors.New("out of range")
}
offset := querySize * curPage
query = query.Offset(offset).Limit(querySize)
var app []AppStoreApp
if _, err := db.client.GetAll(ctx, query, &app); err != nil {
return nil, err
}
return &app, nil
But is this efficient, and is there a better way to do it?
Also, it's simple to check whether a previous button should be enabled since you can just say if curPage > 1
then it should be enabled.. but how about checking if next button should be enabled? Perhaps by setting querySize to 51, and then only using 50 of the results?
Any help/advice would be much appreciated :)