effect-qb 0.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1294 -0
- package/dist/mysql.js +57575 -0
- package/dist/postgres.js +6303 -0
- package/package.json +42 -0
- package/src/internal/aggregation-validation.ts +57 -0
- package/src/internal/case-analysis.ts +50 -0
- package/src/internal/coercion-analysis.ts +30 -0
- package/src/internal/coercion-errors.ts +29 -0
- package/src/internal/coercion-kind.ts +32 -0
- package/src/internal/coercion-normalize.ts +7 -0
- package/src/internal/coercion-rules.ts +25 -0
- package/src/internal/column-state.ts +453 -0
- package/src/internal/column.ts +417 -0
- package/src/internal/datatypes/define.ts +44 -0
- package/src/internal/datatypes/lookup.ts +280 -0
- package/src/internal/datatypes/shape.ts +72 -0
- package/src/internal/derived-table.ts +149 -0
- package/src/internal/dialect.ts +30 -0
- package/src/internal/executor.ts +390 -0
- package/src/internal/expression-ast.ts +349 -0
- package/src/internal/expression.ts +325 -0
- package/src/internal/grouping-key.ts +82 -0
- package/src/internal/json/ast.ts +63 -0
- package/src/internal/json/errors.ts +13 -0
- package/src/internal/json/path.ts +227 -0
- package/src/internal/json/shape.ts +1 -0
- package/src/internal/json/types.ts +386 -0
- package/src/internal/mysql-dialect.ts +39 -0
- package/src/internal/mysql-renderer.ts +37 -0
- package/src/internal/plan.ts +64 -0
- package/src/internal/postgres-dialect.ts +34 -0
- package/src/internal/postgres-renderer.ts +40 -0
- package/src/internal/predicate-analysis.ts +71 -0
- package/src/internal/predicate-atom.ts +43 -0
- package/src/internal/predicate-branches.ts +40 -0
- package/src/internal/predicate-context.ts +279 -0
- package/src/internal/predicate-formula.ts +100 -0
- package/src/internal/predicate-key.ts +28 -0
- package/src/internal/predicate-nnf.ts +12 -0
- package/src/internal/predicate-normalize.ts +202 -0
- package/src/internal/projection-alias.ts +15 -0
- package/src/internal/projections.ts +101 -0
- package/src/internal/query-ast.ts +297 -0
- package/src/internal/query-factory.ts +6757 -0
- package/src/internal/query-requirements.ts +40 -0
- package/src/internal/query.ts +1590 -0
- package/src/internal/renderer.ts +102 -0
- package/src/internal/runtime-normalize.ts +344 -0
- package/src/internal/runtime-schema.ts +428 -0
- package/src/internal/runtime-value.ts +85 -0
- package/src/internal/schema-derivation.ts +131 -0
- package/src/internal/sql-expression-renderer.ts +1353 -0
- package/src/internal/table-options.ts +225 -0
- package/src/internal/table.ts +674 -0
- package/src/mysql/column.ts +30 -0
- package/src/mysql/datatypes/index.ts +6 -0
- package/src/mysql/datatypes/spec.ts +180 -0
- package/src/mysql/errors/catalog.ts +51662 -0
- package/src/mysql/errors/fields.ts +21 -0
- package/src/mysql/errors/index.ts +18 -0
- package/src/mysql/errors/normalize.ts +232 -0
- package/src/mysql/errors/requirements.ts +73 -0
- package/src/mysql/executor.ts +134 -0
- package/src/mysql/query.ts +189 -0
- package/src/mysql/renderer.ts +19 -0
- package/src/mysql/table.ts +157 -0
- package/src/mysql.ts +18 -0
- package/src/postgres/column.ts +20 -0
- package/src/postgres/datatypes/index.ts +8 -0
- package/src/postgres/datatypes/spec.ts +264 -0
- package/src/postgres/errors/catalog.ts +452 -0
- package/src/postgres/errors/fields.ts +48 -0
- package/src/postgres/errors/index.ts +4 -0
- package/src/postgres/errors/normalize.ts +209 -0
- package/src/postgres/errors/requirements.ts +65 -0
- package/src/postgres/errors/types.ts +38 -0
- package/src/postgres/executor.ts +131 -0
- package/src/postgres/query.ts +189 -0
- package/src/postgres/renderer.ts +29 -0
- package/src/postgres/table.ts +157 -0
- package/src/postgres.ts +18 -0
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import type * as Expression from "./expression.js"
|
|
2
|
+
import type * as Query from "./query.js"
|
|
3
|
+
import type * as JsonPath from "./json/path.js"
|
|
4
|
+
import type { JsonNode } from "./json/ast.js"
|
|
5
|
+
|
|
6
|
+
/** Symbol used to attach internal expression-AST metadata to runtime values. */
|
|
7
|
+
export const TypeId: unique symbol = Symbol.for("effect-qb/ExpressionAst")
|
|
8
|
+
|
|
9
|
+
export type TypeId = typeof TypeId
|
|
10
|
+
|
|
11
|
+
/** Bound column reference captured by the internal expression AST. */
|
|
12
|
+
export interface ColumnNode<
|
|
13
|
+
TableName extends string = string,
|
|
14
|
+
ColumnName extends string = string
|
|
15
|
+
> {
|
|
16
|
+
readonly kind: "column"
|
|
17
|
+
readonly tableName: TableName
|
|
18
|
+
readonly columnName: ColumnName
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Constant literal captured by the internal expression AST. */
|
|
22
|
+
export interface LiteralNode<Value = unknown> {
|
|
23
|
+
readonly kind: "literal"
|
|
24
|
+
readonly value: Value
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Explicit type cast captured by the internal expression AST. */
|
|
28
|
+
export interface CastNode<
|
|
29
|
+
Value extends Expression.Any = Expression.Any,
|
|
30
|
+
Target extends Expression.DbType.Any = Expression.DbType.Any
|
|
31
|
+
> {
|
|
32
|
+
readonly kind: "cast"
|
|
33
|
+
readonly value: Value
|
|
34
|
+
readonly target: Target
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** `excluded.column` reference used inside insert conflict handlers. */
|
|
38
|
+
export interface ExcludedNode<
|
|
39
|
+
ColumnName extends string = string
|
|
40
|
+
> {
|
|
41
|
+
readonly kind: "excluded"
|
|
42
|
+
readonly columnName: ColumnName
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Unary expression kinds supported by the current query layer. */
|
|
46
|
+
export type UnaryKind =
|
|
47
|
+
| "isNull"
|
|
48
|
+
| "isNotNull"
|
|
49
|
+
| "not"
|
|
50
|
+
| "upper"
|
|
51
|
+
| "lower"
|
|
52
|
+
| "count"
|
|
53
|
+
| "max"
|
|
54
|
+
| "min"
|
|
55
|
+
|
|
56
|
+
/** Unary expression node. */
|
|
57
|
+
export interface UnaryNode<
|
|
58
|
+
Kind extends UnaryKind = UnaryKind,
|
|
59
|
+
Value extends Expression.Any = Expression.Any
|
|
60
|
+
> {
|
|
61
|
+
readonly kind: Kind
|
|
62
|
+
readonly value: Value
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Binary expression kinds supported by the current query layer. */
|
|
66
|
+
export type BinaryKind =
|
|
67
|
+
| "eq"
|
|
68
|
+
| "neq"
|
|
69
|
+
| "lt"
|
|
70
|
+
| "lte"
|
|
71
|
+
| "gt"
|
|
72
|
+
| "gte"
|
|
73
|
+
| "like"
|
|
74
|
+
| "ilike"
|
|
75
|
+
| "isDistinctFrom"
|
|
76
|
+
| "isNotDistinctFrom"
|
|
77
|
+
| "contains"
|
|
78
|
+
| "containedBy"
|
|
79
|
+
| "overlaps"
|
|
80
|
+
|
|
81
|
+
/** Binary expression node. */
|
|
82
|
+
export interface BinaryNode<
|
|
83
|
+
Kind extends BinaryKind = BinaryKind,
|
|
84
|
+
Left extends Expression.Any = Expression.Any,
|
|
85
|
+
Right extends Expression.Any = Expression.Any
|
|
86
|
+
> {
|
|
87
|
+
readonly kind: Kind
|
|
88
|
+
readonly left: Left
|
|
89
|
+
readonly right: Right
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Variadic expression kinds supported by the current query layer. */
|
|
93
|
+
export type VariadicKind = "and" | "or" | "coalesce" | "concat" | "in" | "notIn" | "between"
|
|
94
|
+
|
|
95
|
+
/** Variadic expression node. */
|
|
96
|
+
export interface VariadicNode<
|
|
97
|
+
Kind extends VariadicKind = VariadicKind,
|
|
98
|
+
Values extends readonly Expression.Any[] = readonly Expression.Any[]
|
|
99
|
+
> {
|
|
100
|
+
readonly kind: Kind
|
|
101
|
+
readonly values: Values
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** One `when ... then ...` branch inside a searched `case`. */
|
|
105
|
+
export interface CaseBranchNode<
|
|
106
|
+
Predicate extends Expression.Any = Expression.Any,
|
|
107
|
+
Then extends Expression.Any = Expression.Any
|
|
108
|
+
> {
|
|
109
|
+
readonly when: Predicate
|
|
110
|
+
readonly then: Then
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Searched `case when ... then ... else ... end` expression node. */
|
|
114
|
+
export interface CaseNode<
|
|
115
|
+
Branches extends readonly CaseBranchNode[] = readonly CaseBranchNode[],
|
|
116
|
+
Else extends Expression.Any = Expression.Any
|
|
117
|
+
> {
|
|
118
|
+
readonly kind: "case"
|
|
119
|
+
readonly branches: Branches
|
|
120
|
+
readonly else: Else
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** `exists (<subquery>)` expression node. */
|
|
124
|
+
export interface ExistsNode<
|
|
125
|
+
PlanValue extends Query.QueryPlan<any, any, any, any, any, any, any, any, any, any> = Query.QueryPlan<any, any, any, any, any, any, any, any, any, any>
|
|
126
|
+
> {
|
|
127
|
+
readonly kind: "exists"
|
|
128
|
+
readonly plan: PlanValue
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Scalar subquery expression node. */
|
|
132
|
+
export interface ScalarSubqueryNode<
|
|
133
|
+
PlanValue extends Query.QueryPlan<any, any, any, any, any, any, any, any, any, any> = Query.QueryPlan<any, any, any, any, any, any, any, any, any, any>
|
|
134
|
+
> {
|
|
135
|
+
readonly kind: "scalarSubquery"
|
|
136
|
+
readonly plan: PlanValue
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** `value in (<subquery>)` expression node. */
|
|
140
|
+
export interface InSubqueryNode<
|
|
141
|
+
Left extends Expression.Any = Expression.Any,
|
|
142
|
+
PlanValue extends Query.QueryPlan<any, any, any, any, any, any, any, any, any, any> = Query.QueryPlan<any, any, any, any, any, any, any, any, any, any>
|
|
143
|
+
> {
|
|
144
|
+
readonly kind: "inSubquery"
|
|
145
|
+
readonly left: Left
|
|
146
|
+
readonly plan: PlanValue
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** `value <op> any|all (<subquery>)` expression node. */
|
|
150
|
+
export interface QuantifiedComparisonNode<
|
|
151
|
+
Kind extends "comparisonAny" | "comparisonAll" = "comparisonAny" | "comparisonAll",
|
|
152
|
+
Operator extends "eq" | "neq" | "lt" | "lte" | "gt" | "gte" = "eq" | "neq" | "lt" | "lte" | "gt" | "gte",
|
|
153
|
+
Left extends Expression.Any = Expression.Any,
|
|
154
|
+
PlanValue extends Query.QueryPlan<any, any, any, any, any, any, any, any, any, any> = Query.QueryPlan<any, any, any, any, any, any, any, any, any, any>
|
|
155
|
+
> {
|
|
156
|
+
readonly kind: Kind
|
|
157
|
+
readonly operator: Operator
|
|
158
|
+
readonly left: Left
|
|
159
|
+
readonly plan: PlanValue
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Ordering term inside a window specification. */
|
|
163
|
+
export interface WindowOrderByNode<
|
|
164
|
+
Value extends Expression.Any = Expression.Any
|
|
165
|
+
> {
|
|
166
|
+
readonly value: Value
|
|
167
|
+
readonly direction: "asc" | "desc"
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Window function kinds supported by the query layer. */
|
|
171
|
+
export type WindowKind = "rowNumber" | "rank" | "denseRank" | "over"
|
|
172
|
+
|
|
173
|
+
/** Window function expression node. */
|
|
174
|
+
export interface WindowNode<
|
|
175
|
+
Kind extends WindowKind = WindowKind,
|
|
176
|
+
Value extends Expression.Any | undefined = Expression.Any | undefined,
|
|
177
|
+
PartitionBy extends readonly Expression.Any[] = readonly Expression.Any[],
|
|
178
|
+
OrderBy extends readonly WindowOrderByNode[] = readonly WindowOrderByNode[]
|
|
179
|
+
> {
|
|
180
|
+
readonly kind: "window"
|
|
181
|
+
readonly function: Kind
|
|
182
|
+
readonly value?: Value
|
|
183
|
+
readonly partitionBy: PartitionBy
|
|
184
|
+
readonly orderBy: OrderBy
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export type JsonSegmentTuple = readonly any[]
|
|
188
|
+
|
|
189
|
+
export type JsonAccessKind =
|
|
190
|
+
| "jsonGet"
|
|
191
|
+
| "jsonPath"
|
|
192
|
+
| "jsonAccess"
|
|
193
|
+
| "jsonTraverse"
|
|
194
|
+
| "jsonGetText"
|
|
195
|
+
| "jsonPathText"
|
|
196
|
+
| "jsonAccessText"
|
|
197
|
+
| "jsonTraverseText"
|
|
198
|
+
|
|
199
|
+
export interface JsonAccessNode<
|
|
200
|
+
Kind extends JsonAccessKind = JsonAccessKind,
|
|
201
|
+
Base extends Expression.Any = Expression.Any,
|
|
202
|
+
Segments extends JsonSegmentTuple = JsonSegmentTuple
|
|
203
|
+
> {
|
|
204
|
+
readonly kind: Kind
|
|
205
|
+
readonly base: Base
|
|
206
|
+
readonly segments: Segments
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export type JsonKeyPredicateKind =
|
|
210
|
+
| "jsonHasKey"
|
|
211
|
+
| "jsonKeyExists"
|
|
212
|
+
| "jsonHasAnyKeys"
|
|
213
|
+
| "jsonHasAllKeys"
|
|
214
|
+
|
|
215
|
+
export interface JsonKeyPredicateNode<
|
|
216
|
+
Kind extends JsonKeyPredicateKind = JsonKeyPredicateKind,
|
|
217
|
+
Base extends Expression.Any = Expression.Any,
|
|
218
|
+
Keys extends readonly string[] = readonly string[]
|
|
219
|
+
> {
|
|
220
|
+
readonly kind: Kind
|
|
221
|
+
readonly base: Base
|
|
222
|
+
readonly keys: Keys
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export type JsonBinaryKind = "jsonConcat" | "jsonMerge"
|
|
226
|
+
|
|
227
|
+
export interface JsonBinaryNode<
|
|
228
|
+
Kind extends JsonBinaryKind = JsonBinaryKind,
|
|
229
|
+
Left extends Expression.Any = Expression.Any,
|
|
230
|
+
Right extends Expression.Any = Expression.Any
|
|
231
|
+
> {
|
|
232
|
+
readonly kind: Kind
|
|
233
|
+
readonly left: Left
|
|
234
|
+
readonly right: Right
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export type JsonDeleteKind = "jsonDelete" | "jsonDeletePath" | "jsonRemove"
|
|
238
|
+
|
|
239
|
+
export interface JsonDeleteNode<
|
|
240
|
+
Kind extends JsonDeleteKind = JsonDeleteKind,
|
|
241
|
+
Base extends Expression.Any = Expression.Any,
|
|
242
|
+
Segments extends JsonSegmentTuple = JsonSegmentTuple
|
|
243
|
+
> {
|
|
244
|
+
readonly kind: Kind
|
|
245
|
+
readonly base: Base
|
|
246
|
+
readonly segments: Segments
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export interface JsonSetNode<
|
|
250
|
+
Base extends Expression.Any = Expression.Any,
|
|
251
|
+
Segments extends JsonSegmentTuple = JsonSegmentTuple,
|
|
252
|
+
NewValue extends Expression.Any = Expression.Any
|
|
253
|
+
> {
|
|
254
|
+
readonly kind: "jsonSet"
|
|
255
|
+
readonly base: Base
|
|
256
|
+
readonly segments: Segments
|
|
257
|
+
readonly newValue: NewValue
|
|
258
|
+
readonly createMissing: boolean
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export interface JsonInsertNode<
|
|
262
|
+
Base extends Expression.Any = Expression.Any,
|
|
263
|
+
Segments extends JsonSegmentTuple = JsonSegmentTuple,
|
|
264
|
+
Insert extends Expression.Any = Expression.Any
|
|
265
|
+
> {
|
|
266
|
+
readonly kind: "jsonInsert"
|
|
267
|
+
readonly base: Base
|
|
268
|
+
readonly segments: Segments
|
|
269
|
+
readonly insert: Insert
|
|
270
|
+
readonly insertAfter: boolean
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export type JsonQueryPredicateKind = "jsonPathExists" | "jsonPathMatch"
|
|
274
|
+
|
|
275
|
+
export interface JsonQueryPredicateNode<
|
|
276
|
+
Kind extends JsonQueryPredicateKind = JsonQueryPredicateKind,
|
|
277
|
+
Base extends Expression.Any = Expression.Any,
|
|
278
|
+
QueryValue extends Expression.Any | JsonPath.Path<any> | string = Expression.Any | JsonPath.Path<any> | string
|
|
279
|
+
> {
|
|
280
|
+
readonly kind: Kind
|
|
281
|
+
readonly base: Base
|
|
282
|
+
readonly query: QueryValue
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export interface JsonBuildObjectEntryNode<
|
|
286
|
+
Key extends string = string,
|
|
287
|
+
Value extends Expression.Any = Expression.Any
|
|
288
|
+
> {
|
|
289
|
+
readonly key: Key
|
|
290
|
+
readonly value: Value
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export interface JsonBuildObjectNode<
|
|
294
|
+
Entries extends readonly JsonBuildObjectEntryNode[] = readonly JsonBuildObjectEntryNode[]
|
|
295
|
+
> {
|
|
296
|
+
readonly kind: "jsonBuildObject"
|
|
297
|
+
readonly entries: Entries
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export interface JsonBuildArrayNode<
|
|
301
|
+
Values extends readonly Expression.Any[] = readonly Expression.Any[]
|
|
302
|
+
> {
|
|
303
|
+
readonly kind: "jsonBuildArray"
|
|
304
|
+
readonly values: Values
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export interface JsonWrapNode<
|
|
308
|
+
Kind extends "jsonToJson" | "jsonToJsonb" = "jsonToJson" | "jsonToJsonb",
|
|
309
|
+
Value extends Expression.Any = Expression.Any
|
|
310
|
+
> {
|
|
311
|
+
readonly kind: Kind
|
|
312
|
+
readonly value: Value
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export interface JsonUnaryNode<
|
|
316
|
+
Kind extends "jsonTypeOf" | "jsonLength" | "jsonKeys" | "jsonStripNulls" = "jsonTypeOf" | "jsonLength" | "jsonKeys" | "jsonStripNulls",
|
|
317
|
+
Value extends Expression.Any = Expression.Any
|
|
318
|
+
> {
|
|
319
|
+
readonly kind: Kind
|
|
320
|
+
readonly value: Value
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** Union of all internal expression nodes. */
|
|
324
|
+
export type Any =
|
|
325
|
+
| ColumnNode
|
|
326
|
+
| LiteralNode
|
|
327
|
+
| CastNode
|
|
328
|
+
| ExcludedNode
|
|
329
|
+
| UnaryNode
|
|
330
|
+
| BinaryNode
|
|
331
|
+
| VariadicNode
|
|
332
|
+
| CaseNode
|
|
333
|
+
| ExistsNode
|
|
334
|
+
| ScalarSubqueryNode
|
|
335
|
+
| InSubqueryNode
|
|
336
|
+
| QuantifiedComparisonNode
|
|
337
|
+
| WindowNode
|
|
338
|
+
| JsonNode
|
|
339
|
+
| JsonAccessNode
|
|
340
|
+
| JsonKeyPredicateNode
|
|
341
|
+
| JsonBinaryNode
|
|
342
|
+
| JsonDeleteNode
|
|
343
|
+
| JsonSetNode
|
|
344
|
+
| JsonInsertNode
|
|
345
|
+
| JsonQueryPredicateNode
|
|
346
|
+
| JsonBuildObjectNode
|
|
347
|
+
| JsonBuildArrayNode
|
|
348
|
+
| JsonWrapNode
|
|
349
|
+
| JsonUnaryNode
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import type { Pipeable } from "effect/Pipeable"
|
|
2
|
+
import type * as Schema from "effect/Schema"
|
|
3
|
+
import type { RuntimeOfDbType as RuntimeOfDbTypeLookup } from "./datatypes/lookup.js"
|
|
4
|
+
|
|
5
|
+
export type {
|
|
6
|
+
BigIntString,
|
|
7
|
+
DecimalString,
|
|
8
|
+
InstantString,
|
|
9
|
+
JsonPrimitive,
|
|
10
|
+
JsonValue,
|
|
11
|
+
LocalDateString,
|
|
12
|
+
LocalDateTimeString,
|
|
13
|
+
LocalTimeString,
|
|
14
|
+
OffsetTimeString,
|
|
15
|
+
YearString
|
|
16
|
+
} from "./runtime-value.js"
|
|
17
|
+
|
|
18
|
+
/** Symbol used to attach expression metadata to runtime values. */
|
|
19
|
+
export const TypeId: unique symbol = Symbol.for("effect-qb/Expression")
|
|
20
|
+
|
|
21
|
+
export type TypeId = typeof TypeId
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Bound source provenance for a column-like expression.
|
|
25
|
+
*
|
|
26
|
+
* `tableName` is the logical source identity currently visible to the query
|
|
27
|
+
* layer. For aliased sources this is the alias, while `baseTableName` retains
|
|
28
|
+
* the underlying physical table name for downstream renderer work.
|
|
29
|
+
*/
|
|
30
|
+
export interface ColumnSource<
|
|
31
|
+
TableName extends string = string,
|
|
32
|
+
ColumnName extends string = string,
|
|
33
|
+
BaseTableName extends string = TableName
|
|
34
|
+
> {
|
|
35
|
+
readonly tableName: TableName
|
|
36
|
+
readonly columnName: ColumnName
|
|
37
|
+
readonly baseTableName: BaseTableName
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Three-state nullability lattice.
|
|
42
|
+
*
|
|
43
|
+
* `"never"` means non-null, `"maybe"` means nullable, and `"always"` means the
|
|
44
|
+
* expression is known to be `null`.
|
|
45
|
+
*/
|
|
46
|
+
export type Nullability = "never" | "maybe" | "always"
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* High-level classification of an expression.
|
|
50
|
+
*
|
|
51
|
+
* - `scalar`: regular per-row expression
|
|
52
|
+
* - `aggregate`: grouped expression such as `count(*)`
|
|
53
|
+
* - `window`: windowed expression such as `row_number() over (...)`
|
|
54
|
+
*/
|
|
55
|
+
export type AggregationKind = "scalar" | "aggregate" | "window"
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Whether an expression should still be promoted by optional-source scope.
|
|
59
|
+
*
|
|
60
|
+
* Most expressions propagate optional-source nullability because a missing
|
|
61
|
+
* joined row turns their inputs into `null`. Some expressions, such as
|
|
62
|
+
* `coalesce(...)`, `is null`, and aggregates, already model their own
|
|
63
|
+
* null-handling semantics and should not be promoted again by plan scope.
|
|
64
|
+
*/
|
|
65
|
+
export type SourceNullabilityMode = "propagate" | "resolved"
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Phantom dependency map of source names referenced by an expression.
|
|
69
|
+
*
|
|
70
|
+
* This is intentionally separate from runtime provenance (`source`). The
|
|
71
|
+
* dependency map is the cheap, composable type-level representation used by the
|
|
72
|
+
* query layer to resolve scope-sensitive nullability after joins. Dependencies
|
|
73
|
+
* are tracked by logical source identity, which means aliased sources are kept
|
|
74
|
+
* distinct from one another even when they point at the same base table.
|
|
75
|
+
*/
|
|
76
|
+
export type SourceDependencies = Record<string, true>
|
|
77
|
+
|
|
78
|
+
/** Database-type descriptors carried alongside decoded runtime types. */
|
|
79
|
+
export declare namespace DbType {
|
|
80
|
+
/** Base SQL type descriptor. */
|
|
81
|
+
export interface Base<Dialect extends string, Kind extends string> {
|
|
82
|
+
readonly dialect: Dialect
|
|
83
|
+
readonly kind: Kind
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** JSON-like database type. */
|
|
87
|
+
export interface Json<
|
|
88
|
+
Dialect extends string = "postgres",
|
|
89
|
+
SchemaName extends string = "json"
|
|
90
|
+
> extends Base<Dialect, SchemaName>
|
|
91
|
+
{
|
|
92
|
+
readonly variant: "json"
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Array database type. */
|
|
96
|
+
export interface Array<
|
|
97
|
+
Dialect extends string = string,
|
|
98
|
+
Element extends Any = any,
|
|
99
|
+
Kind extends string = string
|
|
100
|
+
> extends Base<Dialect, Kind> {
|
|
101
|
+
readonly element: Element
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Range database type. */
|
|
105
|
+
export interface Range<
|
|
106
|
+
Dialect extends string = string,
|
|
107
|
+
Subtype extends Any = any,
|
|
108
|
+
Kind extends string = string
|
|
109
|
+
> extends Base<Dialect, Kind> {
|
|
110
|
+
readonly subtype: Subtype
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Multirange database type. */
|
|
114
|
+
export interface Multirange<
|
|
115
|
+
Dialect extends string = string,
|
|
116
|
+
Subtype extends Any = any,
|
|
117
|
+
Kind extends string = string
|
|
118
|
+
> extends Base<Dialect, Kind> {
|
|
119
|
+
readonly subtype: Subtype
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Composite/record database type. */
|
|
123
|
+
export interface Composite<
|
|
124
|
+
Dialect extends string = string,
|
|
125
|
+
Fields extends Record<string, Any> = Record<string, any>,
|
|
126
|
+
Kind extends string = string
|
|
127
|
+
> extends Base<Dialect, Kind> {
|
|
128
|
+
readonly fields: Fields
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Named domain database type. */
|
|
132
|
+
export interface Domain<
|
|
133
|
+
Dialect extends string = string,
|
|
134
|
+
BaseType extends Any = any,
|
|
135
|
+
Kind extends string = string
|
|
136
|
+
> extends Base<Dialect, Kind> {
|
|
137
|
+
readonly base: BaseType
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Enumeration database type. */
|
|
141
|
+
export interface Enum<
|
|
142
|
+
Dialect extends string = string,
|
|
143
|
+
Kind extends string = string
|
|
144
|
+
> extends Base<Dialect, Kind> {
|
|
145
|
+
readonly variant: "enum"
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Set database type. */
|
|
149
|
+
export interface Set<
|
|
150
|
+
Dialect extends string = string,
|
|
151
|
+
Kind extends string = string
|
|
152
|
+
> extends Base<Dialect, Kind> {
|
|
153
|
+
readonly variant: "set"
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export type PgUuid = Base<"postgres", "uuid">
|
|
157
|
+
export type PgText = Base<"postgres", "text">
|
|
158
|
+
export type PgVarchar = Base<"postgres", "varchar">
|
|
159
|
+
export type PgChar = Base<"postgres", "char">
|
|
160
|
+
export type PgCitext = Base<"postgres", "citext">
|
|
161
|
+
export type PgInt2 = Base<"postgres", "int2">
|
|
162
|
+
export type PgInt4 = Base<"postgres", "int4">
|
|
163
|
+
export type PgInt8 = Base<"postgres", "int8">
|
|
164
|
+
export type PgNumeric = Base<"postgres", "numeric">
|
|
165
|
+
export type PgFloat4 = Base<"postgres", "float4">
|
|
166
|
+
export type PgFloat8 = Base<"postgres", "float8">
|
|
167
|
+
export type PgBool = Base<"postgres", "bool">
|
|
168
|
+
export type PgDate = Base<"postgres", "date">
|
|
169
|
+
export type PgTime = Base<"postgres", "time">
|
|
170
|
+
export type PgTimestamp = Base<"postgres", "timestamp">
|
|
171
|
+
export type PgInterval = Base<"postgres", "interval">
|
|
172
|
+
export type PgBytea = Base<"postgres", "bytea">
|
|
173
|
+
export type PgJsonb = Base<"postgres", "jsonb">
|
|
174
|
+
export type PgArray<Element extends Any = any> = Array<"postgres", Element, string>
|
|
175
|
+
export type PgRange<Subtype extends Any = any, Kind extends string = string> = Range<"postgres", Subtype, Kind>
|
|
176
|
+
export type PgMultirange<Subtype extends Any = any, Kind extends string = string> = Multirange<"postgres", Subtype, Kind>
|
|
177
|
+
export type PgComposite<Fields extends Record<string, Any> = Record<string, any>, Kind extends string = string> = Composite<"postgres", Fields, Kind>
|
|
178
|
+
export type PgDomain<BaseType extends Any = any, Kind extends string = string> = Domain<"postgres", BaseType, Kind>
|
|
179
|
+
|
|
180
|
+
export type MySqlUuid = Base<"mysql", "uuid">
|
|
181
|
+
export type MySqlText = Base<"mysql", "text">
|
|
182
|
+
export type MySqlVarchar = Base<"mysql", "varchar">
|
|
183
|
+
export type MySqlChar = Base<"mysql", "char">
|
|
184
|
+
export type MySqlTinyInt = Base<"mysql", "tinyint">
|
|
185
|
+
export type MySqlSmallInt = Base<"mysql", "smallint">
|
|
186
|
+
export type MySqlMediumInt = Base<"mysql", "mediumint">
|
|
187
|
+
export type MySqlInt = Base<"mysql", "int">
|
|
188
|
+
export type MySqlBigInt = Base<"mysql", "bigint">
|
|
189
|
+
export type MySqlNumeric = Base<"mysql", "decimal">
|
|
190
|
+
export type MySqlFloat = Base<"mysql", "float">
|
|
191
|
+
export type MySqlDouble = Base<"mysql", "double">
|
|
192
|
+
export type MySqlBool = Base<"mysql", "boolean">
|
|
193
|
+
export type MySqlDate = Base<"mysql", "date">
|
|
194
|
+
export type MySqlTime = Base<"mysql", "time">
|
|
195
|
+
export type MySqlDatetime = Base<"mysql", "datetime">
|
|
196
|
+
export type MySqlTimestamp = Base<"mysql", "timestamp">
|
|
197
|
+
export type MySqlBinary = Base<"mysql", "binary">
|
|
198
|
+
export type MySqlVarBinary = Base<"mysql", "varbinary">
|
|
199
|
+
export type MySqlBlob = Base<"mysql", "blob">
|
|
200
|
+
export type MySqlArray<Element extends Any = any> = Array<"mysql", Element, string>
|
|
201
|
+
export type MySqlComposite<Fields extends Record<string, Any> = Record<string, any>, Kind extends string = string> = Composite<"mysql", Fields, Kind>
|
|
202
|
+
export type MySqlDomain<BaseType extends Any = any, Kind extends string = string> = Domain<"mysql", BaseType, Kind>
|
|
203
|
+
|
|
204
|
+
export type Any =
|
|
205
|
+
| PgUuid
|
|
206
|
+
| PgText
|
|
207
|
+
| PgVarchar
|
|
208
|
+
| PgChar
|
|
209
|
+
| PgCitext
|
|
210
|
+
| PgInt2
|
|
211
|
+
| PgInt4
|
|
212
|
+
| PgInt8
|
|
213
|
+
| PgNumeric
|
|
214
|
+
| PgFloat4
|
|
215
|
+
| PgFloat8
|
|
216
|
+
| PgBool
|
|
217
|
+
| PgDate
|
|
218
|
+
| PgTime
|
|
219
|
+
| PgTimestamp
|
|
220
|
+
| PgInterval
|
|
221
|
+
| PgBytea
|
|
222
|
+
| PgJsonb
|
|
223
|
+
| PgArray
|
|
224
|
+
| PgRange
|
|
225
|
+
| PgMultirange
|
|
226
|
+
| PgComposite
|
|
227
|
+
| PgDomain
|
|
228
|
+
| MySqlUuid
|
|
229
|
+
| MySqlText
|
|
230
|
+
| MySqlVarchar
|
|
231
|
+
| MySqlChar
|
|
232
|
+
| MySqlTinyInt
|
|
233
|
+
| MySqlSmallInt
|
|
234
|
+
| MySqlMediumInt
|
|
235
|
+
| MySqlInt
|
|
236
|
+
| MySqlBigInt
|
|
237
|
+
| MySqlNumeric
|
|
238
|
+
| MySqlFloat
|
|
239
|
+
| MySqlDouble
|
|
240
|
+
| MySqlBool
|
|
241
|
+
| MySqlDate
|
|
242
|
+
| MySqlTime
|
|
243
|
+
| MySqlDatetime
|
|
244
|
+
| MySqlTimestamp
|
|
245
|
+
| MySqlBinary
|
|
246
|
+
| MySqlVarBinary
|
|
247
|
+
| MySqlBlob
|
|
248
|
+
| MySqlArray
|
|
249
|
+
| MySqlComposite
|
|
250
|
+
| MySqlDomain
|
|
251
|
+
| Json
|
|
252
|
+
| Base<string, string>
|
|
253
|
+
| Array<string, any, string>
|
|
254
|
+
| Range<string, any, string>
|
|
255
|
+
| Multirange<string, any, string>
|
|
256
|
+
| Composite<string, Record<string, any>, string>
|
|
257
|
+
| Domain<string, any, string>
|
|
258
|
+
| Enum<string, string>
|
|
259
|
+
| Set<string, string>
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Canonical static metadata stored on an expression. */
|
|
263
|
+
export interface State<
|
|
264
|
+
Runtime,
|
|
265
|
+
Db extends DbType.Any,
|
|
266
|
+
Nullable extends Nullability,
|
|
267
|
+
Dialect extends string,
|
|
268
|
+
Aggregation extends AggregationKind,
|
|
269
|
+
Source = never,
|
|
270
|
+
Dependencies extends SourceDependencies = {},
|
|
271
|
+
SourceNullability extends SourceNullabilityMode = "propagate"
|
|
272
|
+
> {
|
|
273
|
+
readonly runtime: Runtime
|
|
274
|
+
readonly dbType: Db
|
|
275
|
+
readonly runtimeSchema?: Schema.Schema.Any
|
|
276
|
+
readonly nullability: Nullable
|
|
277
|
+
readonly dialect: Dialect
|
|
278
|
+
readonly aggregation: Aggregation
|
|
279
|
+
readonly source: Source
|
|
280
|
+
readonly sourceNullability: SourceNullability
|
|
281
|
+
/**
|
|
282
|
+
* Type-level source dependency map used for lazy nullability resolution.
|
|
283
|
+
*
|
|
284
|
+
* Unlike `source`, which preserves runtime provenance detail for diagnostics
|
|
285
|
+
* and plan assembly, `dependencies` only needs to record which tables are
|
|
286
|
+
* referenced at all.
|
|
287
|
+
*/
|
|
288
|
+
readonly dependencies: Dependencies
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* A typed SQL expression.
|
|
293
|
+
*
|
|
294
|
+
* `Runtime` is the decoded TypeScript type while `Db` captures the SQL-level
|
|
295
|
+
* type identity. Both are needed: multiple SQL types may decode to the same
|
|
296
|
+
* runtime type but still have different comparison/cast semantics.
|
|
297
|
+
*/
|
|
298
|
+
export interface Expression<
|
|
299
|
+
Runtime,
|
|
300
|
+
Db extends DbType.Any,
|
|
301
|
+
Nullable extends Nullability = "never",
|
|
302
|
+
Dialect extends string = Db["dialect"],
|
|
303
|
+
Aggregation extends AggregationKind = "scalar",
|
|
304
|
+
Source = never,
|
|
305
|
+
Dependencies extends SourceDependencies = {},
|
|
306
|
+
SourceNullability extends SourceNullabilityMode = "propagate"
|
|
307
|
+
> extends Pipeable {
|
|
308
|
+
readonly [TypeId]: State<Runtime, Db, Nullable, Dialect, Aggregation, Source, Dependencies, SourceNullability>
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** Convenience alias for any expression-like value. */
|
|
312
|
+
export type Any = Expression<any, DbType.Any, Nullability, string, AggregationKind, any, SourceDependencies, SourceNullabilityMode>
|
|
313
|
+
/** Extracts an expression's decoded runtime type. */
|
|
314
|
+
export type RuntimeOf<Value extends Any> = Value[typeof TypeId]["runtime"]
|
|
315
|
+
/** Extracts an expression's database-type descriptor. */
|
|
316
|
+
export type DbTypeOf<Value extends Any> = Value[typeof TypeId]["dbType"]
|
|
317
|
+
/** Extracts an expression's nullability state. */
|
|
318
|
+
export type NullabilityOf<Value extends Any> = Value[typeof TypeId]["nullability"]
|
|
319
|
+
/** Extracts an expression's source dependency map. */
|
|
320
|
+
export type DependenciesOf<Value extends Any> = Value[typeof TypeId]["dependencies"]
|
|
321
|
+
/** Extracts how plan-scope nullability should apply to an expression. */
|
|
322
|
+
export type SourceNullabilityOf<Value extends Any> = Value[typeof TypeId]["sourceNullability"]
|
|
323
|
+
|
|
324
|
+
/** Maps a database type descriptor back to its decoded runtime type. */
|
|
325
|
+
export type RuntimeOfDbType<Db extends DbType.Any> = RuntimeOfDbTypeLookup<Db>
|