Class: Context

Context

new Context()

Class representing a context which can be used to execute SQL statements in chronological order and use transactions safely within the scope of the context.
Parameters:
Type Description
Pool Connection pool to be used for this context
Source:

Methods

begin() → {Promise.<string, Error>}

Begin a transaction for this context
Source:
Returns:
- A promise which resolves after openning a transaction or an Error if rejected.
Type
Promise.<string, Error>

commit() → {Promise.<string, Error>}

Commit a transaction opened for this context
Source:
Returns:
- A promise which resolves after committing a transaction or an Error if rejected.
Type
Promise.<string, Error>

end() → {Promise.<string, Error>}

Rollback any open transactions and end the context by releasing the connection used back to the pool.
Source:
Returns:
- A promise to a context ID string which resolved after the context is ended or an Error if rejected.
Type
Promise.<string, Error>

id() → {string}

Return the context ID
Source:
Returns:
- Context ID.
Type
string

prepare(sql) → {Promise.<Statement, Error>}

Prepare a statement which is only valid to be executed within this context
Parameters:
Name Type Description
sql string SQL statement to prepare
Source:
Returns:
- A promise to a statement object or an Error if rejected.
Type
Promise.<Statement, Error>

query(sql) → {Promise.<Cursor, Error>}

Run a query within this context
Parameters:
Name Type Description
sql string SQL query to run
Source:
Returns:
- A promise to a results cursor or an Error if rejected.
Type
Promise.<Cursor, Error>

rollback() → {Promise.<string, Error>}

Rollback a transaction opened for this context
Source:
Returns:
- A promise which resolves after rolling-back a transaction or an Error if rejected.
Type
Promise.<string, Error>