| Safe Haskell | None |
|---|
Network.HTTP.QueryString.Pickle
Contents
- class IsQuery a where
- queryPickler :: PU a
- toQuery :: IsQuery a => a -> [(ByteString, ByteString)]
- fromQuery :: IsQuery a => [(ByteString, ByteString)] -> Either String a
- encodeQuery :: (ByteString -> ByteString) -> [(ByteString, ByteString)] -> ByteString
- decodeQuery :: (ByteString -> ByteString) -> ByteString -> [(ByteString, ByteString)]
- data Query
- = List [Query]
- | Pair ByteString Query
- | Value ByteString
- data QueryPU a = QueryPU {}
- data QueryOptions = QueryOptions {
- queryCtorModifier :: String -> String
- queryFieldModifier :: String -> String
- defaultQueryOptions :: QueryOptions
- loweredQueryOptions :: QueryOptions
- class GIsQuery f where
- gQueryPickler :: QueryOptions -> PU a -> PU (f a)
- genericQueryPickler :: (Generic x, GIsQuery (Rep x)) => QueryOptions -> PU x
- qpWrap :: (a -> b, b -> a) -> PU a -> PU b
- qpElem :: ByteString -> PU a -> PU a
- qpPair :: PU a -> PU b -> PU (a, b)
- qpLift :: a -> PU a
- qpPrim :: (Read a, Show a) => PU a
- qpOption :: PU a -> PU (Maybe a)
- qpDefault :: a -> PU a -> PU a
- qpSum :: PU (f r) -> PU (g r) -> PU ((f :+: g) r)
- qpEither :: PU a -> PU b -> PU (Either a b)
- qpOrdinalList :: PU a -> PU [a]
- qpList :: PU a -> PU [a]
Class
A type that has a pairing of pickler + unpickler.
Using the DeriveGeneric language extension, this class specifies a default generic implementation using genericQueryPickler.
For example:
{-# LANGUAGE DeriveGeneric #-} import GHC.Generics data Foo = Foo { fooIntX :: Int, fooIntY :: Int } deriving (Generic) instance IsQuery Foo Note that you can parameterise some of the options to genericQueryPickler by specifying an implementation instead of using DefaultSignatures.
The previous example:
instance IsQuery Foo where queryPickler =genericQueryPicklerdefaultQueryOptions
More examples of creating queryPickler implementations can be found in the README or in the tests.
Methods
queryPickler :: PU aSource
Functions
toQuery :: IsQuery a => a -> [(ByteString, ByteString)]Source
Pickle a data type with an IsQuery instance to an association list.
fromQuery :: IsQuery a => [(ByteString, ByteString)] -> Either String aSource
Unpickle an association list to an IsQuery type, returning an error message when unpickling fails.
Arguments
| :: (ByteString -> ByteString) | URL Value Encoder |
| -> [(ByteString, ByteString)] | Key/Value Pairs |
| -> ByteString |
Helper to encode an association list as a single canonical query string.
Arguments
| :: (ByteString -> ByteString) | URL Value Decoder |
| -> ByteString | Input Query String |
| -> [(ByteString, ByteString)] |
Helper to decode a query string to an association list.
Data Types
Internal tree representation for queries.
Constructors
| List [Query] | |
| Pair ByteString Query | |
| Value ByteString |
Pairing of pickler to unpickler.
Options
data QueryOptions Source
Options for genericQueryPickler to parameterise how constructor and record field labels are un/pickled.
For example:
import GHC.Generics data Bar { barThisIsAByteString :: ByteString } deriving (Generic) instance IsQuery Foo where queryPickler = genericQueryPickler $ Options { queryCtorModifier = id , queryFieldModifier = dropWhile isLower } Would remove bar from the record field barThisIsAByteString so the resulting pair for that field in the association list would be (ThisIsAByteString, n :: Int).
The above example is how defaultQueryOptions behaves.
Constructors
| QueryOptions | |
Fields
| |
defaultQueryOptions :: QueryOptionsSource
Strips lowercase prefixes from record fields.
loweredQueryOptions :: QueryOptionsSource
Strips lowercase prefixes from record fields and subsequently lowercases the remaining identifier.
Generics
Methods
gQueryPickler :: QueryOptions -> PU a -> PU (f a)Source
genericQueryPickler :: (Generic x, GIsQuery (Rep x)) => QueryOptions -> PU xSource
Combinators
qpElem :: ByteString -> PU a -> PU aSource
qpOrdinalList :: PU a -> PU [a]Source