{-# LANGUAGE
DataKinds
, PolyKinds
, RankNTypes
, TypeOperators
#-}
module Squeal.PostgreSQL.Session.Connection
( LibPQ.Connection
, connectdb
, finish
, lowerConnection
, SOP.K (..)
, SOP.unK
) where
import Control.Monad.IO.Class
import Data.ByteString (ByteString)
import Squeal.PostgreSQL.Type.Schema
import qualified Generics.SOP as SOP
import qualified Database.PostgreSQL.LibPQ as LibPQ
connectdb
:: forall (db :: SchemasType) io
. MonadIO io
=> ByteString
-> io (SOP.K LibPQ.Connection db)
connectdb :: forall (db :: SchemasType) (io :: * -> *).
MonadIO io =>
ByteString -> io (K Connection db)
connectdb = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall k a (b :: k). a -> K a b
SOP.K forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> IO Connection
LibPQ.connectdb
finish :: MonadIO io => SOP.K LibPQ.Connection db -> io ()
finish :: forall {k} (io :: * -> *) (db :: k).
MonadIO io =>
K Connection db -> io ()
finish = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. Connection -> IO ()
LibPQ.finish forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} a (b :: k). K a b -> a
SOP.unK
lowerConnection
:: SOP.K LibPQ.Connection (schema ': db)
-> SOP.K LibPQ.Connection db
lowerConnection :: forall {a} (schema :: a) (db :: [a]).
K Connection (schema : db) -> K Connection db
lowerConnection (SOP.K Connection
conn) = forall k a (b :: k). a -> K a b
SOP.K Connection
conn