Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Transaction<$$>

A database transaction.

Transactions are groups of related database operations, such as adding, removing, and qurying data. Transactions are atomic: if an error occurs during a transaction, all operations will be cancelled.

Type parameters

  • $$

Hierarchy

  • Transaction

Index

Properties

Readonly $

$: $$

The transaction shorthand object.

An operation such as

await tx.$.myStore.add(myitem)

Will add an item to the database store called myStore.

Also see Example.

Readonly genuine

genuine: boolean

See Versioning.

stores

The object stores that the transaction has access to.

For non-programmatic code, Transaction.$ is nicer to use.

Accessors

mode

state

  • get state(): "active" | "committed" | "aborted"
  • Current transaction state.

    active - In progress.

    committed - Successfully complete.

    aborted - Unsuccessful.

    Returns "active" | "committed" | "aborted"

Methods

abort

  • abort(): void

addStore

  • addStore<Item>(storeName: string): Store<Item>

commit

  • commit(): void
  • Commit a transaction, applying all staged changes to the database.

    Returns void

removeStore

  • removeStore(name: string): void

wrap

  • wrap<R>(callback: (tx: Transaction<$$>) => Promise<R>): Promise<R>
  • Run some code with the transaction. If the code successfully completes, commit the transaction. If the code calls .abort() or throws an exception, abort the transaction.

    Type parameters

    • R

    Parameters

    Returns Promise<R>

wrapSynchronous

  • wrapSynchronous<R>(callback: (tx: Transaction<$$>) => R): R

Generated using TypeDoc