Transactions

Commit behavior can be configured at the connection or statement level.

Transaction Boundaries

By default, transactions are configured with auto-commit enabled. For more complex transaction scenarios involving commits with multiple statements, disable auto-commit, and control the transaction boundaries.

The following example shows how to configure the commit behavior at the connection level, and manually control transaction boundaries with options to commit or rollback:

const { Driver } = require('nuodb')

var driver = new Driver();
(async () => {
  const connection = await driver.connect(...)
  try {
    await connection.execute(...)
    await connection.execute(...)
    const connection.commit()
  } catch (e) {
    await connection.rollback()
    throw e
  } finally {
    await connection.close()
  }
})().catch(e => console.log(err.stack))

Transaction Isolation Level

The two isolation levels that are supported in the driver are the following:

  • Isolation.CONSISTENT_READ

  • Isolation.READ_COMMITTED

The isolation level is specified when executing a transaction. For example:

var { Driver, Isolation } = require('nuodb');
...
var results = await connection.execute(
'SELECT 1 AS VALUE FROM DUAL', {
isolationLevel: Isolation.CONSISTENT_READ
});
...