How to implement paging in Yesod?

Asked

Viewed 33 times

0

I have a problem. I need this code below to return a specific amount of lines (Limit) 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 believe it is outdated: (the book has not been updated since 2011!). The example of the book is this:

resultsForPage pageNumber = do
    let resultsPerPage = 10
    selectList
        [ PersonAge >=. 18
        ]
        [ Desc PersonAge
        , Asc PersonLastName
        , Asc PersonFirstName
        , LimitTo resultsPerPage
        , OffsetBy $ (pageNumber - 1) * resultsPerPage
        ]
  • 1

    Young man, our language is Portuguese, translate your question there.

  • Which version of Haskell/Yesod are you using ? if you are in 2.0 this is wrong, ps, tell which one to know the kk answer

  • I managed to solve the problem, thank you!! I missed the desc/asc (attributeDaTable) to reference which table is being treated.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.