function Transaction(adapter) {
    this.adapter = adapter;
    this.inTransaction = false;

    adapter.trx = this;
}

Transaction.prototype.start = function(waitTransaction, callback) {
    var self = this;

    function begin() {
        self.adapter.query('BEGIN')
            .success(function() {
                callback(function(cb) { self.commit(cb) },
                         function(cb) { self.rollback(cb) });
            })
            .error(callback);
    }

    function doStart() {
        if (!self.inTransaction) {
            self.inTransaction = true;
            begin();
        } else {
            if (waitTransaction)
                self.waitTransaction(doStart);
            else
                begin();
        }    
    }

    doStart();
}

Transaction.prototype.commit = function(callback) {
    var self = this;

    if (this.inTransaction) {
        this.adapter.query('COMMIT')
            .success(function () {
                self.inTransaction = false;
                if (callback) callback();
            })
            .error(function (error) {
                self.inTransaction = false;
                if (callback) callback(error);
                throw error;
            });
    } else if (callback) callback();
}

Transaction.prototype.rollback = function(callback) {
    var self = this;

    if (this.inTransaction) {
        this.adapter.query('ROLLBACK')
            .success(function () {
                self.inTransaction = false;   
                if (callback) callback(); 
            })
            .error(function (error) {
                self.inTransaction = false;
                if (callback) callback(error);
                throw error;
            });
    } else if (callback) callback();
}

Transaction.prototype.waitTransaction = function(callback, waitTimeout) {

    var self = this;
    waitTimeout = waitTimeout || 1;

    function checkInTransaction() {
        if (self.inTransaction) {
            // console.log('Waiting...');
            setTimeout(function() {
                process.nextTick(checkInTransaction)
            }, waitTimeout);
        } else
            process.nextTick(callback);
    }

    checkInTransaction();
}

module.exports = function(adapter) {
    return new Transaction(adapter);
}

@@ -2211,16 +2211,19 @@
 n();%0A%7D%0A%0A
+// 
 module.e
@@ -2247,24 +2247,27 @@
 (adapter) %7B%0A
+// 
     return n
@@ -2291,10 +2291,122 @@
 apter);%0A
-%7D
+// %7D%0A%0A// Update: Allow create another instance for connection pooling (for example)%0Amodule.exports = Transaction;
 %0A

Update transactions.js