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