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

livequerycollectionconfig.md

158 lines3.8 KB

1---
2id: LiveQueryCollectionConfig
3title: LiveQueryCollectionConfig
4---
5​
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7​
8# Interface: LiveQueryCollectionConfig\<TContext, TResult\>
9​
10Defined in: [packages/db/src/query/live-query-collection.ts:47](https://github.com/TanStack/db/blob/main/packages/db/src/query/live-query-collection.ts#L47)
11​
12Configuration interface for live query collection options
13​
14## Example
15​
16```typescript
17const config: LiveQueryCollectionConfig<any, any> = {
18 // id is optional - will auto-generate "live-query-1", "live-query-2", etc.
19 query: (q) => q
20 .from({ comment: commentsCollection })
21 .join(
22 { user: usersCollection },
23 ({ comment, user }) => eq(comment.user_id, user.id)
24 )
25 .where(({ comment }) => eq(comment.active, true))
26 .select(({ comment, user }) => ({
27 id: comment.id,
28 content: comment.content,
29 authorName: user.name,
30 })),
31 // getKey is optional - defaults to using stream key
32 getKey: (item) => item.id,
34```
35​
36## Type Parameters
37​
38• **TContext** *extends* [`Context`](../context.md)
39​
40• **TResult** *extends* `object` = [`GetResult`](../../type-aliases/getresult.md)\<`TContext`\> & `object`
41​
42## Properties
43​
44### gcTime?
45​
46```ts
47optional gcTime: number;
48```
49​
50Defined in: [packages/db/src/query/live-query-collection.ts:90](https://github.com/TanStack/db/blob/main/packages/db/src/query/live-query-collection.ts#L90)
51​
52GC time for the collection
53​
54***
55​
56### getKey()?
57​
58```ts
59optional getKey: (item) => string | number;
60```
61​
62Defined in: [packages/db/src/query/live-query-collection.ts:68](https://github.com/TanStack/db/blob/main/packages/db/src/query/live-query-collection.ts#L68)
63​
64Function to extract the key from result items
65If not provided, defaults to using the key from the D2 stream
66​
67#### Parameters
68​
69##### item
70​
71`TResult`
72​
73#### Returns
74​
75`string` \| `number`
76​
77***
78​
79### id?
80​
81```ts
82optional id: string;
83```
84​
85Defined in: [packages/db/src/query/live-query-collection.ts:55](https://github.com/TanStack/db/blob/main/packages/db/src/query/live-query-collection.ts#L55)
86​
87Unique identifier for the collection
88If not provided, defaults to `live-query-${number}` with auto-incrementing number
89​
90***
91​
92### onDelete?
93​
94```ts
95optional onDelete: DeleteMutationFn<TResult, string | number, Record<string, Fn>>;
96```
97​
98Defined in: [packages/db/src/query/live-query-collection.ts:80](https://github.com/TanStack/db/blob/main/packages/db/src/query/live-query-collection.ts#L80)
99​
100***
101​
102### onInsert?
103​
104```ts
105optional onInsert: InsertMutationFn<TResult, string | number, Record<string, Fn>>;
106```
107​
108Defined in: [packages/db/src/query/live-query-collection.ts:78](https://github.com/TanStack/db/blob/main/packages/db/src/query/live-query-collection.ts#L78)
109​
110Optional mutation handlers
111​
112***
113​
114### onUpdate?
115​
116```ts
117optional onUpdate: UpdateMutationFn<TResult, string | number, Record<string, Fn>>;
118```
119​
120Defined in: [packages/db/src/query/live-query-collection.ts:79](https://github.com/TanStack/db/blob/main/packages/db/src/query/live-query-collection.ts#L79)
121​
122***
123​
124### query
125​
126```ts
127query:
128 | QueryBuilder<TContext>
129| (q) => QueryBuilder<TContext>;
130```
131​
132Defined in: [packages/db/src/query/live-query-collection.ts:60](https://github.com/TanStack/db/blob/main/packages/db/src/query/live-query-collection.ts#L60)
133​
134Query builder function that defines the live query
135​
136***
137​
138### schema?
139​
140```ts
141optional schema: StandardSchemaV1<unknown, unknown>;
142```
143​
144Defined in: [packages/db/src/query/live-query-collection.ts:73](https://github.com/TanStack/db/blob/main/packages/db/src/query/live-query-collection.ts#L73)
145​
146Optional schema for validation
147​
148***
149​
150### startSync?
151​
152```ts
153optional startSync: boolean;
154```
155​
156Defined in: [packages/db/src/query/live-query-collection.ts:85](https://github.com/TanStack/db/blob/main/packages/db/src/query/live-query-collection.ts#L85)
157​
158Start sync / the query immediately