effect-qb 0.14.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/dist/mysql.js +61270 -4259
- package/dist/postgres/metadata.js +176 -82
- package/dist/postgres.js +5903 -3316
- package/package.json +14 -1
- 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 +36 -47
- package/src/internal/column.ts +21 -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/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 +132 -31
- 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 → predicate/analysis.ts} +3 -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} +8 -5
- 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 → 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 → predicate/normalize.ts} +19 -19
- package/src/internal/predicate/runtime.d.ts +31 -0
- package/src/internal/{predicate-runtime.ts → predicate/runtime.ts} +9 -6
- 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 +389 -313
- package/src/internal/renderer.ts +7 -21
- package/src/internal/row-set.d.ts +53 -0
- package/src/internal/{plan.ts → row-set.ts} +11 -9
- 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 +191 -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 +94 -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 +69 -7
- 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} +1 -1
- package/src/{internal/mysql-query.ts → mysql/internal/dsl.ts} +1024 -2082
- 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 -91
- 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 +11 -12
- package/src/postgres/column.ts +178 -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 +37 -5
- 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} +1 -1
- package/src/{internal/postgres-query.ts → postgres/internal/dsl.ts} +1085 -2089
- package/src/{internal/postgres-renderer.ts → postgres/internal/renderer.ts} +6 -6
- 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 +19 -17
- 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 +3 -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 +29 -2
- package/src/postgres.ts +6 -4
- package/src/internal/expression.ts +0 -327
- 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
- /package/src/internal/{predicate-atom.ts → predicate/atom.ts} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type * as Expression from "
|
|
2
|
-
import type * as ExpressionAst from "
|
|
3
|
-
import type { ColumnKeyOfExpression, ValueKey } from "./
|
|
4
|
-
import type { AllFormula, AnyFormula, AtomFormula, FalseFormula, NotFormula, PredicateFormula, TrueFormula } from "./
|
|
5
|
-
import type { EqColumnAtom, EqLiteralAtom, NeqLiteralAtom, NonNullAtom, NullAtom, UnknownAtom } from "./
|
|
1
|
+
import type * as Expression from "../scalar.js"
|
|
2
|
+
import type * as ExpressionAst from "../expression-ast.js"
|
|
3
|
+
import type { ColumnKeyOfExpression, ValueKey } from "./key.js"
|
|
4
|
+
import type { AllFormula, AnyFormula, AtomFormula, FalseFormula, NotFormula, PredicateFormula, TrueFormula } from "./formula.js"
|
|
5
|
+
import type { EqColumnAtom, EqLiteralAtom, NeqLiteralAtom, NonNullAtom, NullAtom, UnknownAtom } from "./atom.js"
|
|
6
6
|
|
|
7
7
|
type AstOf<Value extends Expression.Any> = Value extends {
|
|
8
8
|
readonly [ExpressionAst.TypeId]: infer Ast extends ExpressionAst.Any
|
|
@@ -16,8 +16,8 @@ type True = TrueFormula
|
|
|
16
16
|
type False = FalseFormula
|
|
17
17
|
|
|
18
18
|
type UnknownTag<Tag extends string> = AtomFormula<UnknownAtom<Tag>>
|
|
19
|
-
type AtomOf<Atom extends import("./
|
|
20
|
-
type FactOf<Atom extends import("./
|
|
19
|
+
type AtomOf<Atom extends import("./atom.js").PredicateAtom> = AtomFormula<Atom>
|
|
20
|
+
type FactOf<Atom extends import("./atom.js").PredicateAtom> = AtomFormula<Atom>
|
|
21
21
|
|
|
22
22
|
type NonNullFactsOfExpression<Value extends Expression.Any> =
|
|
23
23
|
[ColumnKeyOfExpression<Value>] extends [never]
|
|
@@ -31,7 +31,7 @@ type CombineFacts<
|
|
|
31
31
|
? Right
|
|
32
32
|
: [Right] extends [never]
|
|
33
33
|
? Left
|
|
34
|
-
: import("./
|
|
34
|
+
: import("./formula.js").NormalizeBooleanConstants<AllFormula<[Left, Right]>>
|
|
35
35
|
|
|
36
36
|
type FactsOfExpressions<Values extends readonly Expression.Any[]> =
|
|
37
37
|
Values extends readonly [
|
|
@@ -77,7 +77,7 @@ type FormulaOfEq<
|
|
|
77
77
|
? False
|
|
78
78
|
: AtomOf<EqLiteralAtom<ColumnKeyOfExpression<Left>, ValueKey<RightLiteral>>>
|
|
79
79
|
: UnknownTag<"eq:unsupported">
|
|
80
|
-
: AtomOf<import("./
|
|
80
|
+
: AtomOf<import("./atom.js").EqColumnAtom<ColumnKeyOfExpression<Left>, ColumnKeyOfExpression<Right>>>
|
|
81
81
|
|
|
82
82
|
type FormulaOfNeq<
|
|
83
83
|
Left extends Expression.Any,
|
|
@@ -149,11 +149,11 @@ type FormulaOfIsNotDistinctFrom<
|
|
|
149
149
|
|
|
150
150
|
type OrFormulas<
|
|
151
151
|
Items extends readonly PredicateFormula[]
|
|
152
|
-
> = import("./
|
|
152
|
+
> = import("./formula.js").NormalizeBooleanConstants<AnyFormula<Items>>
|
|
153
153
|
|
|
154
154
|
type AndFormulas<
|
|
155
155
|
Items extends readonly PredicateFormula[]
|
|
156
|
-
> = import("./
|
|
156
|
+
> = import("./formula.js").NormalizeBooleanConstants<AllFormula<Items>>
|
|
157
157
|
|
|
158
158
|
type FormulaTupleOf<
|
|
159
159
|
Values extends readonly Expression.Any[]
|
|
@@ -163,11 +163,11 @@ type FormulaTupleOf<
|
|
|
163
163
|
|
|
164
164
|
type AllFormulaOfValues<
|
|
165
165
|
Values extends readonly Expression.Any[]
|
|
166
|
-
> = import("./
|
|
166
|
+
> = import("./formula.js").NormalizeBooleanConstants<AllFormula<FormulaTupleOf<Values>>>
|
|
167
167
|
|
|
168
168
|
type AnyFormulaOfValues<
|
|
169
169
|
Values extends readonly Expression.Any[]
|
|
170
|
-
> = import("./
|
|
170
|
+
> = import("./formula.js").NormalizeBooleanConstants<AnyFormula<FormulaTupleOf<Values>>>
|
|
171
171
|
|
|
172
172
|
type FormulaOfInValues<
|
|
173
173
|
Left extends Expression.Any,
|
|
@@ -202,10 +202,10 @@ type FormulaOfVariadic<
|
|
|
202
202
|
? Values extends readonly [infer Left extends Expression.Any, ...infer Tail extends readonly Expression.Any[]]
|
|
203
203
|
? OrFormulas<FormulaOfInValues<Left, Tail>>
|
|
204
204
|
: False
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
205
|
+
: Kind extends "notIn"
|
|
206
|
+
? Values extends readonly [infer Left extends Expression.Any, ...infer Tail extends readonly Expression.Any[]]
|
|
207
|
+
? CombineFacts<NonNullFactsOfExpression<Left>, AndFormulas<FormulaOfNotInValues<Left, Tail>>>
|
|
208
|
+
: True
|
|
209
209
|
: Kind extends "between"
|
|
210
210
|
? FactsOfExpressions<Values> extends infer Facts extends PredicateFormula
|
|
211
211
|
? [Facts] extends [never]
|
|
@@ -226,7 +226,7 @@ type FormulaOfUnary<
|
|
|
226
226
|
? UnknownTag<"isNotNull:unsupported">
|
|
227
227
|
: AtomOf<NonNullAtom<ColumnKeyOfExpression<Inner>>>
|
|
228
228
|
: Kind extends "not"
|
|
229
|
-
? import("./
|
|
229
|
+
? import("./formula.js").Not<FormulaOfExpression<Inner>>
|
|
230
230
|
: UnknownTag<`unary:${Kind}`>
|
|
231
231
|
|
|
232
232
|
type FormulaOfBinary<
|
|
@@ -242,7 +242,7 @@ type FormulaOfBinary<
|
|
|
242
242
|
: Kind extends "isNotDistinctFrom"
|
|
243
243
|
? FormulaOfIsNotDistinctFrom<Left, Right>
|
|
244
244
|
: Kind extends "isDistinctFrom"
|
|
245
|
-
? import("./
|
|
245
|
+
? import("./formula.js").Not<FormulaOfIsNotDistinctFrom<Left, Right>>
|
|
246
246
|
: CombineFacts<NonNullFactsOfExpression<Left>, NonNullFactsOfExpression<Right>>
|
|
247
247
|
|
|
248
248
|
type FormulaOfAst<
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as Expression from "../scalar.js";
|
|
2
|
+
import type { PredicateAtom } from "./atom.js";
|
|
3
|
+
import type { AtomFormula, FalseFormula, PredicateFormula, TrueFormula } from "./formula.js";
|
|
4
|
+
export interface RuntimeContext {
|
|
5
|
+
readonly nonNullKeys: ReadonlySet<string>;
|
|
6
|
+
readonly nullKeys: ReadonlySet<string>;
|
|
7
|
+
readonly eqLiterals: ReadonlyMap<string, string>;
|
|
8
|
+
readonly neqLiterals: ReadonlyMap<string, ReadonlySet<string>>;
|
|
9
|
+
readonly sourceNames: ReadonlySet<string>;
|
|
10
|
+
readonly contradiction: boolean;
|
|
11
|
+
readonly unknown: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const trueFormula: () => TrueFormula;
|
|
14
|
+
export declare const falseFormula: () => FalseFormula;
|
|
15
|
+
export declare const atomFormula: <Atom extends PredicateAtom>(atom: Atom) => AtomFormula<Atom>;
|
|
16
|
+
export declare const allFormula: (items: readonly PredicateFormula[]) => PredicateFormula;
|
|
17
|
+
export declare const anyFormula: (items: readonly PredicateFormula[]) => PredicateFormula;
|
|
18
|
+
export declare const notFormula: (item: PredicateFormula) => PredicateFormula;
|
|
19
|
+
export declare const andFormula: (left: PredicateFormula, right: PredicateFormula) => PredicateFormula;
|
|
20
|
+
export declare const orFormula: (left: PredicateFormula, right: PredicateFormula) => PredicateFormula;
|
|
21
|
+
export declare const analyzeFormula: (formula: PredicateFormula) => RuntimeContext;
|
|
22
|
+
export declare const normalizeFormula: (formula: PredicateFormula) => PredicateFormula;
|
|
23
|
+
export declare const formulaOfExpression: (value: Expression.Any) => PredicateFormula;
|
|
24
|
+
export declare const formulaOfPredicate: (value: boolean | Expression.Any) => PredicateFormula;
|
|
25
|
+
export declare const assumeFormulaTrue: (assumptions: PredicateFormula, formula: PredicateFormula) => PredicateFormula;
|
|
26
|
+
export declare const assumeFormulaFalse: (assumptions: PredicateFormula, formula: PredicateFormula) => PredicateFormula;
|
|
27
|
+
export declare const contradictsFormula: (assumptions: PredicateFormula, formula: PredicateFormula) => boolean;
|
|
28
|
+
export declare const impliesFormula: (assumptions: PredicateFormula, formula: PredicateFormula) => boolean;
|
|
29
|
+
export declare const guaranteedNonNullKeys: (assumptions: PredicateFormula) => ReadonlySet<string>;
|
|
30
|
+
export declare const guaranteedNullKeys: (assumptions: PredicateFormula) => ReadonlySet<string>;
|
|
31
|
+
export declare const guaranteedSourceNames: (assumptions: PredicateFormula) => ReadonlySet<string>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as Expression from "
|
|
2
|
-
import * as ExpressionAst from "
|
|
3
|
-
import type { PredicateAtom } from "./
|
|
1
|
+
import * as Expression from "../scalar.js"
|
|
2
|
+
import * as ExpressionAst from "../expression-ast.js"
|
|
3
|
+
import type { PredicateAtom } from "./atom.js"
|
|
4
4
|
import type {
|
|
5
5
|
EqColumnAtom,
|
|
6
6
|
EqLiteralAtom,
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
NonNullAtom,
|
|
9
9
|
NullAtom,
|
|
10
10
|
UnknownAtom
|
|
11
|
-
} from "./
|
|
11
|
+
} from "./atom.js"
|
|
12
12
|
import type {
|
|
13
13
|
AllFormula,
|
|
14
14
|
AnyFormula,
|
|
@@ -17,7 +17,7 @@ import type {
|
|
|
17
17
|
NotFormula,
|
|
18
18
|
PredicateFormula,
|
|
19
19
|
TrueFormula
|
|
20
|
-
} from "./
|
|
20
|
+
} from "./formula.js"
|
|
21
21
|
|
|
22
22
|
export interface RuntimeContext {
|
|
23
23
|
readonly nonNullKeys: ReadonlySet<string>
|
|
@@ -622,7 +622,10 @@ export const formulaOfExpression = (value: Expression.Any): PredicateFormula =>
|
|
|
622
622
|
const [left, ...rest] = ast.values
|
|
623
623
|
return left === undefined
|
|
624
624
|
? trueFormula()
|
|
625
|
-
:
|
|
625
|
+
: combineFacts(
|
|
626
|
+
nonNullFactsOfExpression(left),
|
|
627
|
+
allFormula(rest.map((value: Expression.Any) => formulaOfNeq(left, value)))
|
|
628
|
+
)
|
|
626
629
|
}
|
|
627
630
|
case "between":
|
|
628
631
|
return combineFacts(
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Symbol used to attach explicit projection-alias metadata to an expression. */
|
|
2
|
+
export declare const TypeId: unique symbol;
|
|
3
|
+
export type TypeId = typeof TypeId;
|
|
4
|
+
/**
|
|
5
|
+
* Projection-alias metadata carried by a runtime expression wrapper.
|
|
6
|
+
*
|
|
7
|
+
* This is intentionally orthogonal to the scalar expression AST. Aliasing does
|
|
8
|
+
* not change SQL semantics; it only changes how a selected expression is named
|
|
9
|
+
* in the rendered `SELECT ... AS ...` list.
|
|
10
|
+
*/
|
|
11
|
+
export interface State<Alias extends string = string> {
|
|
12
|
+
readonly alias: Alias;
|
|
13
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as Expression from "./scalar.js";
|
|
2
|
+
/**
|
|
3
|
+
* Flat projection metadata shared by renderers and executors.
|
|
4
|
+
*
|
|
5
|
+
* `path` identifies where a value should be decoded in the nested result row,
|
|
6
|
+
* while `alias` is the flat SQL column alias used by the rendered query.
|
|
7
|
+
*/
|
|
8
|
+
export interface Projection {
|
|
9
|
+
readonly path: readonly string[];
|
|
10
|
+
readonly alias: string;
|
|
11
|
+
}
|
|
12
|
+
/** Selection leaf paired with its resolved projection alias. */
|
|
13
|
+
export interface FlattenedProjection {
|
|
14
|
+
readonly path: readonly string[];
|
|
15
|
+
readonly expression: Expression.Any;
|
|
16
|
+
readonly alias: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Flattens a nested selection object into leaf expressions with decode paths
|
|
20
|
+
* and resolved SQL aliases.
|
|
21
|
+
*/
|
|
22
|
+
export declare const flattenSelection: (selection: Record<string, unknown>, path?: readonly string[]) => readonly FlattenedProjection[];
|
|
23
|
+
/**
|
|
24
|
+
* Validates the flattened projection set shared by renderer and executor code.
|
|
25
|
+
*
|
|
26
|
+
* This rejects:
|
|
27
|
+
* - duplicate SQL aliases
|
|
28
|
+
* - duplicate decode paths
|
|
29
|
+
* - conflicting prefix paths like `profile` and `profile.id`
|
|
30
|
+
*/
|
|
31
|
+
export declare const validateProjections: (projections: readonly Projection[]) => void;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import type * as Expression from "./scalar.js";
|
|
2
|
+
/** Symbol used to attach query-clause AST metadata to query-plan values. */
|
|
3
|
+
export declare const TypeId: unique symbol;
|
|
4
|
+
export type TypeId = typeof TypeId;
|
|
5
|
+
/** Statement kinds supported by the current query AST. */
|
|
6
|
+
export type QueryStatement = "select" | "set" | "insert" | "update" | "delete" | "truncate" | "merge" | "transaction" | "commit" | "rollback" | "savepoint" | "rollbackTo" | "releaseSavepoint" | "createTable" | "createIndex" | "dropIndex" | "alterTable" | "dropTable";
|
|
7
|
+
/** Base `FROM` clause recorded by the query AST. */
|
|
8
|
+
export interface FromClause<TableName extends string = string> {
|
|
9
|
+
readonly kind: "from";
|
|
10
|
+
readonly tableName: TableName;
|
|
11
|
+
readonly baseTableName: string;
|
|
12
|
+
readonly source: unknown;
|
|
13
|
+
}
|
|
14
|
+
/** Boolean predicate recorded in a `WHERE` clause. */
|
|
15
|
+
export interface WhereClause<Predicate extends Expression.Any = Expression.Any> {
|
|
16
|
+
readonly kind: "where";
|
|
17
|
+
readonly predicate: Predicate;
|
|
18
|
+
}
|
|
19
|
+
/** Boolean predicate recorded in a `HAVING` clause. */
|
|
20
|
+
export interface HavingClause<Predicate extends Expression.Any = Expression.Any> {
|
|
21
|
+
readonly kind: "having";
|
|
22
|
+
readonly predicate: Predicate;
|
|
23
|
+
}
|
|
24
|
+
/** Assignment recorded in a mutation statement. */
|
|
25
|
+
export interface AssignmentClause<Value extends Expression.Any = Expression.Any> {
|
|
26
|
+
readonly tableName?: string;
|
|
27
|
+
readonly columnName: string;
|
|
28
|
+
readonly value: Value;
|
|
29
|
+
}
|
|
30
|
+
/** One row in a multi-row `values (...)` insert source. */
|
|
31
|
+
export interface InsertValuesRowClause<Values extends readonly AssignmentClause[] = readonly AssignmentClause[]> {
|
|
32
|
+
readonly values: Values;
|
|
33
|
+
}
|
|
34
|
+
/** Additional insert source kinds beyond a single literal row. */
|
|
35
|
+
export type InsertSourceClause = {
|
|
36
|
+
readonly kind: "values";
|
|
37
|
+
readonly columns: readonly [string, ...string[]];
|
|
38
|
+
readonly rows: readonly [InsertValuesRowClause, ...InsertValuesRowClause[]];
|
|
39
|
+
} | {
|
|
40
|
+
readonly kind: "query";
|
|
41
|
+
readonly columns: readonly [string, ...string[]];
|
|
42
|
+
readonly query: unknown;
|
|
43
|
+
} | {
|
|
44
|
+
readonly kind: "unnest";
|
|
45
|
+
readonly columns: readonly [string, ...string[]];
|
|
46
|
+
readonly values: readonly {
|
|
47
|
+
readonly columnName: string;
|
|
48
|
+
readonly values: readonly unknown[];
|
|
49
|
+
}[];
|
|
50
|
+
};
|
|
51
|
+
/** One branch inside a `merge` statement. */
|
|
52
|
+
export type MergeMatchedClause<Predicate extends Expression.Any | undefined = Expression.Any | undefined> = {
|
|
53
|
+
readonly kind: "update";
|
|
54
|
+
readonly values: readonly AssignmentClause[];
|
|
55
|
+
readonly predicate?: Predicate;
|
|
56
|
+
} | {
|
|
57
|
+
readonly kind: "delete";
|
|
58
|
+
readonly predicate?: Predicate;
|
|
59
|
+
};
|
|
60
|
+
/** Insert branch inside a `merge` statement. */
|
|
61
|
+
export interface MergeNotMatchedClause<Predicate extends Expression.Any | undefined = Expression.Any | undefined> {
|
|
62
|
+
readonly kind: "insert";
|
|
63
|
+
readonly values: readonly AssignmentClause[];
|
|
64
|
+
readonly predicate?: Predicate;
|
|
65
|
+
}
|
|
66
|
+
/** Payload recorded by a `merge` statement. */
|
|
67
|
+
export interface MergeClause<On extends Expression.Any = Expression.Any, Predicate extends Expression.Any | undefined = Expression.Any | undefined> {
|
|
68
|
+
readonly kind: "merge";
|
|
69
|
+
readonly on: On;
|
|
70
|
+
readonly whenMatched?: MergeMatchedClause<Predicate>;
|
|
71
|
+
readonly whenNotMatched?: MergeNotMatchedClause<Predicate>;
|
|
72
|
+
}
|
|
73
|
+
/** DDL payload recorded by schema-manipulation statements. */
|
|
74
|
+
export type DdlClause = {
|
|
75
|
+
readonly kind: "createTable";
|
|
76
|
+
readonly ifNotExists: boolean;
|
|
77
|
+
} | {
|
|
78
|
+
readonly kind: "dropTable";
|
|
79
|
+
readonly ifExists: boolean;
|
|
80
|
+
} | {
|
|
81
|
+
readonly kind: "createIndex";
|
|
82
|
+
readonly name: string;
|
|
83
|
+
readonly columns: readonly [string, ...string[]];
|
|
84
|
+
readonly unique: boolean;
|
|
85
|
+
readonly ifNotExists: boolean;
|
|
86
|
+
} | {
|
|
87
|
+
readonly kind: "dropIndex";
|
|
88
|
+
readonly name: string;
|
|
89
|
+
readonly ifExists: boolean;
|
|
90
|
+
};
|
|
91
|
+
/** Truncate payload recorded by a truncate statement. */
|
|
92
|
+
export interface TruncateClause {
|
|
93
|
+
readonly kind: "truncate";
|
|
94
|
+
readonly restartIdentity: boolean;
|
|
95
|
+
readonly cascade: boolean;
|
|
96
|
+
}
|
|
97
|
+
/** Transaction-control payload recorded by transactional statements. */
|
|
98
|
+
export type TransactionClause = {
|
|
99
|
+
readonly kind: "transaction";
|
|
100
|
+
readonly isolationLevel?: "read committed" | "repeatable read" | "serializable";
|
|
101
|
+
readonly readOnly?: boolean;
|
|
102
|
+
} | {
|
|
103
|
+
readonly kind: "commit";
|
|
104
|
+
} | {
|
|
105
|
+
readonly kind: "rollback";
|
|
106
|
+
} | {
|
|
107
|
+
readonly kind: "savepoint";
|
|
108
|
+
readonly name: string;
|
|
109
|
+
} | {
|
|
110
|
+
readonly kind: "rollbackTo";
|
|
111
|
+
readonly name: string;
|
|
112
|
+
} | {
|
|
113
|
+
readonly kind: "releaseSavepoint";
|
|
114
|
+
readonly name: string;
|
|
115
|
+
} | {
|
|
116
|
+
readonly kind: "dropTable";
|
|
117
|
+
readonly ifExists: boolean;
|
|
118
|
+
} | {
|
|
119
|
+
readonly kind: "createIndex";
|
|
120
|
+
readonly name: string;
|
|
121
|
+
readonly columns: readonly [string, ...string[]];
|
|
122
|
+
readonly unique: boolean;
|
|
123
|
+
readonly ifNotExists: boolean;
|
|
124
|
+
} | {
|
|
125
|
+
readonly kind: "dropIndex";
|
|
126
|
+
readonly name: string;
|
|
127
|
+
readonly ifExists: boolean;
|
|
128
|
+
};
|
|
129
|
+
/** Locking mode attached to a select statement. */
|
|
130
|
+
export interface LockClause {
|
|
131
|
+
readonly kind: "lock";
|
|
132
|
+
readonly mode: "update" | "share" | "lowPriority" | "ignore" | "quick";
|
|
133
|
+
readonly nowait?: boolean;
|
|
134
|
+
readonly skipLocked?: boolean;
|
|
135
|
+
}
|
|
136
|
+
/** Conflict target attached to a Postgres insert statement. */
|
|
137
|
+
export type ConflictTargetClause = {
|
|
138
|
+
readonly kind: "columns";
|
|
139
|
+
readonly columns: readonly [string, ...string[]];
|
|
140
|
+
readonly where?: Expression.Any;
|
|
141
|
+
} | {
|
|
142
|
+
readonly kind: "constraint";
|
|
143
|
+
readonly name: string;
|
|
144
|
+
};
|
|
145
|
+
/** Conflict clause attached to an insert statement. */
|
|
146
|
+
export interface ConflictClause {
|
|
147
|
+
readonly kind: "conflict";
|
|
148
|
+
readonly target?: ConflictTargetClause;
|
|
149
|
+
readonly action: "doNothing" | "doUpdate";
|
|
150
|
+
readonly values?: readonly AssignmentClause[];
|
|
151
|
+
readonly where?: Expression.Any;
|
|
152
|
+
}
|
|
153
|
+
/** Join kinds supported by the current query layer. */
|
|
154
|
+
export type JoinKind = "inner" | "left" | "right" | "full" | "cross";
|
|
155
|
+
/** Join clause recorded by the query AST. */
|
|
156
|
+
export interface JoinClause<TableName extends string = string, Kind extends JoinKind = JoinKind, On extends Expression.Any | undefined = Expression.Any | undefined> {
|
|
157
|
+
readonly kind: Kind;
|
|
158
|
+
readonly tableName: TableName;
|
|
159
|
+
readonly baseTableName: string;
|
|
160
|
+
readonly source: unknown;
|
|
161
|
+
readonly on?: On;
|
|
162
|
+
}
|
|
163
|
+
/** Sort direction recorded by an `ORDER BY` clause. */
|
|
164
|
+
export type OrderDirection = "asc" | "desc";
|
|
165
|
+
/** Ordering clause recorded by the query AST. */
|
|
166
|
+
export interface OrderByClause<Value extends Expression.Any = Expression.Any> {
|
|
167
|
+
readonly kind: "orderBy";
|
|
168
|
+
readonly value: Value;
|
|
169
|
+
readonly direction: OrderDirection;
|
|
170
|
+
}
|
|
171
|
+
/** Set-operator kinds supported by compound queries. */
|
|
172
|
+
export type SetOperatorKind = "union" | "intersect" | "except";
|
|
173
|
+
/** Compound-query clause recorded by the query AST. */
|
|
174
|
+
export interface SetOperationClause {
|
|
175
|
+
readonly kind: SetOperatorKind;
|
|
176
|
+
readonly all?: boolean;
|
|
177
|
+
readonly query: unknown;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Internal query AST stored alongside public `Plan` metadata.
|
|
181
|
+
*
|
|
182
|
+
* The public plan state tracks selection, required sources, available sources,
|
|
183
|
+
* and dialect. This AST captures the clause ordering needed to eventually
|
|
184
|
+
* render or optimize a SQL query.
|
|
185
|
+
*/
|
|
186
|
+
export interface Ast<Selection = unknown, Grouped extends string = never, Statement extends QueryStatement = "select"> {
|
|
187
|
+
readonly kind: Statement;
|
|
188
|
+
readonly select: Selection;
|
|
189
|
+
readonly distinct?: boolean;
|
|
190
|
+
readonly distinctOn?: readonly Expression.Any[];
|
|
191
|
+
readonly setBase?: unknown;
|
|
192
|
+
readonly recursive?: boolean;
|
|
193
|
+
readonly from?: FromClause;
|
|
194
|
+
readonly fromSources?: readonly FromClause[];
|
|
195
|
+
readonly into?: FromClause;
|
|
196
|
+
readonly target?: FromClause;
|
|
197
|
+
readonly targets?: readonly FromClause[];
|
|
198
|
+
readonly using?: FromClause;
|
|
199
|
+
readonly values?: readonly AssignmentClause[];
|
|
200
|
+
readonly insertSource?: InsertSourceClause;
|
|
201
|
+
readonly set?: readonly AssignmentClause[];
|
|
202
|
+
readonly ddl?: DdlClause;
|
|
203
|
+
readonly truncate?: TruncateClause;
|
|
204
|
+
readonly merge?: MergeClause;
|
|
205
|
+
readonly transaction?: TransactionClause;
|
|
206
|
+
readonly lock?: LockClause;
|
|
207
|
+
readonly conflict?: ConflictClause;
|
|
208
|
+
readonly where: readonly WhereClause[];
|
|
209
|
+
readonly having: readonly HavingClause[];
|
|
210
|
+
readonly joins: readonly JoinClause[];
|
|
211
|
+
readonly groupBy: readonly Expression.Any[];
|
|
212
|
+
readonly orderBy: readonly OrderByClause[];
|
|
213
|
+
readonly limit?: Expression.Any;
|
|
214
|
+
readonly offset?: Expression.Any;
|
|
215
|
+
readonly setOperations?: readonly SetOperationClause[];
|
|
216
|
+
readonly groupedSources?: Grouped;
|
|
217
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Query capabilities directly modeled by the current plan AST. */
|
|
2
|
+
export type QueryCapability = "read" | "write" | "ddl" | "transaction" | "locking";
|
|
3
|
+
/**
|
|
4
|
+
* Capability or query-mode requirement associated with a dialect error.
|
|
5
|
+
*
|
|
6
|
+
* Not every requirement is currently expressible by query plans. The extra
|
|
7
|
+
* vocabulary exists so dialect maps can stay stable as the plan surface grows.
|
|
8
|
+
*/
|
|
9
|
+
export type QueryRequirement = QueryCapability | "ddl" | "transaction" | "locking";
|
|
10
|
+
/** Runtime capability list for the current read-only query plans. */
|
|
11
|
+
export declare const read_query_capabilities: readonly ["read"];
|
|
12
|
+
/** Type-level union of two capability sets. */
|
|
13
|
+
export type MergeCapabilities<Left extends QueryCapability, Right extends QueryCapability> = Left | Right;
|
|
14
|
+
/** Type-level union of capability sets across a readonly tuple. */
|
|
15
|
+
export type MergeCapabilityTuple<Values extends readonly QueryCapability[], Current extends QueryCapability = never> = Values extends readonly [
|
|
16
|
+
infer Head extends QueryCapability,
|
|
17
|
+
...infer Tail extends readonly QueryCapability[]
|
|
18
|
+
] ? MergeCapabilityTuple<Tail, Current | Head> : Current;
|
|
19
|
+
/** Dedupes and normalizes capability lists at runtime. */
|
|
20
|
+
export declare const union_query_capabilities: (...values: readonly (readonly QueryCapability[])[]) => readonly QueryCapability[];
|