Safe Haskell | None |
---|---|
Language | Haskell2010 |
- class HasParams a where
- class HasEField a where
- class HasEValue a where
- mkParams :: HasParams a => Params a
- mkEField :: HasEField a => Params a
- mkEValue :: HasEValue a => Value a
- gParams :: (Generic a, Code a ~ '[xs], All HasEField xs) => Params a
- gEEnumValue :: (Generic a, All (Equal '[]) (Code a)) => NP (K Text) (Code a) -> Value a
Documentation
class HasParams a where Source #
A type that can be encoded into database parameters, using Hasql's Params
encoder.
Your data type needs to derive GHC Generic
, and using this derive
an instance of SOP Generic
. From here you can derive an instance
of HasParams
. This gives you access to a value mkParams
, which you can use
to get a value of type Params
.
{-# DeriveGeneric #-}
import Data.Text (Text)
import Data.UUID (UUID)
import qualified GHC.Generics as GHC
import Generics.SOP
import Hasql.Query (statement)
import Hasql.Session (Session, query)
import qualified Hasql.Decoders as HD
import qualified Hasql.Encoders as HE
data Person = Person
{ personId :: UUID
, personName :: Text
, personAge :: Int
} deriving (GHC.Generic)
instance Generic Person
instance HasParams Person
-- Search for a Person
with a matching UUID
createPerson :: Person -> Session ()
createPerson person =
query person preparedStatement
where
preparedStatement = statement sql encoder decoder True
sql = "INSERT INTO people (id, name, age) VALUES ($1, $2, $3)"
encoder = mkParams
decoder = HD.unit
All * HasEField ((:) * a ((:) * b ([] *))) => HasParams (a, b) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ([] *)))) => HasParams (a, b, c) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ([] *))))) => HasParams (a, b, c, d) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ([] *)))))) => HasParams (a, b, c, d, e) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ([] *))))))) => HasParams (a, b, c, d, e, f) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ([] *)))))))) => HasParams (a, b, c, d, e, f, g) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ([] *))))))))) => HasParams (a, b, c, d, e, f, g, h) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ((:) * i ([] *)))))))))) => HasParams (a, b, c, d, e, f, g, h, i) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ((:) * i ((:) * j ([] *))))))))))) => HasParams (a, b, c, d, e, f, g, h, i, j) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ((:) * i ((:) * j ((:) * k ([] *)))))))))))) => HasParams (a, b, c, d, e, f, g, h, i, j, k) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ((:) * i ((:) * j ((:) * k ((:) * l ([] *))))))))))))) => HasParams (a, b, c, d, e, f, g, h, i, j, k, l) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ((:) * i ((:) * j ((:) * k ((:) * l ((:) * m ([] *)))))))))))))) => HasParams (a, b, c, d, e, f, g, h, i, j, k, l, m) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ((:) * i ((:) * j ((:) * k ((:) * l ((:) * m ((:) * n ([] *))))))))))))))) => HasParams (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ((:) * i ((:) * j ((:) * k ((:) * l ((:) * m ((:) * n ((:) * o ([] *)))))))))))))))) => HasParams (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ((:) * i ((:) * j ((:) * k ((:) * l ((:) * m ((:) * n ((:) * o ((:) * p ([] *))))))))))))))))) => HasParams (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ((:) * i ((:) * j ((:) * k ((:) * l ((:) * m ((:) * n ((:) * o ((:) * p ((:) * q ([] *)))))))))))))))))) => HasParams (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ((:) * i ((:) * j ((:) * k ((:) * l ((:) * m ((:) * n ((:) * o ((:) * p ((:) * q ((:) * r ([] *))))))))))))))))))) => HasParams (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ((:) * i ((:) * j ((:) * k ((:) * l ((:) * m ((:) * n ((:) * o ((:) * p ((:) * q ((:) * r ((:) * s ([] *)))))))))))))))))))) => HasParams (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ((:) * i ((:) * j ((:) * k ((:) * l ((:) * m ((:) * n ((:) * o ((:) * p ((:) * q ((:) * r ((:) * s ((:) * t ([] *))))))))))))))))))))) => HasParams (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ((:) * i ((:) * j ((:) * k ((:) * l ((:) * m ((:) * n ((:) * o ((:) * p ((:) * q ((:) * r ((:) * s ((:) * t ((:) * u ([] *)))))))))))))))))))))) => HasParams (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ((:) * i ((:) * j ((:) * k ((:) * l ((:) * m ((:) * n ((:) * o ((:) * p ((:) * q ((:) * r ((:) * s ((:) * t ((:) * u ((:) * v ([] *))))))))))))))))))))))) => HasParams (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ((:) * i ((:) * j ((:) * k ((:) * l ((:) * m ((:) * n ((:) * o ((:) * p ((:) * q ((:) * r ((:) * s ((:) * t ((:) * u ((:) * v ((:) * w ([] *)))))))))))))))))))))))) => HasParams (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ((:) * i ((:) * j ((:) * k ((:) * l ((:) * m ((:) * n ((:) * o ((:) * p ((:) * q ((:) * r ((:) * s ((:) * t ((:) * u ((:) * v ((:) * w ((:) * x ([] *))))))))))))))))))))))))) => HasParams (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ((:) * i ((:) * j ((:) * k ((:) * l ((:) * m ((:) * n ((:) * o ((:) * p ((:) * q ((:) * r ((:) * s ((:) * t ((:) * u ((:) * v ((:) * w ((:) * x ((:) * y ([] *)))))))))))))))))))))))))) => HasParams (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y) Source # | |
All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ((:) * g ((:) * h ((:) * i ((:) * j ((:) * k ((:) * l ((:) * m ((:) * n ((:) * o ((:) * p ((:) * q ((:) * r ((:) * s ((:) * t ((:) * u ((:) * v ((:) * w ((:) * x ((:) * y ((:) * z ([] *))))))))))))))))))))))))))) => HasParams (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) Source # | |
class HasEField a where Source #
A type representing a value encoder lifted into a composable params encoder.
Fields with HasEValue
instances will be automatically lifted into some
common wrappers, including vectors, lists, and maybe.
HasEField Int Source # | |
HasEField Word16 Source # | |
HasEField Word32 Source # | |
HasEField Word64 Source # | |
HasEValue a => HasEField a Source # | |
HasEValue a => HasEField [Maybe a] Source # | |
HasEValue a => HasEField [a] Source # | |
HasEField (Maybe Int) Source # | |
HasEField (Maybe Word16) Source # | |
HasEField (Maybe Word32) Source # | |
HasEField (Maybe Word64) Source # | |
HasEValue a => HasEField (Maybe a) Source # | |
HasEValue a => HasEField (Vector (Maybe a)) Source # | |
HasEValue a => HasEField (Vector a) Source # | |
class HasEValue a where Source #
A type representing a encoder of an individual value. Instances should be defined manually for each type.