Open History to see the last commit
1---
2id: compileQuery
3title: compileQuery
4---
5
6# Function: compileQuery()
7
8```ts
9function compileQuery(
10 rawQuery,
11 inputs,
12 collections,
13 subscriptions,
14 callbacks,
15 lazySources,
16 optimizableOrderByCollections,
17 setWindowFn,
18 cache,
19 queryMapping): CompilationResult;
20```
21
22Defined in: [packages/db/src/query/compiler/index.ts:86](https://github.com/TanStack/db/blob/main/packages/db/src/query/compiler/index.ts#L86)
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 aliases that should load data lazily
63
64### optimizableOrderByCollections
65
66`Record`\<`string`, `OrderByOptimizationInfo`\>
67
68Map of collection 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 mapping from optimized queries to original queries
85
86## Returns
87
88`CompilationResult`
89
90A CompilationResult with the pipeline, source WHERE clauses, and alias metadata