hasql/tasty/Main/Connection.hs

25 lines
679 B
Haskell
Raw Normal View History

2022-06-20 13:54:54 +03:00
module Main.Connection where
2016-01-24 19:15:11 +03:00
2024-04-19 07:38:30 +03:00
import Hasql.Connection qualified 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"
2023-10-16 04:01:31 +03:00
password = "postgres"
2016-01-24 19:15:11 +03:00
database = "postgres"
use connection =
lift $ handler connection
release connection =
lift $ HC.release connection