Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

any-db-transaction

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

any-db-transaction - npm Package Compare versions

Comparing version 2.1.3 to 2.2.0

tests/no-auto-rollback-no-framework.js

2

package.json
{
"name": "any-db-transaction",
"version": "2.1.3",
"version": "2.2.0",
"description": "Transaction object for Any-DB adapters",

@@ -5,0 +5,0 @@ "main": "transaction.js",

@@ -16,27 +16,28 @@ var fs = require('fs')

}
var urls = URLS.filter(function (url) {
return true // TODO select database via env or command line?
})
tape(description, function (t) {
t.plan(urls.length)
var pool = opts.pool
urls.forEach(function (url) {
var backend = url.split(':').shift()
if (backend == 'sqlite3') fs.unlink('/tmp/any_db_test.db', function () {})
var queryable, cleanup;
if (pool) {
queryable = anyDB.createPool(url, pool)
cleanup = queryable.close.bind(queryable)
} else {
queryable = anyDB.createConnection(url)
cleanup = queryable.end.bind(queryable)
var pool = opts.pool
URLS.forEach(function (url) {
var backend = url.split(':').shift()
if (backend == 'sqlite3') {
try {
fs.unlinkSync('/tmp/any_db_test.db');
} catch (err) {
console.error(err);
// ignore it
}
}
t.test(backend + ' - ' + description, function (t) {
callback(queryable, t)
t.on('end', cleanup)
})
var queryable, cleanup;
if (pool) {
queryable = anyDB.createPool(url, pool)
cleanup = queryable.close.bind(queryable)
} else {
queryable = anyDB.createConnection(url)
cleanup = queryable.end.bind(queryable)
}
tape(backend + ' - ' + description, function (t) {
callback(queryable, t)
t.on('end', cleanup)
})
})
}

@@ -8,3 +8,13 @@ var inherits = require('inherits')

function begin (queryable, beginStatement, callback) {
function begin (queryable, options, beginStatement, callback) {
if (typeof options != 'object') {
callback = beginStatement;
beginStatement = options;
options = {};
}
if (undefined === options.autoRollback) {
options.autoRollback = true;
}
if (typeof beginStatement == 'function') {

@@ -22,5 +32,6 @@ callback = beginStatement

var tx = new Transaction({
adapter: adapter,
begin: beginStatement,
callback: callback
adapter: adapter,
begin: beginStatement,
callback: callback,
autoRollback: options.autoRollback
})

@@ -72,2 +83,3 @@

this._nestingLevel = opts.nestingLevel || 0
this._autoRollback = opts.autoRollback;

@@ -97,7 +109,12 @@ this._emitQuery = function (query) { this.emit('query', query) }.bind(this)

var rollback = this.rollback.implementations['open']
if (this.state() !== 'closed' && this._connection) {
if (this.state() !== 'closed' && this._connection && this._autoRollback) {
rollback.call(this, function (rollbackErr) {
if (rollbackErr) self.emit('error', rollbackErr)
else if (!skipEmit) self.emit('error', err)
})
if (rollbackErr) {
rollbackErr.previous = err;
self.emit('error', rollbackErr)
}
else if (!skipEmit) {
self.emit('error', err)
}
}, err)
}

@@ -305,3 +322,3 @@ else if (!skipEmit) self.emit('error', err)

if (err) {
self.handleError(new CloseFailedError(action, err), callback)
self.handleError(new CloseFailedError(err, action), callback)
} else {

@@ -319,6 +336,7 @@ self.emit(action + ':complete')

inherits(CloseFailedError, Error)
function CloseFailedError(err, action, previous) {
function CloseFailedError(err, action) {
Error.captureStackTrace(this, CloseFailedError)
this.name = action + ' failed'
this.message = err + "\nError causing rollback: " + previous
this.message = err.getMessage()
this.previous = null;
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc