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 import: base
hs-source-dirs: testing-utils hs-source-dirs: testing-utils
exposed-modules: exposed-modules:
Hasql.TestingUtils.Session Hasql.TestingUtils.Constants
Hasql.TestingUtils.TestingDsl
build-depends: build-depends:
hasql, hasql,

View File

@ -5,7 +5,7 @@ import Hasql.Decoders qualified as Decoders
import Hasql.Encoders qualified as Encoders import Hasql.Encoders qualified as Encoders
import Hasql.Session qualified as Session import Hasql.Session qualified as Session
import Hasql.Statement qualified as Statement 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.Connection qualified as Connection
import Main.Prelude hiding (assert) import Main.Prelude hiding (assert)
import Main.Statements qualified as Statements 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, ( Session.Session,
SessionError (..), SessionError (..),
Session.QueryError (..), Session.QueryError (..),
@ -11,6 +11,7 @@ where
import Hasql.Connection qualified as Connection import Hasql.Connection qualified as Connection
import Hasql.Session qualified as Session import Hasql.Session qualified as Session
import Hasql.Statement qualified as Statement import Hasql.Statement qualified as Statement
import Hasql.TestingUtils.Constants qualified as Constants
import Prelude import Prelude
data SessionError data SessionError
@ -23,16 +24,7 @@ runSession session =
runExceptT $ acquire >>= \connection -> use connection <* release connection runExceptT $ acquire >>= \connection -> use connection <* release connection
where where
acquire = acquire =
ExceptT $ fmap (mapLeft ConnectionError) $ Connection.acquire settings ExceptT $ fmap (mapLeft ConnectionError) $ Connection.acquire Constants.localConnectionSettings
where
settings =
Connection.settings host port user password database
where
host = "localhost"
port = 5432
user = "postgres"
password = "postgres"
database = "postgres"
use connection = use connection =
ExceptT ExceptT
$ fmap (mapLeft SessionError) $ fmap (mapLeft SessionError)