Open History to see the last commit
1---
2id: createObjectStore
3title: createObjectStore
4---
5
6```ts
7function createObjectStore(
8 db,
9 storeName,
10 options?): IDBObjectStore;
11```
12
13Defined in: [packages/db/src/indexed-db-wrapper.ts:191](https://github.com/TanStack/db/blob/main/packages/db/src/indexed-db-wrapper.ts#L191)
14
15Creates an object store during a database upgrade.
16
17This function must be called within an onupgradeneeded callback
18(i.e., within a versionchange transaction). Calling it outside of
19an upgrade context will throw an error.
20
21## Parameters
22
23### db
24
25`IDBDatabase`
26
27The IDBDatabase instance
28
29### storeName
30
31`string`
32
33The name of the object store to create
34
35### options?
36
37`IDBObjectStoreParameters`
38
39Optional configuration for the object store (keyPath, autoIncrement)
40
41## Returns
42
43`IDBObjectStore`
44
45The created IDBObjectStore
46
47## Throws
48
49Error if not called during a version change transaction
50
51## Example
52
53```typescript
54const db = await openDatabase('myApp', 1, (db) => {
55 createObjectStore(db, 'todos', { keyPath: 'id' })
56 createObjectStore(db, 'users', { keyPath: 'id', autoIncrement: true })
57})
58```