mirror of
https://github.com/nikita-volkov/hasql.git
synced 2024-12-26 20:12:09 +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 (pure "SET client_min_messages TO WARNING")
|
||||
|
||||
|
||||
|
@ -13,7 +13,7 @@ import qualified Hasql.Settings as Settings
|
||||
-- |
|
||||
-- A single connection to the database.
|
||||
data Connection =
|
||||
Connection !LibPQ.Connection !Bool !PreparedStatementRegistry.PreparedStatementRegistry
|
||||
Connection !(MVar LibPQ.Connection) !Bool !PreparedStatementRegistry.PreparedStatementRegistry
|
||||
|
||||
-- |
|
||||
-- Possible details of the connection acquistion error.
|
||||
@ -24,18 +24,21 @@ type ConnectionError =
|
||||
-- Acquire a connection using the provided settings encoded according to the PostgreSQL format.
|
||||
acquire :: Settings.Settings -> IO (Either ConnectionError Connection)
|
||||
acquire settings =
|
||||
{-# SCC "acquire" #-}
|
||||
{-# SCC "acquire" #-}
|
||||
runEitherT $ do
|
||||
pqConnection <- lift (IO.acquireConnection settings)
|
||||
lift (IO.checkConnectionStatus pqConnection) >>= traverse left
|
||||
lift (IO.initConnection pqConnection)
|
||||
integerDatetimes <- lift (IO.getIntegerDatetimes pqConnection)
|
||||
registry <- lift (IO.acquirePreparedStatementRegistry)
|
||||
pure (Connection pqConnection integerDatetimes registry)
|
||||
pqConnectionRef <- lift (newMVar pqConnection)
|
||||
pure (Connection pqConnectionRef integerDatetimes registry)
|
||||
|
||||
-- |
|
||||
-- Release the connection.
|
||||
release :: Connection -> IO ()
|
||||
release (Connection pqConnection _ _) =
|
||||
LibPQ.finish pqConnection
|
||||
|
||||
release (Connection pqConnectionRef _ _) =
|
||||
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 template encoder decoder preparable =
|
||||
Query $ Kleisli $ \params -> ReaderT $ \(Connection.Connection pqConnection integerDatetimes registry) -> do
|
||||
EitherT $ IO.sendParametricQuery pqConnection integerDatetimes registry template encoder preparable params
|
||||
EitherT $ IO.getResults pqConnection integerDatetimes decoder
|
||||
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.getResults pqConnection integerDatetimes decoder
|
||||
|
||||
|
@ -29,8 +29,9 @@ run (Session impl) connection =
|
||||
-- nor can any results of it be collected.
|
||||
sql :: ByteString -> Session ()
|
||||
sql sql =
|
||||
Session $ ReaderT $ \(Connection.Connection pqConnection integerDatetimes registry) ->
|
||||
EitherT $ fmap (mapLeft unsafeCoerce) $ IO.sendNonparametricQuery pqConnection sql
|
||||
Session $ ReaderT $ \(Connection.Connection pqConnectionRef integerDatetimes registry) ->
|
||||
EitherT $ fmap (mapLeft unsafeCoerce) $ withMVar pqConnectionRef $ \pqConnection ->
|
||||
IO.sendNonparametricQuery pqConnection sql
|
||||
|
||||
-- |
|
||||
-- Parameters and a specification of the parametric query to apply them to.
|
||||
|
Loading…
Reference in New Issue
Block a user