API reference

Every public class, method, and event in @codexo/exojs. Generated from source.

C

classIndexedDbDatabase

@codexo/exojs / assets / stable

Database implementation backed by the browser's IndexedDB API. Each object store is created with a `keyPath` of `"name"`, so records are stored as `{ name, data }` objects. The store names are fixed at construction: this is a database with a declared schema, which is what makes it suitable for structured application data such as save games, and unsuitable for a cache whose namespaces are only known at runtime - IndexedDbStore exists for that. Schema migrations run in two modes: - **Default** - the constructor-supplied `storeNames` are diffed against the existing stores and object stores added or deleted accordingly. - **Explicit** - a `migrations` map keyed by target version runs the corresponding callback for each version between `oldVersion` and `newVersion`. A callback returning `false` aborts the upgrade, leaving the database at its previous version. A write resolves only once its transaction has committed, so awaiting a write and then reading it back cannot miss. Every failure rejects with an AssetCacheError that names the failed AssetCacheOperation, the store and key involved, and carries the originating `DOMException` as `cause` - so a `QuotaExceededError` is distinguishable from a transaction or schema failure without parsing message text. That holds for the parts of the IndexedDB API that throw synchronously instead of failing a request just as it does for a failed request.

3
props
8
methods
0
events
Import
import { IndexedDbDatabase } from '@codexo/exojs'

Database implementation backed by the browser's IndexedDB API.

Each object store is created with a `keyPath` of `"name"`, so records are stored as `{ name, data }` objects. The store names are fixed at construction: this is a database with a declared schema, which is what makes it suitable for structured application data such as save games, and unsuitable for a cache whose namespaces are only known at runtime - IndexedDbStore exists for that.

Schema migrations run in two modes: - **Default** - the constructor-supplied `storeNames` are diffed against the existing stores and object stores added or deleted accordingly. - **Explicit** - a `migrations` map keyed by target version runs the corresponding callback for each version between `oldVersion` and `newVersion`. A callback returning `false` aborts the upgrade, leaving the database at its previous version.

A write resolves only once its transaction has committed, so awaiting a write and then reading it back cannot miss.

Every failure rejects with an AssetCacheError that names the failed AssetCacheOperation, the store and key involved, and carries the originating `DOMException` as `cause` - so a `QuotaExceededError` is distinguishable from a transaction or schema failure without parsing message text. That holds for the parts of the IndexedDB API that throw synchronously instead of failing a request just as it does for a failed request.

Constructors1
new(name: string, version: number, storeNames: readonly string[], migrations?: Record<number, (db: IDBDatabase, transaction: IDBTransaction) => boolean>): IndexedDbDatabase
Methods8
clearStorage(type: string): Promise<boolean>
Removes all entries from the type object store without dropping the store itself. Resolves true on success.
connect(): Promise<boolean>
Opens the database connection, running any pending schema migrations. Resolves to true when the connection is ready; rejects on error. Calling this when already connected is a no-op that resolves true.
delete(type: string, name: string): Promise<boolean>
Deletes the entry with the given name from the type object store. Resolves true on success.
deleteStorage(): Promise<boolean>
Disconnects and then permanently deletes the entire database. Resolves true on success.
destroy(): void
Synchronously closes any open handles without waiting for pending transactions to complete. Prefer disconnect for graceful teardown.
disconnect(): Promise<boolean>
Closes the live database connection and resets the connected state. Always resolves true; safe to call when not connected.
load(type: string, name: string): Promise<T | null>
Retrieves the entry with the given name from the type object store, or null if no such entry exists.
save(type: string, name: string, data: unknown): Promise<void>
Persists data under name within the type object store, replacing any existing entry with the same name.
Properties3
name: string
Human-readable database identifier, typically an application name.
version: number
Schema version used during upgradeneeded migrations.
connected: boolean
Whether a live connection to the underlying database is open.
Source