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.
Exports every registered entity store as a plain, JSON-serialisable object keyed by entity class name.
Records are exported verbatim, including the internal
__idb_createdAt / __idb_updatedAt timestamp fields, so a subsequent
Database.importDatabase restores them exactly.
A promise resolving to { EntityName: records[] }.
Returns the names of all entity classes registered with this database.
An array of entity class name strings.
Returns the actual version of the open IDB database.
This is usually the highest version annotation across all registered
entities, but can be higher when the on-disk database was created at a
greater version (downgrades are ignored) or when a schema change without
a version bump triggered an automatic reconciliation upgrade.
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.
Imports a dump produced by Database.exportDatabase.
Records are written verbatim with put semantics: records whose primary
key already exists are overwritten, all others are inserted. Existing
records not present in the dump are kept unless options.clear is set.
Validation, key generation, and timestamp injection are intentionally
bypassed so the imported data matches the exported data exactly.
Dump entries whose entity name is not registered in this database are skipped (a debug message is logged).
{ EntityName: records[] } as returned by exportDatabase.
Set clear: true to empty each store before importing.
Pulls records from the given SyncAdapter and upserts them into the local stores by primary key.
For each registered entity, adapter.pull(entityName) is called once.
Returned records are written verbatim with put semantics (existing
keys are overwritten, other local records are kept). When the adapter
returns undefined for an entity, its local store is left untouched.
Conflict resolution is intentionally delegated to the adapter/backend - locally, pulled records win by primary key.
The sync adapter supplying the records.
Pushes the full contents of every registered entity store to the given
SyncAdapter, one adapter.push(entityName, records) call per
entity.
The sync adapter receiving the records.
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 declared database version is the highest
versionvalue across all registered@DataClassentities. On everyonupgradeneededevent the full declared schema is reconciled against the actual one: missing stores and indexes are created and indexes that are no longer declared are removed. If the schema changed without a version bump, the drift is detected after opening and a follow-up upgrade is triggered automatically. If the declared version is lower than the version stored on disk (an entity'sversionwas decreased), the database opens at the existing on-disk version instead of failing with aVersionError- IndexedDB cannot downgrade. Changes that would require destructive action (key-path changes, stores whose entity is no longer registered) are never applied automatically; they are reported through the error log instead.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