Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

Context.md

140 lines3.4 KB

1---
2id: Context
3title: Context
4---
5​
6# Interface: Context
7​
8Defined in: [packages/db/src/query/builder/types.ts:43](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L43)
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:45](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L45)
41​
42***
43​
44### fromSourceName
45​
46```ts
47fromSourceName: string;
48```
49​
50Defined in: [packages/db/src/query/builder/types.ts:51](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L51)
51​
52***
53​
54### fromSourceNames?
55​
56```ts
57optional fromSourceNames: readonly string[];
58```
59​
60Defined in: [packages/db/src/query/builder/types.ts:53](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L53)
61​
62***
63​
64### hasJoins?
65​
66```ts
67optional hasJoins: boolean;
68```
69​
70Defined in: [packages/db/src/query/builder/types.ts:57](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L57)
71​
72***
73​
74### hasResult?
75​
76```ts
77optional hasResult: true;
78```
79​
80Defined in: [packages/db/src/query/builder/types.ts:66](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L66)
81​
82***
83​
84### hasUnionFrom?
85​
86```ts
87optional hasUnionFrom: true;
88```
89​
90Defined in: [packages/db/src/query/builder/types.ts:55](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L55)
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:59](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L59)
101​
102***
103​
104### refsSchema?
105​
106```ts
107optional refsSchema: ContextSchema;
108```
109​
110Defined in: [packages/db/src/query/builder/types.ts:49](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L49)
111​
112***
113​
114### result?
115​
116```ts
117optional result: any;
118```
119​
120Defined in: [packages/db/src/query/builder/types.ts:64](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L64)
121​
122***
123​
124### schema
125​
126```ts
127schema: ContextSchema;
128```
129​
130Defined in: [packages/db/src/query/builder/types.ts:47](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L47)
131​
132***
133​
134### singleResult?
135​
136```ts
137optional singleResult: boolean;
138```
139​
140Defined in: [packages/db/src/query/builder/types.ts:68](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L68)