TanStack
API Reference

indexedDBCollectionOptions

Call Signature

ts
function indexedDBCollectionOptions<T, TKey>(config): CollectionConfig<InferSchemaOutput<T>, TKey, T, IndexedDBCollectionUtils<InferSchemaOutput<T>, InferSchemaInput<T>>> & object;

Defined in: packages/indexeddb-db-collection/src/indexeddb.ts:406

Creates IndexedDB collection options for use with a standard Collection. This provides persistent local storage with cross-tab synchronization.

IMPORTANT: You must first create the database with createIndexedDB() and pass the instance to this function. This ensures all stores are created upfront in a single upgrade transaction.

Type Parameters

T

T extends StandardSchemaV1<unknown, unknown>

TKey

TKey extends string | number = string | number

Parameters

config

IndexedDBCollectionConfig<InferSchemaOutput<T>, T, TKey> & object

Returns

CollectionConfig<InferSchemaOutput<T>, TKey, T, IndexedDBCollectionUtils<InferSchemaOutput<T>, InferSchemaInput<T>>> & object

Examples

ts
// Step 1: Create database with all stores
const db = await createIndexedDB({
  name: 'myApp',
  version: 1,
  stores: ['todos', 'users'],
})

// Step 2: Create collections using the shared database
const todosCollection = createCollection(
  indexedDBCollectionOptions({
    db,
    name: 'todos',
    schema: todoSchema,
    getKey: (item: { id: string }) => item.id,
  })
)
ts
// Without schema (explicit type)
const todosCollection = createCollection(
  indexedDBCollectionOptions<Todo>({
    db,
    name: 'todos',
    getKey: (item: { id: string }) => item.id,
  })
)

Call Signature

ts
function indexedDBCollectionOptions<T, TKey>(config): CollectionConfig<T, TKey, never, IndexedDBCollectionUtils<T, T>> & object;

Defined in: packages/indexeddb-db-collection/src/indexeddb.ts:424

Creates IndexedDB collection options for use with a standard Collection. This provides persistent local storage with cross-tab synchronization.

IMPORTANT: You must first create the database with createIndexedDB() and pass the instance to this function. This ensures all stores are created upfront in a single upgrade transaction.

Type Parameters

T

T extends object

TKey

TKey extends string | number = string | number

Parameters

config

IndexedDBCollectionConfig<T, never, TKey> & object

Returns

CollectionConfig<T, TKey, never, IndexedDBCollectionUtils<T, T>> & object

Examples

ts
// Step 1: Create database with all stores
const db = await createIndexedDB({
  name: 'myApp',
  version: 1,
  stores: ['todos', 'users'],
})

// Step 2: Create collections using the shared database
const todosCollection = createCollection(
  indexedDBCollectionOptions({
    db,
    name: 'todos',
    schema: todoSchema,
    getKey: (item: { id: string }) => item.id,
  })
)
ts
// Without schema (explicit type)
const todosCollection = createCollection(
  indexedDBCollectionOptions<Todo>({
    db,
    name: 'todos',
    getKey: (item: { id: string }) => item.id,
  })
)