lib/transactions.js
function (connectionName, callback) {
        var self = this,
            _db = Transaction.databases[connectionName],
            transactionId;

        // validate db setup prior to every connection. this ensures nothing goes forward post teardown
        if (!_db) {
            callback(new AdapterError(AdapterError.TRANSACTION_NOT_SETUP));
        }

        // validate connection name
        if (!connectionName) {
            callback(new AdapterError(AdapterError.TRANSACTION_NOT_IDENTIFIED));
        }

        // if this transaction is already connected, then continue
        if (self.connection()) {
            // @todo implement error check when multi-db conn is attempted
            // // callback with error if connection name and current connection mismatch
            // if (connectionName !== self.connection().identity) {
            //     callback(new AdapterError(AdapterError.TRANSACTION_MULTI_DB_CONNECTION_ATTEMPTED));
            // }
            callback(undefined, self.connection());
            return;
        }

        // at this point, it seems like the connection has not been setup yet, so we setup one and then move forward
        transactionId = self.id(); // this will return and cache a new transaction ID if not already present

        // set the actual connection name
        self._connectionName = connectionName;

        _db.getConnection(function (error, conn) {
            if (!error) {
                self._connection = conn; // save reference
                Transaction.associateConnection(conn, transactionId, _db.transactionConfig); // @note disassociate on dc
            }

            callback(error, self._connection);
        });
    }
function (connectionName, callback) {
        var self = this,
            _db = Transaction.databases[connectionName],
            transactionId;

        // validate db setup prior to every connection. this ensures nothing goes forward post teardown
        if (!_db) {
            callback(new AdapterError(AdapterError.TRANSACTION_NOT_SETUP));
        }

        // validate connection name
        if (!connectionName) {
            callback(new AdapterError(AdapterError.TRANSACTION_NOT_IDENTIFIED));
        }

        // if this transaction is already connected, then continue
        if (self.connection()) {
            // @todo implement error check when multi-db conn is attempted
            // // callback with error if connection name and current connection mismatch
            // if (connectionName !== self.connection().identity) {
            //     callback(new AdapterError(AdapterError.TRANSACTION_MULTI_DB_CONNECTION_ATTEMPTED));
            // }
            callback(undefined, self.connection());
            return;
        }

        // at this point, it seems like the connection has not been setup yet, so we setup one and then move forward
        transactionId = self.id(); // this will return and cache a new transaction ID if not already present

        // set the actual connection name
        self._connectionName = connectionName;

        _db.getConnection(function (error, conn) {
            if (!error) {
                self._connection = conn; // save reference
                Transaction.associateConnection(conn, transactionId, _db.transactionConfig); // @note disassociate on dc
            }

            callback(error, self._connection);
        });
    }
function ( connectionName , callback ) { var self = this , _db = Transaction . databases [ connectionName ] , transactionId ; // validate db setup prior to every connection. this ensures nothing goes forward post teardown if ( ! _db ) { callback ( new AdapterError ( AdapterError . TRANSACTION_NOT_SETUP ) ) ; } // validate connection name if ( ! connectionName ) { callback ( new AdapterError ( AdapterError . TRANSACTION_NOT_IDENTIFIED ) ) ; } // if this transaction is already connected, then continue if ( self . connection ( ) ) { // @todo implement error check when multi-db conn is attempted // // callback with error if connection name and current connection mismatch // if (connectionName !== self.connection().identity) { //     callback(new AdapterError(AdapterError.TRANSACTION_MULTI_DB_CONNECTION_ATTEMPTED)); // } callback ( undefined , self . connection ( ) ) ; return ; } // at this point, it seems like the connection has not been setup yet, so we setup one and then move forward transactionId = self . id ( ) ; // this will return and cache a new transaction ID if not already present // set the actual connection name self . _connectionName = connectionName ; _db . getConnection ( function ( error , conn ) { if ( ! error ) { self . _connection = conn ; // save reference Transaction . associateConnection ( conn , transactionId , _db . transactionConfig ) ; // @note disassociate on dc } callback ( error , self . _connection ) ; } ) ; }
Creates a connection if not already connected.

@private
@returns {mysql.Connection}
Creates a connection if not already connected .