Rename a few things

This commit is contained in:
Nikita Volkov 2015-11-16 20:03:33 +03:00
parent 79d3be1a78
commit eb9c4be732
3 changed files with 13 additions and 14 deletions

View File

@ -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

View File

@ -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

View File

@ -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 =