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/createObjectStore.md
createObjectStore
ts
function createObjectStore(
db,
storeName,
options?): IDBObjectStore;Defined in: packages/db/src/indexed-db-wrapper.ts:191
Creates an object store during a database upgrade.
This function must be called within an onupgradeneeded callback (i.e., within a versionchange transaction). Calling it outside of an upgrade context will throw an error.
Parameters#
db#
IDBDatabase
The IDBDatabase instance
storeName#
string
The name of the object store to create
options?#
IDBObjectStoreParameters
Optional configuration for the object store (keyPath, autoIncrement)
Returns#
IDBObjectStore
The created IDBObjectStore
Throws#
Error if not called during a version change transaction
Example#
ts
const db = await openDatabase('myApp', 1, (db) => {
createObjectStore(db, 'todos', { keyPath: 'id' })
createObjectStore(db, 'users', { keyPath: 'id', autoIncrement: true })
})