Merge origin/master

This commit is contained in:
Nikita Volkov 2016-01-06 09:39:14 +03:00
commit 90b7868678
5 changed files with 21 additions and 13 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# NOTICE
With the recent releases and more to come still, the Hasql ecosystem undergoes some major changes. It is expected that the users will need a thorough introduction. Hence this notice is to inform you that a thorough documentation with tutorials targeted at both the newcomers and the users who need to migrate from the older versions of the ecosystem are coming soon and are slated to be published during the January of 2016.

View File

@ -29,5 +29,3 @@ setEncodersToUTF8 =
setMinClientMessagesToWarning :: Commands setMinClientMessagesToWarning :: Commands
setMinClientMessagesToWarning = setMinClientMessagesToWarning =
Commands (pure "SET client_min_messages TO WARNING") Commands (pure "SET client_min_messages TO WARNING")

View File

@ -13,7 +13,7 @@ import qualified Hasql.Settings as Settings
-- | -- |
-- A single connection to the database. -- A single connection to the database.
data Connection = data Connection =
Connection !LibPQ.Connection !Bool !PreparedStatementRegistry.PreparedStatementRegistry Connection !(MVar LibPQ.Connection) !Bool !PreparedStatementRegistry.PreparedStatementRegistry
-- | -- |
-- Possible details of the connection acquistion error. -- Possible details of the connection acquistion error.
@ -31,11 +31,14 @@ acquire settings =
lift (IO.initConnection pqConnection) lift (IO.initConnection pqConnection)
integerDatetimes <- lift (IO.getIntegerDatetimes pqConnection) integerDatetimes <- lift (IO.getIntegerDatetimes pqConnection)
registry <- lift (IO.acquirePreparedStatementRegistry) registry <- lift (IO.acquirePreparedStatementRegistry)
pure (Connection pqConnection integerDatetimes registry) pqConnectionRef <- lift (newMVar pqConnection)
pure (Connection pqConnectionRef integerDatetimes registry)
-- | -- |
-- Release the connection. -- Release the connection.
release :: Connection -> IO () release :: Connection -> IO ()
release (Connection pqConnection _ _) = release (Connection pqConnectionRef _ _) =
LibPQ.finish pqConnection mask_ $ do
nullConnection <- LibPQ.newNullConnection
pqConnection <- swapMVar pqConnectionRef nullConnection
IO.releaseConnection pqConnection

View File

@ -52,7 +52,10 @@ instance Profunctor Query where
statement :: ByteString -> Encoders.Params.Params a -> Decoders.Results.Results b -> Bool -> Query a b statement :: ByteString -> Encoders.Params.Params a -> Decoders.Results.Results b -> Bool -> Query a b
statement template encoder decoder preparable = statement template encoder decoder preparable =
Query $ Kleisli $ \params -> ReaderT $ \(Connection.Connection pqConnection integerDatetimes registry) -> do Query $ Kleisli $ \params ->
ReaderT $ \(Connection.Connection pqConnectionRef integerDatetimes registry) ->
EitherT $ withMVar pqConnectionRef $ \pqConnection ->
runEitherT $ do
EitherT $ IO.sendParametricQuery pqConnection integerDatetimes registry template encoder preparable params EitherT $ IO.sendParametricQuery pqConnection integerDatetimes registry template encoder preparable params
EitherT $ IO.getResults pqConnection integerDatetimes decoder EitherT $ IO.getResults pqConnection integerDatetimes decoder

View File

@ -29,8 +29,9 @@ run (Session impl) connection =
-- nor can any results of it be collected. -- nor can any results of it be collected.
sql :: ByteString -> Session () sql :: ByteString -> Session ()
sql sql = sql sql =
Session $ ReaderT $ \(Connection.Connection pqConnection integerDatetimes registry) -> Session $ ReaderT $ \(Connection.Connection pqConnectionRef integerDatetimes registry) ->
EitherT $ fmap (mapLeft unsafeCoerce) $ IO.sendNonparametricQuery pqConnection sql EitherT $ fmap (mapLeft unsafeCoerce) $ withMVar pqConnectionRef $ \pqConnection ->
IO.sendNonparametricQuery pqConnection sql
-- | -- |
-- Parameters and a specification of the parametric query to apply them to. -- Parameters and a specification of the parametric query to apply them to.