new TransactionMode(tiLevelopt, readOnlyopt, deferrableopt) → {txMode.TransactionMode}
Alternative Syntax: TransactionMode({tiLevel, readOnly, deferrable})
⇒ TransactionMode
Constructs a complete transaction-opening command, based on the parameters:
- isolation level
- access mode
- deferrable mode
The type is available from the txMode namespace.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
tiLevel |
txMode.isolationLevel | object |
<optional> |
Transaction Isolation Level, or an object with parameters, if the alternative syntax is used. |
readOnly |
boolean |
<optional> |
Sets transaction access mode based on the read-only flag:
|
deferrable |
boolean |
<optional> |
Sets transaction deferrable mode based on the boolean value:
It is used only when |
- Source:
- See:
Returns:
Example
const TransactionMode = pgp.txMode.TransactionMode;
const isolationLevel = pgp.txMode.isolationLevel;
// Create a reusable transaction mode (serializable + read-only + deferrable):
const tmSRD = new TransactionMode({
tiLevel: isolationLevel.serializable,
readOnly: true,
deferrable: true
});
const myTransaction = t => {
return t.any('SELECT * FROM table');
}
myTransaction.txMode = tmSRD; // assign transaction mode;
db.tx(myTransaction)
.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. |
Returns:
- Type
- string