> ## Documentation Index
> Fetch the complete documentation index at: https://docs.revoengine.com/llms.txt
> Use this file to discover all available pages before exploring further.

# api.transactionDatabase()

> Public low-code contract, signatures and examples for api.transactionDatabase.

## `api.transactionDatabase()`

Runs database-data operations inside a short-lived transaction.

Notes:

* Commits automatically when the callback resolves.
* Rolls back automatically when the callback throws.
* The default timeout is 15,000 ms.
* Use `&#123; flexTimeout: true &#125;` when the transaction intentionally needs
  the enclosing execution's remaining timeout budget.
* Long transactions reserve a database connection and may retain locks;
  keep waits and remote side effects outside the callback when possible.
* SERIALIZABLE is the default isolation level.
* Parallel tx.\* operations are rejected; await each tx.\* call sequentially.

### Signature

```ts theme={null}
static transactionDatabase<T>(
      callback: (tx: DatabaseTransactionApi) => Promise<T> | T,
      options?: DatabaseTransactionStartOptions,
    ): Promise<T>;
```

### Example

```ts theme={null}
await api.transactionDatabase(async (tx) => {
  const existing = await tx.getDatabaseData(
    'contracts',
    { filter: { field: 'contractId', op: 'eq', value: api.input('contractId') }, take: 1 },
    { lock: 'update' },
  );
  if (existing.results === 0) {
    await tx.insertDatabaseData('contracts', [
      { contractId: api.input('contractId') },
    ]);
  }
});
```

See [all api methods](https://docs.revoengine.com/low-code/reference/api.md) or [runtime basics](https://docs.revoengine.com/low-code/overview.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.