{-# 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 :: ByteString -> io (K Connection db)
connectdb = (Connection -> K Connection db)
-> io Connection -> io (K Connection db)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Connection -> K Connection db
forall k a (b :: k). a -> K a b
SOP.K (io Connection -> io (K Connection db))
-> (ByteString -> io Connection)
-> ByteString
-> io (K Connection db)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO Connection -> io Connection
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Connection -> io Connection)
-> (ByteString -> IO Connection) -> ByteString -> io Connection
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 :: K Connection db -> io ()
finish = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ())
-> (K Connection db -> IO ()) -> K Connection db -> io ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Connection -> IO ()
LibPQ.finish (Connection -> IO ())
-> (K Connection db -> Connection) -> K Connection db -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. K Connection db -> Connection
forall k a (b :: k). K a b -> a
SOP.unK
lowerConnection
:: SOP.K LibPQ.Connection (schema ': db)
-> SOP.K LibPQ.Connection db
lowerConnection :: K Connection (schema : db) -> K Connection db
lowerConnection (SOP.K Connection
conn) = Connection -> K Connection db
forall k a (b :: k). a -> K a b
SOP.K Connection
conn