createDB()
The core factory function that opens an IndexedDB connection and creates typed Store instances.
Usage
createDB() is the framework-agnostic entry point. It takes a DatabaseConfig object and returns a Database instance with typed store accessors.
database.ts
DatabaseConfig
The configuration object passed to createDB().
| Name | Type | Description |
|---|---|---|
name * | string | Name of the IndexedDB database |
version * | number | Schema version — increment when changing stores/indexes |
stores * | DBSchema | Object mapping store names to their configuration |
ssr | SSRStrategy | How to handle server-side calls (default: 'noop') |
onUpgrade | function | Custom migration callback for onupgradeneeded |
onBlocked | function | Called when another tab blocks version change |
debug | boolean | Enable console logging for all operations (default: false) |
StoreConfig
Configuration for each object store.
| Name | Type | Description |
|---|---|---|
keyPath * | string | The property used as the primary key |
autoIncrement | boolean | Auto-generate keys when not provided (default: false) |
indexes | Record<string, IndexConfig> | Secondary indexes for querying |
IndexConfig
Configuration for secondary indexes on a store.
| Name | Type | Description |
|---|---|---|
keyPath * | string | string[] | The property (or properties) to index |
unique | boolean | Whether indexed values must be unique (default: false) |
multiEntry | boolean | If keyPath is an array value, index each element (default: false) |
Database methods
The returned Database object provides these utility methods in addition to the typed store accessors.
| Name | Type | Description |
|---|---|---|
getRawDB() | Promise<IDBDatabase> | Get the underlying native IDBDatabase instance |
close() | Promise<void> | Close the database connection |