mirror of
https://github.com/nikita-volkov/hasql.git
synced 2024-12-24 18:53:24 +03:00
Factor constants out
This commit is contained in:
parent
463559446d
commit
b49c94ed2a
@ -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,
|
||||
|
@ -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
|
||||
|
13
testing-utils/Hasql/TestingUtils/Constants.hs
Normal file
13
testing-utils/Hasql/TestingUtils/Constants.hs
Normal 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"
|
@ -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)
|
Loading…
Reference in New Issue
Block a user