git.iko.soy/typeable/postgresql-simple
on master help sign in
Merge pull request #74 from stevemao/withConnect

add withConnect: Memory bracket around `connect` and `close`

commit22daa1a40d2631b2fa014197349a5d487a297192 authorOleg Grenrus <oleg.grenrus@iki.fi> dateSat 23 Apr 2022, 15:02 (4 years ago) parent82426e15231a40
2 files changed+5
src/Database/PostgreSQL/Simple.hs+1 src/Database/PostgreSQL/Simple/Internal.hs+4
src/Database/PostgreSQL/Simple.hs+1
@@ -73,6 +73,7 @@ module Database.PostgreSQL.Simple
7373 , Base.connectPostgreSQL
7474 , Base.close
7575 , Base.connect
76+ , Base.withConnect
7677 , Base.ConnectInfo(..)
7778 , Base.defaultConnectInfo
7879 , Base.postgreSQLConnectionString
src/Database/PostgreSQL/Simple/Internal.hs+4
@@ -155,6 +155,10 @@ defaultConnectInfo = ConnectInfo {
155155connect :: ConnectInfo -> IO Connection
156156connect = connectPostgreSQL . postgreSQLConnectionString
157157
158+-- | Memory bracket around 'connect' and 'close'.
159+withConnect :: ConnectInfo -> (Connection -> IO c) -> IO c
160+withConnect connInfo = bracket (connect connInfo) close
161+
158162-- | Attempt to make a connection based on a libpq connection string.
159163-- See <https://www.postgresql.org/docs/9.5/static/libpq-connect.html#LIBPQ-CONNSTRING>
160164-- for more information. Also note that environment variables also affect