Stability | experimental |
---|---|
Maintainer | woozletoff@gmail.com |
Safe Haskell | None |
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")
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.
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.