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

liveQueryCollectionOptions.md

63 lines1.6 KB

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