function executeTransaction<T>(
db,
storeNames,
mode,
callback): Promise<T>;Defined in: packages/indexeddb-db-collection/src/wrapper.ts:248
Executes a callback within an IndexedDB transaction.
This function handles transaction lifecycle automatically:
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' })
})