mirror of
https://github.com/nikita-volkov/hasql.git
synced 2024-12-28 04:57:14 +03:00
Merge origin/master
This commit is contained in:
commit
90b7868678
3
README.md
Normal file
3
README.md
Normal 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.
|
@ -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")
|
||||||
|
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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 ->
|
||||||
EitherT $ IO.sendParametricQuery pqConnection integerDatetimes registry template encoder preparable params
|
ReaderT $ \(Connection.Connection pqConnectionRef integerDatetimes registry) ->
|
||||||
EitherT $ IO.getResults pqConnection integerDatetimes decoder
|
EitherT $ withMVar pqConnectionRef $ \pqConnection ->
|
||||||
|
runEitherT $ do
|
||||||
|
EitherT $ IO.sendParametricQuery pqConnection integerDatetimes registry template encoder preparable params
|
||||||
|
EitherT $ IO.getResults pqConnection integerDatetimes decoder
|
||||||
|
|
||||||
|
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user