txMode.TransactionMode(optionsopt) → {txMode.TransactionMode}

new TransactionMode(optionsopt) → {txMode.TransactionMode}

Constructs a complete transaction-opening BEGIN command, from these options:

  • isolation level
  • access mode
  • deferrable mode

The type is available from the txMode namespace.

Parameters:
Name Type Attributes Description
options <optional>

Transaction Mode options.

Properties
Name Type Attributes Description
tiLevel txMode.isolationLevel <optional>

Transaction Isolation Level.

readOnly boolean <optional>

Sets transaction access mode based on the read-only flag:

  • undefined - access mode not specified (default)
  • true - access mode is set to READ ONLY
  • false - access mode is set to READ WRITE
deferrable boolean <optional>

Sets transaction deferrable mode based on the boolean value:

  • undefined - deferrable mode not specified (default)
  • true - mode is set to DEFERRABLE
  • false - mode is set to NOT DEFERRABLE

It is used only when tiLevel=isolationLevel.serializable and readOnly=true, or else it is ignored.

Source:
See:
Returns:
Type
txMode.TransactionMode
Example
const {TransactionMode, isolationLevel} = pgp.txMode;

// Create a reusable transaction mode (serializable + read-only + deferrable):
const mode = new TransactionMode({
    tiLevel: isolationLevel.serializable,
    readOnly: true,
    deferrable: true
});

db.tx({mode}, t => {
    return t.any('SELECT * FROM table');
})
    .then(data => {
        // success;
    })
    .catch(error => {
        // error
    });

// Instead of the default BEGIN, such transaction will start with:

// BEGIN ISOLATION LEVEL SERIALIZABLE READ ONLY DEFERRABLE

Methods

begin(capopt) → {string}

Returns a complete BEGIN statement, according to all the parameters passed into the class.

This method is primarily for internal use by the library.

Parameters:
Name Type Attributes Default Description
cap boolean <optional>
false

Indicates whether the returned SQL must be capitalized.

Source:
Returns:
Type
string