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

liveQueryCollectionOptions.md

59 lines1.6 KB

1---
2id: liveQueryCollectionOptions
3title: liveQueryCollectionOptions
4---
5​
6# Function: liveQueryCollectionOptions()
7​
8```ts
9function liveQueryCollectionOptions<TContext, TResult>(config): CollectionConfigForContext<TContext, TResult, {
10}> & object;
11```
12​
13Defined in: [packages/db/src/query/live-query-collection.ts:62](https://github.com/TanStack/db/blob/main/packages/db/src/query/live-query-collection.ts#L62)
14​
15Creates live query collection options for use with createCollection
16​
17## Type Parameters
18​
19### TContext
20​
21`TContext` *extends* [`Context`](../interfaces/Context.md)
22​
23### TResult
24​
25`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\] \}
26​
27## Parameters
28​
29### config
30​
31[`LiveQueryCollectionConfig`](../interfaces/LiveQueryCollectionConfig.md)\<`TContext`, `TResult`\>
32​
33Configuration options for the live query collection
34​
35## Returns
36​
37`CollectionConfigForContext`\<`TContext`, `TResult`, \{
38\}\> & `object`
39​
40Collection options that can be passed to createCollection
41​
42## Example
43​
44```typescript
45const options = liveQueryCollectionOptions({
46 // id is optional - will auto-generate if not provided
47 query: (q) => q
48 .from({ post: postsCollection })
49 .where(({ post }) => eq(post.published, true))
50 .select(({ post }) => ({
51 id: post.id,
52 title: post.title,
53 content: post.content,
54 })),
55 // getKey is optional - will use stream key if not provided
56})
57​
58const collection = createCollection(options)
59```