Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

livequerycollectionoptions.md

55 lines1.6 KB

1---
2id: liveQueryCollectionOptions
3title: liveQueryCollectionOptions
4---
5​
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7​
8# Function: liveQueryCollectionOptions()
9​
10```ts
11function liveQueryCollectionOptions<TContext, TResult>(config): CollectionConfig<TResult>
12```
13​
14Defined in: [packages/db/src/query/live-query-collection.ts:117](https://github.com/TanStack/db/blob/main/packages/db/src/query/live-query-collection.ts#L117)
15​
16Creates live query collection options for use with createCollection
17​
18## Type Parameters
19​
20• **TContext** *extends* [`Context`](../../interfaces/context.md)
21​
22• **TResult** *extends* `object` = \{ \[K in string \| number \| symbol\]: (TContext\["result"\] extends object ? any\[any\] : TContext\["hasJoins"\] extends true ? TContext\["schema"\] : TContext\["schema"\]\[TContext\["fromSourceName"\]\])\[K\] \}
23​
24## Parameters
25​
26### config
27​
28[`LiveQueryCollectionConfig`](../../interfaces/livequerycollectionconfig.md)\<`TContext`, `TResult`\>
29​
30Configuration options for the live query collection
31​
32## Returns
33​
34[`CollectionConfig`](../../interfaces/collectionconfig.md)\<`TResult`\>
35​
36Collection options that can be passed to createCollection
37​
38## Example
39​
40```typescript
41const options = liveQueryCollectionOptions({
42 // id is optional - will auto-generate if not provided
43 query: (q) => q
44 .from({ post: postsCollection })
45 .where(({ post }) => eq(post.published, true))
46 .select(({ post }) => ({
47 id: post.id,
48 title: post.title,
49 content: post.content,
50 })),
51 // getKey is optional - will use stream key if not provided
52})
53​
54const collection = createCollection(options)
55```