Safe Haskell | None |
---|
- 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 PU a = PU {}
- data GenericQueryOptions = GenericQueryOptions {
- constructorTagModifier :: String -> String
- fieldLabelModifier :: String -> String
- defaultQueryOptions :: Options
- loweredQueryOptions :: Options
- genericQueryPickler :: (Generic x, GIsQuery (Rep x)) => Options -> 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 { 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 =genericQueryPickler
defaultOptions
More examples of creating queryPickler
implementations can be found in the
README
or in the tests
.
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.
:: (ByteString -> ByteString) | URL Value Encoder |
-> [(ByteString, ByteString)] | Key/Value Pairs |
-> ByteString |
Helper to encode an association list as a single canonical query string.
:: (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.
Pairing of pickler to unpickler.
Options
data GenericQueryOptions 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
{ constructorTagModifier = id
, fieldLabelModifier = 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 defaultOptions
behaves.
GenericQueryOptions | |
|
defaultQueryOptions :: OptionsSource
Strips lowercase prefixes from record fields.
loweredQueryOptions :: OptionsSource
Strips lowercase prefixes from record fields and subsequently lowercases the remaining identifier.
Generics
genericQueryPickler :: (Generic x, GIsQuery (Rep x)) => Options -> PU xSource
Combinators
qpElem :: ByteString -> PU a -> PU aSource
qpOrdinalList :: PU a -> PU [a]Source