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

liveQueryCollectionOptions.md

61 lines1.5 KB

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