I have a problem. I need this code below to return a specific amount of lines (LimitTo), from a specific number of results (OffsetBy). The code of the application I'm doing for this purpose is this:
getBuscR :: Int -> Handler Value
getBuscR pageNumber = do
let numberOfPages = 15
results <- runDB $ selectList [] [LimitTo numberOfPages, OffsetBy $ (pageNumber - 1) * numberOfpages]
sendStatusJSON ok200 (object ["answer" := results])
I made the previous code based on this example that is in the yesod documentation. But I think it's out of date: (the book has not been updated since 2011!). The book's example is this:
resultsForPage pageNumber = do
let resultsPerPage = 10
selectList
[ PersonAge >=. 18
]
[ Desc PersonAge
, Asc PersonLastName
, Asc PersonFirstName
, LimitTo resultsPerPage
, OffsetBy $ (pageNumber - 1) * resultsPerPage
]