Skip to content

Commit 5231a40

Browse files
committed
add withConnect: Memory bracket around connect and close
1 parent 6cabb13 commit 5231a40

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/Database/PostgreSQL/Simple.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ defaultConnectInfo = ConnectInfo {
155155
connect :: ConnectInfo -> IO Connection
156156
connect = 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

0 commit comments

Comments
 (0)