-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathConnection.hs
More file actions
32 lines (25 loc) · 1.09 KB
/
Connection.hs
File metadata and controls
32 lines (25 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Connection where
import Control.Exception (bracket)
import Database.PostgreSQL.Driver.Connection
import Database.PostgreSQL.Driver.Error
import Database.PostgreSQL.Driver.Settings
-- | Creates a connection.
withConnection :: (Connection -> IO a) -> IO a
withConnection = bracket (getConnection <$> connect defaultSettings) close
-- | Creates a common connection.
withConnectionCommon :: (ConnectionCommon -> IO a) -> IO a
withConnectionCommon = bracket
(getConnection <$> connectCommon defaultSettings) close
-- | Creates connection than collects all server messages in chan.
withConnectionCommonAll :: (ConnectionCommon -> IO a) -> IO a
withConnectionCommonAll = bracket
(getConnection <$> connectCommon' defaultSettings filterAllowedAll) close
defaultSettings = defaultConnectionSettings
{ settingsHost = "localhost"
, settingsDatabase = "travis_test"
, settingsUser = "postgres"
, settingsPassword = ""
}
getConnection :: Either Error (AbsConnection c)-> AbsConnection c
getConnection (Left e) = error $ "Connection error " ++ show e
getConnection (Right c) = c