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
|
- Source:
- See:
Returns:
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