effect-qb 0.13.0 → 0.15.0
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 +6 -1431
- package/dist/mysql.js +61945 -3611
- package/dist/postgres/metadata.js +2818 -0
- package/dist/postgres.js +9942 -5591
- package/package.json +21 -10
- package/src/internal/aggregation-validation.ts +3 -3
- package/src/internal/case-analysis.d.ts +18 -0
- package/src/internal/case-analysis.ts +4 -4
- package/src/internal/coercion/analysis.d.ts +7 -0
- package/src/internal/{coercion-analysis.ts → coercion/analysis.ts} +3 -3
- package/src/internal/coercion/errors.d.ts +17 -0
- package/src/internal/{coercion-errors.ts → coercion/errors.ts} +1 -1
- package/src/internal/coercion/kind.d.ts +4 -0
- package/src/internal/{coercion-kind.ts → coercion/kind.ts} +2 -2
- package/src/internal/{coercion-normalize.ts → coercion/normalize.ts} +1 -1
- package/src/internal/coercion/rules.d.ts +6 -0
- package/src/internal/{coercion-rules.ts → coercion/rules.ts} +2 -2
- package/src/internal/column-state.d.ts +190 -0
- package/src/internal/column-state.ts +119 -56
- package/src/internal/column.ts +387 -149
- package/src/internal/datatypes/define.d.ts +17 -0
- package/src/internal/datatypes/define.ts +18 -34
- package/src/internal/datatypes/lookup.d.ts +44 -0
- package/src/internal/datatypes/lookup.ts +61 -152
- package/src/internal/datatypes/shape.d.ts +16 -0
- package/src/internal/datatypes/shape.ts +1 -1
- package/src/internal/derived-table.d.ts +4 -0
- package/src/internal/derived-table.ts +21 -16
- package/src/internal/dsl-mutation-runtime.ts +378 -0
- package/src/internal/dsl-plan-runtime.ts +387 -0
- package/src/internal/dsl-query-runtime.ts +160 -0
- package/src/internal/dsl-transaction-ddl-runtime.ts +263 -0
- package/src/internal/executor.ts +173 -38
- package/src/internal/expression-ast.ts +19 -5
- package/src/internal/grouping-key.d.ts +3 -0
- package/src/internal/grouping-key.ts +1 -1
- package/src/internal/implication-runtime.d.ts +15 -0
- package/src/internal/implication-runtime.ts +171 -0
- package/src/internal/json/ast.d.ts +30 -0
- package/src/internal/json/ast.ts +1 -1
- package/src/internal/json/errors.d.ts +8 -0
- package/src/internal/json/path.d.ts +75 -0
- package/src/internal/json/path.ts +1 -1
- package/src/internal/json/types.d.ts +62 -0
- package/src/internal/predicate/analysis.d.ts +20 -0
- package/src/internal/{predicate-analysis.ts → predicate/analysis.ts} +13 -3
- package/src/internal/predicate/atom.d.ts +28 -0
- package/src/internal/{predicate-branches.ts → predicate/branches.ts} +2 -2
- package/src/internal/predicate/context.d.ts +67 -0
- package/src/internal/{predicate-context.ts → predicate/context.ts} +111 -32
- package/src/internal/predicate/formula.d.ts +35 -0
- package/src/internal/{predicate-formula.ts → predicate/formula.ts} +32 -20
- package/src/internal/predicate/key.d.ts +11 -0
- package/src/internal/{predicate-key.ts → predicate/key.ts} +2 -2
- package/src/internal/{predicate-nnf.ts → predicate/nnf.ts} +2 -2
- package/src/internal/predicate/normalize.d.ts +53 -0
- package/src/internal/predicate/normalize.ts +273 -0
- package/src/internal/predicate/runtime.d.ts +31 -0
- package/src/internal/predicate/runtime.ts +679 -0
- package/src/internal/projection-alias.d.ts +13 -0
- package/src/internal/projections.d.ts +31 -0
- package/src/internal/projections.ts +1 -1
- package/src/internal/query-ast.d.ts +217 -0
- package/src/internal/query-ast.ts +1 -1
- package/src/internal/query-requirements.d.ts +20 -0
- package/src/internal/query.d.ts +775 -0
- package/src/internal/query.ts +767 -275
- package/src/internal/renderer.ts +7 -21
- package/src/internal/row-set.d.ts +53 -0
- package/src/internal/{plan.ts → row-set.ts} +23 -11
- package/src/internal/{runtime-normalize.ts → runtime/normalize.ts} +9 -31
- package/src/internal/{runtime-schema.ts → runtime/schema.ts} +84 -55
- package/src/internal/runtime/value.d.ts +22 -0
- package/src/internal/{runtime-value.ts → runtime/value.ts} +2 -2
- package/src/internal/scalar.d.ts +107 -0
- package/src/internal/scalar.ts +191 -0
- package/src/internal/schema-derivation.d.ts +105 -0
- package/src/internal/schema-derivation.ts +93 -21
- package/src/internal/schema-expression.d.ts +18 -0
- package/src/internal/schema-expression.ts +75 -0
- package/src/internal/table-options.d.ts +94 -0
- package/src/internal/table-options.ts +94 -8
- package/src/internal/table.d.ts +173 -0
- package/src/internal/table.ts +135 -54
- package/src/mysql/column.ts +95 -18
- package/src/mysql/datatypes/index.ts +58 -3
- package/src/mysql/errors/generated.ts +57336 -0
- package/src/mysql/errors/index.ts +1 -0
- package/src/mysql/errors/normalize.ts +55 -53
- package/src/mysql/errors/types.ts +74 -0
- package/src/mysql/executor.ts +69 -7
- package/src/mysql/function/aggregate.ts +1 -5
- package/src/mysql/function/core.ts +1 -3
- package/src/mysql/function/index.ts +1 -1
- package/src/mysql/function/string.ts +1 -5
- package/src/mysql/function/temporal.ts +12 -15
- package/src/mysql/function/window.ts +1 -6
- package/src/{internal/mysql-dialect.ts → mysql/internal/dialect.ts} +1 -1
- package/src/mysql/internal/dsl.ts +6115 -0
- package/src/{internal/mysql-renderer.ts → mysql/internal/renderer.ts} +6 -6
- package/src/mysql/internal/sql-expression-renderer.ts +1455 -0
- package/src/mysql/json.ts +2 -0
- package/src/mysql/query.ts +111 -86
- package/src/mysql/renderer.ts +1 -1
- package/src/mysql/table.ts +1 -1
- package/src/mysql.ts +6 -4
- package/src/postgres/cast.ts +30 -0
- package/src/postgres/column.ts +178 -20
- package/src/postgres/datatypes/index.d.ts +515 -0
- package/src/postgres/datatypes/index.ts +49 -5
- package/src/postgres/datatypes/spec.d.ts +412 -0
- package/src/postgres/errors/generated.ts +2636 -0
- package/src/postgres/errors/index.ts +1 -0
- package/src/postgres/errors/normalize.ts +47 -62
- package/src/postgres/errors/types.ts +92 -34
- package/src/postgres/executor.ts +37 -5
- package/src/postgres/function/aggregate.ts +1 -5
- package/src/postgres/function/core.ts +20 -2
- package/src/postgres/function/index.ts +1 -1
- package/src/postgres/function/string.ts +1 -5
- package/src/postgres/function/temporal.ts +12 -15
- package/src/postgres/function/window.ts +1 -6
- package/src/{internal/postgres-dialect.ts → postgres/internal/dialect.ts} +1 -1
- package/src/{internal/query-factory.ts → postgres/internal/dsl.ts} +1568 -2120
- package/src/{internal/postgres-renderer.ts → postgres/internal/renderer.ts} +6 -6
- package/src/postgres/internal/schema-ddl.ts +108 -0
- package/src/postgres/internal/schema-model.ts +150 -0
- package/src/{internal → postgres/internal}/sql-expression-renderer.ts +112 -46
- package/src/postgres/json.ts +493 -0
- package/src/postgres/metadata.ts +31 -0
- package/src/postgres/query.ts +113 -86
- package/src/postgres/renderer.ts +3 -13
- package/src/postgres/schema-expression.ts +17 -0
- package/src/postgres/schema-management.ts +204 -0
- package/src/postgres/schema.ts +35 -0
- package/src/postgres/table.ts +316 -42
- package/src/postgres/type.ts +31 -0
- package/src/postgres.ts +20 -4
- package/CHANGELOG.md +0 -134
- package/src/internal/expression.ts +0 -327
- package/src/internal/predicate-normalize.ts +0 -202
- package/src/mysql/function/json.ts +0 -4
- package/src/mysql/private/query.ts +0 -13
- package/src/postgres/function/json.ts +0 -4
- package/src/postgres/private/query.ts +0 -13
- /package/src/internal/{predicate-atom.ts → predicate/atom.ts} +0 -0
|
@@ -1,327 +0,0 @@
|
|
|
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 PgTimetz = Base<"postgres", "timetz">
|
|
172
|
-
export type PgTimestamptz = Base<"postgres", "timestamptz">
|
|
173
|
-
export type PgInterval = Base<"postgres", "interval">
|
|
174
|
-
export type PgBytea = Base<"postgres", "bytea">
|
|
175
|
-
export type PgJsonb = Base<"postgres", "jsonb">
|
|
176
|
-
export type PgArray<Element extends Any = any> = Array<"postgres", Element, string>
|
|
177
|
-
export type PgRange<Subtype extends Any = any, Kind extends string = string> = Range<"postgres", Subtype, Kind>
|
|
178
|
-
export type PgMultirange<Subtype extends Any = any, Kind extends string = string> = Multirange<"postgres", Subtype, Kind>
|
|
179
|
-
export type PgComposite<Fields extends Record<string, Any> = Record<string, any>, Kind extends string = string> = Composite<"postgres", Fields, Kind>
|
|
180
|
-
export type PgDomain<BaseType extends Any = any, Kind extends string = string> = Domain<"postgres", BaseType, Kind>
|
|
181
|
-
|
|
182
|
-
export type MySqlUuid = Base<"mysql", "uuid">
|
|
183
|
-
export type MySqlText = Base<"mysql", "text">
|
|
184
|
-
export type MySqlVarchar = Base<"mysql", "varchar">
|
|
185
|
-
export type MySqlChar = Base<"mysql", "char">
|
|
186
|
-
export type MySqlTinyInt = Base<"mysql", "tinyint">
|
|
187
|
-
export type MySqlSmallInt = Base<"mysql", "smallint">
|
|
188
|
-
export type MySqlMediumInt = Base<"mysql", "mediumint">
|
|
189
|
-
export type MySqlInt = Base<"mysql", "int">
|
|
190
|
-
export type MySqlBigInt = Base<"mysql", "bigint">
|
|
191
|
-
export type MySqlNumeric = Base<"mysql", "decimal">
|
|
192
|
-
export type MySqlFloat = Base<"mysql", "float">
|
|
193
|
-
export type MySqlDouble = Base<"mysql", "double">
|
|
194
|
-
export type MySqlBool = Base<"mysql", "boolean">
|
|
195
|
-
export type MySqlDate = Base<"mysql", "date">
|
|
196
|
-
export type MySqlTime = Base<"mysql", "time">
|
|
197
|
-
export type MySqlDatetime = Base<"mysql", "datetime">
|
|
198
|
-
export type MySqlTimestamp = Base<"mysql", "timestamp">
|
|
199
|
-
export type MySqlBinary = Base<"mysql", "binary">
|
|
200
|
-
export type MySqlVarBinary = Base<"mysql", "varbinary">
|
|
201
|
-
export type MySqlBlob = Base<"mysql", "blob">
|
|
202
|
-
export type MySqlArray<Element extends Any = any> = Array<"mysql", Element, string>
|
|
203
|
-
export type MySqlComposite<Fields extends Record<string, Any> = Record<string, any>, Kind extends string = string> = Composite<"mysql", Fields, Kind>
|
|
204
|
-
export type MySqlDomain<BaseType extends Any = any, Kind extends string = string> = Domain<"mysql", BaseType, Kind>
|
|
205
|
-
|
|
206
|
-
export type Any =
|
|
207
|
-
| PgUuid
|
|
208
|
-
| PgText
|
|
209
|
-
| PgVarchar
|
|
210
|
-
| PgChar
|
|
211
|
-
| PgCitext
|
|
212
|
-
| PgInt2
|
|
213
|
-
| PgInt4
|
|
214
|
-
| PgInt8
|
|
215
|
-
| PgNumeric
|
|
216
|
-
| PgFloat4
|
|
217
|
-
| PgFloat8
|
|
218
|
-
| PgBool
|
|
219
|
-
| PgDate
|
|
220
|
-
| PgTime
|
|
221
|
-
| PgTimestamp
|
|
222
|
-
| PgInterval
|
|
223
|
-
| PgBytea
|
|
224
|
-
| PgJsonb
|
|
225
|
-
| PgArray
|
|
226
|
-
| PgRange
|
|
227
|
-
| PgMultirange
|
|
228
|
-
| PgComposite
|
|
229
|
-
| PgDomain
|
|
230
|
-
| MySqlUuid
|
|
231
|
-
| MySqlText
|
|
232
|
-
| MySqlVarchar
|
|
233
|
-
| MySqlChar
|
|
234
|
-
| MySqlTinyInt
|
|
235
|
-
| MySqlSmallInt
|
|
236
|
-
| MySqlMediumInt
|
|
237
|
-
| MySqlInt
|
|
238
|
-
| MySqlBigInt
|
|
239
|
-
| MySqlNumeric
|
|
240
|
-
| MySqlFloat
|
|
241
|
-
| MySqlDouble
|
|
242
|
-
| MySqlBool
|
|
243
|
-
| MySqlDate
|
|
244
|
-
| MySqlTime
|
|
245
|
-
| MySqlDatetime
|
|
246
|
-
| MySqlTimestamp
|
|
247
|
-
| MySqlBinary
|
|
248
|
-
| MySqlVarBinary
|
|
249
|
-
| MySqlBlob
|
|
250
|
-
| MySqlArray
|
|
251
|
-
| MySqlComposite
|
|
252
|
-
| MySqlDomain
|
|
253
|
-
| Json
|
|
254
|
-
| Base<string, string>
|
|
255
|
-
| Array<string, any, string>
|
|
256
|
-
| Range<string, any, string>
|
|
257
|
-
| Multirange<string, any, string>
|
|
258
|
-
| Composite<string, Record<string, any>, string>
|
|
259
|
-
| Domain<string, any, string>
|
|
260
|
-
| Enum<string, string>
|
|
261
|
-
| Set<string, string>
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/** Canonical static metadata stored on an expression. */
|
|
265
|
-
export interface State<
|
|
266
|
-
Runtime,
|
|
267
|
-
Db extends DbType.Any,
|
|
268
|
-
Nullable extends Nullability,
|
|
269
|
-
Dialect extends string,
|
|
270
|
-
Aggregation extends AggregationKind,
|
|
271
|
-
Source = never,
|
|
272
|
-
Dependencies extends SourceDependencies = {},
|
|
273
|
-
SourceNullability extends SourceNullabilityMode = "propagate"
|
|
274
|
-
> {
|
|
275
|
-
readonly runtime: Runtime
|
|
276
|
-
readonly dbType: Db
|
|
277
|
-
readonly runtimeSchema?: Schema.Schema.Any
|
|
278
|
-
readonly nullability: Nullable
|
|
279
|
-
readonly dialect: Dialect
|
|
280
|
-
readonly aggregation: Aggregation
|
|
281
|
-
readonly source: Source
|
|
282
|
-
readonly sourceNullability: SourceNullability
|
|
283
|
-
/**
|
|
284
|
-
* Type-level source dependency map used for lazy nullability resolution.
|
|
285
|
-
*
|
|
286
|
-
* Unlike `source`, which preserves runtime provenance detail for diagnostics
|
|
287
|
-
* and plan assembly, `dependencies` only needs to record which tables are
|
|
288
|
-
* referenced at all.
|
|
289
|
-
*/
|
|
290
|
-
readonly dependencies: Dependencies
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* A typed SQL expression.
|
|
295
|
-
*
|
|
296
|
-
* `Runtime` is the decoded TypeScript type while `Db` captures the SQL-level
|
|
297
|
-
* type identity. Both are needed: multiple SQL types may decode to the same
|
|
298
|
-
* runtime type but still have different comparison/cast semantics.
|
|
299
|
-
*/
|
|
300
|
-
export interface Expression<
|
|
301
|
-
Runtime,
|
|
302
|
-
Db extends DbType.Any,
|
|
303
|
-
Nullable extends Nullability = "never",
|
|
304
|
-
Dialect extends string = Db["dialect"],
|
|
305
|
-
Aggregation extends AggregationKind = "scalar",
|
|
306
|
-
Source = never,
|
|
307
|
-
Dependencies extends SourceDependencies = {},
|
|
308
|
-
SourceNullability extends SourceNullabilityMode = "propagate"
|
|
309
|
-
> extends Pipeable {
|
|
310
|
-
readonly [TypeId]: State<Runtime, Db, Nullable, Dialect, Aggregation, Source, Dependencies, SourceNullability>
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/** Convenience alias for any expression-like value. */
|
|
314
|
-
export type Any = Expression<any, DbType.Any, Nullability, string, AggregationKind, any, SourceDependencies, SourceNullabilityMode>
|
|
315
|
-
/** Extracts an expression's decoded runtime type. */
|
|
316
|
-
export type RuntimeOf<Value extends Any> = Value[typeof TypeId]["runtime"]
|
|
317
|
-
/** Extracts an expression's database-type descriptor. */
|
|
318
|
-
export type DbTypeOf<Value extends Any> = Value[typeof TypeId]["dbType"]
|
|
319
|
-
/** Extracts an expression's nullability state. */
|
|
320
|
-
export type NullabilityOf<Value extends Any> = Value[typeof TypeId]["nullability"]
|
|
321
|
-
/** Extracts an expression's source dependency map. */
|
|
322
|
-
export type DependenciesOf<Value extends Any> = Value[typeof TypeId]["dependencies"]
|
|
323
|
-
/** Extracts how plan-scope nullability should apply to an expression. */
|
|
324
|
-
export type SourceNullabilityOf<Value extends Any> = Value[typeof TypeId]["sourceNullability"]
|
|
325
|
-
|
|
326
|
-
/** Maps a database type descriptor back to its decoded runtime type. */
|
|
327
|
-
export type RuntimeOfDbType<Db extends DbType.Any> = RuntimeOfDbTypeLookup<Db>
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import type * as Expression from "./expression.js"
|
|
2
|
-
import type * as ExpressionAst from "./expression-ast.js"
|
|
3
|
-
import type { ColumnKeyOfExpression, ValueKey } from "./predicate-key.js"
|
|
4
|
-
import type { AllFormula, AnyFormula, AtomFormula, FalseFormula, NotFormula, PredicateFormula, TrueFormula } from "./predicate-formula.js"
|
|
5
|
-
import type { EqColumnAtom, EqLiteralAtom, NeqLiteralAtom, NonNullAtom, NullAtom, UnknownAtom } from "./predicate-atom.js"
|
|
6
|
-
|
|
7
|
-
type AstOf<Value extends Expression.Any> = Value extends {
|
|
8
|
-
readonly [ExpressionAst.TypeId]: infer Ast extends ExpressionAst.Any
|
|
9
|
-
} ? Ast : never
|
|
10
|
-
|
|
11
|
-
type LiteralValueOfExpression<Value extends Expression.Any> = AstOf<Value> extends ExpressionAst.LiteralNode<infer Literal>
|
|
12
|
-
? Literal
|
|
13
|
-
: never
|
|
14
|
-
|
|
15
|
-
type True = TrueFormula
|
|
16
|
-
type False = FalseFormula
|
|
17
|
-
|
|
18
|
-
type UnknownTag<Tag extends string> = AtomFormula<UnknownAtom<Tag>>
|
|
19
|
-
type AtomOf<Atom extends import("./predicate-atom.js").PredicateAtom> = AtomFormula<Atom>
|
|
20
|
-
type FactOf<Atom extends import("./predicate-atom.js").PredicateAtom> = AtomFormula<Atom>
|
|
21
|
-
|
|
22
|
-
type NonNullFactsOfExpression<Value extends Expression.Any> =
|
|
23
|
-
[ColumnKeyOfExpression<Value>] extends [never]
|
|
24
|
-
? never
|
|
25
|
-
: FactOf<NonNullAtom<ColumnKeyOfExpression<Value>>>
|
|
26
|
-
|
|
27
|
-
type CombineFacts<
|
|
28
|
-
Left extends PredicateFormula,
|
|
29
|
-
Right extends PredicateFormula
|
|
30
|
-
> = [Left] extends [never]
|
|
31
|
-
? Right
|
|
32
|
-
: [Right] extends [never]
|
|
33
|
-
? Left
|
|
34
|
-
: import("./predicate-formula.js").NormalizeBooleanConstants<AllFormula<[Left, Right]>>
|
|
35
|
-
|
|
36
|
-
type FactsOfExpressions<Values extends readonly Expression.Any[]> =
|
|
37
|
-
Values extends readonly [
|
|
38
|
-
infer Head extends Expression.Any,
|
|
39
|
-
...infer Tail extends readonly Expression.Any[]
|
|
40
|
-
]
|
|
41
|
-
? CombineFacts<FormulaOfExpression<Head>, FactsOfExpressions<Tail>>
|
|
42
|
-
: never
|
|
43
|
-
|
|
44
|
-
type FormulaOfEq<
|
|
45
|
-
Left extends Expression.Any,
|
|
46
|
-
Right extends Expression.Any
|
|
47
|
-
> =
|
|
48
|
-
[ColumnKeyOfExpression<Left>] extends [never]
|
|
49
|
-
? [ColumnKeyOfExpression<Right>] extends [never]
|
|
50
|
-
? LiteralValueOfExpression<Left> extends infer LeftLiteral
|
|
51
|
-
? LiteralValueOfExpression<Right> extends infer RightLiteral
|
|
52
|
-
? [LeftLiteral] extends [never]
|
|
53
|
-
? UnknownTag<"eq:unsupported">
|
|
54
|
-
: [RightLiteral] extends [never]
|
|
55
|
-
? UnknownTag<"eq:unsupported">
|
|
56
|
-
: LeftLiteral extends null
|
|
57
|
-
? False
|
|
58
|
-
: RightLiteral extends null
|
|
59
|
-
? False
|
|
60
|
-
: [LeftLiteral] extends [RightLiteral]
|
|
61
|
-
? True
|
|
62
|
-
: False
|
|
63
|
-
: UnknownTag<"eq:unsupported">
|
|
64
|
-
: UnknownTag<"eq:unsupported">
|
|
65
|
-
: LiteralValueOfExpression<Left> extends infer LeftLiteral
|
|
66
|
-
? [LeftLiteral] extends [never]
|
|
67
|
-
? UnknownTag<"eq:unsupported">
|
|
68
|
-
: LeftLiteral extends null
|
|
69
|
-
? False
|
|
70
|
-
: AtomOf<EqLiteralAtom<ColumnKeyOfExpression<Right>, ValueKey<LeftLiteral>>>
|
|
71
|
-
: UnknownTag<"eq:unsupported">
|
|
72
|
-
: [ColumnKeyOfExpression<Right>] extends [never]
|
|
73
|
-
? LiteralValueOfExpression<Right> extends infer RightLiteral
|
|
74
|
-
? [RightLiteral] extends [never]
|
|
75
|
-
? UnknownTag<"eq:unsupported">
|
|
76
|
-
: RightLiteral extends null
|
|
77
|
-
? False
|
|
78
|
-
: AtomOf<EqLiteralAtom<ColumnKeyOfExpression<Left>, ValueKey<RightLiteral>>>
|
|
79
|
-
: UnknownTag<"eq:unsupported">
|
|
80
|
-
: AtomOf<import("./predicate-atom.js").EqColumnAtom<ColumnKeyOfExpression<Left>, ColumnKeyOfExpression<Right>>>
|
|
81
|
-
|
|
82
|
-
type FormulaOfVariadic<
|
|
83
|
-
Kind extends ExpressionAst.VariadicKind,
|
|
84
|
-
Values extends readonly Expression.Any[]
|
|
85
|
-
> = Kind extends "and"
|
|
86
|
-
? import("./predicate-formula.js").NormalizeBooleanConstants<import("./predicate-formula.js").AllFormula<{
|
|
87
|
-
readonly [K in keyof Values]: Values[K] extends Expression.Any ? FormulaOfExpression<Values[K]> : never
|
|
88
|
-
} & readonly PredicateFormula[]>>
|
|
89
|
-
: Kind extends "or"
|
|
90
|
-
? import("./predicate-formula.js").NormalizeBooleanConstants<import("./predicate-formula.js").AnyFormula<{
|
|
91
|
-
readonly [K in keyof Values]: Values[K] extends Expression.Any ? FormulaOfExpression<Values[K]> : never
|
|
92
|
-
} & readonly PredicateFormula[]>>
|
|
93
|
-
: Kind extends "in" | "notIn" | "between"
|
|
94
|
-
? FactsOfExpressions<Values> extends infer Facts extends PredicateFormula
|
|
95
|
-
? [Facts] extends [never]
|
|
96
|
-
? UnknownTag<`variadic:${Kind}`>
|
|
97
|
-
: Facts
|
|
98
|
-
: UnknownTag<`variadic:${Kind}`>
|
|
99
|
-
: UnknownTag<`variadic:${Kind}`>
|
|
100
|
-
|
|
101
|
-
export type FormulaOfExpression<Value extends Expression.Any> =
|
|
102
|
-
AstOf<Value> extends infer Ast extends ExpressionAst.Any
|
|
103
|
-
? Ast extends ExpressionAst.LiteralNode<infer Literal>
|
|
104
|
-
? Literal extends true
|
|
105
|
-
? True
|
|
106
|
-
: Literal extends false
|
|
107
|
-
? False
|
|
108
|
-
: UnknownTag<"literal:non-boolean">
|
|
109
|
-
: Ast extends ExpressionAst.UnaryNode<infer Kind extends ExpressionAst.UnaryKind, infer Inner extends Expression.Any>
|
|
110
|
-
? Kind extends "isNull"
|
|
111
|
-
? [ColumnKeyOfExpression<Inner>] extends [never]
|
|
112
|
-
? UnknownTag<"isNull:unsupported">
|
|
113
|
-
: AtomOf<NullAtom<ColumnKeyOfExpression<Inner>>>
|
|
114
|
-
: Kind extends "isNotNull"
|
|
115
|
-
? [ColumnKeyOfExpression<Inner>] extends [never]
|
|
116
|
-
? UnknownTag<"isNotNull:unsupported">
|
|
117
|
-
: AtomOf<NonNullAtom<ColumnKeyOfExpression<Inner>>>
|
|
118
|
-
: Kind extends "not"
|
|
119
|
-
? import("./predicate-formula.js").Not<FormulaOfExpression<Inner>>
|
|
120
|
-
: UnknownTag<`unary:${Kind}`>
|
|
121
|
-
: Ast extends ExpressionAst.BinaryNode<"eq", infer Left extends Expression.Any, infer Right extends Expression.Any>
|
|
122
|
-
? FormulaOfEq<Left, Right>
|
|
123
|
-
: Ast extends ExpressionAst.BinaryNode<"neq", infer Left extends Expression.Any, infer Right extends Expression.Any>
|
|
124
|
-
? Left extends Expression.Any
|
|
125
|
-
? Right extends Expression.Any
|
|
126
|
-
? [ColumnKeyOfExpression<Left>] extends [never]
|
|
127
|
-
? [ColumnKeyOfExpression<Right>] extends [never]
|
|
128
|
-
? LiteralValueOfExpression<Left> extends infer LeftLiteral
|
|
129
|
-
? LiteralValueOfExpression<Right> extends infer RightLiteral
|
|
130
|
-
? [LeftLiteral] extends [never]
|
|
131
|
-
? UnknownTag<"neq:unsupported">
|
|
132
|
-
: [RightLiteral] extends [never]
|
|
133
|
-
? UnknownTag<"neq:unsupported">
|
|
134
|
-
: LeftLiteral extends null
|
|
135
|
-
? False
|
|
136
|
-
: RightLiteral extends null
|
|
137
|
-
? False
|
|
138
|
-
: [LeftLiteral] extends [RightLiteral]
|
|
139
|
-
? False
|
|
140
|
-
: True
|
|
141
|
-
: UnknownTag<"neq:unsupported">
|
|
142
|
-
: UnknownTag<"neq:unsupported">
|
|
143
|
-
: CombineFacts<NonNullFactsOfExpression<Left>, NonNullFactsOfExpression<Right>>
|
|
144
|
-
: CombineFacts<NonNullFactsOfExpression<Left>, NonNullFactsOfExpression<Right>>
|
|
145
|
-
: UnknownTag<"neq:unsupported">
|
|
146
|
-
: UnknownTag<"neq:unsupported">
|
|
147
|
-
: Ast extends ExpressionAst.BinaryNode<infer Kind extends "lt" | "lte" | "gt" | "gte" | "like" | "ilike" | "isDistinctFrom" | "isNotDistinctFrom" | "contains" | "containedBy" | "overlaps", infer Left extends Expression.Any, infer Right extends Expression.Any>
|
|
148
|
-
? Kind extends "isNotDistinctFrom"
|
|
149
|
-
? Left extends Expression.Any
|
|
150
|
-
? Right extends Expression.Any
|
|
151
|
-
? LiteralValueOfExpression<Left> extends infer LeftLiteral
|
|
152
|
-
? LiteralValueOfExpression<Right> extends infer RightLiteral
|
|
153
|
-
? [LeftLiteral] extends [never]
|
|
154
|
-
? [RightLiteral] extends [never]
|
|
155
|
-
? UnknownTag<"isNotDistinctFrom:unsupported">
|
|
156
|
-
: RightLiteral extends null
|
|
157
|
-
? [ColumnKeyOfExpression<Left>] extends [never]
|
|
158
|
-
? UnknownTag<"isNotDistinctFrom:unsupported">
|
|
159
|
-
: AtomOf<NullAtom<ColumnKeyOfExpression<Left>>>
|
|
160
|
-
: UnknownTag<"isNotDistinctFrom:unsupported">
|
|
161
|
-
: LeftLiteral extends null
|
|
162
|
-
? [ColumnKeyOfExpression<Right>] extends [never]
|
|
163
|
-
? UnknownTag<"isNotDistinctFrom:unsupported">
|
|
164
|
-
: AtomOf<NullAtom<ColumnKeyOfExpression<Right>>>
|
|
165
|
-
: RightLiteral extends null
|
|
166
|
-
? [ColumnKeyOfExpression<Left>] extends [never]
|
|
167
|
-
? UnknownTag<"isNotDistinctFrom:unsupported">
|
|
168
|
-
: AtomOf<NullAtom<ColumnKeyOfExpression<Left>>>
|
|
169
|
-
: [ColumnKeyOfExpression<Left>] extends [never]
|
|
170
|
-
? [ColumnKeyOfExpression<Right>] extends [never]
|
|
171
|
-
? CombineFacts<NonNullFactsOfExpression<Left>, NonNullFactsOfExpression<Right>>
|
|
172
|
-
: AtomOf<EqLiteralAtom<ColumnKeyOfExpression<Right>, ValueKey<LeftLiteral>>>
|
|
173
|
-
: AtomOf<EqLiteralAtom<ColumnKeyOfExpression<Left>, ValueKey<RightLiteral>>>
|
|
174
|
-
: UnknownTag<"isNotDistinctFrom:unsupported">
|
|
175
|
-
: UnknownTag<"isNotDistinctFrom:unsupported">
|
|
176
|
-
: UnknownTag<"isNotDistinctFrom:unsupported">
|
|
177
|
-
: UnknownTag<"isNotDistinctFrom:unsupported">
|
|
178
|
-
: Kind extends "isDistinctFrom"
|
|
179
|
-
? UnknownTag<"isDistinctFrom:unsupported">
|
|
180
|
-
: CombineFacts<NonNullFactsOfExpression<Left>, NonNullFactsOfExpression<Right>>
|
|
181
|
-
: Ast extends ExpressionAst.VariadicNode<"and", infer Values extends readonly Expression.Any[]>
|
|
182
|
-
? import("./predicate-formula.js").NormalizeBooleanConstants<import("./predicate-formula.js").AllFormula<{
|
|
183
|
-
readonly [K in keyof Values]: Values[K] extends Expression.Any ? FormulaOfExpression<Values[K]> : never
|
|
184
|
-
} & readonly PredicateFormula[]>>
|
|
185
|
-
: Ast extends ExpressionAst.VariadicNode<"or", infer Values extends readonly Expression.Any[]>
|
|
186
|
-
? import("./predicate-formula.js").NormalizeBooleanConstants<import("./predicate-formula.js").AnyFormula<{
|
|
187
|
-
readonly [K in keyof Values]: Values[K] extends Expression.Any ? FormulaOfExpression<Values[K]> : never
|
|
188
|
-
} & readonly PredicateFormula[]>>
|
|
189
|
-
: Ast extends ExpressionAst.VariadicNode<infer Kind extends "in" | "notIn" | "between", infer Values extends readonly Expression.Any[]>
|
|
190
|
-
? CombineFacts<NonNullFactsOfExpression<Values[number]>, UnknownTag<`variadic:${Kind}`>>
|
|
191
|
-
: Ast extends ExpressionAst.BinaryNode<infer Kind extends ExpressionAst.BinaryKind, infer Left extends Expression.Any, infer Right extends Expression.Any>
|
|
192
|
-
? Kind extends "eq"
|
|
193
|
-
? FormulaOfEq<Left, Right>
|
|
194
|
-
: CombineFacts<NonNullFactsOfExpression<Left>, NonNullFactsOfExpression<Right>>
|
|
195
|
-
: UnknownTag<`expr:${Ast["kind"]}`>
|
|
196
|
-
: UnknownTag<"missing-ast">
|
|
197
|
-
|
|
198
|
-
export type FormulaOfPredicate<Value> =
|
|
199
|
-
Value extends true ? True :
|
|
200
|
-
Value extends false ? False :
|
|
201
|
-
Value extends Expression.Any ? FormulaOfExpression<Value> :
|
|
202
|
-
UnknownTag<"predicate:unsupported">
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as Expression from "../../internal/expression.js"
|
|
2
|
-
import { makeDialectQuery } from "../../internal/query-factory.js"
|
|
3
|
-
import { mysqlDatatypes } from "../datatypes/index.js"
|
|
4
|
-
|
|
5
|
-
export const mysqlQuery = makeDialectQuery({
|
|
6
|
-
dialect: "mysql",
|
|
7
|
-
textDb: { dialect: "mysql", kind: "text" } as Expression.DbType.MySqlText,
|
|
8
|
-
numericDb: { dialect: "mysql", kind: "double" } as Expression.DbType.MySqlDouble,
|
|
9
|
-
boolDb: { dialect: "mysql", kind: "boolean" } as Expression.DbType.MySqlBool,
|
|
10
|
-
timestampDb: { dialect: "mysql", kind: "timestamp" } as Expression.DbType.MySqlTimestamp,
|
|
11
|
-
nullDb: { dialect: "mysql", kind: "null" } as Expression.DbType.Base<"mysql", "null">,
|
|
12
|
-
type: mysqlDatatypes
|
|
13
|
-
})
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as Expression from "../../internal/expression.js"
|
|
2
|
-
import { makeDialectQuery } from "../../internal/query-factory.js"
|
|
3
|
-
import { postgresDatatypes } from "../datatypes/index.js"
|
|
4
|
-
|
|
5
|
-
export const postgresQuery = makeDialectQuery({
|
|
6
|
-
dialect: "postgres",
|
|
7
|
-
textDb: { dialect: "postgres", kind: "text" } as Expression.DbType.PgText,
|
|
8
|
-
numericDb: { dialect: "postgres", kind: "float8" } as Expression.DbType.PgFloat8,
|
|
9
|
-
boolDb: { dialect: "postgres", kind: "bool" } as Expression.DbType.PgBool,
|
|
10
|
-
timestampDb: { dialect: "postgres", kind: "timestamp" } as Expression.DbType.PgTimestamp,
|
|
11
|
-
nullDb: { dialect: "postgres", kind: "null" } as Expression.DbType.Base<"postgres", "null">,
|
|
12
|
-
type: postgresDatatypes
|
|
13
|
-
})
|
|
File without changes
|