Open History to see the last commit
1---
2id: compileQuery
3title: compileQuery
4---
5
6```ts
7function compileQuery(
8 rawQuery,
9 inputs,
10 collections,
11 subscriptions,
12 callbacks,
13 lazySources,
14 optimizableOrderByCollections,
15 setWindowFn,
16 cache,
17 queryMapping,
18 parentKeyStream?,
19 childCorrelationField?): CompilationResult;
20```
21
22Defined in: [packages/db/src/query/compiler/index.ts:368](https://github.com/TanStack/db/blob/main/packages/db/src/query/compiler/index.ts#L368)
23
24Compiles a query IR into a D2 pipeline
25
26## Parameters
27
28### rawQuery
29
30[`QueryIR`](../@tanstack/namespaces/IR/interfaces/QueryIR.md)
31
32The query IR to compile
33
34### inputs
35
36`Record`\<`string`, [`KeyedStream`](../type-aliases/KeyedStream.md)\>
37
38Mapping of source aliases to input streams (e.g., `{ employee: input1, manager: input2 }`)
39
40### collections
41
42`Record`\<`string`, [`Collection`](../interfaces/Collection.md)\<`any`, `any`, `any`, `any`, `any`\>\>
43
44Mapping of collection IDs to Collection instances
45
46### subscriptions
47
48`Record`\<`string`, `CollectionSubscription`\>
49
50Mapping of source aliases to CollectionSubscription instances
51
52### callbacks
53
54`Record`\<`string`, `LazyCollectionCallbacks`\>
55
56Mapping of source aliases to lazy loading callbacks
57
58### lazySources
59
60`Set`\<`string`\>
61
62Set of source identities that should load data lazily
63
64### optimizableOrderByCollections
65
66`Record`\<`string`, `OrderByOptimizationInfo`\>
67
68Map of source IDs to order-by optimization info
69
70### setWindowFn
71
72(`windowFn`) => `void`
73
74### cache
75
76`QueryCache` = `...`
77
78Optional cache for compiled subqueries (used internally for recursion)
79
80### queryMapping
81
82`QueryMapping` = `...`
83
84Optional lineage from optimized queries to user-defined queries
85
86### parentKeyStream?
87
88[`KeyedStream`](../type-aliases/KeyedStream.md)
89
90### childCorrelationField?
91
92[`PropRef`](../@tanstack/namespaces/IR/classes/PropRef.md)\<`any`\>
93
94## Returns
95
96`CompilationResult`
97
98A CompilationResult with the pipeline, source WHERE clauses, and alias metadata