mirror of
https://github.com/nikita-volkov/hasql.git
synced 2024-11-26 23:33:02 +03:00
25 lines
679 B
Haskell
25 lines
679 B
Haskell
module Main.Connection where
|
|
|
|
import Hasql.Connection qualified as HC
|
|
import Main.Prelude
|
|
|
|
with :: (HC.Connection -> IO a) -> IO (Either HC.ConnectionError a)
|
|
with handler =
|
|
runExceptT $ acquire >>= \connection -> use connection <* release connection
|
|
where
|
|
acquire =
|
|
ExceptT $ HC.acquire settings
|
|
where
|
|
settings =
|
|
HC.settings host port user password database
|
|
where
|
|
host = "localhost"
|
|
port = 5432
|
|
user = "postgres"
|
|
password = "postgres"
|
|
database = "postgres"
|
|
use connection =
|
|
lift $ handler connection
|
|
release connection =
|
|
lift $ HC.release connection
|