Open History to see the last commit
1---
2id: Context
3title: Context
4---
5
6# Interface: Context
7
8Defined in: [packages/db/src/query/builder/types.ts:44](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L44)
9
10Context - The central state container for query builder operations
11
12This interface tracks all the information needed to build and type-check queries:
13
14**Schema Management**:
15- `baseSchema`: The original tables/collections from the `from()` clause
16- `schema`: Current available tables (expands with joins, contracts with subqueries)
17
18**Query State**:
19- `fromSourceName`: Which table was used in `from()` or the first
20 `unionAll()` source - needed for optionality logic
21- `hasJoins`: Whether any joins have been added (affects result type inference)
22- `joinTypes`: Maps table aliases to their join types for optionality calculations
23
24**Result Tracking**:
25- `result`: The final shape after `select()` - undefined until select is called
26
27The context evolves through the query builder chain:
281. `from()` sets baseSchema and schema to the same thing
292. `join()` expands schema and sets hasJoins/joinTypes
303. `select()` sets result to the projected shape
31
32## Properties
33
34### baseSchema
35
36```ts
37baseSchema: ContextSchema;
38```
39
40Defined in: [packages/db/src/query/builder/types.ts:46](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L46)
41
42***
43
44### fromSourceName
45
46```ts
47fromSourceName: string;
48```
49
50Defined in: [packages/db/src/query/builder/types.ts:52](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L52)
51
52***
53
54### fromSourceNames?
55
56```ts
57optional fromSourceNames: readonly string[];
58```
59
60Defined in: [packages/db/src/query/builder/types.ts:54](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L54)
61
62***
63
64### hasJoins?
65
66```ts
67optional hasJoins: boolean;
68```
69
70Defined in: [packages/db/src/query/builder/types.ts:58](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L58)
71
72***
73
74### hasResult?
75
76```ts
77optional hasResult: true;
78```
79
80Defined in: [packages/db/src/query/builder/types.ts:67](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L67)
81
82***
83
84### hasUnionFrom?
85
86```ts
87optional hasUnionFrom: true;
88```
89
90Defined in: [packages/db/src/query/builder/types.ts:56](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L56)
91
92***
93
94### joinTypes?
95
96```ts
97optional joinTypes: Record<string, "inner" | "left" | "right" | "full" | "outer" | "cross">;
98```
99
100Defined in: [packages/db/src/query/builder/types.ts:60](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L60)
101
102***
103
104### refsSchema?
105
106```ts
107optional refsSchema: ContextSchema;
108```
109
110Defined in: [packages/db/src/query/builder/types.ts:50](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L50)
111
112***
113
114### result?
115
116```ts
117optional result: any;
118```
119
120Defined in: [packages/db/src/query/builder/types.ts:65](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L65)
121
122***
123
124### schema
125
126```ts
127schema: ContextSchema;
128```
129
130Defined in: [packages/db/src/query/builder/types.ts:48](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L48)
131
132***
133
134### singleResult?
135
136```ts
137optional singleResult: boolean;
138```
139
140Defined in: [packages/db/src/query/builder/types.ts:69](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L69)