pg-using-bluebird
Advanced tools
Comparing version 3.2.1 to 3.3.1
12
index.js
@@ -189,4 +189,7 @@ "use strict"; // eslint-disable-line semi | ||
return { | ||
pool: pool, | ||
getConnection: getConnectionWithEnv, | ||
getTransaction: getTransactionWithEnv, | ||
withConnection: withConnection, | ||
withTransaction: withTransaction, | ||
queryAsync: queryRowsWithEnv, | ||
@@ -200,2 +203,3 @@ queryRowsAsync: queryRowsWithEnv, | ||
function getConnectionWithEnv() { return getConnection(queryConfig, connectMultiArgAsync) } | ||
@@ -214,2 +218,10 @@ | ||
} | ||
function withConnection(statements) { | ||
return using(getConnectionWithEnv(), statements) | ||
} | ||
function withTransaction(statements) { | ||
return using(getTransactionWithEnv(), statements) | ||
} | ||
} |
{ | ||
"name": "pg-using-bluebird", | ||
"version": "3.2.1", | ||
"version": "3.3.1", | ||
"description": "Helpers for managing PostgreSQL connections", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -148,2 +148,26 @@ "use strict"; // eslint-disable-line semi | ||
describe('withConnection', function () { | ||
it('wraps using() and getConnection()', function () { | ||
return pgrmWithDefaults.withConnection(assertResponseObj) | ||
}) | ||
it('does not rollback errors', function () { | ||
return pgrmWithDefaults.withConnection(function (conn) { | ||
return insert1IntoFoo(conn).then(throwAnError) | ||
}).catch(assertOneEventuallyInFoo) | ||
}) | ||
}) | ||
describe('withTransaction', function () { | ||
it('wraps using() and getTransaction()', function () { | ||
return pgrmWithDefaults.withTransaction(assertResponseObj) | ||
}) | ||
it('rolls back the transaction if the function throws', function () { | ||
return pgrmWithDefaults.withTransaction(function (tx) { | ||
return insert1IntoFoo(tx).then(throwAnError) | ||
}).catch(assertFooIsEventuallyEmpty) | ||
}) | ||
}) | ||
function insert1IntoFoo(connOrTx) { | ||
@@ -150,0 +174,0 @@ return connOrTx.queryAsync("insert into foo(bar) values (1)") |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36674
630