mirror of
https://github.com/nikita-volkov/hasql.git
synced 2024-11-26 11:57:01 +03:00
Rename a few things
This commit is contained in:
parent
79d3be1a78
commit
eb9c4be732
@ -13,7 +13,7 @@ import qualified Hasql.Deserialization as HD
|
||||
|
||||
main =
|
||||
do
|
||||
connectionEither <- H.acquire settings
|
||||
connectionEither <- H.connect settings
|
||||
case connectionEither of
|
||||
Left e -> print e
|
||||
Right connection -> do
|
||||
|
@ -3,16 +3,15 @@ module Hasql
|
||||
-- * Connection
|
||||
Connection,
|
||||
Settings.Settings(..),
|
||||
acquire,
|
||||
release,
|
||||
ConnectionError(..),
|
||||
connect,
|
||||
disconnect,
|
||||
-- * Query
|
||||
Query(..),
|
||||
query,
|
||||
-- * Errors
|
||||
AcquisitionError(..),
|
||||
ResultsError(..),
|
||||
ResultError(..),
|
||||
RowError(..),
|
||||
query,
|
||||
)
|
||||
where
|
||||
|
||||
@ -80,13 +79,13 @@ data RowError =
|
||||
|
||||
-- |
|
||||
-- A connection acquistion error.
|
||||
type AcquisitionError =
|
||||
type ConnectionError =
|
||||
Maybe ByteString
|
||||
|
||||
-- |
|
||||
-- Acquire a connection using the provided settings.
|
||||
acquire :: Settings.Settings -> IO (Either AcquisitionError Connection)
|
||||
acquire settings =
|
||||
connect :: Settings.Settings -> IO (Either ConnectionError Connection)
|
||||
connect settings =
|
||||
runEitherT $ do
|
||||
pqConnection <- lift (IO.acquireConnection settings)
|
||||
lift (IO.checkConnectionStatus pqConnection) >>= traverse left
|
||||
@ -97,8 +96,8 @@ acquire settings =
|
||||
|
||||
-- |
|
||||
-- Release the connection.
|
||||
release :: Connection -> IO ()
|
||||
release (Connection pqConnection _ _) =
|
||||
disconnect :: Connection -> IO ()
|
||||
disconnect (Connection pqConnection _ _) =
|
||||
LibPQ.finish pqConnection
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@ newtype Session a =
|
||||
deriving (Functor, Applicative, Monad, MonadIO)
|
||||
|
||||
data SessionError =
|
||||
ConnectionError (H.AcquisitionError) |
|
||||
ConnectionError (H.ConnectionError) |
|
||||
ResultsError (H.ResultsError)
|
||||
deriving (Show, Eq)
|
||||
|
||||
@ -20,7 +20,7 @@ session (Session impl) =
|
||||
runEitherT $ acquire >>= \connection -> use connection <* release connection
|
||||
where
|
||||
acquire =
|
||||
EitherT $ fmap (mapLeft ConnectionError) $ H.acquire settings
|
||||
EitherT $ fmap (mapLeft ConnectionError) $ H.connect settings
|
||||
where
|
||||
settings =
|
||||
H.ParametricSettings host port user password database
|
||||
@ -34,7 +34,7 @@ session (Session impl) =
|
||||
bimapEitherT ResultsError id $
|
||||
runReaderT impl connection
|
||||
release connection =
|
||||
lift $ H.release connection
|
||||
lift $ H.disconnect connection
|
||||
|
||||
query :: a -> H.Query a b -> Session b
|
||||
query params query =
|
||||
|
Loading…
Reference in New Issue
Block a user