| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Web.Hyperbole.Data.QueryData
Synopsis
- newtype Param = Param {}
- newtype QueryData = QueryData (Map Param Text)
- parseParam :: FromJSON a => Value -> Either String a
- encodeParam :: ToJSON a => a -> Text
- decodeParam :: FromJSON a => Text -> Either String a
- singleton :: ToJSON a => Param -> a -> QueryData
- insert :: ToJSON a => Param -> a -> QueryData -> QueryData
- insertAll :: ToQuery a => a -> QueryData -> QueryData
- delete :: Param -> QueryData -> QueryData
- lookup :: FromJSON a => Param -> QueryData -> Maybe a
- require :: FromJSON a => Param -> QueryData -> Either String a
- filterKey :: (Param -> Bool) -> QueryData -> QueryData
- member :: Param -> QueryData -> Bool
- elems :: QueryData -> [Text]
- render :: QueryData -> Text
- parse :: Text -> QueryData
- queryData :: Query -> QueryData
- fromQueryData :: QueryData -> Query
- class FromQuery a where
- parseQuery :: QueryData -> Either String a
- class ToQuery a where
- class GFromQuery (f :: k -> Type) where
- gParseQuery :: forall (p :: k). QueryData -> Either String (f p)
- class GToQuery (f :: k -> Type) where
Documentation
Key-value store for query params and sessions
encodeParam :: ToJSON a => a -> Text Source #
decodeParam :: FromJSON a => Text -> Either String a Source #
Decode a parameter from JSON. Uses unquoted strings when possible
fromQueryData :: QueryData -> Query Source #
class FromQuery a where Source #
Decode a type from a QueryData. Missing fields are set to def
data Filters = Filters
{ active :: Bool
, term :: Text
}
deriving (Generic, Eq, FromQuery, ToQuery)
>>>parseQuery $ QueryData.parse "active=true&search=asdf"Right (Filters True "asdf")
>>>parseQuery $ QueryData.parse "search=asdf"Right (Filters False "asdf")
Minimal complete definition
Nothing
Methods
parseQuery :: QueryData -> Either String a Source #
default parseQuery :: (Generic a, GFromQuery (Rep a)) => QueryData -> Either String a Source #
class ToQuery a where Source #
A page can store state in the browser query string. ToQuery and FromQuery control how a datatype is encoded to a full query string
data Filters = Filters
{ active :: Bool
, term :: Text
}
deriving (Generic, Eq, FromQuery, ToQuery)
>>>QueryData.render $ toQuery $ Filter True "asdf""active=true&search=asdf"
If the value of a field is the same as Default, it will be omitted from the query string
>>>QueryData.render $ toQuery $ Filter True """active=true"
>>>QueryData.render $ toQuery $ Filter False """"
Minimal complete definition
Nothing
Methods
class GFromQuery (f :: k -> Type) where Source #
Generic decoding of records from a Query
Instances
| (GFromQuery f, GFromQuery g) => GFromQuery (f :*: g :: k -> Type) Source # | |
Defined in Web.Hyperbole.Data.QueryData | |
| GFromQuery f => GFromQuery (M1 C c f :: k -> Type) Source # | |
Defined in Web.Hyperbole.Data.QueryData | |
| GFromQuery f => GFromQuery (M1 D d f :: k -> Type) Source # | |
Defined in Web.Hyperbole.Data.QueryData | |
| Selector s => GFromQuery (M1 S s (K1 R Text :: k -> Type) :: k -> Type) Source # | |
| (Selector s, FromJSON a, Default a) => GFromQuery (M1 S s (K1 R a :: k -> Type) :: k -> Type) Source # | |
class GToQuery (f :: k -> Type) where Source #
Generic encoding of records to a Query
Instances
| (GToQuery f, GToQuery g) => GToQuery (f :*: g :: k -> Type) Source # | |
| GToQuery f => GToQuery (M1 C d f :: k -> Type) Source # | |
| GToQuery f => GToQuery (M1 D d f :: k -> Type) Source # | |
| Selector s => GToQuery (M1 S s (K1 R Text :: k -> Type) :: k -> Type) Source # | |
| (Selector s, ToJSON a, Eq a, Default a) => GToQuery (M1 S s (K1 R a :: k -> Type) :: k -> Type) Source # | |