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

Context.md

138 lines3.4 KB

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