hyperbole-0.4.2: Interactive HTML apps using type-safe serverside Haskell
Safe HaskellNone
LanguageGHC2021

Web.Hyperbole.Data.QueryData

Synopsis

Documentation

newtype Param Source #

Constructors

Param 

Fields

Instances

Instances details
IsString Param Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Methods

fromString :: String -> Param #

Show Param Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Methods

showsPrec :: Int -> Param -> ShowS #

show :: Param -> String #

showList :: [Param] -> ShowS #

Eq Param Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Methods

(==) :: Param -> Param -> Bool #

(/=) :: Param -> Param -> Bool #

Ord Param Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Methods

compare :: Param -> Param -> Ordering #

(<) :: Param -> Param -> Bool #

(<=) :: Param -> Param -> Bool #

(>) :: Param -> Param -> Bool #

(>=) :: Param -> Param -> Bool #

max :: Param -> Param -> Param #

min :: Param -> Param -> Param #

newtype QueryData Source #

Key-value store for query params and sessions

Constructors

QueryData (Map Param ParamValue) 

class FromQuery a where Source #

Decode a type from a QueryData. Missing fields are set to defaultParam

data Filters = Filters
  { active :: Bool
  , term :: Text
  }
  deriving (Generic, FromQuery, ToQuery)
>>> parseQuery $ parse "active=true&search=asdf"
Right (Filters True "asdf")
>>> parseQuery $ parse "search=asdf"
Right (Filters False "asdf")

Minimal complete definition

Nothing

Instances

Instances details
FromQuery QueryData Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

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, FromQuery, ToQuery)
>>> render $ toQuery $ Filter True "asdf"
"active=true&search=asdf"

If the value of a field is the same as DefaultParam, it will be omitted from the query string

>>> render $ toQuery $ Filter True ""
"active=true"
>>> render $ toQuery $ Filter False ""
""

Minimal complete definition

Nothing

Methods

toQuery :: a -> QueryData Source #

default toQuery :: (Generic a, GToQuery (Rep a)) => a -> QueryData Source #

Instances

Instances details
ToQuery Query Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

ToQuery QueryData Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

class ToParam a where Source #

sessions, forms, and querys all encode data as query strings. ToParam and FromParam control how a datatype is encoded to a parameter. By default it simply url-encodes the show instance.

data Todo = Todo
  { id :: TodoId
  , task :: Text
  , completed :: Bool
  }
  deriving (Show, Read, ToParam, FromParam)
data Tags = Tags [Text]

instance ToParam Tags where
  toParam (Tags ts) = ParamValue $ Text.intercalate "," ts

Minimal complete definition

Nothing

Methods

toParam :: a -> ParamValue Source #

default toParam :: Show a => a -> ParamValue Source #

Instances

Instances details
ToParam Word16 Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

ToParam Word32 Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

ToParam Word64 Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

ToParam Word8 Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

ToParam Text Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

ToParam UTCTime Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

ToParam Integer Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

ToParam Bool Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

ToParam Char Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

ToParam Double Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

ToParam Float Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

ToParam Int Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

ToParam Word Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

ToParam a => ToParam (Maybe a) Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Show a => ToParam [a] Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Methods

toParam :: [a] -> ParamValue Source #

(ToParam a, ToParam b) => ToParam (Either a b) Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Methods

toParam :: Either a b -> ParamValue Source #

(Show k, Show v) => ToParam (Map k v) Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Methods

toParam :: Map k v -> ParamValue Source #

class FromParam a where Source #

Decode data from a query, session, or form parameter value

data Todo = Todo
  { id :: TodoId
  , task :: Text
  , completed :: Bool
  }
  deriving (Show, Read, ToParam, FromParam)
data Tags = Tags [Text]

instance FromParam Tags where
  parseParam (ParamValue t) =
    pure $ Tags $ Text.splitOn "," t

Minimal complete definition

Nothing

Instances

Instances details
FromParam Word16 Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

FromParam Word32 Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

FromParam Word64 Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

FromParam Word8 Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

FromParam Text Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

FromParam UTCTime Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

FromParam Integer Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

FromParam Bool Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

FromParam Char Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

FromParam Double Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

FromParam Float Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

FromParam Int Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

FromParam Word Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

FromParam a => FromParam (Maybe a) Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Read a => FromParam [a] Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

(FromParam a, FromParam b) => FromParam (Either a b) Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

(Read k, Read v, Ord k) => FromParam (Map k v) Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

showQueryParam :: Show a => a -> ParamValue Source #

Encode a Show as a query param

readQueryParam :: Read a => ParamValue -> Either Text a Source #

Decode a Read as a query param

parseParams :: (Traversable t, FromParam a) => t ParamValue -> Either Text (t a) Source #

Parse a Traversable (list) of params

class GFromQuery (f :: k -> Type) where Source #

Generic decoding of records from a Query

Methods

gParseQuery :: forall (p :: k). QueryData -> Either Text (f p) Source #

Instances

Instances details
(GFromQuery f, GFromQuery g) => GFromQuery (f :*: g :: k -> Type) Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Methods

gParseQuery :: forall (p :: k). QueryData -> Either Text ((f :*: g) p) Source #

GFromQuery f => GFromQuery (M1 C c f :: k -> Type) Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Methods

gParseQuery :: forall (p :: k). QueryData -> Either Text (M1 C c f p) Source #

GFromQuery f => GFromQuery (M1 D d f :: k -> Type) Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Methods

gParseQuery :: forall (p :: k). QueryData -> Either Text (M1 D d f p) Source #

(Selector s, FromParam a, DefaultParam a) => GFromQuery (M1 S s (K1 R a :: k -> Type) :: k -> Type) Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Methods

gParseQuery :: forall (p :: k). QueryData -> Either Text (M1 S s (K1 R a :: k -> Type) p) Source #

class GToQuery (f :: k -> Type) where Source #

Generic encoding of records to a Query

Methods

gToQuery :: forall (p :: k). f p -> QueryData Source #

Instances

Instances details
(GToQuery f, GToQuery g) => GToQuery (f :*: g :: k -> Type) Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Methods

gToQuery :: forall (p :: k). (f :*: g) p -> QueryData Source #

GToQuery f => GToQuery (M1 C d f :: k -> Type) Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Methods

gToQuery :: forall (p :: k). M1 C d f p -> QueryData Source #

GToQuery f => GToQuery (M1 D d f :: k -> Type) Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Methods

gToQuery :: forall (p :: k). M1 D d f p -> QueryData Source #

(Selector s, ToParam a, Eq a, DefaultParam a) => GToQuery (M1 S s (K1 R a :: k -> Type) :: k -> Type) Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Methods

gToQuery :: forall (p :: k). M1 S s (K1 R a :: k -> Type) p -> QueryData Source #

class DefaultParam a where Source #

Data.Default doesn't have a Text instance. This class does

Minimal complete definition

Nothing

Methods

defaultParam :: a Source #

default defaultParam :: Default a => a Source #

Instances

Instances details
DefaultParam Text Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Default a => DefaultParam a Source # 
Instance details

Defined in Web.Hyperbole.Data.QueryData

Methods

defaultParam :: a Source #