src/transaction.js
function makeTransactor(trx, connection, trxClient) {
  const transactor = makeKnex(trxClient);

  transactor.withUserParams = () => {
    throw new Error(
      'Cannot set user params on a transaction - it can only inherit params from main knex instance'
    );
  };

  transactor.isTransaction = true;
  transactor.userParams = trx.userParams || {};

  transactor.transaction = function(container, options) {
    return trxClient.transaction(container, options, trx);
  };
  transactor.savepoint = function(container, options) {
    return transactor.transaction(container, options);
  };

  if (trx.client.transacting) {
    transactor.commit = (value) => trx.release(connection, value);
    transactor.rollback = (error) => trx.rollbackTo(connection, error);
  } else {
    transactor.commit = (value) => trx.commit(connection, value);
    transactor.rollback = (error) => trx.rollback(connection, error);
  }

  return transactor;
}
function makeTransactor(trx, connection, trxClient) {
  const transactor = makeKnex(trxClient);

  transactor.withUserParams = () => {
    throw new Error(
      'Cannot set user params on a transaction - it can only inherit params from main knex instance'
    );
  };

  transactor.isTransaction = true;
  transactor.userParams = trx.userParams || {};

  transactor.transaction = function(container, options) {
    return trxClient.transaction(container, options, trx);
  };
  transactor.savepoint = function(container, options) {
    return transactor.transaction(container, options);
  };

  if (trx.client.transacting) {
    transactor.commit = (value) => trx.release(connection, value);
    transactor.rollback = (error) => trx.rollbackTo(connection, error);
  } else {
    transactor.commit = (value) => trx.commit(connection, value);
    transactor.rollback = (error) => trx.rollback(connection, error);
  }

  return transactor;
}
function makeTransactor ( trx , connection , trxClient ) { const transactor = makeKnex ( trxClient ) ; transactor . withUserParams = ( ) => { throw new Error ( 'Cannot set user params on a transaction - it can only inherit params from main knex instance' ) ; } ; transactor . isTransaction = true ; transactor . userParams = trx . userParams || { } ; transactor . transaction = function ( container , options ) { return trxClient . transaction ( container , options , trx ) ; } ; transactor . savepoint = function ( container , options ) { return transactor . transaction ( container , options ) ; } ; if ( trx . client . transacting ) { transactor . commit = ( value ) => trx . release ( connection , value ) ; transactor . rollback = ( error ) => trx . rollbackTo ( connection , error ) ; } else { transactor . commit = ( value ) => trx . commit ( connection , value ) ; transactor . rollback = ( error ) => trx . rollback ( connection , error ) ; } return transactor ; }
The transactor is a full featured knex object, with a "commit", a "rollback" and a "savepoint" function. The "savepoint" is just sugar for creating a new transaction. If the rollback is run inside a savepoint, it rolls back to the last savepoint - otherwise it rolls back the transaction.
The transactor is a full featured knex object with a commit a rollback and a savepoint function . The savepoint is just sugar for creating a new transaction . If the rollback is run inside a savepoint it rolls back to the last savepoint - otherwise it rolls back the transaction .