Portability | Not portable |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Documentation
:: HasDB layout m | |
=> Proxy layout | API layout |
-> Proxy m | PostgreSQL monad we operate in |
-> DB layout m | Derived functions |
Derive DB client from API
class HasDB layout m where Source #
Derive DB client from API
deriveDBWithCtx :: Proxy layout -> Proxy m -> QueryContext ToField -> DB layout m Source #
Derive DB client from API layout
(HasDB api1 m, HasDB api2 m) => HasDB ((:<|>) api1 api2) m Source # | Deriving several procedures to query DB API type API = Procedure "time" Integer :| ArgNamed "a" Int :> Procedure "square" (Only Int) data MyMonad m a -- Your application monad with connection pool and logger instance HasPostgres m instance MonadLogger m time :: MyMonad (Only Integer) square :: Int -> MyMonad (Only Int) (time, square) = deriveDB (Proxy :: Proxy API) (Proxy :: Proxy MyMonad) Upper example will derive separate endpoints with the following SQL calls: >>> SELECT time(); >>> SELECT square("a" => ?); |
(KnownSymbol n, FromRow a, MonadPostgres m) => HasDB (Procedure n a) m Source # | Deriving call to DB procedure with single result type API = Arg "a" Int -> Procedure "squareReturning" (Int, Int) data MyMonad m a -- Your application monad with connection pool and logger instance HasPostgres m instance MonadLogger m square :: Int -> MyMonad (Int, Int) square = deriveDB (Proxy :: Proxy API) (Proxy :: Proxy MyMonad) Upper example will derive the following SQL call: >>> SELECT * FROM squareReturning() AS t; The instance expects that return type of SQL stored function is a single row. |
(KnownSymbol n, FromRow a, MonadPostgres m) => HasDB (Procedure n (Maybe a)) m Source # | Deriving call to DB procedure with optional result data User -- user data instance FromRow User type API = ArgPos Int :> Procedure "user" (Maybe User) data MyMonad m a -- Your application monad with connection pool and logger instance HasPostgres m instance MonadLogger m getUsers :: MyMonad (Maybe User) getUsers = deriveDB (Proxy :: Proxy API) (Proxy :: Proxy MyMonad) Upper example will derive the following SQL call: >>> SELECT * FROM user(?) AS t; |
(KnownSymbol n, FromRow a, MonadPostgres m) => HasDB (Procedure n [a]) m Source # | Deriving call to DB procedure with multiple result data User -- user data instance FromRow User type API = Procedure "users" [User] data MyMonad m a -- Your application monad with connection pool and logger instance HasPostgres m instance MonadLogger m getUsers :: MyMonad [User] getUsers = deriveDB (Proxy :: Proxy API) (Proxy :: Proxy MyMonad) Upper example will derive the following SQL call: >>> SELECT * FROM users() AS t; And the instance expects that |
(KnownSymbol n, MonadPostgres m) => HasDB (Procedure n ()) m Source # | Deriving call to DB procedure with no return type data User -- user data instance ToRow User type API = Arg "user" User :> Procedure "registerUser" () data MyMonad m a -- Your application monad with connection pool and logger instance HasPostgres m instance MonadLogger m getUsers :: User -> MyMonad () getUsers = deriveDB (Proxy :: Proxy API) (Proxy :: Proxy MyMonad) Upper example will derive the following SQL call: >>> SELECT registerUser("user" => ?); And the instance expects that |
(ToField a, HasDB api m) => HasDB ((:>) * * (ArgPos a) api) m Source # | Deriving call to DB procedure with positional arguments type API = Arg Int :> Arg Int :> Procedure "sum" (Only Int) data MyMonad m a -- Your application monad with connection pool and logger instance HasPostgres m instance MonadLogger m dbSum :: Int -> Int -> MyMonad (Only Int) dbSum = deriveDB (Proxy :: Proxy API) (Proxy :: Proxy MyMonad) Upper example will derive the following SQL call: >>> SELECT * FROM sum(?, ?) AS t; |
(ToField a, HasDB api m) => HasDB ((:>) * * (ArgPos (Default a)) api) m Source # | Deriving call to DB procedure with positional default arguments type API = ArgPos (Default Int) :> Procedure "foo" (Only Int) data MyMonad m a -- Your application monad with connection pool and logger instance HasPostgres m instance MonadLogger m dbFoo :: Default Int -> MyMonad (Only Int) dbFoo = deriveDB (Proxy :: Proxy API) (Proxy :: Proxy MyMonad) Upper example will derive the following SQL call: >>> SELECT * FROM foo(DEFAULT) AS t; |
(ToField a, HasDB api m) => HasDB ((:>) * * (ArgPos (Variadic a)) api) m Source # | Deriving call to DB procedure with positional variadic arguments type API = ArgPos (Variadic Int) :> Procedure "mleast" (Only Int) data MyMonad m a -- Your application monad with connection pool and logger instance HasPostgres m instance MonadLogger m dbMleast :: Variadic Int -> MyMonad (Only Int) dbMleast = deriveDB (Proxy :: Proxy API) (Proxy :: Proxy MyMonad) Upper example will derive the following SQL call: >>> SELECT * FROM mleast(VARIADIC ?) AS t; |
(KnownSymbol n, ToField a, HasDB api m) => HasDB ((:>) * * (ArgNamed n (Default a)) api) m Source # | Deriving call to DB procedure with named default arguments type API = ArgNamed "a" (Defaultable Int) :> Procedure "foo" (Only Int) data MyMonad m a -- Your application monad with connection pool and logger instance HasPostgres m instance MonadLogger m dbFoo :: Defaultable Int -> MyMonad (Only Int) dbFoo = deriveDB (Proxy :: Proxy API) (Proxy :: Proxy MyMonad) Upper example will derive the following SQL call: >>> SELECT * FROM default(DEFAULT) AS t; |
(KnownSymbol n, ToField a, HasDB api m) => HasDB ((:>) * * (ArgNamed n (Variadic a)) api) m Source # | Deriving call to DB procedure with named variadic arguments type API = ArgNamed "arr" (Variadic Int) :> Procedure "mleast" (Only Int) data MyMonad m a -- Your application monad with connection pool and logger instance HasPostgres m instance MonadLogger m dbMleast :: Variadic Int -> MyMonad (Only Int) dbMleast = deriveDB (Proxy :: Proxy API) (Proxy :: Proxy MyMonad) Upper example will derive the following SQL call: >>> SELECT * FROM mleast(VARIADIC "arr" => ?) AS t; |
(KnownSymbol n, ToField a, HasDB api m) => HasDB ((:>) * * (ArgNamed n a) api) m Source # | Deriving call to DB procedure with named arguments type API = ArgNamed "a" Int :> ArgNamed "b" Int :> Procedure "sum" (Only Int) data MyMonad m a -- Your application monad with connection pool and logger instance HasPostgres m instance MonadLogger m dbSum :: Int -> Int -> MyMonad (Only Int) dbSum = deriveDB (Proxy :: Proxy API) (Proxy :: Proxy MyMonad) Upper example will derive the following SQL call: >>> SELECT * FROM sum("a" => ?, "b" => ?) AS t; |
(KnownSymbol n, HasDB api m) => HasDB ((:>) Symbol * n api) m Source # | Deriving several procedures to query DB API type API = "public" :> Procedure "time" (Only Integer) data MyMonad m a -- Your application monad with connection pool and logger instance HasPostgres m instance MonadLogger m time :: MyMonad (Only Integer) time = deriveDB (Proxy :: Proxy API) (Proxy :: Proxy MyMonad) The Note that there could be only one schema marker. If there are more than one the later (righter) will override previous ones. |