Options
All
  • Public
  • Public/Protected
  • All
Menu

A class representing a QLDB transaction.

Every transaction is tied to a parent (Pooled)QldbSession, meaning that if the parent session is closed or invalidated, the child transaction is automatically closed and cannot be used. Only one transaction can be active at any given time per parent session, and thus every transaction should call Transaction.abort or Transaction.commit when it is no longer needed, or when a new transaction is desired from the parent session.

An InvalidSessionException indicates that the parent session is dead, and a new transaction cannot be created without a new (Pooled)QldbSession being created from the parent driver.

Any unexpected errors that occur within a transaction should not be retried using the same transaction, as the state of the transaction is now ambiguous.

When an OCC conflict occurs, the transaction is closed and must be handled manually by creating a new transaction and re-executing the desired queries.

Hierarchy

  • Transaction

Implements

Index

Constructors

constructor

  • Create a Transaction.

    Parameters

    • communicator: Communicator

      The Communicator object representing a communication channel with QLDB.

    • txnId: string

      The ID of the transaction.

    Returns Transaction

Properties

Private _communicator

_communicator: Communicator

Private _hashLock

_hashLock: Lock

Private _isClosed

_isClosed: boolean

Private _txnHash

_txnHash: QldbHash

Private _txnId

_txnId: string

Methods

Private _internalClose

  • _internalClose(): void

Private _sendExecute

  • _sendExecute(statement: string, parameters: any[]): Promise<ExecuteStatementResult>
  • Helper method to execute statement against QLDB.

    throws

    TransactionClosedError when transaction is closed.

    Parameters

    • statement: string

      A statement to execute against QLDB as a string.

    • parameters: any[]

      An optional list of Ion values or JavaScript native types that are convertible to Ion for filling in parameters of the statement.

    Returns Promise<ExecuteStatementResult>

    Promise which fulfills with a ExecuteStatementResult object.

abort

  • abort(): Promise<void>
  • Abort this transaction and close child ResultReadable objects. No-op if already closed by commit or previous abort.

    Returns Promise<void>

    Promise which fulfills with void.

commit

  • commit(): Promise<void>
  • Commits and closes child ResultReadable objects.

    throws

    TransactionClosedError when this transaction is closed.

    throws

    ClientException when the commit digest from commit transaction result does not match.

    Returns Promise<void>

    Promise which fulfills with void.

execute

  • execute(statement: string, ...parameters: any[]): Promise<Result>
  • Execute the specified statement in the current transaction. This method returns a promise which eventually returns all the results loaded into memory.

    throws

    Error when the passed argument value cannot be converted into Ion

    Parameters

    • statement: string

      A statement to execute against QLDB as a string.

    • Rest ...parameters: any[]

      Variable number of arguments, where each argument corresponds to a placeholder (?) in the PartiQL query. The argument could be any native JavaScript type or an Ion DOM type. Details of Ion DOM type and JavaScript type

    Returns Promise<Result>

    Promise which fulfills with all results loaded into memory

executeAndStreamResults

  • executeAndStreamResults(statement: string, ...parameters: any[]): Promise<ResultReadable>
  • Execute the specified statement in the current transaction. This method returns a promise which fulfills with Readable Stream, which allows you to stream one record at time

    throws

    TransactionClosedError when the transaction is closed.

    throws

    Error when the passed argument value cannot be converted into Ion

    Parameters

    • statement: string

      A statement to execute against QLDB as a string.

    • Rest ...parameters: any[]

      Variable number of arguments, where each argument corresponds to a placeholder (?) in the PartiQL query. The argument could be any native JavaScript type or an Ion DOM type. Details of Ion DOM type and JavaScript type

    Returns Promise<ResultReadable>

    Promise which fulfills with a Readable Stream

getTransactionId

  • getTransactionId(): string
  • Retrieve the transaction ID associated with this transaction.

    Returns string

    The transaction ID.

Generated using TypeDoc