git.iko.soy/typeable/postgresql-simple
on master help sign in
Merge pull request #74 from stevemao/withConnect
22daa1aOleg Grenrus
src/Database/PostgreSQL/Simple.hs+1
@@ -73,6 +73,7 @@ module Database.PostgreSQL.Simple
73 , Base.connectPostgreSQL
73 , Base.connectPostgreSQL
74 , Base.close
74 , Base.close
75 , Base.connect
75 , Base.connect
76+ , Base.withConnect
76 , Base.ConnectInfo(..)
77 , Base.ConnectInfo(..)
77 , Base.defaultConnectInfo
78 , Base.defaultConnectInfo
78 , Base.postgreSQLConnectionString
79 , Base.postgreSQLConnectionString
src/Database/PostgreSQL/Simple/Internal.hs+4
@@ -155,6 +155,10 @@ defaultConnectInfo = ConnectInfo {
155connect :: ConnectInfo -> IO Connection
155connect :: ConnectInfo -> IO Connection
156connect = connectPostgreSQL . postgreSQLConnectionString
156connect = connectPostgreSQL . postgreSQLConnectionString
157
157
158+-- | Memory bracket around 'connect' and 'close'.
159+withConnect :: ConnectInfo -> (Connection -> IO c) -> IO c
160+withConnect connInfo = bracket (connect connInfo) close
161+
158-- | Attempt to make a connection based on a libpq connection string.
162-- | Attempt to make a connection based on a libpq connection string.
159-- See <https://www.postgresql.org/docs/9.5/static/libpq-connect.html#LIBPQ-CONNSTRING>
163-- See <https://www.postgresql.org/docs/9.5/static/libpq-connect.html#LIBPQ-CONNSTRING>
160-- for more information. Also note that environment variables also affect
164-- for more information. Also note that environment variables also affect