📄 tanstack/db/latest/docs/reference/interfaces/LiveQueryCollectionConfig

File: LiveQueryCollectionConfig.md | Updated: 11/15/2025

Source: https://tanstack.com/db/latest/docs/reference/interfaces/LiveQueryCollectionConfig



TanStack

DB v0v0

Search...

+ K

Auto

Log In

TanStack StartRC

Docs Examples GitHub Contributors

TanStack Router

Docs Examples GitHub Contributors

TanStack Query

Docs Examples GitHub Contributors

TanStack Table

Docs Examples Github Contributors

TanStack Formnew

Docs Examples Github Contributors

TanStack DBbeta

Docs Github Contributors

TanStack Virtual

Docs Examples Github Contributors

TanStack Paceralpha

Docs Examples Github Contributors

TanStack Storealpha

Docs Examples Github Contributors

TanStack Devtoolsalpha

Docs Github Contributors

More Libraries

Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide

Documentation

Framework

React logo

React

Version

Latest

Search...

+ K

Menu

Getting Started

Guides

Collections

Frameworks

Community

API Reference

Framework

React logo

React

Version

Latest

Menu

Getting Started

Guides

Collections

Frameworks

Community

API Reference

On this page

LiveQueryCollectionConfig

Copy Markdown

Interface: LiveQueryCollectionConfig<TContext, TResult>
=======================================================

Defined in: packages/db/src/query/live/types.ts:53

Configuration interface for live query collection options

Example
-------

typescript

const config: LiveQueryCollectionConfig<any, any> = {
  // id is optional - will auto-generate "live-query-1", "live-query-2", etc.
  query: (q) => q
    .from({ comment: commentsCollection })
    .join(
      { user: usersCollection },
      ({ comment, user }) => eq(comment.user_id, user.id)
    )
    .where(({ comment }) => eq(comment.active, true))
    .select(({ comment, user }) => ({
      id: comment.id,
      content: comment.content,
      authorName: user.name,
    })),
  // getKey is optional - defaults to using stream key
  getKey: (item) => item.id,
}


const config: LiveQueryCollectionConfig<any, any> = {
  // id is optional - will auto-generate "live-query-1", "live-query-2", etc.
  query: (q) => q
    .from({ comment: commentsCollection })
    .join(
      { user: usersCollection },
      ({ comment, user }) => eq(comment.user_id, user.id)
    )
    .where(({ comment }) => eq(comment.active, true))
    .select(({ comment, user }) => ({
      id: comment.id,
      content: comment.content,
      authorName: user.name,
    })),
  // getKey is optional - defaults to using stream key
  getKey: (item) => item.id,
}

Type Parameters
---------------
### TContext

TContext extends Context

### TResult

TResult extends object = GetResult <TContext> & object

Properties
----------
### defaultStringCollation?

ts

optional defaultStringCollation: StringCollationConfig;


optional defaultStringCollation: StringCollationConfig;

Defined in: packages/db/src/query/live/types.ts:107

Optional compare options for string sorting. If provided, these will be used instead of inheriting from the FROM collection.


### gcTime?

ts

optional gcTime: number;


optional gcTime: number;

Defined in: packages/db/src/query/live/types.ts:96

GC time for the collection


### getKey()?

ts

optional getKey: (item) => string | number;


optional getKey: (item) => string | number;

Defined in: packages/db/src/query/live/types.ts:74

Function to extract the key from result items If not provided, defaults to using the key from the D2 stream

#### Parameters ##### item

TResult

#### Returns

string | number


### id?

ts

optional id: string;


optional id: string;

Defined in: packages/db/src/query/live/types.ts:61

Unique identifier for the collection If not provided, defaults to live-query-${number} with auto-incrementing number


### onDelete?

ts

optional onDelete: DeleteMutationFn<TResult, string | number, UtilsRecord, any>;


optional onDelete: DeleteMutationFn<TResult, string | number, UtilsRecord, any>;

Defined in: packages/db/src/query/live/types.ts:86


### onInsert?

ts

optional onInsert: InsertMutationFn<TResult, string | number, UtilsRecord, any>;


optional onInsert: InsertMutationFn<TResult, string | number, UtilsRecord, any>;

Defined in: packages/db/src/query/live/types.ts:84

Optional mutation handlers


### onUpdate?

ts

optional onUpdate: UpdateMutationFn<TResult, string | number, UtilsRecord, any>;


optional onUpdate: UpdateMutationFn<TResult, string | number, UtilsRecord, any>;

Defined in: packages/db/src/query/live/types.ts:85


### query

ts

query: 
  | QueryBuilder<TContext>
| (q) => QueryBuilder<TContext>;


query: 
  | QueryBuilder<TContext>
| (q) => QueryBuilder<TContext>;

Defined in: packages/db/src/query/live/types.ts:66

Query builder function that defines the live query


### schema?

ts

optional schema: undefined;


optional schema: undefined;

Defined in: packages/db/src/query/live/types.ts:79

Optional schema for validation


### singleResult?

ts

optional singleResult: true;


optional singleResult: true;

Defined in: packages/db/src/query/live/types.ts:101

If enabled the collection will return a single object instead of an array


### startSync?

ts

optional startSync: boolean;


optional startSync: boolean;

Defined in: packages/db/src/query/live/types.ts:91

Start sync / the query immediately

Edit on GitHub

Home

Partners Become a Partner

Code RabbitCode Rabbit CloudflareCloudflare AG GridAG Grid NetlifyNetlify NeonNeon WorkOSWorkOS ClerkClerk ConvexConvex ElectricElectric SentrySentry PrismaPrisma StrapiStrapi UnkeyUnkey

scarf analytics