postgres-wire/tests/Connection.hs
2017-02-01 05:09:35 +03:00

27 lines
876 B
Haskell

module Connection where
import Control.Exception (bracket)
import Database.PostgreSQL.Driver.Connection
import Database.PostgreSQL.Driver.Settings
-- | Creates connection with default filter.
withConnection :: (Connection -> IO a) -> IO a
withConnection = bracket (getConnection <$> connect defaultSettings) close
-- | Creates connection than collects all server messages in chan.
withConnectionAll :: (Connection -> IO a) -> IO a
withConnectionAll = bracket
(getConnection <$> connectWith defaultSettings filterAllowedAll) close
defaultSettings = defaultConnectionSettings
{ settingsHost = "localhost"
, settingsDatabase = "travis_test"
, settingsUser = "postgres"
, settingsPassword = ""
}
getConnection :: Either Error Connection -> Connection
getConnection (Left e) = error $ "Connection error " ++ show e
getConnection (Right c) = c