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
package/package.json
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "effect-qb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/relsunkaev/effect-qb.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/relsunkaev/effect-qb/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/relsunkaev/effect-qb#readme",
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=22",
|
|
16
|
+
"bun": ">=1.3.5"
|
|
17
|
+
},
|
|
5
18
|
"files": [
|
|
6
19
|
"dist",
|
|
7
20
|
"src",
|
|
8
|
-
"CHANGELOG.md",
|
|
9
21
|
"README.md"
|
|
10
22
|
],
|
|
11
23
|
"exports": {
|
|
@@ -13,6 +25,10 @@
|
|
|
13
25
|
"types": "./src/postgres.ts",
|
|
14
26
|
"import": "./dist/postgres.js"
|
|
15
27
|
},
|
|
28
|
+
"./postgres/metadata": {
|
|
29
|
+
"types": "./src/postgres/metadata.ts",
|
|
30
|
+
"import": "./dist/postgres/metadata.js"
|
|
31
|
+
},
|
|
16
32
|
"./mysql": {
|
|
17
33
|
"types": "./src/mysql.ts",
|
|
18
34
|
"import": "./dist/mysql.js"
|
|
@@ -28,22 +44,17 @@
|
|
|
28
44
|
"access": "public"
|
|
29
45
|
},
|
|
30
46
|
"scripts": {
|
|
31
|
-
"build": "bun scripts/build
|
|
32
|
-
"release": "bun scripts/release.ts",
|
|
33
|
-
"test": "bun test",
|
|
34
|
-
"test:types": "bunx tsgo -p tsconfig.type-tests.json",
|
|
35
|
-
"test:integration": "bun scripts/test-integration.ts",
|
|
47
|
+
"build": "bun scripts/build.ts",
|
|
36
48
|
"prepack": "bun run build"
|
|
37
49
|
},
|
|
38
50
|
"devDependencies": {
|
|
39
|
-
"@effect/sql-mysql2": "0.48.0",
|
|
40
|
-
"@effect/sql-pg": "0.48.0",
|
|
41
51
|
"@types/bun": "latest",
|
|
42
52
|
"@typescript/native-preview": "latest"
|
|
43
53
|
},
|
|
44
54
|
"dependencies": {
|
|
45
55
|
"@effect/experimental": "^0.57.0",
|
|
46
56
|
"@effect/sql": "^0.48.0",
|
|
47
|
-
"effect": "^3.19.3"
|
|
57
|
+
"effect": "^3.19.3",
|
|
58
|
+
"pgsql-ast-parser": "^12.0.2"
|
|
48
59
|
}
|
|
49
60
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as Expression from "./
|
|
1
|
+
import * as Expression from "./scalar.js"
|
|
2
2
|
import { groupingKeyOfExpression } from "./grouping-key.js"
|
|
3
3
|
|
|
4
4
|
/** Recursive selection value accepted by aggregate-shape validation. */
|
|
@@ -13,7 +13,7 @@ const isExpression = (value: unknown): value is Expression.Any =>
|
|
|
13
13
|
|
|
14
14
|
const selectionHasAggregate = (selection: SelectionValue): boolean => {
|
|
15
15
|
if (isExpression(selection)) {
|
|
16
|
-
return selection[Expression.TypeId].
|
|
16
|
+
return selection[Expression.TypeId].kind === "aggregate"
|
|
17
17
|
}
|
|
18
18
|
return Object.values(selection).some((value) => selectionHasAggregate(value))
|
|
19
19
|
}
|
|
@@ -23,7 +23,7 @@ const isGroupedSelectionValid = (
|
|
|
23
23
|
groupedExpressions: ReadonlySet<string>
|
|
24
24
|
): boolean => {
|
|
25
25
|
if (isExpression(selection)) {
|
|
26
|
-
const aggregation = selection[Expression.TypeId].
|
|
26
|
+
const aggregation = selection[Expression.TypeId].kind
|
|
27
27
|
if (aggregation === "aggregate") {
|
|
28
28
|
return true
|
|
29
29
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type * as Expression from "./scalar.js";
|
|
2
|
+
import type * as ExpressionAst from "./expression-ast.js";
|
|
3
|
+
import type { PredicateFormula } from "./predicate/formula.js";
|
|
4
|
+
import type { AssumeFormulaFalse, AssumeFormulaTrue, Contradicts, Implies } from "./predicate/analysis.js";
|
|
5
|
+
import type { FormulaOfExpression } from "./predicate/normalize.js";
|
|
6
|
+
export interface CasePath<Assumptions extends PredicateFormula, Value extends Expression.Any> {
|
|
7
|
+
readonly assumptions: Assumptions;
|
|
8
|
+
readonly value: Value;
|
|
9
|
+
}
|
|
10
|
+
type PredicateFormulaOf<Predicate extends Expression.Any> = FormulaOfExpression<Predicate>;
|
|
11
|
+
export type CaseBranchAssumeTrue<Assumptions extends PredicateFormula, Predicate extends Expression.Any> = AssumeFormulaTrue<Assumptions, PredicateFormulaOf<Predicate>>;
|
|
12
|
+
export type CaseBranchAssumeFalse<Assumptions extends PredicateFormula, Predicate extends Expression.Any> = AssumeFormulaFalse<Assumptions, PredicateFormulaOf<Predicate>>;
|
|
13
|
+
export type CaseBranchDecision<Assumptions extends PredicateFormula, Predicate extends Expression.Any> = Contradicts<Assumptions, Predicate> extends true ? "skip" : Implies<Assumptions, Predicate> extends true ? "take" : "branch";
|
|
14
|
+
export type ReachableCasePaths<Assumptions extends PredicateFormula, Branches extends readonly ExpressionAst.CaseBranchNode[], Else extends Expression.Any> = Branches extends readonly [
|
|
15
|
+
infer Head extends ExpressionAst.CaseBranchNode,
|
|
16
|
+
...infer Tail extends readonly ExpressionAst.CaseBranchNode[]
|
|
17
|
+
] ? CaseBranchDecision<Assumptions, Head["when"]> extends "skip" ? ReachableCasePaths<Assumptions, Tail, Else> : CaseBranchDecision<Assumptions, Head["when"]> extends "take" ? CasePath<CaseBranchAssumeTrue<Assumptions, Head["when"]>, Head["then"]> : CasePath<CaseBranchAssumeTrue<Assumptions, Head["when"]>, Head["then"]> | ReachableCasePaths<CaseBranchAssumeFalse<Assumptions, Head["when"]>, Tail, Else> : CasePath<Assumptions, Else>;
|
|
18
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type * as Expression from "./
|
|
1
|
+
import type * as Expression from "./scalar.js"
|
|
2
2
|
import type * as ExpressionAst from "./expression-ast.js"
|
|
3
|
-
import type { PredicateFormula } from "./predicate
|
|
4
|
-
import type { AssumeFormulaFalse, AssumeFormulaTrue, Contradicts, Implies } from "./predicate
|
|
5
|
-
import type { FormulaOfExpression } from "./predicate
|
|
3
|
+
import type { PredicateFormula } from "./predicate/formula.js"
|
|
4
|
+
import type { AssumeFormulaFalse, AssumeFormulaTrue, Contradicts, Implies } from "./predicate/analysis.js"
|
|
5
|
+
import type { FormulaOfExpression } from "./predicate/normalize.js"
|
|
6
6
|
|
|
7
7
|
export interface CasePath<
|
|
8
8
|
Assumptions extends PredicateFormula,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type * as Expression from "../scalar.js";
|
|
2
|
+
import type { CastTargetError, OperandCompatibilityError } from "./errors.js";
|
|
3
|
+
import type { CanCastDbType, CanCompareDbTypes, CanTextuallyCoerceDbType } from "./rules.js";
|
|
4
|
+
export type ComparableDbType<Left extends Expression.DbType.Any, Right extends Expression.DbType.Any, Dialect extends string, Operator extends string = "comparison"> = CanCompareDbTypes<Left, Right, Dialect> extends true ? Right : OperandCompatibilityError<Operator, Left, Right, Dialect, "the same db type family">;
|
|
5
|
+
export type TextCompatibleDbType<Db extends Expression.DbType.Any, Dialect extends string, Operator extends string = "text operator"> = CanTextuallyCoerceDbType<Db, Dialect> extends true ? Db : OperandCompatibilityError<Operator, Db, Db, Dialect, "a text-compatible db type">;
|
|
6
|
+
export type CastableDbType<Source extends Expression.DbType.Any, Target extends Expression.DbType.Any, Dialect extends string> = CanCastDbType<Source, Target, Dialect> extends true ? Target : CastTargetError<Source, Target, Dialect>;
|
|
7
|
+
export type RuntimeOfDbType<Db extends Expression.DbType.Any> = Expression.RuntimeOfDbType<Db>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type * as Expression from "
|
|
2
|
-
import type { CastTargetError, OperandCompatibilityError } from "./
|
|
3
|
-
import type { CanCastDbType, CanCompareDbTypes, CanTextuallyCoerceDbType } from "./
|
|
1
|
+
import type * as Expression from "../scalar.js"
|
|
2
|
+
import type { CastTargetError, OperandCompatibilityError } from "./errors.js"
|
|
3
|
+
import type { CanCastDbType, CanCompareDbTypes, CanTextuallyCoerceDbType } from "./rules.js"
|
|
4
4
|
|
|
5
5
|
export type ComparableDbType<
|
|
6
6
|
Left extends Expression.DbType.Any,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type * as Expression from "../scalar.js";
|
|
2
|
+
export type OperandCompatibilityError<Operator extends string, Left extends Expression.DbType.Any, Right extends Expression.DbType.Any, Dialect extends string, Expected extends string> = {
|
|
3
|
+
readonly __effect_qb_error__: "effect-qb: incompatible operand types";
|
|
4
|
+
readonly __effect_qb_operator__: Operator;
|
|
5
|
+
readonly __effect_qb_left_db_type__: Left;
|
|
6
|
+
readonly __effect_qb_right_db_type__: Right;
|
|
7
|
+
readonly __effect_qb_dialect__: Dialect;
|
|
8
|
+
readonly __effect_qb_expected__: Expected;
|
|
9
|
+
readonly __effect_qb_hint__: "Use cast(...) or pick values from the same db type family";
|
|
10
|
+
};
|
|
11
|
+
export type CastTargetError<Source extends Expression.DbType.Any, Target extends Expression.DbType.Any, Dialect extends string> = {
|
|
12
|
+
readonly __effect_qb_error__: "effect-qb: unsupported cast target";
|
|
13
|
+
readonly __effect_qb_source_db_type__: Source;
|
|
14
|
+
readonly __effect_qb_target_db_type__: Target;
|
|
15
|
+
readonly __effect_qb_dialect__: Dialect;
|
|
16
|
+
readonly __effect_qb_hint__: "Use one of the supported Q.type.<kind>() witnesses";
|
|
17
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type * as Expression from "../scalar.js";
|
|
2
|
+
import type { FamilyOfDbType } from "../datatypes/lookup.js";
|
|
3
|
+
export type CoercionKind = "text" | "numeric" | "boolean" | "date" | "time" | "timestamp" | "binary" | "interval" | "uuid" | "json" | "xml" | "bit" | "identifier" | "network" | "spatial" | "textsearch" | "range" | "multirange" | "array" | "record" | "domain" | "enum" | "set" | "money" | "null" | `other:${string}`;
|
|
4
|
+
export type CoercionKindOf<Db extends Expression.DbType.Any> = FamilyOfDbType<Db>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type * as Expression from "../scalar.js";
|
|
2
|
+
import type { CanCastDbType as LookupCanCastDbType, CanCompareDbTypes as LookupCanCompareDbTypes, CanContainDbTypes as LookupCanContainDbTypes, CanTextuallyCoerceDbType as LookupCanTextuallyCoerceDbType } from "../datatypes/lookup.js";
|
|
3
|
+
export type CanCompareDbTypes<Left extends Expression.DbType.Any, Right extends Expression.DbType.Any, Dialect extends string> = LookupCanCompareDbTypes<Left, Right, Dialect>;
|
|
4
|
+
export type CanContainDbTypes<Left extends Expression.DbType.Any, Right extends Expression.DbType.Any, Dialect extends string> = LookupCanContainDbTypes<Left, Right, Dialect>;
|
|
5
|
+
export type CanTextuallyCoerceDbType<Db extends Expression.DbType.Any, Dialect extends string> = LookupCanTextuallyCoerceDbType<Db, Dialect>;
|
|
6
|
+
export type CanCastDbType<Source extends Expression.DbType.Any, Target extends Expression.DbType.Any, Dialect extends string> = LookupCanCastDbType<Source, Target, Dialect>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type * as Expression from "
|
|
2
|
-
import type { CanCastDbType as LookupCanCastDbType, CanCompareDbTypes as LookupCanCompareDbTypes, CanContainDbTypes as LookupCanContainDbTypes, CanTextuallyCoerceDbType as LookupCanTextuallyCoerceDbType } from "
|
|
1
|
+
import type * as Expression from "../scalar.js"
|
|
2
|
+
import type { CanCastDbType as LookupCanCastDbType, CanCompareDbTypes as LookupCanCompareDbTypes, CanContainDbTypes as LookupCanContainDbTypes, CanTextuallyCoerceDbType as LookupCanTextuallyCoerceDbType } from "../datatypes/lookup.js"
|
|
3
3
|
|
|
4
4
|
export type CanCompareDbTypes<
|
|
5
5
|
Left extends Expression.DbType.Any,
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import type * as Brand from "effect/Brand";
|
|
2
|
+
import { type Pipeable } from "effect/Pipeable";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import * as Expression from "./scalar.js";
|
|
5
|
+
import * as ExpressionAst from "./expression-ast.js";
|
|
6
|
+
import type * as SchemaExpression from "./schema-expression.js";
|
|
7
|
+
/** Symbol used to attach column-definition metadata. */
|
|
8
|
+
export declare const ColumnTypeId: unique symbol;
|
|
9
|
+
/** Symbol used to attach bound-column provenance. */
|
|
10
|
+
export declare const BoundColumnTypeId: unique symbol;
|
|
11
|
+
export type ColumnTypeId = typeof ColumnTypeId;
|
|
12
|
+
export type BoundColumnTypeId = typeof BoundColumnTypeId;
|
|
13
|
+
export type DdlExpression = Expression.Any | SchemaExpression.Any;
|
|
14
|
+
/** Lazy reference to another bound column. */
|
|
15
|
+
export interface ColumnReference<Target = unknown> {
|
|
16
|
+
readonly target: () => Target;
|
|
17
|
+
readonly name?: string;
|
|
18
|
+
readonly onUpdate?: "noAction" | "restrict" | "cascade" | "setNull" | "setDefault";
|
|
19
|
+
readonly onDelete?: "noAction" | "restrict" | "cascade" | "setNull" | "setDefault";
|
|
20
|
+
readonly deferrable?: boolean;
|
|
21
|
+
readonly initiallyDeferred?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** Inline single-column index metadata. */
|
|
24
|
+
export interface ColumnIndexOptions {
|
|
25
|
+
readonly name?: string;
|
|
26
|
+
readonly method?: string;
|
|
27
|
+
readonly include?: readonly string[];
|
|
28
|
+
readonly predicate?: DdlExpression;
|
|
29
|
+
readonly order?: "asc" | "desc";
|
|
30
|
+
readonly nulls?: "first" | "last";
|
|
31
|
+
readonly operatorClass?: string;
|
|
32
|
+
readonly collation?: string;
|
|
33
|
+
}
|
|
34
|
+
/** Inline single-column unique-constraint metadata. */
|
|
35
|
+
export interface ColumnUniqueOptions {
|
|
36
|
+
readonly name?: string;
|
|
37
|
+
readonly nullsNotDistinct?: boolean;
|
|
38
|
+
readonly deferrable?: boolean;
|
|
39
|
+
readonly initiallyDeferred?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/** Complete static state tracked for a column definition. */
|
|
42
|
+
export interface ColumnState<Select, Insert, Update, Db extends Expression.DbType.Any, Nullable extends boolean, HasDefault extends boolean, Generated extends boolean, PrimaryKey extends boolean, Unique extends boolean, Ref, Dependencies extends Expression.BindingId = never> {
|
|
43
|
+
readonly select: Select;
|
|
44
|
+
readonly insert: Insert;
|
|
45
|
+
readonly update: Update;
|
|
46
|
+
readonly dbType: Db;
|
|
47
|
+
readonly nullable: Nullable;
|
|
48
|
+
readonly hasDefault: HasDefault;
|
|
49
|
+
readonly generated: Generated;
|
|
50
|
+
readonly primaryKey: PrimaryKey;
|
|
51
|
+
readonly unique: Unique;
|
|
52
|
+
readonly references: Ref;
|
|
53
|
+
readonly brand?: true;
|
|
54
|
+
readonly index?: ColumnIndexOptions;
|
|
55
|
+
readonly uniqueConstraint?: ColumnUniqueOptions;
|
|
56
|
+
readonly defaultValue?: DdlExpression;
|
|
57
|
+
readonly generatedValue?: DdlExpression;
|
|
58
|
+
readonly ddlType?: string;
|
|
59
|
+
readonly identity?: {
|
|
60
|
+
readonly generation: "always" | "byDefault";
|
|
61
|
+
};
|
|
62
|
+
readonly enum?: {
|
|
63
|
+
readonly name: string;
|
|
64
|
+
readonly schemaName?: string;
|
|
65
|
+
readonly values: readonly [string, ...string[]];
|
|
66
|
+
};
|
|
67
|
+
readonly dependencies?: Dependencies;
|
|
68
|
+
}
|
|
69
|
+
/** Unbound column definition produced by the `Column` DSL. */
|
|
70
|
+
export interface ColumnDefinition<Select, Insert, Update, Db extends Expression.DbType.Any, Nullable extends boolean, HasDefault extends boolean, Generated extends boolean, PrimaryKey extends boolean, Unique extends boolean, Ref, Dependencies extends Expression.BindingId = never> extends Pipeable, Expression.Scalar<Select, Db, Nullable extends true ? "maybe" : "never", Db["dialect"], "scalar", Dependencies> {
|
|
71
|
+
readonly pipe: Pipeable["pipe"];
|
|
72
|
+
readonly [ColumnTypeId]: ColumnState<Select, Insert, Update, Db, Nullable, HasDefault, Generated, PrimaryKey, Unique, Ref, Dependencies>;
|
|
73
|
+
readonly schema: Schema.Schema<NonNullable<Select>, any, any>;
|
|
74
|
+
readonly metadata: {
|
|
75
|
+
readonly dbType: Db;
|
|
76
|
+
readonly nullable: Nullable;
|
|
77
|
+
readonly hasDefault: HasDefault;
|
|
78
|
+
readonly generated: Generated;
|
|
79
|
+
readonly primaryKey: PrimaryKey;
|
|
80
|
+
readonly unique: Unique;
|
|
81
|
+
readonly references: Ref;
|
|
82
|
+
readonly brand?: true;
|
|
83
|
+
readonly index?: ColumnIndexOptions;
|
|
84
|
+
readonly uniqueConstraint?: ColumnUniqueOptions;
|
|
85
|
+
readonly defaultValue?: DdlExpression;
|
|
86
|
+
readonly generatedValue?: DdlExpression;
|
|
87
|
+
readonly ddlType?: string;
|
|
88
|
+
readonly identity?: {
|
|
89
|
+
readonly generation: "always" | "byDefault";
|
|
90
|
+
};
|
|
91
|
+
readonly enum?: {
|
|
92
|
+
readonly name: string;
|
|
93
|
+
readonly schemaName?: string;
|
|
94
|
+
readonly values: readonly [string, ...string[]];
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/** Column definition bound to a concrete table and column name. */
|
|
99
|
+
export interface BoundColumn<Select, Insert, Update, Db extends Expression.DbType.Any, Nullable extends boolean, HasDefault extends boolean, Generated extends boolean, PrimaryKey extends boolean, Unique extends boolean, Ref, TableName extends string, ColumnName extends string, BaseTableName extends string = TableName> extends ColumnDefinition<Select, Insert, Update, Db, Nullable, HasDefault, Generated, PrimaryKey, Unique, Ref, TableName> {
|
|
100
|
+
readonly [BoundColumnTypeId]: {
|
|
101
|
+
readonly tableName: TableName;
|
|
102
|
+
readonly columnName: ColumnName;
|
|
103
|
+
readonly baseTableName: BaseTableName;
|
|
104
|
+
readonly schemaName?: string;
|
|
105
|
+
};
|
|
106
|
+
readonly [Expression.TypeId]: Expression.State<Select, Db, Nullable extends true ? "maybe" : "never", Db["dialect"], "scalar", TableName>;
|
|
107
|
+
readonly [ExpressionAst.TypeId]: ExpressionAst.ColumnNode<TableName, ColumnName>;
|
|
108
|
+
}
|
|
109
|
+
/** Convenience alias for any column definition. */
|
|
110
|
+
export type AnyColumnDefinition = ColumnDefinition<any, any, any, Expression.DbType.Any, boolean, boolean, boolean, boolean, boolean, any, any>;
|
|
111
|
+
/** Convenience alias for any bound column. */
|
|
112
|
+
export type AnyBoundColumn = BoundColumn<any, any, any, Expression.DbType.Any, boolean, boolean, boolean, boolean, boolean, any, string, string, string>;
|
|
113
|
+
/** Constructs a runtime column-definition object from schema and metadata. */
|
|
114
|
+
export declare const makeColumnDefinition: <Select, Insert, Update, Db extends Expression.DbType.Any, Nullable extends boolean, HasDefault extends boolean, Generated extends boolean, PrimaryKey extends boolean, Unique extends boolean, Ref, Dependencies extends string = never>(schema: Schema.Schema<NonNullable<Select>, any, any>, metadata: {
|
|
115
|
+
readonly dbType: Db;
|
|
116
|
+
readonly nullable: Nullable;
|
|
117
|
+
readonly hasDefault: HasDefault;
|
|
118
|
+
readonly generated: Generated;
|
|
119
|
+
readonly primaryKey: PrimaryKey;
|
|
120
|
+
readonly unique: Unique;
|
|
121
|
+
readonly references: Ref;
|
|
122
|
+
readonly brand?: true | undefined;
|
|
123
|
+
readonly index?: ColumnIndexOptions | undefined;
|
|
124
|
+
readonly uniqueConstraint?: ColumnUniqueOptions | undefined;
|
|
125
|
+
readonly defaultValue?: DdlExpression | undefined;
|
|
126
|
+
readonly generatedValue?: DdlExpression | undefined;
|
|
127
|
+
readonly ddlType?: string | undefined;
|
|
128
|
+
readonly identity?: {
|
|
129
|
+
readonly generation: "always" | "byDefault";
|
|
130
|
+
} | undefined;
|
|
131
|
+
readonly enum?: {
|
|
132
|
+
readonly name: string;
|
|
133
|
+
readonly schemaName?: string | undefined;
|
|
134
|
+
readonly values: readonly [string, ...string[]];
|
|
135
|
+
} | undefined;
|
|
136
|
+
}) => ColumnDefinition<Select, Insert, Update, Db, Nullable, HasDefault, Generated, PrimaryKey, Unique, Ref, Dependencies>;
|
|
137
|
+
export declare const remapColumnDefinition: <Select, Insert, Update, Db extends Expression.DbType.Any, Nullable extends boolean, HasDefault extends boolean, Generated extends boolean, PrimaryKey extends boolean, Unique extends boolean, Ref, Dependencies extends string = never>(column: ColumnDefinition<Select, Insert, Update, Db, Nullable, HasDefault, Generated, PrimaryKey, Unique, Ref, Dependencies>, options?: {
|
|
138
|
+
readonly schema?: Schema.Schema.Any | undefined;
|
|
139
|
+
readonly metadata?: {
|
|
140
|
+
readonly dbType: Db;
|
|
141
|
+
readonly nullable: Nullable;
|
|
142
|
+
readonly hasDefault: HasDefault;
|
|
143
|
+
readonly generated: Generated;
|
|
144
|
+
readonly primaryKey: PrimaryKey;
|
|
145
|
+
readonly unique: Unique;
|
|
146
|
+
readonly references: Ref;
|
|
147
|
+
readonly brand?: true | undefined;
|
|
148
|
+
readonly index?: ColumnIndexOptions | undefined;
|
|
149
|
+
readonly uniqueConstraint?: ColumnUniqueOptions | undefined;
|
|
150
|
+
readonly defaultValue?: DdlExpression | undefined;
|
|
151
|
+
readonly generatedValue?: DdlExpression | undefined;
|
|
152
|
+
readonly ddlType?: string | undefined;
|
|
153
|
+
readonly identity?: {
|
|
154
|
+
readonly generation: "always" | "byDefault";
|
|
155
|
+
} | undefined;
|
|
156
|
+
readonly enum?: {
|
|
157
|
+
readonly name: string;
|
|
158
|
+
readonly schemaName?: string | undefined;
|
|
159
|
+
readonly values: readonly [string, ...string[]];
|
|
160
|
+
} | undefined;
|
|
161
|
+
} | undefined;
|
|
162
|
+
}) => ColumnDefinition<Select, Insert, Update, Db, Nullable, HasDefault, Generated, PrimaryKey, Unique, Ref, Dependencies>;
|
|
163
|
+
/** Attaches table/column provenance to an existing column definition. */
|
|
164
|
+
export declare const bindColumn: <TableName extends string, ColumnName extends string, BaseTableName extends string, SchemaName extends string | undefined, Column extends AnyColumnDefinition>(tableName: TableName, columnName: ColumnName, column: Column, baseTableName: BaseTableName, schemaName?: SchemaName | undefined) => BoundColumnFrom<Column, TableName, ColumnName, BaseTableName>;
|
|
165
|
+
/** Extracts the internal state record for a column. */
|
|
166
|
+
export type ColumnStateOf<Column extends AnyColumnDefinition> = Column[typeof ColumnTypeId];
|
|
167
|
+
/** Extracts the read/select type of a column. */
|
|
168
|
+
export type SelectType<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["select"];
|
|
169
|
+
/** Extracts the insert type of a column. */
|
|
170
|
+
export type InsertType<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["insert"];
|
|
171
|
+
/** Extracts the update type of a column. */
|
|
172
|
+
export type UpdateType<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["update"];
|
|
173
|
+
/** Extracts whether a column is nullable. */
|
|
174
|
+
export type IsNullable<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["nullable"];
|
|
175
|
+
/** Extracts whether a column has a server-side default. */
|
|
176
|
+
export type HasDefault<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["hasDefault"];
|
|
177
|
+
/** Extracts whether a column is generated by the database. */
|
|
178
|
+
export type IsGenerated<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["generated"];
|
|
179
|
+
/** Extracts whether a column is part of a primary key. */
|
|
180
|
+
export type IsPrimaryKey<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["primaryKey"];
|
|
181
|
+
/** Extracts whether a column is unique. */
|
|
182
|
+
export type IsUnique<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["unique"];
|
|
183
|
+
/** Extracts a column's foreign-key reference metadata. */
|
|
184
|
+
export type ReferencesOf<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["references"];
|
|
185
|
+
/** Extracts the non-null select type of a column. */
|
|
186
|
+
export type BaseSelectType<Column extends AnyColumnDefinition> = NonNullable<SelectType<Column>>;
|
|
187
|
+
type BrandedValue<Value, BrandName extends string> = [Extract<Value, null | undefined>] extends [never] ? Value & Brand.Brand<BrandName> : (Exclude<Value, null | undefined> & Brand.Brand<BrandName>) | Extract<Value, null | undefined>;
|
|
188
|
+
/** Rebinds a generic column definition to a specific table and key. */
|
|
189
|
+
export type BoundColumnFrom<Column extends AnyColumnDefinition, TableName extends string, ColumnName extends string, BaseTableName extends string = TableName> = BoundColumn<Column["metadata"]["brand"] extends true ? BrandedValue<SelectType<Column>, `${TableName}.${ColumnName}`> : SelectType<Column>, Column["metadata"]["brand"] extends true ? BrandedValue<InsertType<Column>, `${TableName}.${ColumnName}`> : InsertType<Column>, Column["metadata"]["brand"] extends true ? BrandedValue<UpdateType<Column>, `${TableName}.${ColumnName}`> : UpdateType<Column>, ColumnStateOf<Column>["dbType"], IsNullable<Column>, HasDefault<Column>, IsGenerated<Column>, IsPrimaryKey<Column>, IsUnique<Column>, ReferencesOf<Column>, TableName, ColumnName, BaseTableName>;
|
|
190
|
+
export {};
|