Opens a multi-store IDB transaction and returns a
TransactionalDatabase with per-entity repositories that share the
underlying IDBTransaction.
Use the returned handle's commit() and rollback() methods to finalise
or discard the transaction. For automatic commit/rollback, prefer the
callback-based Database.transaction method.
Names of the entity classes whose stores will be enrolled in the transaction.
IDB transaction mode ('readonly' or 'readwrite').
Defaults to 'readwrite'.
A promise resolving to a TransactionalDatabase handle.
Returns the names of all entity classes registered with this database.
An array of entity class name strings.
Returns the current IDB database version, derived from the highest
version annotation across all registered entities.
The database version number.
Returns the schema version of a single registered entity.
The class name of the entity to look up.
The entity's version number, or undefined if not registered.
Returns a Map of each registered entity name to its configured schema
version.
A Map<string, number> where keys are entity class names and
values are version numbers.
Executes callback within a single readwrite IDB transaction that spans
all registered entities. Commits automatically on success; rolls back
and rethrows on any error.
The type of the value returned by callback.
An async or synchronous function receiving the TransactionalDatabase handle. The callback's return value is forwarded to the caller.
A promise resolving to the value returned by callback.
StaticbuildCreates and initialises a new Database instance, opening the underlying IndexedDB database and generating entity repositories.
This is the only public way to obtain a Database instance.
A Record mapping entity names to their EntityRepository
types, used to type the returned object's named repository properties.
The name passed to indexedDB.open.
The @DataClass-decorated entity constructors to register.
A promise resolving to a fully initialised DatabaseWithRepositories instance.
Central access point for an IndexedDB database managed by idb-ts.
A
Databaseinstance owns the IDB connection, maintains entity repositories, and runs retention-cleanup background jobs. Always obtain instances through the async factory Database.build - the constructor is private.Remarks
Schema versioning. The effective database version is the highest
versionvalue across all registered@DataClassentities. On eachonupgradeneededevent, only stores whoseversionexceeds the previous database version are created or updated, so additive schema evolution is handled automatically.Retention cleanup. When entities declare
@RetentionPolicy, a periodicsetIntervaljob is started after the database opens. The interval is the GCD of all configured retention periods (in milliseconds), ensuring every policy is evaluated at the right frequency with a single timer.Repository access. After
buildresolves, each registered entity is accessible as a named property on the returned object:Example