| Stability | experimental |
|---|---|
| Maintainer | woozletoff@gmail.com |
| Safe Haskell | None |
Web.RBB.Blog.Query
Contents
Description
This module provides some functions and data types that can be used to manage
search and query data for a list of Entry values.
- data EntryQuery = EntryQuery {}
- data SortMethod
- = Update
- | Identifier
- | Author
- data SortOrder
- = Ascending
- | Descending
- sortMethodToComparator :: SortMethod -> SortOrder -> Entry -> Entry -> Ordering
Documentation
data EntryQuery Source
The request data provided inside a URL.
Example: ?id=42&sortBy=Identifier
Example backend implementation using the Happstack package:
import Happstack.Server (look, HasRqData, ServerPartT)
maybeLookAndRead :: (Monad m, Read a, Alternative m, HasRqData m)
=> a -> String -> m a
maybeLookAndRead a qry = do
l <- optional $ look qry
return $ fromMaybe a (maybe (Just a) readMaybe l)
-- | Parse the supported request data and present it in a data type.
parseQueryRqData :: ServerPartT IO EntryQuery
parseQueryRqData = EntryQuery
<$> (sortMethodToComparator
<$> maybeLookAndRead Update "sortBy"
<*> maybeLookAndRead Descending "sortOrder")
Constructors
| EntryQuery | |
Instances
| Default EntryQuery | The |
Sorting
data SortMethod Source
Simple enum that provides Show and read instances so that a parser can convert the sting directly to a value of this type.
Constructors
| Update | |
| Identifier | |
| Author |
Instances
Constructors
| Ascending | |
| Descending |
sortMethodToComparator :: SortMethod -> SortOrder -> Entry -> Entry -> OrderingSource
Convert a SortMethod value to a sorting function that can be used in
confunction with functions sortBy from Data.List.