2022-06-20 13:54:54 +03:00
|
|
|
module Main.Connection where
|
2016-01-24 19:15:11 +03:00
|
|
|
|
|
|
|
import qualified Hasql.Connection as HC
|
2022-06-20 13:54:54 +03:00
|
|
|
import Main.Prelude
|
2016-01-24 19:15:11 +03:00
|
|
|
|
|
|
|
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
|