Open History to see the last commit
1---
2id: LiveQueryCollectionConfig
3title: LiveQueryCollectionConfig
4---
5
6# Interface: LiveQueryCollectionConfig\<TContext, TResult\>
7
8Defined in: [packages/db/src/query/live/types.ts:59](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L59)
9
10Configuration interface for live query collection options
11
12## Example
13
14```typescript
15const config: LiveQueryCollectionConfig<any, any> = {
16 // id is optional - will auto-generate "live-query-1", "live-query-2", etc.
17 query: (q) => q
18 .from({ comment: commentsCollection })
19 .join(
20 { user: usersCollection },
21 ({ comment, user }) => eq(comment.user_id, user.id)
22 )
23 .where(({ comment }) => eq(comment.active, true))
24 .select(({ comment, user }) => ({
25 id: comment.id,
26 content: comment.content,
27 authorName: user.name,
28 })),
29 // getKey is optional - defaults to using stream key
30 getKey: (item) => item.id,
31}
32```
33
34## Type Parameters
35
36### TContext
37
38`TContext` *extends* [`Context`](Context.md)
39
40### TResult
41
42`TResult` *extends* `object` = `RootQueryResult`\<`TContext`\>
43
44## Properties
45
46### defaultStringCollation?
47
48```ts
49optional defaultStringCollation: StringCollationConfig;
50```
51
52Defined in: [packages/db/src/query/live/types.ts:115](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L115)
53
54Optional compare options for string sorting.
55If provided, these will be used instead of inheriting from the FROM collection.
56
57***
58
59### gcTime?
60
61```ts
62optional gcTime: number;
63```
64
65Defined in: [packages/db/src/query/live/types.ts:104](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L104)
66
67GC time for the collection
68
69***
70
71### getKey()?
72
73```ts
74optional getKey: (item) => string | number;
75```
76
77Defined in: [packages/db/src/query/live/types.ts:82](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L82)
78
79Function to extract the key from result items
80If not provided, defaults to using the key from the D2 stream
81
82#### Parameters
83
84##### item
85
86`TResult`
87
88#### Returns
89
90`string` \| `number`
91
92***
93
94### id?
95
96```ts
97optional id: string;
98```
99
100Defined in: [packages/db/src/query/live/types.ts:67](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L67)
101
102Unique identifier for the collection
103If not provided, defaults to `live-query-${number}` with auto-incrementing number
104
105***
106
107### onDelete?
108
109```ts
110optional onDelete: DeleteMutationFn<TResult, string | number, UtilsRecord, any>;
111```
112
113Defined in: [packages/db/src/query/live/types.ts:94](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L94)
114
115***
116
117### onInsert?
118
119```ts
120optional onInsert: InsertMutationFn<TResult, string | number, UtilsRecord, any>;
121```
122
123Defined in: [packages/db/src/query/live/types.ts:92](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L92)
124
125Optional mutation handlers
126
127***
128
129### onUpdate?
130
131```ts
132optional onUpdate: UpdateMutationFn<TResult, string | number, UtilsRecord, any>;
133```
134
135Defined in: [packages/db/src/query/live/types.ts:93](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L93)
136
137***
138
139### query
140
141```ts
142query:
143 | (q) => QueryBuilder<TContext> & RootObjectResultConstraint<TContext>
144| QueryBuilder<TContext> & RootObjectResultConstraint<TContext>;
145```
146
147Defined in: [packages/db/src/query/live/types.ts:72](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L72)
148
149Query builder function that defines the live query
150
151***
152
153### schema?
154
155```ts
156optional schema: undefined;
157```
158
159Defined in: [packages/db/src/query/live/types.ts:87](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L87)
160
161Optional schema for validation
162
163***
164
165### singleResult?
166
167```ts
168optional singleResult: true;
169```
170
171Defined in: [packages/db/src/query/live/types.ts:109](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L109)
172
173If enabled the collection will return a single object instead of an array
174
175***
176
177### startSync?
178
179```ts
180optional startSync: boolean;
181```
182
183Defined in: [packages/db/src/query/live/types.ts:99](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L99)
184
185Start sync / the query immediately