Skip to content

Class: Transaction ​

Defined in: packages/core/src/api/transaction.ts:31

Constructors ​

Constructor ​

ts
new Transaction(
   att, 
   handle, 
   options): Transaction;

Defined in: packages/core/src/api/transaction.ts:42

Parameters ​

ParameterType
attAttachment
handlenumber
optionsTransactionOptions

Returns ​

Transaction

Accessors ​

autoUpgraded ​

Get Signature ​

ts
get autoUpgraded(): boolean;

Defined in: packages/core/src/api/transaction.ts:61

True once autoUpgradeReadOnly has promoted this transaction to read-write.

Returns ​

boolean


handle ​

Get Signature ​

ts
get handle(): number;

Defined in: packages/core/src/api/transaction.ts:52

Server-side transaction handle (changes across restart).

Returns ​

number


isFinished ​

Get Signature ​

ts
get isFinished(): boolean;

Defined in: packages/core/src/api/transaction.ts:56

Returns ​

boolean

Methods ​

[asyncDispose]() ​

ts
asyncDispose: Promise<void>;

Defined in: packages/core/src/api/transaction.ts:161

await using tx = await db.startTransaction() → rolls back at scope exit unless the transaction was committed (or rolled back) explicitly.

Returns ​

Promise<void>


commit() ​

ts
commit(): Promise<void>;

Defined in: packages/core/src/api/transaction.ts:204

Returns ​

Promise<void>


commitRetaining() ​

ts
commitRetaining(): Promise<void>;

Defined in: packages/core/src/api/transaction.ts:234

Commit but keep the transaction context open for further work.

Returns ​

Promise<void>


execute() ​

ts
execute(
   sql, 
   params?, 
options?): Promise<number>;

Defined in: packages/core/src/api/transaction.ts:126

Run a statement, returning only the affected-record count.

Parameters ​

ParameterTypeDefault value
sqlstringundefined
paramsQueryParams[]
options?QueryOptionsundefined

Returns ​

Promise<number>


executeBatch() ​

ts
executeBatch(
   sql, 
   rows, 
options?): Promise<BatchResult>;

Defined in: packages/core/src/api/transaction.ts:135

Bulk-run one DML statement against many parameter rows inside THIS transaction via the wire batch API (Firebird 4+). Nothing commits here — the caller owns the transaction. See Attachment.executeBatch.

Parameters ​

ParameterType
sqlstring
rowsBatchRows
options?BatchOptions

Returns ​

Promise<BatchResult>


query() ​

ts
query<T>(
   sql, 
   params?, 
options?): Promise<T[]>;

Defined in: packages/core/src/api/transaction.ts:87

Run a statement and return its rows (query<T> types them).

Type Parameters ​

Type ParameterDefault type
TRow

Parameters ​

ParameterTypeDefault value
sqlstringundefined
paramsQueryParams[]
options?QueryOptionsundefined

Returns ​

Promise<T[]>


queryOne() ​

ts
queryOne<T>(
   sql, 
   params?, 
options?): Promise<T | undefined>;

Defined in: packages/core/src/api/transaction.ts:96

Run a statement and return the FIRST row, or undefined when the result is empty. The whole result set is still fetched — put FIRST 1 (or a unique predicate) in the SQL when the query could match many rows.

Type Parameters ​

Type ParameterDefault type
TRow

Parameters ​

ParameterTypeDefault value
sqlstringundefined
paramsQueryParams[]
options?QueryOptionsundefined

Returns ​

Promise<T | undefined>


queryStream() ​

ts
queryStream<T>(
   sql, 
   params?, 
options?): AsyncGenerator<T>;

Defined in: packages/core/src/api/transaction.ts:145

Stream rows lazily within THIS transaction (no commit/rollback here — the caller owns the transaction). Backpressure at batch granularity. Lazy blob handles from this stream stay valid until the transaction ends.

Type Parameters ​

Type ParameterDefault type
TRow

Parameters ​

ParameterTypeDefault value
sqlstringundefined
paramsQueryParams[]
options?QueryOptionsundefined

Returns ​

AsyncGenerator<T>


restart() ​

ts
restart(options?): Promise<void>;

Defined in: packages/core/src/api/transaction.ts:257

Finish the current transaction and immediately start a fresh one on the same connection, reusing the same isolation strategy — or a new one if transaction options are supplied. Reuses this Transaction object (its handle changes). Any lazy blob handles from before the restart become invalid (reading them throws FirebirdBlobError).

ts
await tx.restart();                         // commit, reopen, same strategy
await tx.restart({ action: 'rollback' });   // rollback, reopen, same strategy
await tx.restart({ readOnly: false });      // commit, reopen with a new strategy

Parameters ​

ParameterType
optionsRestartOptions

Returns ​

Promise<void>


rollback() ​

ts
rollback(): Promise<void>;

Defined in: packages/core/src/api/transaction.ts:221

Returns ​

Promise<void>


rollbackRetaining() ​

ts
rollbackRetaining(): Promise<void>;

Defined in: packages/core/src/api/transaction.ts:239

Returns ​

Promise<void>


run() ​

ts
run<T>(
   sql, 
   params?, 
options?): Promise<QueryResult<T>>;

Defined in: packages/core/src/api/transaction.ts:101

Run a statement and return rows + affected-record count.

Type Parameters ​

Type ParameterDefault type
TRow

Parameters ​

ParameterTypeDefault value
sqlstringundefined
paramsQueryParams[]
options?QueryOptionsundefined

Returns ​

Promise<QueryResult<T>>


transaction() ​

ts
transaction<T>(fn): Promise<T>;

Defined in: packages/core/src/api/transaction.ts:182

Run fn inside a SAVEPOINT (a nested transaction): released on success, rolled back to on error — the outer transaction survives either way. Nests arbitrarily (savepoint names are depth-based). fn receives THIS transaction: statements always run on the one server transaction.

ts
await db.transaction(async (tx) => {
  await tx.execute('insert into audit values (?)', [1]);
  await tx.transaction(async () => {              // savepoint scope
    await tx.execute('insert into risky values (?)', [2]);
    throw new Error('undo just the inner part');
  }).catch(() => {});
  // audit row survives; risky row was rolled back
});

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterType
fn(tx) => Promise<T>

Returns ​

Promise<T>

MIT Licensed. Contains data derived from the Firebird project under IDPL/IPL.