mirror of
https://github.com/nikita-volkov/hasql.git
synced 2024-12-28 04:57:14 +03:00
29 lines
742 B
Haskell
29 lines
742 B
Haskell
module Main.Connection
|
|
where
|
|
|
|
import Main.Prelude
|
|
import qualified Hasql.Connection as HC
|
|
import qualified Hasql.Statement as HQ
|
|
import qualified Hasql.Session
|
|
|
|
|
|
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 = ""
|
|
database = "postgres"
|
|
use connection =
|
|
lift $ handler connection
|
|
release connection =
|
|
lift $ HC.release connection
|