Open History to see the last commit
1---
2id: createIndexedDB
3title: createIndexedDB
4---
5
6```ts
7function createIndexedDB(options): Promise<IndexedDBInstance>;
8```
9
10Defined in: [packages/db/src/indexed-db.ts:290](https://github.com/TanStack/db/blob/main/packages/db/src/indexed-db.ts#L290)
11
12Creates or opens an IndexedDB database with the specified stores.
13Call this once at app startup, then pass the instance to collections.
14The connection closes on versionchange so another context can upgrade or
15delete the database. Affected Collections enter error and retain their rows.
16Recreate affected Collections with a new instance before
17further persistence.
18
19All stores are created in a single upgrade transaction, avoiding
20version race conditions when multiple collections share a database.
21
22## Parameters
23
24### options
25
26[`CreateIndexedDBOptions`](../interfaces/CreateIndexedDBOptions.md)
27
28## Returns
29
30`Promise`\<[`IndexedDBInstance`](../interfaces/IndexedDBInstance.md)\>
31
32## Example
33
34```typescript
35const db = await createIndexedDB({
36 name: 'myApp',
37 version: 1,
38 stores: ['todos', 'users', 'settings'],
39})
40
41const todosCollection = createCollection(
42 indexedDBCollectionOptions({
43 db,
44 name: 'todos',
45 getKey: (item: { id: string }) => item.id,
46 })
47)
48```