hasql-generic-0.1.0.5: Generic encoder and decoder deriving for Hasql

Safe HaskellNone
LanguageHaskell2010

Hasql.Generic.HasParams

Synopsis

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

Methods

mkParams :: Params a Source #

mkParams :: (Generic a, Code a ~ '[xs], All HasEField xs) => Params a Source #

Instances

All * HasEField ((:) * a ((:) * b ([] *))) => HasParams (a, b) Source # 

Methods

mkParams :: Params (a, b) Source #

All * HasEField ((:) * a ((:) * b ((:) * c ([] *)))) => HasParams (a, b, c) Source # 

Methods

mkParams :: Params (a, b, c) Source #

All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ([] *))))) => HasParams (a, b, c, d) Source # 

Methods

mkParams :: Params (a, b, c, d) Source #

All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ([] *)))))) => HasParams (a, b, c, d, e) Source # 

Methods

mkParams :: Params (a, b, c, d, e) Source #

All * HasEField ((:) * a ((:) * b ((:) * c ((:) * d ((:) * e ((:) * f ([] *))))))) => HasParams (a, b, c, d, e, f) Source # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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 # 

Methods

mkParams :: Params (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.

Minimal complete definition

mkEField

Methods

mkEField :: Params a Source #

gParams :: (Generic a, Code a ~ '[xs], All HasEField xs) => Params a Source #

Generate a 'Params a' generically

gEEnumValue :: (Generic a, All (Equal '[]) (Code a)) => NP (K Text) (Code a) -> Value a Source #

Derive a HasEValue for enumeration types