Transactable
Updated on April 7, 2026Source codeTests
Transactable is a class that enriches a database name (String), allowing it to:
- Open an IndexedDB database
- Run transactions against an IndexedDB database
- Close an IndexedDB database connection
- Delete an IndexedDB database
Construct a Transactable instance
The Transactable constructor accepts two parameters:
Parameter
Type
Required
Description
nameString
yes
The name of the IndexedDB database to be made transactable.
optionsObject
no
Options for the
Transactable instance. No options are currently accepted.State and methods
Property
Type
Description
Parameters
Return value
nameGetter/Setter
See return value
N/A
The name (String) passed to the constructor.
If you assign a value directly to name, a setter will pass the new value to setName.
statusGetter
See return value
N/A
The status (String) of the Transactable instance.
See the Status reference section for all possible values and their meanings.
dbGetter
See return value
N/A
The
IDBDatabase instance. Available after the database has been opened.transactionGetter
See return value
N/A
The current
IDBTransaction instance. Available while a transaction is in progress via transact.errorGetter
See return value
N/A
The most recent
Error encountered, populated after openerrored, transacterrored, or deleteerrored.setName(newName)Function
Stops all active listeners and sets a new database name.
The new
name (String)The
Transactable instanceopen(options)Function
Opens the IndexedDB database. See the
open options section.See below
The
Transactable instancetransact(effect, options)Function
Runs a transaction against the open database. See the
transact options section.See below
The
Transactable instancereadonly(effect, options)Function
Shorthand for
transact(...) with mode: 'readonly'.Same as
transact, except mode is not accepted.The
Transactable instancereadwrite(effect, options)Function
Shorthand for
transact(...) with mode: 'readwrite'.Same as
transact, except mode is not accepted.The
Transactable instanceversionchange(effect, options)Function
Shorthand for
transact(...) with mode: 'versionchange'.Same as
transact, except mode is not accepted.The
Transactable instanceclose()Function
Closes the IndexedDB database connection.
None
The
Transactable instancedelete()Function
Deletes the IndexedDB database.
None
The
Transactable instancestop()Function
Closes the database and stops any active event listeners.
None
The
Transactable instanceopen options
Option
Type
Default
Description
versionNumber
undefined
The version of the IndexedDB database to open. If omitted, the browser uses the existing version (or 1 for a new database).
upgradeFunction
undefined
A callback
(db: IDBDatabase) => void called when the database needs to be upgraded (i.e., when upgradeneeded fires). Use this to create or modify object stores and indexes.transact options
Option
Type
Default
Description
storeNamesString or String[]
[]The name(s) of the object store(s) to include in the transaction.
modeString
'readonly'The transaction mode. Valid values are
'readonly', 'readwrite', and 'versionchange'.durabilityString
undefined
The durability hint for the transaction. Passed directly to
IDBDatabase.transaction.Status reference
Status
Description
constructingThe instance is being constructed.
readyConstruction is complete; no database has been opened yet.
openingopen() has been called and the database is opening.openedThe database has been successfully opened.
openblockedThe open request was blocked by an existing connection.
openerroredThe open request encountered an error.
upgradeneededThe database requires a version upgrade. The
upgrade callback runs during this phase, after which status transitions to opened.closingclose() has been called and the database is closing.closedThe database connection has been closed.
transactingtransact() has been called and the transaction is in progress.transactedThe transaction completed successfully.
transacterroredThe transaction encountered an error.
transactabortedThe transaction was aborted.
deletingdelete() has been called and the database is being deleted.deleteerroredThe deletion request encountered an error.
deletedThe database has been successfully deleted.
Using with TypeScript
Transactable exports the following TypeScript types:
import type {
TransactableOptions,
TransactableStatus,
TransactEffect,
OpenOptions,
TransactOptions,
} from '@baleada/logic'
API design compliance
Spec
Compliance status
Notes
Access functionality by constructing an instance
Constructor accepts two parameters: a piece of state, and an
options object.Constructor does not access the DOM
IndexedDB is not accessed until
open() is called.Takes the form of a JavaScript Object
State and methods are accessible through properties of the object
Methods always return the instance
Stores the constructor's state in a public getter named after the state's type
nameHas a public method you can use to set a new value for that public getter
setNameHas a setter for that getter so you can assign a new value directly
Any other public getters that should be set by you in some cases also have setters and
set<Property> methodsnone
Has at least one additional getter property that you can't (and shouldn't) set directly
status, db, transaction, errorHas one or more public methods that expose core functionality
open, transact, readonly, readwrite, versionchange, close, delete, stopEither has no side effects or has side effects that can be cleaned up with a
stop methodUses the sentence template to decide what state type should be accepted by a constructor
"A name can be transacted."
Constructor does not accept options that only customize the behavior of public methods, it allows those options to be passed to the method itself as a parameter.
Named after its core action, proper-cased and suffixed with
able