mirror of
https://github.com/nikita-volkov/hasql.git
synced 2024-12-25 19:21:31 +03:00
51 lines
1.5 KiB
Haskell
51 lines
1.5 KiB
Haskell
module Hasql.TestingUtils.TestingDsl
|
|
( Session.Session,
|
|
SessionError (..),
|
|
Session.QueryError (..),
|
|
Session.CommandError (..),
|
|
Pipeline.Pipeline,
|
|
Statement.Statement (..),
|
|
runSessionOnLocalDb,
|
|
runPipelineOnLocalDb,
|
|
runStatementInSession,
|
|
runPipelineInSession,
|
|
)
|
|
where
|
|
|
|
import Hasql.Connection qualified as Connection
|
|
import Hasql.Pipeline qualified as Pipeline
|
|
import Hasql.Session qualified as Session
|
|
import Hasql.Statement qualified as Statement
|
|
import Hasql.TestingUtils.Constants qualified as Constants
|
|
import Prelude
|
|
|
|
data SessionError
|
|
= ConnectionError (Connection.ConnectionError)
|
|
| SessionError (Session.QueryError)
|
|
deriving (Show, Eq)
|
|
|
|
runSessionOnLocalDb :: Session.Session a -> IO (Either SessionError a)
|
|
runSessionOnLocalDb session =
|
|
runExceptT $ acquire >>= \connection -> use connection <* release connection
|
|
where
|
|
acquire =
|
|
ExceptT $ fmap (mapLeft ConnectionError) $ Connection.acquire Constants.localConnectionSettings
|
|
use connection =
|
|
ExceptT
|
|
$ fmap (mapLeft SessionError)
|
|
$ Session.run session connection
|
|
release connection =
|
|
lift $ Connection.release connection
|
|
|
|
runPipelineOnLocalDb :: Pipeline.Pipeline a -> IO (Either SessionError a)
|
|
runPipelineOnLocalDb =
|
|
runSessionOnLocalDb . Session.pipeline
|
|
|
|
runStatementInSession :: Statement.Statement a b -> a -> Session.Session b
|
|
runStatementInSession statement params =
|
|
Session.statement params statement
|
|
|
|
runPipelineInSession :: Pipeline.Pipeline a -> Session.Session a
|
|
runPipelineInSession =
|
|
Session.pipeline
|