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:37](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L37)
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()` - needed for optionality logic
20- `hasJoins`: Whether any joins have been added (affects result type inference)
21- `joinTypes`: Maps table aliases to their join types for optionality calculations
22
23**Result Tracking**:
24- `result`: The final shape after `select()` - undefined until select is called
25
26The context evolves through the query builder chain:
271. `from()` sets baseSchema and schema to the same thing
282. `join()` expands schema and sets hasJoins/joinTypes
293. `select()` sets result to the projected shape
30
31## Properties
32
33### baseSchema
34
35```ts
36baseSchema: ContextSchema;
37```
38
39Defined in: [packages/db/src/query/builder/types.ts:39](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L39)
40
41***
42
43### fromSourceName
44
45```ts
46fromSourceName: string;
47```
48
49Defined in: [packages/db/src/query/builder/types.ts:43](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L43)
50
51***
52
53### hasJoins?
54
55```ts
56optional hasJoins: boolean;
57```
58
59Defined in: [packages/db/src/query/builder/types.ts:45](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L45)
60
61***
62
63### hasResult?
64
65```ts
66optional hasResult: true;
67```
68
69Defined in: [packages/db/src/query/builder/types.ts:54](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L54)
70
71***
72
73### joinTypes?
74
75```ts
76optional joinTypes: Record<string, "inner" | "left" | "right" | "full" | "outer" | "cross">;
77```
78
79Defined in: [packages/db/src/query/builder/types.ts:47](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L47)
80
81***
82
83### result?
84
85```ts
86optional result: any;
87```
88
89Defined in: [packages/db/src/query/builder/types.ts:52](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L52)
90
91***
92
93### schema
94
95```ts
96schema: ContextSchema;
97```
98
99Defined in: [packages/db/src/query/builder/types.ts:41](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L41)
100
101***
102
103### singleResult?
104
105```ts
106optional singleResult: boolean;
107```
108
109Defined in: [packages/db/src/query/builder/types.ts:56](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L56)