DB Docs
API Reference
- Core API Reference
- Collection
- createCollection
- liveQueryCollectionOptions
- createLiveQueryCollection
- createOptimisticAction
- createTransaction
- Electric DB Collection
- electricCollectionOptions
- Query DB Collection
- queryCollectionOptions
- RxDB DB Collection
- rxdbCollectionOptions
- PowerSync Collection
- powerSyncCollectionOptions
- createIndexedDB
- indexedDBCollectionOptions
- React Hooks
- useLiveQuery
AI/LLM: This documentation page is available in plain markdown format at/db/latest/docs/reference/functions/createIndexedDB.md
API Reference
createIndexedDB
ts
function createIndexedDB(options): Promise<IndexedDBInstance>;Defined in: packages/db/src/indexed-db.ts:290
Creates or opens an IndexedDB database with the specified stores. Call this once at app startup, then pass the instance to collections. The connection closes on versionchange so another context can upgrade or delete the database. Affected Collections enter error and retain their rows. Recreate affected Collections with a new instance before further persistence.
All stores are created in a single upgrade transaction, avoiding version race conditions when multiple collections share a database.
Parameters#
options#
Returns#
Promise<IndexedDBInstance>
Example#
ts
const db = await createIndexedDB({
name: 'myApp',
version: 1,
stores: ['todos', 'users', 'settings'],
})
const todosCollection = createCollection(
indexedDBCollectionOptions({
db,
name: 'todos',
getKey: (item: { id: string }) => item.id,
})
)