effect-qb 0.14.0 → 0.16.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/dist/mysql.js +61555 -4252
- package/dist/postgres/metadata.js +728 -104
- package/dist/postgres.js +6906 -4023
- package/package.json +15 -2
- 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 +43 -47
- package/src/internal/column.ts +43 -305
- package/src/internal/datatypes/define.d.ts +17 -0
- package/src/internal/datatypes/define.ts +18 -4
- 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/dialect.ts +12 -1
- 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 +146 -34
- package/src/internal/expression-ast.ts +15 -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 +4 -4
- 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 +183 -0
- package/src/internal/predicate/atom.d.ts +28 -0
- package/src/internal/{predicate-atom.ts → predicate/atom.ts} +7 -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} +163 -20
- package/src/internal/predicate/formula.d.ts +35 -0
- package/src/internal/{predicate-formula.ts → predicate/formula.ts} +1 -1
- package/src/internal/predicate/key.d.ts +11 -0
- package/src/internal/predicate/key.ts +73 -0
- 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 → predicate/normalize.ts} +130 -49
- package/src/internal/predicate/runtime.d.ts +31 -0
- package/src/internal/{predicate-runtime.ts → predicate/runtime.ts} +127 -17
- 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 +683 -369
- package/src/internal/renderer.ts +11 -21
- package/src/internal/row-set.d.ts +53 -0
- package/src/internal/{plan.ts → row-set.ts} +11 -9
- package/src/internal/runtime/driver-value-mapping.ts +186 -0
- package/src/internal/{runtime-normalize.ts → runtime/normalize.ts} +9 -31
- package/src/internal/{runtime-schema.ts → runtime/schema.ts} +13 -38
- 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 +202 -0
- package/src/internal/schema-derivation.d.ts +105 -0
- package/src/internal/schema-expression.d.ts +18 -0
- package/src/internal/schema-expression.ts +38 -7
- package/src/internal/table-options.d.ts +94 -0
- package/src/internal/table-options.ts +8 -2
- package/src/internal/table.d.ts +173 -0
- package/src/internal/table.ts +32 -14
- package/src/mysql/column.ts +95 -18
- package/src/mysql/datatypes/index.ts +47 -7
- 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 +88 -11
- package/src/mysql/function/aggregate.ts +1 -5
- package/src/mysql/function/core.ts +1 -4
- package/src/mysql/function/index.ts +0 -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} +12 -6
- package/src/{internal/mysql-query.ts → mysql/internal/dsl.ts} +1299 -2143
- package/src/mysql/internal/renderer.ts +46 -0
- package/src/mysql/internal/sql-expression-renderer.ts +1501 -0
- package/src/mysql/json.ts +2 -0
- package/src/mysql/query.ts +111 -91
- package/src/mysql/renderer.ts +8 -3
- package/src/mysql/table.ts +1 -1
- package/src/mysql.ts +6 -4
- package/src/postgres/cast.ts +30 -16
- package/src/postgres/column.ts +179 -46
- package/src/postgres/datatypes/index.d.ts +515 -0
- package/src/postgres/datatypes/index.ts +22 -13
- 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 +54 -7
- package/src/postgres/function/aggregate.ts +1 -5
- package/src/postgres/function/core.ts +12 -6
- package/src/postgres/function/index.ts +0 -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} +12 -6
- package/src/{internal/postgres-query.ts → postgres/internal/dsl.ts} +1356 -2133
- package/src/{internal/postgres-renderer.ts → postgres/internal/renderer.ts} +17 -8
- package/src/postgres/internal/schema-ddl.ts +108 -0
- package/src/{internal/postgres-schema-model.ts → postgres/internal/schema-model.ts} +12 -6
- package/src/{internal → postgres/internal}/sql-expression-renderer.ts +79 -25
- package/src/postgres/{function/json.ts → json.ts} +77 -85
- package/src/postgres/metadata.ts +2 -2
- package/src/postgres/query.ts +113 -89
- package/src/postgres/renderer.ts +8 -13
- package/src/postgres/schema-expression.ts +2 -1
- package/src/postgres/schema-management.ts +1 -1
- package/src/postgres/table.ts +12 -4
- package/src/postgres/type.ts +33 -2
- package/src/postgres.ts +6 -4
- package/src/internal/expression.ts +0 -327
- package/src/internal/mysql-renderer.ts +0 -37
- package/src/internal/predicate-analysis.ts +0 -81
- package/src/internal/predicate-key.ts +0 -28
- package/src/internal/schema-ddl.ts +0 -55
- package/src/mysql/function/json.ts +0 -4
- package/src/mysql/private/query.ts +0 -1
- package/src/postgres/private/query.ts +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export {
|
|
2
2
|
TypeId,
|
|
3
3
|
fromAst,
|
|
4
|
+
fromSql,
|
|
4
5
|
isSchemaExpression,
|
|
5
6
|
normalize,
|
|
6
7
|
parseExpression,
|
|
@@ -13,4 +14,4 @@ export {
|
|
|
13
14
|
export {
|
|
14
15
|
normalizeDdlExpressionSql,
|
|
15
16
|
renderDdlExpressionSql
|
|
16
|
-
} from "
|
|
17
|
+
} from "./internal/schema-ddl.js"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Schema from "effect/Schema"
|
|
2
2
|
import { pipeArguments, type Pipeable } from "effect/Pipeable"
|
|
3
3
|
|
|
4
|
-
import type * as Expression from "../internal/
|
|
4
|
+
import type * as Expression from "../internal/scalar.js"
|
|
5
5
|
import { makeColumnDefinition, type ColumnDefinition } from "../internal/column-state.js"
|
|
6
6
|
|
|
7
7
|
export const EnumTypeId: unique symbol = Symbol.for("effect-qb/SchemaManagement/Enum")
|
package/src/postgres/table.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as Schema from "effect/Schema"
|
|
2
2
|
|
|
3
|
-
import type * as Expression from "../internal/
|
|
3
|
+
import type * as Expression from "../internal/scalar.js"
|
|
4
4
|
import { ColumnTypeId, type AnyColumnDefinition } from "../internal/column-state.js"
|
|
5
5
|
import * as BaseTable from "../internal/table.js"
|
|
6
6
|
|
|
@@ -144,11 +144,15 @@ type RichIndexKeyInput =
|
|
|
144
144
|
readonly column: string
|
|
145
145
|
readonly order?: "asc" | "desc"
|
|
146
146
|
readonly nulls?: "first" | "last"
|
|
147
|
+
readonly operatorClass?: string
|
|
148
|
+
readonly collation?: string
|
|
147
149
|
}
|
|
148
150
|
| {
|
|
149
151
|
readonly expression: DdlExpressionLike
|
|
150
152
|
readonly order?: "asc" | "desc"
|
|
151
153
|
readonly nulls?: "first" | "last"
|
|
154
|
+
readonly operatorClass?: string
|
|
155
|
+
readonly collation?: string
|
|
152
156
|
}
|
|
153
157
|
|
|
154
158
|
type RichIndexInput<Columns extends string | readonly string[] = string | readonly string[]> = {
|
|
@@ -208,17 +212,21 @@ const normalizeIndexKeys = (
|
|
|
208
212
|
keys: readonly [RichIndexKeyInput, ...RichIndexKeyInput[]]
|
|
209
213
|
): readonly [BaseTable.IndexKeySpec, ...BaseTable.IndexKeySpec[]] =>
|
|
210
214
|
keys.map((key) => "expression" in key
|
|
211
|
-
|
|
215
|
+
? {
|
|
212
216
|
kind: "expression",
|
|
213
217
|
expression: key.expression,
|
|
214
218
|
order: key.order,
|
|
215
|
-
nulls: key.nulls
|
|
219
|
+
nulls: key.nulls,
|
|
220
|
+
operatorClass: key.operatorClass,
|
|
221
|
+
collation: key.collation
|
|
216
222
|
}
|
|
217
223
|
: {
|
|
218
224
|
kind: "column",
|
|
219
225
|
column: key.column,
|
|
220
226
|
order: key.order,
|
|
221
|
-
nulls: key.nulls
|
|
227
|
+
nulls: key.nulls,
|
|
228
|
+
operatorClass: key.operatorClass,
|
|
229
|
+
collation: key.collation
|
|
222
230
|
}) as unknown as readonly [BaseTable.IndexKeySpec, ...BaseTable.IndexKeySpec[]]
|
|
223
231
|
|
|
224
232
|
export const primaryKey: {
|
package/src/postgres/type.ts
CHANGED
|
@@ -1,4 +1,35 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type * as Expression from "../internal/scalar.js"
|
|
2
|
+
import { postgresDatatypes } from "./datatypes/index.js"
|
|
3
|
+
import { type as postgresType } from "./internal/dsl.js"
|
|
4
|
+
|
|
5
|
+
type PostgresTypeNamespace = typeof postgresDatatypes & {
|
|
6
|
+
readonly array: <Element extends Expression.DbType.Any>(
|
|
7
|
+
element: Element
|
|
8
|
+
) => Expression.DbType.Array<"postgres", Element, `${Element["kind"]}[]`>
|
|
9
|
+
readonly range: <Kind extends string, Subtype extends Expression.DbType.Any>(
|
|
10
|
+
kind: Kind,
|
|
11
|
+
subtype: Subtype
|
|
12
|
+
) => Expression.DbType.Range<"postgres", Subtype, Kind>
|
|
13
|
+
readonly multirange: <Kind extends string, Subtype extends Expression.DbType.Any>(
|
|
14
|
+
kind: Kind,
|
|
15
|
+
subtype: Subtype
|
|
16
|
+
) => Expression.DbType.Multirange<"postgres", Subtype, Kind>
|
|
17
|
+
readonly record: <Kind extends string, Fields extends Record<string, Expression.DbType.Any>>(
|
|
18
|
+
kind: Kind,
|
|
19
|
+
fields: Fields
|
|
20
|
+
) => Expression.DbType.Composite<"postgres", Fields, Kind>
|
|
21
|
+
readonly domain: <Kind extends string, Base extends Expression.DbType.Any>(
|
|
22
|
+
kind: Kind,
|
|
23
|
+
base: Base
|
|
24
|
+
) => Expression.DbType.Domain<"postgres", Base, Kind>
|
|
25
|
+
readonly enum: <Kind extends string>(kind: Kind) => Expression.DbType.Enum<"postgres", Kind>
|
|
26
|
+
readonly set: <Kind extends string>(kind: Kind) => Expression.DbType.Set<"postgres", Kind>
|
|
27
|
+
readonly custom: <Kind extends string>(kind: Kind) => Expression.DbType.Base<"postgres", Kind>
|
|
28
|
+
readonly driverValueMapping: <Db extends Expression.DbType.Any>(
|
|
29
|
+
dbType: Db,
|
|
30
|
+
mapping: Expression.DriverValueMapping
|
|
31
|
+
) => Db
|
|
32
|
+
}
|
|
2
33
|
|
|
3
34
|
/** Postgres database-type constructors for casts and typed column references. */
|
|
4
|
-
export const type =
|
|
35
|
+
export const type: PostgresTypeNamespace = postgresType
|
package/src/postgres.ts
CHANGED
|
@@ -4,16 +4,18 @@ export * as Column from "./postgres/column.js"
|
|
|
4
4
|
export * as Datatypes from "./postgres/datatypes/index.js"
|
|
5
5
|
/** Postgres SQLSTATE catalog and error normalization helpers. */
|
|
6
6
|
export * as Errors from "./postgres/errors/index.js"
|
|
7
|
-
/** Shared scalar SQL
|
|
8
|
-
export * as
|
|
7
|
+
/** Shared scalar SQL interfaces and DB-type descriptors. */
|
|
8
|
+
export * as Scalar from "./internal/scalar.js"
|
|
9
9
|
/** Postgres cast helpers. */
|
|
10
10
|
export { cast as Cast } from "./postgres/cast.js"
|
|
11
11
|
/** Postgres-specialized SQL function expressions. */
|
|
12
12
|
export * as Function from "./postgres/function/index.js"
|
|
13
|
+
/** Postgres-specialized JSON expression helpers. */
|
|
14
|
+
export * as Json from "./postgres/json.js"
|
|
13
15
|
/** Postgres-specialized typed query execution contracts. */
|
|
14
16
|
export * as Executor from "./postgres/executor.js"
|
|
15
|
-
/** Shared logical
|
|
16
|
-
export * as
|
|
17
|
+
/** Shared logical row-set interfaces. */
|
|
18
|
+
export * as RowSet from "./internal/row-set.js"
|
|
17
19
|
/** Postgres-specialized query-construction DSL. */
|
|
18
20
|
export * as Query from "./postgres/query.js"
|
|
19
21
|
/** Postgres database-type constructors for casts and typed references. */
|
|
@@ -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: SchemaName extends "jsonb" ? "jsonb" : "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,37 +0,0 @@
|
|
|
1
|
-
import * as Query from "./query.js"
|
|
2
|
-
import { type RenderState } from "./dialect.js"
|
|
3
|
-
import { mysqlDialect } from "./mysql-dialect.js"
|
|
4
|
-
import { type Projection } from "./projections.js"
|
|
5
|
-
import { renderQueryAst } from "./sql-expression-renderer.js"
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal rendered-query payload produced by the built-in MySQL renderer.
|
|
9
|
-
*/
|
|
10
|
-
export interface MysqlRenderResult {
|
|
11
|
-
readonly sql: string
|
|
12
|
-
readonly params: readonly unknown[]
|
|
13
|
-
readonly projections: readonly Projection[]
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Renders the current query AST into MySQL-shaped SQL plus bind parameters.
|
|
18
|
-
*/
|
|
19
|
-
export const renderMysqlPlan = <PlanValue extends Query.QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
20
|
-
plan: Query.DialectCompatiblePlan<PlanValue, "mysql">
|
|
21
|
-
): MysqlRenderResult => {
|
|
22
|
-
const state: RenderState = {
|
|
23
|
-
params: [],
|
|
24
|
-
ctes: [],
|
|
25
|
-
cteNames: new Set<string>()
|
|
26
|
-
}
|
|
27
|
-
const rendered = renderQueryAst(
|
|
28
|
-
Query.getAst(plan as Query.QueryPlan<any, any, any, any, any, any, any, any, any, any>) as any,
|
|
29
|
-
state,
|
|
30
|
-
mysqlDialect
|
|
31
|
-
)
|
|
32
|
-
return {
|
|
33
|
-
sql: rendered.sql,
|
|
34
|
-
params: state.params,
|
|
35
|
-
projections: rendered.projections
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import type { AnalyzeFormula } from "./predicate-context.js"
|
|
2
|
-
import type { FormulaOfPredicate } from "./predicate-normalize.js"
|
|
3
|
-
import type { And, Not, PredicateFormula, TrueFormula } from "./predicate-formula.js"
|
|
4
|
-
|
|
5
|
-
type ContextOf<Formula extends PredicateFormula> = AnalyzeFormula<Formula>
|
|
6
|
-
|
|
7
|
-
export type GuaranteedNonNullKeys<
|
|
8
|
-
Assumptions extends PredicateFormula
|
|
9
|
-
> = ContextOf<Assumptions>["nonNullKeys"]
|
|
10
|
-
|
|
11
|
-
export type GuaranteedNullKeys<
|
|
12
|
-
Assumptions extends PredicateFormula
|
|
13
|
-
> = ContextOf<Assumptions>["nullKeys"]
|
|
14
|
-
|
|
15
|
-
export type GuaranteedSourceNames<
|
|
16
|
-
Assumptions extends PredicateFormula
|
|
17
|
-
> = ContextOf<Assumptions>["sourceNames"]
|
|
18
|
-
|
|
19
|
-
export type GuaranteedEqLiteral<
|
|
20
|
-
Assumptions extends PredicateFormula,
|
|
21
|
-
Key extends string
|
|
22
|
-
> = Key extends keyof ContextOf<Assumptions>["eqLiterals"]
|
|
23
|
-
? ContextOf<Assumptions>["eqLiterals"][Key]
|
|
24
|
-
: never
|
|
25
|
-
|
|
26
|
-
type IsContradiction<Formula extends PredicateFormula> =
|
|
27
|
-
ContextOf<Formula>["contradiction"] extends true ? true : false
|
|
28
|
-
|
|
29
|
-
type ContradictoryAssumption<
|
|
30
|
-
Assumptions extends PredicateFormula,
|
|
31
|
-
Formula extends PredicateFormula
|
|
32
|
-
> = IsContradiction<And<Assumptions, Formula>>
|
|
33
|
-
|
|
34
|
-
type ContradictionFromNegation<
|
|
35
|
-
Assumptions extends PredicateFormula,
|
|
36
|
-
Formula extends PredicateFormula
|
|
37
|
-
> = IsContradiction<And<Assumptions, Not<Formula>>>
|
|
38
|
-
|
|
39
|
-
export type ContradictsFormula<
|
|
40
|
-
Assumptions extends PredicateFormula,
|
|
41
|
-
Formula extends PredicateFormula
|
|
42
|
-
> = ContradictoryAssumption<Assumptions, Formula>
|
|
43
|
-
|
|
44
|
-
export type ImpliesFormula<
|
|
45
|
-
Assumptions extends PredicateFormula,
|
|
46
|
-
Formula extends PredicateFormula
|
|
47
|
-
> = ContradictionFromNegation<Assumptions, Formula>
|
|
48
|
-
|
|
49
|
-
export type AssumeFormulaTrue<
|
|
50
|
-
Assumptions extends PredicateFormula,
|
|
51
|
-
Formula extends PredicateFormula
|
|
52
|
-
> = Assumptions extends TrueFormula
|
|
53
|
-
? Formula
|
|
54
|
-
: And<Assumptions, Formula>
|
|
55
|
-
|
|
56
|
-
export type AssumeFormulaFalse<
|
|
57
|
-
Assumptions extends PredicateFormula,
|
|
58
|
-
Formula extends PredicateFormula
|
|
59
|
-
> = Assumptions extends TrueFormula
|
|
60
|
-
? Not<Formula>
|
|
61
|
-
: And<Assumptions, Not<Formula>>
|
|
62
|
-
|
|
63
|
-
export type AssumeTrue<
|
|
64
|
-
Assumptions extends PredicateFormula,
|
|
65
|
-
Predicate
|
|
66
|
-
> = AssumeFormulaTrue<Assumptions, FormulaOfPredicate<Predicate>>
|
|
67
|
-
|
|
68
|
-
export type AssumeFalse<
|
|
69
|
-
Assumptions extends PredicateFormula,
|
|
70
|
-
Predicate
|
|
71
|
-
> = AssumeFormulaFalse<Assumptions, FormulaOfPredicate<Predicate>>
|
|
72
|
-
|
|
73
|
-
export type Contradicts<
|
|
74
|
-
Assumptions extends PredicateFormula,
|
|
75
|
-
Predicate
|
|
76
|
-
> = ContradictoryAssumption<Assumptions, FormulaOfPredicate<Predicate>>
|
|
77
|
-
|
|
78
|
-
export type Implies<
|
|
79
|
-
Assumptions extends PredicateFormula,
|
|
80
|
-
Predicate
|
|
81
|
-
> = ContradictionFromNegation<Assumptions, FormulaOfPredicate<Predicate>>
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type * as Expression from "./expression.js"
|
|
2
|
-
import type * as ExpressionAst from "./expression-ast.js"
|
|
3
|
-
|
|
4
|
-
export type ColumnKey<
|
|
5
|
-
TableName extends string,
|
|
6
|
-
ColumnName extends string
|
|
7
|
-
> = `${TableName}.${ColumnName}`
|
|
8
|
-
|
|
9
|
-
export type ColumnKeyOfAst<Ast extends ExpressionAst.Any> =
|
|
10
|
-
Ast extends ExpressionAst.ColumnNode<infer TableName extends string, infer ColumnName extends string>
|
|
11
|
-
? ColumnKey<TableName, ColumnName>
|
|
12
|
-
: never
|
|
13
|
-
|
|
14
|
-
type AstOf<Value extends Expression.Any> = Value extends {
|
|
15
|
-
readonly [ExpressionAst.TypeId]: infer Ast extends ExpressionAst.Any
|
|
16
|
-
} ? Ast : never
|
|
17
|
-
|
|
18
|
-
export type ColumnKeyOfExpression<Value extends Expression.Any> = ColumnKeyOfAst<AstOf<Value>>
|
|
19
|
-
|
|
20
|
-
export type LiteralKey<Value> =
|
|
21
|
-
Value extends string ? `string:${Value}` :
|
|
22
|
-
Value extends number ? `number:${Value}` :
|
|
23
|
-
Value extends boolean ? `boolean:${Value}` :
|
|
24
|
-
Value extends null ? "null" :
|
|
25
|
-
Value extends Date ? `date:${string}` :
|
|
26
|
-
"unknown"
|
|
27
|
-
|
|
28
|
-
export type ValueKey<Value> = LiteralKey<Value>
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type * as Expression from "./expression.js"
|
|
2
|
-
import type { RenderState, SqlDialect } from "./dialect.js"
|
|
3
|
-
import { postgresDialect } from "./postgres-dialect.js"
|
|
4
|
-
import * as SchemaExpression from "./schema-expression.js"
|
|
5
|
-
import { renderExpression } from "./sql-expression-renderer.js"
|
|
6
|
-
import type { DdlExpressionLike } from "./table-options.js"
|
|
7
|
-
import { parse, toSql } from "pgsql-ast-parser"
|
|
8
|
-
|
|
9
|
-
export const renderDdlExpression = (
|
|
10
|
-
expression: DdlExpressionLike,
|
|
11
|
-
state: RenderState,
|
|
12
|
-
dialect: SqlDialect
|
|
13
|
-
): string =>
|
|
14
|
-
SchemaExpression.isSchemaExpression(expression)
|
|
15
|
-
? SchemaExpression.render(expression)
|
|
16
|
-
: renderExpression(expression as Expression.Any, state, dialect)
|
|
17
|
-
|
|
18
|
-
const escapeString = (value: string): string => `'${value.replaceAll("'", "''")}'`
|
|
19
|
-
|
|
20
|
-
const inlineLiteralDialect: SqlDialect<"postgres"> = {
|
|
21
|
-
...postgresDialect,
|
|
22
|
-
renderLiteral(value) {
|
|
23
|
-
if (value === null) {
|
|
24
|
-
return "null"
|
|
25
|
-
}
|
|
26
|
-
if (typeof value === "boolean") {
|
|
27
|
-
return value ? "true" : "false"
|
|
28
|
-
}
|
|
29
|
-
if (typeof value === "number" || typeof value === "bigint") {
|
|
30
|
-
return String(value)
|
|
31
|
-
}
|
|
32
|
-
if (value instanceof Date) {
|
|
33
|
-
return escapeString(value.toISOString())
|
|
34
|
-
}
|
|
35
|
-
return escapeString(String(value))
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const renderDdlExpressionSql = (expression: DdlExpressionLike): string =>
|
|
40
|
-
SchemaExpression.isSchemaExpression(expression)
|
|
41
|
-
? SchemaExpression.render(expression)
|
|
42
|
-
: renderExpression(expression as Expression.Any, {
|
|
43
|
-
params: [],
|
|
44
|
-
ctes: [],
|
|
45
|
-
cteNames: new Set()
|
|
46
|
-
}, inlineLiteralDialect)
|
|
47
|
-
|
|
48
|
-
export const normalizeDdlExpressionSql = (expression: DdlExpressionLike): string => {
|
|
49
|
-
const rendered = renderDdlExpressionSql(expression)
|
|
50
|
-
try {
|
|
51
|
-
return toSql.expr(parse(rendered, "expr"))
|
|
52
|
-
} catch {
|
|
53
|
-
return rendered.trim()
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { mysqlQuery } from "../../internal/mysql-query.js"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { postgresQuery } from "../../internal/postgres-query.js"
|