function executeTransaction<T>(
db,
storeNames,
mode,
callback): Promise<T>;Defined in: packages/db/src/indexed-db-wrapper.ts:266
Executes a callback within an IndexedDB transaction.
This function handles transaction lifecycle automatically:
Creates the transaction with the specified mode
Provides the transaction and object stores to the callback
Waits for both the callback and the transaction to complete (or abort)
Returns the callback's result or rejects with an error
IndexedDB can commit while an async callback is still pending. If that callback later rejects, this function rejects but cannot undo the committed writes.
T
The return type of the callback
IDBDatabase
The IDBDatabase instance
A single store name or array of store names to include in the transaction
string | string[]
IDBTransactionMode
The transaction mode ('readonly', 'readwrite', or 'readwriteflush')
(transaction, stores) => T | Promise<T>
A function that performs operations within the transaction. Receives the transaction and a record of object stores keyed by name. Can be sync or async.
Promise<T>
A promise that resolves to the callback's return value when the transaction completes
// Single store
const result = await executeTransaction(db, 'todos', 'readwrite', (tx, stores) => {
stores.todos.put({ id: 1, text: 'Buy milk' })
return 'done'
})
// Multiple stores
await executeTransaction(db, ['todos', 'users'], 'readwrite', (tx, stores) => {
stores.todos.put({ id: 1, text: 'Task' })
stores.users.put({ id: 1, name: 'Alice' })
})