2016-01-24 19:15:11 +03:00
|
|
|
module Main.Connection
|
|
|
|
where
|
|
|
|
|
|
|
|
import Main.Prelude
|
|
|
|
import qualified Hasql.Connection as HC
|
2018-05-23 13:33:34 +03:00
|
|
|
import qualified Hasql.Statement as HQ
|
2016-01-24 19:15:11 +03:00
|
|
|
import qualified Hasql.Session
|
|
|
|
|
|
|
|
|
|
|
|
with :: (HC.Connection -> IO a) -> IO (Either HC.ConnectionError a)
|
|
|
|
with handler =
|
2017-11-26 11:24:40 +03:00
|
|
|
runExceptT $ acquire >>= \connection -> use connection <* release connection
|
2016-01-24 19:15:11 +03:00
|
|
|
where
|
|
|
|
acquire =
|
2017-11-26 11:24:40 +03:00
|
|
|
ExceptT $ HC.acquire settings
|
2016-01-24 19:15:11 +03:00
|
|
|
where
|
|
|
|
settings =
|
|
|
|
HC.settings host port user password database
|
|
|
|
where
|
|
|
|
host = "localhost"
|
|
|
|
port = 5432
|
|
|
|
user = "postgres"
|
|
|
|
password = ""
|
|
|
|
database = "postgres"
|
|
|
|
use connection =
|
|
|
|
lift $ handler connection
|
|
|
|
release connection =
|
|
|
|
lift $ HC.release connection
|