Factor constants out

This commit is contained in:
Nikita Volkov 2024-04-20 13:59:11 +03:00
parent 463559446d
commit b49c94ed2a
4 changed files with 19 additions and 13 deletions

View File

@ -140,7 +140,8 @@ library testing-utils
import: base
hs-source-dirs: testing-utils
exposed-modules:
Hasql.TestingUtils.Session
Hasql.TestingUtils.Constants
Hasql.TestingUtils.TestingDsl
build-depends:
hasql,

View File

@ -5,7 +5,7 @@ import Hasql.Decoders qualified as Decoders
import Hasql.Encoders qualified as Encoders
import Hasql.Session qualified as Session
import Hasql.Statement qualified as Statement
import Hasql.TestingUtils.Session qualified as Session
import Hasql.TestingUtils.TestingDsl qualified as Session
import Main.Connection qualified as Connection
import Main.Prelude hiding (assert)
import Main.Statements qualified as Statements

View File

@ -0,0 +1,13 @@
module Hasql.TestingUtils.Constants where
import Hasql.Connection qualified as Connection
localConnectionSettings :: Connection.Settings
localConnectionSettings =
Connection.settings host port user password database
where
host = "localhost"
port = 5432
user = "postgres"
password = "postgres"
database = "postgres"

View File

@ -1,4 +1,4 @@
module Hasql.TestingUtils.Session
module Hasql.TestingUtils.TestingDsl
( Session.Session,
SessionError (..),
Session.QueryError (..),
@ -11,6 +11,7 @@ where
import Hasql.Connection qualified as Connection
import Hasql.Session qualified as Session
import Hasql.Statement qualified as Statement
import Hasql.TestingUtils.Constants qualified as Constants
import Prelude
data SessionError
@ -23,16 +24,7 @@ runSession session =
runExceptT $ acquire >>= \connection -> use connection <* release connection
where
acquire =
ExceptT $ fmap (mapLeft ConnectionError) $ Connection.acquire settings
where
settings =
Connection.settings host port user password database
where
host = "localhost"
port = 5432
user = "postgres"
password = "postgres"
database = "postgres"
ExceptT $ fmap (mapLeft ConnectionError) $ Connection.acquire Constants.localConnectionSettings
use connection =
ExceptT
$ fmap (mapLeft SessionError)