durcno 1.0.0-alpha.6 → 1.0.0-alpha.7
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/bin.cjs +112 -7
- package/dist/src/columns/bigint.d.mts +1 -1
- package/dist/src/columns/bigserial.d.mts +1 -1
- package/dist/src/columns/boolean.d.mts +1 -1
- package/dist/src/columns/bytea.d.mts +1 -1
- package/dist/src/columns/char.d.mts +1 -1
- package/dist/src/columns/cidr.d.mts +1 -1
- package/dist/src/columns/common.d.mts +3 -3
- package/dist/src/columns/date.d.mts +1 -1
- package/dist/src/columns/enum.d.mts +2 -2
- package/dist/src/columns/inet.d.mts +1 -1
- package/dist/src/columns/integer.d.mts +1 -1
- package/dist/src/columns/json.d.mts +1 -1
- package/dist/src/columns/jsonb.d.mts +1 -1
- package/dist/src/columns/macaddr.d.mts +1 -1
- package/dist/src/columns/numeric.d.mts +1 -1
- package/dist/src/columns/postgis/geography/linestring.d.mts +1 -1
- package/dist/src/columns/postgis/geography/multilinestring.d.mts +1 -1
- package/dist/src/columns/postgis/geography/multipoint.d.mts +1 -1
- package/dist/src/columns/postgis/geography/multipolygon.d.mts +1 -1
- package/dist/src/columns/postgis/geography/point.d.mts +1 -1
- package/dist/src/columns/postgis/geography/polygon.d.mts +1 -1
- package/dist/src/columns/serial.d.mts +1 -1
- package/dist/src/columns/smallint.d.mts +1 -1
- package/dist/src/columns/smallserial.d.mts +1 -1
- package/dist/src/columns/text.d.mts +1 -1
- package/dist/src/columns/time.d.mts +1 -1
- package/dist/src/columns/timestamp.d.mts +1 -1
- package/dist/src/columns/uuid.d.mts +1 -1
- package/dist/src/columns/varchar.d.mts +1 -1
- package/dist/src/constraints/check.d.mts +103 -21
- package/dist/src/constraints/check.mjs +177 -1
- package/dist/src/db.d.mts +1 -1
- package/dist/src/filters/array.d.mts +2 -2
- package/dist/src/filters/custom.d.mts +1 -1
- package/dist/src/filters/index.d.mts +3 -3
- package/dist/src/index.d.mts +7 -7
- package/dist/src/migration/ddl/table.d.mts +16 -6
- package/dist/src/migration/ddl/table.mjs +15 -5
- package/dist/src/migration/index.d.mts +3 -1
- package/dist/src/migration/index.mjs +3 -1
- package/dist/src/migration/snapshot.d.mts +1 -1
- package/dist/src/models.d.mts +1 -1
- package/dist/src/query-builders/aggregates.d.mts +2 -2
- package/dist/src/query-builders/count.d.mts +2 -2
- package/dist/src/query-builders/delete.d.mts +2 -2
- package/dist/src/query-builders/distinct.d.mts +2 -2
- package/dist/src/query-builders/exists.d.mts +2 -2
- package/dist/src/query-builders/first.d.mts +2 -2
- package/dist/src/query-builders/insert-returning.d.mts +2 -2
- package/dist/src/query-builders/insert.d.mts +2 -2
- package/dist/src/query-builders/pre.d.mts +2 -2
- package/dist/src/query-builders/raw.d.mts +1 -1
- package/dist/src/query-builders/rq.d.mts +2 -2
- package/dist/src/query-builders/select.d.mts +2 -2
- package/dist/src/query-builders/update.d.mts +2 -2
- package/dist/src/sequence.d.mts +1 -1
- package/dist/src/sql.d.mts +1 -1
- package/dist/src/table.d.mts +2 -2
- package/package.json +1 -1
package/dist/bin.cjs
CHANGED
|
@@ -12086,6 +12086,109 @@ function snapshotExprToSQL(expr) {
|
|
|
12086
12086
|
}
|
|
12087
12087
|
throw new Error("Unknown expression type");
|
|
12088
12088
|
}
|
|
12089
|
+
var opToMethod = {
|
|
12090
|
+
"=": "eq",
|
|
12091
|
+
"<>": "neq",
|
|
12092
|
+
">": "gt",
|
|
12093
|
+
">=": "gte",
|
|
12094
|
+
"<": "lt",
|
|
12095
|
+
"<=": "lte",
|
|
12096
|
+
LIKE: "like",
|
|
12097
|
+
"SIMILAR TO": "similarTo",
|
|
12098
|
+
"~": "regex",
|
|
12099
|
+
IN: "in",
|
|
12100
|
+
"NOT IN": "notIn"
|
|
12101
|
+
};
|
|
12102
|
+
var fnOpToMethod = {
|
|
12103
|
+
"=": "fnEq",
|
|
12104
|
+
"<>": "fnNeq",
|
|
12105
|
+
">": "fnGt",
|
|
12106
|
+
">=": "fnGte",
|
|
12107
|
+
"<": "fnLt",
|
|
12108
|
+
"<=": "fnLte"
|
|
12109
|
+
};
|
|
12110
|
+
var reservedMethodAlias = {
|
|
12111
|
+
in: "inOp"
|
|
12112
|
+
};
|
|
12113
|
+
function wrapSql(value) {
|
|
12114
|
+
return `sql\`${value.replace(/`/g, "\\`")}\``;
|
|
12115
|
+
}
|
|
12116
|
+
function collectMethods(expr, names) {
|
|
12117
|
+
if (expr.type === "raw") {
|
|
12118
|
+
names.add("raw");
|
|
12119
|
+
return;
|
|
12120
|
+
}
|
|
12121
|
+
if (expr.type === "comparison") {
|
|
12122
|
+
if (isExprColumnRef(expr.right)) {
|
|
12123
|
+
names.add("raw");
|
|
12124
|
+
return;
|
|
12125
|
+
}
|
|
12126
|
+
if (expr.left.type === "function") {
|
|
12127
|
+
names.add(fnOpToMethod[expr.op] ?? "fnEq");
|
|
12128
|
+
names.add(expr.left.name);
|
|
12129
|
+
} else {
|
|
12130
|
+
names.add(opToMethod[expr.op] ?? "eq");
|
|
12131
|
+
}
|
|
12132
|
+
return;
|
|
12133
|
+
}
|
|
12134
|
+
if (expr.type === "logical") {
|
|
12135
|
+
names.add(expr.op === "AND" ? "and" : "or");
|
|
12136
|
+
for (const e of expr.expressions) {
|
|
12137
|
+
collectMethods(e, names);
|
|
12138
|
+
}
|
|
12139
|
+
return;
|
|
12140
|
+
}
|
|
12141
|
+
if (expr.type === "function") {
|
|
12142
|
+
names.add(expr.name);
|
|
12143
|
+
}
|
|
12144
|
+
}
|
|
12145
|
+
function buildDestructure(names) {
|
|
12146
|
+
return [...names].sort().map((name) => {
|
|
12147
|
+
const alias = reservedMethodAlias[name];
|
|
12148
|
+
return alias ? `${name}: ${alias}` : name;
|
|
12149
|
+
}).join(", ");
|
|
12150
|
+
}
|
|
12151
|
+
function callName(method) {
|
|
12152
|
+
return reservedMethodAlias[method] ?? method;
|
|
12153
|
+
}
|
|
12154
|
+
function renderFunctionExpr(fn) {
|
|
12155
|
+
const args = fn.args.map(
|
|
12156
|
+
(a) => typeof a === "string" ? wrapSql(a) : isExprColumnRef(a) ? JSON.stringify(a.name) : wrapSql(snapshotExprToSQL(a))
|
|
12157
|
+
);
|
|
12158
|
+
return `${fn.name}(${args.join(", ")})`;
|
|
12159
|
+
}
|
|
12160
|
+
function renderExpr(expr) {
|
|
12161
|
+
if (expr.type === "raw") {
|
|
12162
|
+
return `raw(${JSON.stringify(expr.sql)})`;
|
|
12163
|
+
}
|
|
12164
|
+
if (expr.type === "comparison") {
|
|
12165
|
+
if (isExprColumnRef(expr.right)) {
|
|
12166
|
+
return `raw(${JSON.stringify(snapshotExprToSQL(expr))})`;
|
|
12167
|
+
}
|
|
12168
|
+
if (expr.left.type === "function") {
|
|
12169
|
+
const method2 = fnOpToMethod[expr.op] ?? "fnEq";
|
|
12170
|
+
return `${callName(method2)}(${renderFunctionExpr(expr.left)}, ${wrapSql(expr.right)})`;
|
|
12171
|
+
}
|
|
12172
|
+
const method = opToMethod[expr.op] ?? "eq";
|
|
12173
|
+
return `${callName(method)}(${JSON.stringify(expr.left.name)}, ${wrapSql(expr.right)})`;
|
|
12174
|
+
}
|
|
12175
|
+
if (expr.type === "logical") {
|
|
12176
|
+
const method = expr.op === "AND" ? "and" : "or";
|
|
12177
|
+
const parts = expr.expressions.map((e) => renderExpr(e)).join(", ");
|
|
12178
|
+
return `${method}(${parts})`;
|
|
12179
|
+
}
|
|
12180
|
+
if (expr.type === "function") {
|
|
12181
|
+
return renderFunctionExpr(expr);
|
|
12182
|
+
}
|
|
12183
|
+
throw new Error("Unknown SnapshotCheckExpr type");
|
|
12184
|
+
}
|
|
12185
|
+
function snapshotExprToCheckBuilderCode(expr) {
|
|
12186
|
+
const names = /* @__PURE__ */ new Set();
|
|
12187
|
+
collectMethods(expr, names);
|
|
12188
|
+
const destructure = buildDestructure(names);
|
|
12189
|
+
const body = renderExpr(expr);
|
|
12190
|
+
return `({ ${destructure} }) => ${body}`;
|
|
12191
|
+
}
|
|
12089
12192
|
|
|
12090
12193
|
// src/cli/utils.ts
|
|
12091
12194
|
function getOrderedDependencies(items, dependencyMap) {
|
|
@@ -12479,7 +12582,9 @@ function generateMigration(prev, curr, direction, renamedTables = {}, renamedCol
|
|
|
12479
12582
|
);
|
|
12480
12583
|
}
|
|
12481
12584
|
for (const chk of Object.values(currTable.checkConstraints)) {
|
|
12482
|
-
tableBuilder.push(
|
|
12585
|
+
tableBuilder.push(
|
|
12586
|
+
`.check("${chk.name}", ${snapshotExprToCheckBuilderCode(chk.expr)})`
|
|
12587
|
+
);
|
|
12483
12588
|
}
|
|
12484
12589
|
for (const uc of Object.values(currTable.uniqueConstraints ?? {})) {
|
|
12485
12590
|
const cols = uc.columns.map((c) => `"${c}"`).join(", ");
|
|
@@ -12514,9 +12619,9 @@ function generateMigration(prev, curr, direction, renamedTables = {}, renamedCol
|
|
|
12514
12619
|
}
|
|
12515
12620
|
}
|
|
12516
12621
|
if (statements.length === 0) return null;
|
|
12517
|
-
return `import { type DDLStatement, ddl, type MigrationOptions } from "durcno/migration";
|
|
12622
|
+
return `import { type DDLStatement, ddl, sql, type MigrationOptions } from "durcno/migration";
|
|
12518
12623
|
|
|
12519
|
-
export const options: MigrationOptions = ${stringifyMigrationOpts(defaultOptions ?? {
|
|
12624
|
+
export const options: MigrationOptions = ${stringifyMigrationOpts(defaultOptions ?? {})};
|
|
12520
12625
|
|
|
12521
12626
|
export const statements: DDLStatement[] = [
|
|
12522
12627
|
${statements.join(",\n ")},
|
|
@@ -12526,7 +12631,7 @@ export const statements: DDLStatement[] = [
|
|
|
12526
12631
|
function generateNoOpMigration(defaultOptions) {
|
|
12527
12632
|
return `import { type DDLStatement, ddl, type MigrationOptions } from "durcno/migration";
|
|
12528
12633
|
|
|
12529
|
-
export const options: MigrationOptions = ${stringifyMigrationOpts(defaultOptions ?? {
|
|
12634
|
+
export const options: MigrationOptions = ${stringifyMigrationOpts(defaultOptions ?? {})};
|
|
12530
12635
|
|
|
12531
12636
|
export const statements: DDLStatement[] = [];
|
|
12532
12637
|
`;
|
|
@@ -12636,14 +12741,14 @@ function generateAlterTableStmts(prevTable, currTable, tableName, curr, statemen
|
|
|
12636
12741
|
const prevChk = prevTable.checkConstraints[chkName];
|
|
12637
12742
|
if (!prevChk) {
|
|
12638
12743
|
alterStatements.push(
|
|
12639
|
-
`.addCheck("${chkName}", ${
|
|
12744
|
+
`.addCheck("${chkName}", ${snapshotExprToCheckBuilderCode(currChk.expr)})`
|
|
12640
12745
|
);
|
|
12641
12746
|
} else {
|
|
12642
12747
|
const prevSql = snapshotExprToSQL(prevChk.expr);
|
|
12643
12748
|
const currSql = snapshotExprToSQL(currChk.expr);
|
|
12644
12749
|
if (prevSql !== currSql) {
|
|
12645
12750
|
alterStatements.push(
|
|
12646
|
-
`.addCheck("${chkName}", ${
|
|
12751
|
+
`.addCheck("${chkName}", ${snapshotExprToCheckBuilderCode(currChk.expr)})`
|
|
12647
12752
|
);
|
|
12648
12753
|
}
|
|
12649
12754
|
}
|
|
@@ -13498,7 +13603,7 @@ async function status(options) {
|
|
|
13498
13603
|
}
|
|
13499
13604
|
|
|
13500
13605
|
// src/cli/index.ts
|
|
13501
|
-
program.version("1.0.0-alpha.
|
|
13606
|
+
program.version("1.0.0-alpha.6");
|
|
13502
13607
|
var Options = {
|
|
13503
13608
|
config: ["--config <path>", "Path to the config file"]
|
|
13504
13609
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Key } from "../types.mjs";
|
|
2
|
-
import { Sql } from "../sql.mjs";
|
|
3
1
|
import { entityType } from "../symbols.mjs";
|
|
4
|
-
import {
|
|
2
|
+
import { Key } from "../types.mjs";
|
|
5
3
|
import { StdTableColumn, TableColumn } from "../table.mjs";
|
|
4
|
+
import { Arg } from "../query-builders/pre.mjs";
|
|
5
|
+
import { Sql } from "../sql.mjs";
|
|
6
6
|
import * as z from "zod";
|
|
7
7
|
|
|
8
8
|
//#region src/columns/common.d.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Sql } from "../sql.mjs";
|
|
2
|
-
import { Enum } from "../enumtype.mjs";
|
|
3
1
|
import { Column, ColumnConfig } from "./common.mjs";
|
|
2
|
+
import { Enum } from "../enumtype.mjs";
|
|
3
|
+
import { Sql } from "../sql.mjs";
|
|
4
4
|
import * as z from "zod";
|
|
5
5
|
|
|
6
6
|
//#region src/columns/enum.d.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SelfOrReadonly } from "../../../types.mjs";
|
|
2
|
-
import { Sql } from "../../../sql.mjs";
|
|
3
2
|
import { Column, ColumnConfig } from "../../common.mjs";
|
|
3
|
+
import { Sql } from "../../../sql.mjs";
|
|
4
4
|
import * as z from "zod";
|
|
5
5
|
|
|
6
6
|
//#region src/columns/postgis/geography/linestring.d.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SelfOrReadonly } from "../../../types.mjs";
|
|
2
|
-
import { Sql } from "../../../sql.mjs";
|
|
3
2
|
import { Column, ColumnConfig } from "../../common.mjs";
|
|
3
|
+
import { Sql } from "../../../sql.mjs";
|
|
4
4
|
import * as z from "zod";
|
|
5
5
|
|
|
6
6
|
//#region src/columns/postgis/geography/multilinestring.d.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SelfOrReadonly } from "../../../types.mjs";
|
|
2
|
-
import { Sql } from "../../../sql.mjs";
|
|
3
2
|
import { Column, ColumnConfig } from "../../common.mjs";
|
|
3
|
+
import { Sql } from "../../../sql.mjs";
|
|
4
4
|
import * as z from "zod";
|
|
5
5
|
|
|
6
6
|
//#region src/columns/postgis/geography/multipoint.d.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SelfOrReadonly } from "../../../types.mjs";
|
|
2
|
-
import { Sql } from "../../../sql.mjs";
|
|
3
2
|
import { Column, ColumnConfig } from "../../common.mjs";
|
|
3
|
+
import { Sql } from "../../../sql.mjs";
|
|
4
4
|
import * as z from "zod";
|
|
5
5
|
|
|
6
6
|
//#region src/columns/postgis/geography/multipolygon.d.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SelfOrReadonly } from "../../../types.mjs";
|
|
2
|
-
import { Sql } from "../../../sql.mjs";
|
|
3
2
|
import { Column, ColumnConfig } from "../../common.mjs";
|
|
3
|
+
import { Sql } from "../../../sql.mjs";
|
|
4
4
|
import * as z from "zod";
|
|
5
5
|
|
|
6
6
|
//#region src/columns/postgis/geography/point.d.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SelfOrReadonly } from "../../../types.mjs";
|
|
2
|
-
import { Sql } from "../../../sql.mjs";
|
|
3
2
|
import { Column, ColumnConfig } from "../../common.mjs";
|
|
3
|
+
import { Sql } from "../../../sql.mjs";
|
|
4
4
|
import * as z from "zod";
|
|
5
5
|
|
|
6
6
|
//#region src/columns/postgis/geography/polygon.d.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { StdTableColumn } from "../table.mjs";
|
|
2
|
+
import { Sql } from "../sql.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/constraints/check.d.ts
|
|
5
5
|
type ComparisonOp = "=" | "<>" | "<" | ">" | "<=" | ">=" | "IN" | "NOT IN";
|
|
@@ -7,7 +7,7 @@ type PatternOp = "LIKE" | "SIMILAR TO" | "~";
|
|
|
7
7
|
type LogicalOp = "AND" | "OR";
|
|
8
8
|
interface ComparisonExpr {
|
|
9
9
|
type: "comparison";
|
|
10
|
-
left:
|
|
10
|
+
left: StdTableColumn | FunctionExpr;
|
|
11
11
|
op: ComparisonOp | PatternOp;
|
|
12
12
|
right: unknown;
|
|
13
13
|
}
|
|
@@ -19,7 +19,7 @@ interface LogicalExpr {
|
|
|
19
19
|
interface FunctionExpr {
|
|
20
20
|
type: "function";
|
|
21
21
|
name: string;
|
|
22
|
-
args: (
|
|
22
|
+
args: (StdTableColumn | unknown)[];
|
|
23
23
|
}
|
|
24
24
|
interface RawExpr {
|
|
25
25
|
type: "raw";
|
|
@@ -62,24 +62,24 @@ interface SnapshotRawExpr {
|
|
|
62
62
|
}
|
|
63
63
|
type SnapshotCheckExpr = SnapshotComparisonExpr | SnapshotLogicalExpr | SnapshotFunctionExpr | SnapshotRawExpr;
|
|
64
64
|
declare class CheckBuilder {
|
|
65
|
-
eq<TCol extends
|
|
66
|
-
neq<TCol extends
|
|
67
|
-
gt<TCol extends
|
|
68
|
-
gte<TCol extends
|
|
69
|
-
lt<TCol extends
|
|
70
|
-
lte<TCol extends
|
|
71
|
-
like<TCol extends
|
|
72
|
-
similarTo<TCol extends
|
|
73
|
-
regex<TCol extends
|
|
74
|
-
in<TCol extends
|
|
75
|
-
notIn<TCol extends
|
|
65
|
+
eq<TCol extends StdTableColumn>(col: TCol, value: TCol["ValType"]): ComparisonExpr;
|
|
66
|
+
neq<TCol extends StdTableColumn>(col: TCol, value: TCol["ValType"]): ComparisonExpr;
|
|
67
|
+
gt<TCol extends StdTableColumn>(col: TCol, value: TCol["ValType"]): ComparisonExpr;
|
|
68
|
+
gte<TCol extends StdTableColumn>(col: TCol, value: TCol["ValType"]): ComparisonExpr;
|
|
69
|
+
lt<TCol extends StdTableColumn>(col: TCol, value: TCol["ValType"]): ComparisonExpr;
|
|
70
|
+
lte<TCol extends StdTableColumn>(col: TCol, value: TCol["ValType"]): ComparisonExpr;
|
|
71
|
+
like<TCol extends StdTableColumn>(col: TCol, pattern: string): ComparisonExpr;
|
|
72
|
+
similarTo<TCol extends StdTableColumn>(col: TCol, pattern: string): ComparisonExpr;
|
|
73
|
+
regex<TCol extends StdTableColumn>(col: TCol, pattern: string): ComparisonExpr;
|
|
74
|
+
in<TCol extends StdTableColumn>(col: TCol, values: TCol["ValType"][]): ComparisonExpr;
|
|
75
|
+
notIn<TCol extends StdTableColumn>(col: TCol, values: TCol["ValType"][]): ComparisonExpr;
|
|
76
76
|
and(...expressions: CheckExpr[]): LogicalExpr;
|
|
77
77
|
or(...expressions: CheckExpr[]): LogicalExpr;
|
|
78
|
-
length<TCol extends
|
|
79
|
-
lower<TCol extends
|
|
80
|
-
upper<TCol extends
|
|
81
|
-
trim<TCol extends
|
|
82
|
-
coalesce<TCol extends
|
|
78
|
+
length<TCol extends StdTableColumn>(col: TCol): FunctionExpr;
|
|
79
|
+
lower<TCol extends StdTableColumn>(col: TCol): FunctionExpr;
|
|
80
|
+
upper<TCol extends StdTableColumn>(col: TCol): FunctionExpr;
|
|
81
|
+
trim<TCol extends StdTableColumn>(col: TCol): FunctionExpr;
|
|
82
|
+
coalesce<TCol extends StdTableColumn>(col: TCol, defaultValue: TCol["ValType"]): FunctionExpr;
|
|
83
83
|
fnEq(fn: FunctionExpr, value: unknown): ComparisonExpr;
|
|
84
84
|
fnNeq(fn: FunctionExpr, value: unknown): ComparisonExpr;
|
|
85
85
|
fnGt(fn: FunctionExpr, value: number): ComparisonExpr;
|
|
@@ -96,5 +96,87 @@ declare class Check {
|
|
|
96
96
|
getExpression(): string;
|
|
97
97
|
toSnapshotExpr(): SnapshotCheckExpr;
|
|
98
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Callback type for check expressions in migration DDL builders.
|
|
101
|
+
* Receives a {@link MigrationCheckBuilder} and returns a {@link SnapshotCheckExpr}.
|
|
102
|
+
*/
|
|
103
|
+
type MigrationCheckExprCallback = (builder: MigrationCheckBuilder) => SnapshotCheckExpr;
|
|
104
|
+
/**
|
|
105
|
+
* A check-expression builder for use inside migration files.
|
|
106
|
+
*
|
|
107
|
+
* Unlike {@link CheckBuilder}, which works with live {@link TableColumn} objects,
|
|
108
|
+
* this builder accepts column names as strings and values as {@link Sql} instances.
|
|
109
|
+
* It returns {@link SnapshotCheckExpr} objects directly, which are stored by
|
|
110
|
+
* {@link CreateTableBuilder} / {@link AlterTableBuilder} and rendered to SQL
|
|
111
|
+
* via {@link snapshotExprToSQL}.
|
|
112
|
+
*
|
|
113
|
+
* Because all methods are stateless, destructuring is safe:
|
|
114
|
+
* ```typescript
|
|
115
|
+
* .check("positive_price", ({ gt }) => gt("price", sql`0`))
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
declare class MigrationCheckBuilder {
|
|
119
|
+
#private;
|
|
120
|
+
/** `col = value` */
|
|
121
|
+
eq: (col: string, value: Sql) => SnapshotComparisonExpr;
|
|
122
|
+
/** `col <> value` */
|
|
123
|
+
neq: (col: string, value: Sql) => SnapshotComparisonExpr;
|
|
124
|
+
/** `col > value` */
|
|
125
|
+
gt: (col: string, value: Sql) => SnapshotComparisonExpr;
|
|
126
|
+
/** `col >= value` */
|
|
127
|
+
gte: (col: string, value: Sql) => SnapshotComparisonExpr;
|
|
128
|
+
/** `col < value` */
|
|
129
|
+
lt: (col: string, value: Sql) => SnapshotComparisonExpr;
|
|
130
|
+
/** `col <= value` */
|
|
131
|
+
lte: (col: string, value: Sql) => SnapshotComparisonExpr;
|
|
132
|
+
/** `col LIKE pattern` */
|
|
133
|
+
like: (col: string, value: Sql) => SnapshotComparisonExpr;
|
|
134
|
+
/** `col SIMILAR TO pattern` */
|
|
135
|
+
similarTo: (col: string, value: Sql) => SnapshotComparisonExpr;
|
|
136
|
+
/** `col ~ pattern` */
|
|
137
|
+
regex: (col: string, value: Sql) => SnapshotComparisonExpr;
|
|
138
|
+
/**
|
|
139
|
+
* `col IN (...)` — pass the full tuple as a single sql literal:
|
|
140
|
+
* ```typescript
|
|
141
|
+
* in("status", sql`('active', 'pending')`)
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
in: (col: string, value: Sql) => SnapshotComparisonExpr;
|
|
145
|
+
/**
|
|
146
|
+
* `col NOT IN (...)` — pass the full tuple as a single sql literal:
|
|
147
|
+
* ```typescript
|
|
148
|
+
* notIn("status", sql`('archived', 'deleted')`)
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
notIn: (col: string, value: Sql) => SnapshotComparisonExpr;
|
|
152
|
+
/** `(expr1 AND expr2 ...)` */
|
|
153
|
+
and: (...expressions: SnapshotCheckExpr[]) => SnapshotLogicalExpr;
|
|
154
|
+
/** `(expr1 OR expr2 ...)` */
|
|
155
|
+
or: (...expressions: SnapshotCheckExpr[]) => SnapshotLogicalExpr;
|
|
156
|
+
/** `length(col)` */
|
|
157
|
+
length: (col: string) => SnapshotFunctionExpr;
|
|
158
|
+
/** `lower(col)` */
|
|
159
|
+
lower: (col: string) => SnapshotFunctionExpr;
|
|
160
|
+
/** `upper(col)` */
|
|
161
|
+
upper: (col: string) => SnapshotFunctionExpr;
|
|
162
|
+
/** `trim(col)` */
|
|
163
|
+
trim: (col: string) => SnapshotFunctionExpr;
|
|
164
|
+
/** `coalesce(col, default)` */
|
|
165
|
+
coalesce: (col: string, value: Sql) => SnapshotFunctionExpr;
|
|
166
|
+
/** `fn(col) = value` */
|
|
167
|
+
fnEq: (fn: SnapshotFunctionExpr, value: Sql) => SnapshotComparisonExpr;
|
|
168
|
+
/** `fn(col) <> value` */
|
|
169
|
+
fnNeq: (fn: SnapshotFunctionExpr, value: Sql) => SnapshotComparisonExpr;
|
|
170
|
+
/** `fn(col) > value` */
|
|
171
|
+
fnGt: (fn: SnapshotFunctionExpr, value: Sql) => SnapshotComparisonExpr;
|
|
172
|
+
/** `fn(col) >= value` */
|
|
173
|
+
fnGte: (fn: SnapshotFunctionExpr, value: Sql) => SnapshotComparisonExpr;
|
|
174
|
+
/** `fn(col) < value` */
|
|
175
|
+
fnLt: (fn: SnapshotFunctionExpr, value: Sql) => SnapshotComparisonExpr;
|
|
176
|
+
/** `fn(col) <= value` */
|
|
177
|
+
fnLte: (fn: SnapshotFunctionExpr, value: Sql) => SnapshotComparisonExpr;
|
|
178
|
+
/** Emit a raw SQL expression verbatim. */
|
|
179
|
+
raw: (sql: string) => SnapshotRawExpr;
|
|
180
|
+
}
|
|
99
181
|
//#endregion
|
|
100
|
-
export { Check, CheckBuilder, CheckExpr, SnapshotCheckExpr };
|
|
182
|
+
export { Check, CheckBuilder, CheckExpr, MigrationCheckBuilder, MigrationCheckExprCallback, SnapshotCheckExpr };
|
|
@@ -327,5 +327,181 @@ function snapshotExprToSQL(expr) {
|
|
|
327
327
|
}
|
|
328
328
|
throw new Error("Unknown expression type");
|
|
329
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* A check-expression builder for use inside migration files.
|
|
332
|
+
*
|
|
333
|
+
* Unlike {@link CheckBuilder}, which works with live {@link TableColumn} objects,
|
|
334
|
+
* this builder accepts column names as strings and values as {@link Sql} instances.
|
|
335
|
+
* It returns {@link SnapshotCheckExpr} objects directly, which are stored by
|
|
336
|
+
* {@link CreateTableBuilder} / {@link AlterTableBuilder} and rendered to SQL
|
|
337
|
+
* via {@link snapshotExprToSQL}.
|
|
338
|
+
*
|
|
339
|
+
* Because all methods are stateless, destructuring is safe:
|
|
340
|
+
* ```typescript
|
|
341
|
+
* .check("positive_price", ({ gt }) => gt("price", sql`0`))
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
var MigrationCheckBuilder = class {
|
|
345
|
+
/** Builds a column-comparison snapshot node. */
|
|
346
|
+
#colComparison = (col, op, value) => {
|
|
347
|
+
return {
|
|
348
|
+
type: "comparison",
|
|
349
|
+
left: {
|
|
350
|
+
type: "col",
|
|
351
|
+
name: col
|
|
352
|
+
},
|
|
353
|
+
op,
|
|
354
|
+
right: value.toSQL()
|
|
355
|
+
};
|
|
356
|
+
};
|
|
357
|
+
/** Builds a function-comparison snapshot node. */
|
|
358
|
+
#fnComparison = (fn, op, value) => {
|
|
359
|
+
return {
|
|
360
|
+
type: "comparison",
|
|
361
|
+
left: fn,
|
|
362
|
+
op,
|
|
363
|
+
right: value.toSQL()
|
|
364
|
+
};
|
|
365
|
+
};
|
|
366
|
+
/** `col = value` */
|
|
367
|
+
eq = (col, value) => {
|
|
368
|
+
return this.#colComparison(col, "=", value);
|
|
369
|
+
};
|
|
370
|
+
/** `col <> value` */
|
|
371
|
+
neq = (col, value) => {
|
|
372
|
+
return this.#colComparison(col, "<>", value);
|
|
373
|
+
};
|
|
374
|
+
/** `col > value` */
|
|
375
|
+
gt = (col, value) => {
|
|
376
|
+
return this.#colComparison(col, ">", value);
|
|
377
|
+
};
|
|
378
|
+
/** `col >= value` */
|
|
379
|
+
gte = (col, value) => {
|
|
380
|
+
return this.#colComparison(col, ">=", value);
|
|
381
|
+
};
|
|
382
|
+
/** `col < value` */
|
|
383
|
+
lt = (col, value) => {
|
|
384
|
+
return this.#colComparison(col, "<", value);
|
|
385
|
+
};
|
|
386
|
+
/** `col <= value` */
|
|
387
|
+
lte = (col, value) => {
|
|
388
|
+
return this.#colComparison(col, "<=", value);
|
|
389
|
+
};
|
|
390
|
+
/** `col LIKE pattern` */
|
|
391
|
+
like = (col, value) => {
|
|
392
|
+
return this.#colComparison(col, "LIKE", value);
|
|
393
|
+
};
|
|
394
|
+
/** `col SIMILAR TO pattern` */
|
|
395
|
+
similarTo = (col, value) => {
|
|
396
|
+
return this.#colComparison(col, "SIMILAR TO", value);
|
|
397
|
+
};
|
|
398
|
+
/** `col ~ pattern` */
|
|
399
|
+
regex = (col, value) => {
|
|
400
|
+
return this.#colComparison(col, "~", value);
|
|
401
|
+
};
|
|
402
|
+
/**
|
|
403
|
+
* `col IN (...)` — pass the full tuple as a single sql literal:
|
|
404
|
+
* ```typescript
|
|
405
|
+
* in("status", sql`('active', 'pending')`)
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
in = (col, value) => {
|
|
409
|
+
return this.#colComparison(col, "IN", value);
|
|
410
|
+
};
|
|
411
|
+
/**
|
|
412
|
+
* `col NOT IN (...)` — pass the full tuple as a single sql literal:
|
|
413
|
+
* ```typescript
|
|
414
|
+
* notIn("status", sql`('archived', 'deleted')`)
|
|
415
|
+
* ```
|
|
416
|
+
*/
|
|
417
|
+
notIn = (col, value) => {
|
|
418
|
+
return this.#colComparison(col, "NOT IN", value);
|
|
419
|
+
};
|
|
420
|
+
/** `(expr1 AND expr2 ...)` */
|
|
421
|
+
and = (...expressions) => {
|
|
422
|
+
return {
|
|
423
|
+
type: "logical",
|
|
424
|
+
op: "AND",
|
|
425
|
+
expressions
|
|
426
|
+
};
|
|
427
|
+
};
|
|
428
|
+
/** `(expr1 OR expr2 ...)` */
|
|
429
|
+
or = (...expressions) => {
|
|
430
|
+
return {
|
|
431
|
+
type: "logical",
|
|
432
|
+
op: "OR",
|
|
433
|
+
expressions
|
|
434
|
+
};
|
|
435
|
+
};
|
|
436
|
+
/** Builds a single-column function snapshot node. */
|
|
437
|
+
#colFn = (name, col) => {
|
|
438
|
+
return {
|
|
439
|
+
type: "function",
|
|
440
|
+
name,
|
|
441
|
+
args: [{
|
|
442
|
+
type: "col",
|
|
443
|
+
name: col
|
|
444
|
+
}]
|
|
445
|
+
};
|
|
446
|
+
};
|
|
447
|
+
/** `length(col)` */
|
|
448
|
+
length = (col) => {
|
|
449
|
+
return this.#colFn("length", col);
|
|
450
|
+
};
|
|
451
|
+
/** `lower(col)` */
|
|
452
|
+
lower = (col) => {
|
|
453
|
+
return this.#colFn("lower", col);
|
|
454
|
+
};
|
|
455
|
+
/** `upper(col)` */
|
|
456
|
+
upper = (col) => {
|
|
457
|
+
return this.#colFn("upper", col);
|
|
458
|
+
};
|
|
459
|
+
/** `trim(col)` */
|
|
460
|
+
trim = (col) => {
|
|
461
|
+
return this.#colFn("trim", col);
|
|
462
|
+
};
|
|
463
|
+
/** `coalesce(col, default)` */
|
|
464
|
+
coalesce = (col, value) => {
|
|
465
|
+
return {
|
|
466
|
+
type: "function",
|
|
467
|
+
name: "coalesce",
|
|
468
|
+
args: [{
|
|
469
|
+
type: "col",
|
|
470
|
+
name: col
|
|
471
|
+
}, value.toSQL()]
|
|
472
|
+
};
|
|
473
|
+
};
|
|
474
|
+
/** `fn(col) = value` */
|
|
475
|
+
fnEq = (fn, value) => {
|
|
476
|
+
return this.#fnComparison(fn, "=", value);
|
|
477
|
+
};
|
|
478
|
+
/** `fn(col) <> value` */
|
|
479
|
+
fnNeq = (fn, value) => {
|
|
480
|
+
return this.#fnComparison(fn, "<>", value);
|
|
481
|
+
};
|
|
482
|
+
/** `fn(col) > value` */
|
|
483
|
+
fnGt = (fn, value) => {
|
|
484
|
+
return this.#fnComparison(fn, ">", value);
|
|
485
|
+
};
|
|
486
|
+
/** `fn(col) >= value` */
|
|
487
|
+
fnGte = (fn, value) => {
|
|
488
|
+
return this.#fnComparison(fn, ">=", value);
|
|
489
|
+
};
|
|
490
|
+
/** `fn(col) < value` */
|
|
491
|
+
fnLt = (fn, value) => {
|
|
492
|
+
return this.#fnComparison(fn, "<", value);
|
|
493
|
+
};
|
|
494
|
+
/** `fn(col) <= value` */
|
|
495
|
+
fnLte = (fn, value) => {
|
|
496
|
+
return this.#fnComparison(fn, "<=", value);
|
|
497
|
+
};
|
|
498
|
+
/** Emit a raw SQL expression verbatim. */
|
|
499
|
+
raw = (sql) => {
|
|
500
|
+
return {
|
|
501
|
+
type: "raw",
|
|
502
|
+
sql
|
|
503
|
+
};
|
|
504
|
+
};
|
|
505
|
+
};
|
|
330
506
|
//#endregion
|
|
331
|
-
export { CheckBuilder, check, snapshotExprToSQL };
|
|
507
|
+
export { CheckBuilder, MigrationCheckBuilder, check, snapshotExprToSQL };
|
package/dist/src/db.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AnyColumn, AnyRelations, IsTableWC, Relations, TColsToLeftRight, TableWCorNever, TableWithColumns } from "./table.mjs";
|
|
1
2
|
import { SelectBuilder } from "./query-builders/select.mjs";
|
|
2
3
|
import { BuildFilterExpression } from "./filters/index.mjs";
|
|
3
4
|
import { Config } from "./index.mjs";
|
|
@@ -12,7 +13,6 @@ import { InsertReturningQuery } from "./query-builders/insert-returning.mjs";
|
|
|
12
13
|
import { RawQuery } from "./query-builders/raw.mjs";
|
|
13
14
|
import { RelationQueryBuilder } from "./query-builders/rq.mjs";
|
|
14
15
|
import { UpdateBuilder } from "./query-builders/update.mjs";
|
|
15
|
-
import { AnyColumn, AnyRelations, IsTableWC, Relations, TColsToLeftRight, TableWCorNever, TableWithColumns } from "./table.mjs";
|
|
16
16
|
import { $Pool, QueryExecutor } from "./connectors/common.mjs";
|
|
17
17
|
|
|
18
18
|
//#region src/db.d.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Query } from "../query-builders/query.mjs";
|
|
2
|
-
import { Filter } from "./custom.mjs";
|
|
3
1
|
import { AnyColumn, TableColumn } from "../table.mjs";
|
|
2
|
+
import { Filter } from "./custom.mjs";
|
|
3
|
+
import { Query } from "../query-builders/query.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/filters/array.d.ts
|
|
6
6
|
/** Shorthand for the Filter's TableColumn constraint. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Query } from "../query-builders/query.mjs";
|
|
2
1
|
import { AnyColumn, TableColumn } from "../table.mjs";
|
|
2
|
+
import { Query } from "../query-builders/query.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/filters/custom.d.ts
|
|
5
5
|
/** Abstract base class for SQL filter expressions used in `WHERE`/`ON` clauses. */
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Query } from "../query-builders/query.mjs";
|
|
2
1
|
import { Key } from "../types.mjs";
|
|
2
|
+
import { AnyColumn, AnyTableWithColumns, TColsToLeftRight, TableColumn, TableColumnArgs } from "../table.mjs";
|
|
3
3
|
import { SelectQuery } from "../query-builders/select.mjs";
|
|
4
|
-
import { Sql } from "../sql.mjs";
|
|
5
4
|
import { Filter } from "./custom.mjs";
|
|
6
5
|
import { Arg } from "../query-builders/pre.mjs";
|
|
7
|
-
import {
|
|
6
|
+
import { Query } from "../query-builders/query.mjs";
|
|
7
|
+
import { Sql } from "../sql.mjs";
|
|
8
8
|
|
|
9
9
|
//#region src/filters/index.d.ts
|
|
10
10
|
type ConditionExpression<Left extends TableColumnArgs, Right extends Record<string, TableColumnArgs>, TArg extends boolean = false> = EqualValCondition<Left[0], Left[1], Left[2], Left[3], Left[3]["ValType"]> | (TArg extends true ? EqualValCondition<Left[0], Left[1], Left[2], Left[3], Arg<Left[3]["ValType"]>> : never) | { [RightKey in keyof Right]: EqualColCondition<Left[0], Left[1], Left[2], Left[3], Right[RightKey][0], Right[RightKey][1], Right[RightKey][2], Right[RightKey][3]> }[keyof Right] | GreaterEqualValCondition<Left[0], Left[1], Left[2], Left[3], Left[3]["ValType"] | (TArg extends true ? Arg<Left[3]["ValType"]> : never)> | { [RightKey in keyof Right]: GreaterEqualColCondition<Left[0], Left[1], Left[2], Left[3], Right[RightKey][0], Right[RightKey][1], Right[RightKey][2], Right[RightKey][3]> }[keyof Right] | GreaterThanValCondition<Left[0], Left[1], Left[2], Left[3], Left[3]["ValType"] | (TArg extends true ? Arg<Left[3]["ValType"]> : never)> | { [RightKey in keyof Right]: GreaterThanColCondition<Left[0], Left[1], Left[2], Left[3], Right[RightKey][0], Right[RightKey][1], Right[RightKey][2], Right[RightKey][3]> }[keyof Right] | LessThanValCondition<Left[0], Left[1], Left[2], Left[3], Left[3]["ValType"] | (TArg extends true ? Arg<Left[3]["ValType"]> : never)> | { [RightKey in keyof Right]: LessThanColCondition<Left[0], Left[1], Left[2], Left[3], Right[RightKey][0], Right[RightKey][1], Right[RightKey][2], Right[RightKey][3]> }[keyof Right] | LessEqualValCondition<Left[0], Left[1], Left[2], Left[3], Left[3]["ValType"] | (TArg extends true ? Arg<Left[3]["ValType"]> : never)> | { [RightKey in keyof Right]: LessEqualColCondition<Left[0], Left[1], Left[2], Left[3], Right[RightKey][0], Right[RightKey][1], Right[RightKey][2], Right[RightKey][3]> }[keyof Right] | IsNullCondition<Left[0], Left[1], Left[2], Left[3]> | InCondition<Left[0], Left[1], Left[2], Left[3], TArg>;
|
package/dist/src/index.d.mts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { DurcnoLogger } from "./logger.mjs";
|
|
2
|
-
import { Query } from "./query-builders/query.mjs";
|
|
3
2
|
import { Is, Key, Prettify, SelfOrArray, SelfOrReadonly, UnionToIntersection, Valueof } from "./types.mjs";
|
|
3
|
+
import { Column, ColumnConfig, notNull, primaryKey, unique } from "./columns/common.mjs";
|
|
4
|
+
import { PrimaryKeyConstraint, primaryKeyConstraint } from "./constraints/primary-key.mjs";
|
|
5
|
+
import { UniqueConstraint, uniqueConstraint } from "./constraints/unique.mjs";
|
|
6
|
+
import { index, uniqueIndex } from "./indexes.mjs";
|
|
7
|
+
import { AnyColumn, AnyTableColumn, Table, TableColumn, fk, many, one, relations, table } from "./table.mjs";
|
|
4
8
|
import { asc, desc } from "./query-builders/orderby-clause.mjs";
|
|
5
|
-
import { Sql, sql } from "./sql.mjs";
|
|
6
9
|
import { Filter } from "./filters/custom.mjs";
|
|
7
10
|
import { and, eq, gt, gte, isIn, isNotNull, isNull, lt, lte, ne, or } from "./filters/index.mjs";
|
|
8
11
|
import { Sequence, SequenceOptions, sequence } from "./sequence.mjs";
|
|
@@ -30,16 +33,13 @@ import { time } from "./columns/time.mjs";
|
|
|
30
33
|
import { timestamp } from "./columns/timestamp.mjs";
|
|
31
34
|
import { UuidVersion, uuid } from "./columns/uuid.mjs";
|
|
32
35
|
import { varchar } from "./columns/varchar.mjs";
|
|
33
|
-
import { PrimaryKeyConstraint, primaryKeyConstraint } from "./constraints/primary-key.mjs";
|
|
34
|
-
import { UniqueConstraint, uniqueConstraint } from "./constraints/unique.mjs";
|
|
35
36
|
import { arrayAll, arrayContainedBy, arrayContains, arrayHas, arrayOverlaps } from "./filters/array.mjs";
|
|
36
37
|
import { now, uuidv4, uuidv7 } from "./functions/index.mjs";
|
|
37
|
-
import { index, uniqueIndex } from "./indexes.mjs";
|
|
38
38
|
import { Migrations, pk } from "./models.mjs";
|
|
39
39
|
import { database } from "./db.mjs";
|
|
40
40
|
import { Arg, prequery } from "./query-builders/pre.mjs";
|
|
41
|
-
import {
|
|
42
|
-
import {
|
|
41
|
+
import { Query } from "./query-builders/query.mjs";
|
|
42
|
+
import { Sql, sql } from "./sql.mjs";
|
|
43
43
|
import { $Client, Connector, ConnectorOptions } from "./connectors/common.mjs";
|
|
44
44
|
|
|
45
45
|
//#region src/index.d.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OnDeleteAction } from "../../columns/common.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { MigrationCheckExprCallback } from "../../constraints/check.mjs";
|
|
3
3
|
import { Snapshot } from "../snapshot.mjs";
|
|
4
4
|
import { DDLStatement } from "./statement.mjs";
|
|
5
5
|
|
|
@@ -7,7 +7,7 @@ import { DDLStatement } from "./statement.mjs";
|
|
|
7
7
|
/**
|
|
8
8
|
* Defines a foreign-key reference from a column to another table's column.
|
|
9
9
|
*
|
|
10
|
-
* @see {@link ColumnOptions
|
|
10
|
+
* @see {@link ColumnOptions["references"]}
|
|
11
11
|
*/
|
|
12
12
|
interface ColumnReference {
|
|
13
13
|
/** Schema of the referenced table. */
|
|
@@ -82,11 +82,16 @@ declare class CreateTableBuilder extends DDLStatement {
|
|
|
82
82
|
/**
|
|
83
83
|
* Add a CHECK constraint to the table.
|
|
84
84
|
*
|
|
85
|
+
* Mirrors the `checkConstraints` schema API:
|
|
86
|
+
* ```typescript
|
|
87
|
+
* .check("positive_price", ({ gt }) => gt("price", sql`0`))
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
85
90
|
* @param chkName - Constraint name.
|
|
86
|
-
* @param expr -
|
|
91
|
+
* @param expr - A callback receiving {@link MigrationCheckBuilder}.
|
|
87
92
|
* @returns `this` for chaining.
|
|
88
93
|
*/
|
|
89
|
-
check(chkName: string, expr:
|
|
94
|
+
check(chkName: string, expr: MigrationCheckExprCallback): this;
|
|
90
95
|
/**
|
|
91
96
|
* Add a table-level UNIQUE constraint spanning one or more columns.
|
|
92
97
|
*
|
|
@@ -260,11 +265,16 @@ declare class AlterTableBuilder extends DDLStatement {
|
|
|
260
265
|
/**
|
|
261
266
|
* Add a CHECK constraint to the table.
|
|
262
267
|
*
|
|
268
|
+
* Mirrors the `checkConstraints` schema API:
|
|
269
|
+
* ```typescript
|
|
270
|
+
* .addCheck("max_price", ({ lt }) => lt("price", sql`1000000`))
|
|
271
|
+
* ```
|
|
272
|
+
*
|
|
263
273
|
* @param name - Constraint name.
|
|
264
|
-
* @param expr -
|
|
274
|
+
* @param expr - A callback receiving {@link MigrationCheckBuilder}.
|
|
265
275
|
* @returns `this` for chaining.
|
|
266
276
|
*/
|
|
267
|
-
addCheck(name: string, expr:
|
|
277
|
+
addCheck(name: string, expr: MigrationCheckExprCallback): this;
|
|
268
278
|
/**
|
|
269
279
|
* Add a table-level UNIQUE constraint spanning one or more columns.
|
|
270
280
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { MigrationCheckBuilder, snapshotExprToSQL } from "../../constraints/check.mjs";
|
|
1
2
|
import { DDLStatement } from "./statement.mjs";
|
|
2
|
-
import { snapshotExprToSQL } from "../../constraints/check.mjs";
|
|
3
3
|
//#region src/migration/ddl/table.ts
|
|
4
4
|
/**
|
|
5
5
|
* Generates a SQL column definition string from column metadata.
|
|
@@ -68,14 +68,19 @@ var CreateTableBuilder = class extends DDLStatement {
|
|
|
68
68
|
/**
|
|
69
69
|
* Add a CHECK constraint to the table.
|
|
70
70
|
*
|
|
71
|
+
* Mirrors the `checkConstraints` schema API:
|
|
72
|
+
* ```typescript
|
|
73
|
+
* .check("positive_price", ({ gt }) => gt("price", sql`0`))
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
71
76
|
* @param chkName - Constraint name.
|
|
72
|
-
* @param expr -
|
|
77
|
+
* @param expr - A callback receiving {@link MigrationCheckBuilder}.
|
|
73
78
|
* @returns `this` for chaining.
|
|
74
79
|
*/
|
|
75
80
|
check(chkName, expr) {
|
|
76
81
|
this.checks.push({
|
|
77
82
|
name: chkName,
|
|
78
|
-
expr
|
|
83
|
+
expr: expr(new MigrationCheckBuilder())
|
|
79
84
|
});
|
|
80
85
|
return this;
|
|
81
86
|
}
|
|
@@ -412,15 +417,20 @@ var AlterTableBuilder = class extends DDLStatement {
|
|
|
412
417
|
/**
|
|
413
418
|
* Add a CHECK constraint to the table.
|
|
414
419
|
*
|
|
420
|
+
* Mirrors the `checkConstraints` schema API:
|
|
421
|
+
* ```typescript
|
|
422
|
+
* .addCheck("max_price", ({ lt }) => lt("price", sql`1000000`))
|
|
423
|
+
* ```
|
|
424
|
+
*
|
|
415
425
|
* @param name - Constraint name.
|
|
416
|
-
* @param expr -
|
|
426
|
+
* @param expr - A callback receiving {@link MigrationCheckBuilder}.
|
|
417
427
|
* @returns `this` for chaining.
|
|
418
428
|
*/
|
|
419
429
|
addCheck(name, expr) {
|
|
420
430
|
this.actions.push({
|
|
421
431
|
type: "addCheck",
|
|
422
432
|
name,
|
|
423
|
-
expr
|
|
433
|
+
expr: expr(new MigrationCheckBuilder())
|
|
424
434
|
});
|
|
425
435
|
return this;
|
|
426
436
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { sql } from "../sql.mjs";
|
|
2
|
+
import { MigrationCheckBuilder, MigrationCheckExprCallback } from "../constraints/check.mjs";
|
|
1
3
|
import { MIGRATION_NAME_REGEX } from "./consts.mjs";
|
|
2
4
|
import { Snapshot, SnapshotColumn, SnapshotColumnRef, SnapshotEnum, SnapshotSequence, SnapshotTable, SnapshotTableCheck, SnapshotTableIndex, SnapshotTablePrimaryKey, SnapshotTableUnique, createEmptySnapshot, snapshot } from "./snapshot.mjs";
|
|
3
5
|
import { CustomStatement, DDLStatement } from "./ddl/statement.mjs";
|
|
@@ -14,4 +16,4 @@ interface MigrationOptions {
|
|
|
14
16
|
execution?: "joined" | "sequential";
|
|
15
17
|
}
|
|
16
18
|
//#endregion
|
|
17
|
-
export { CustomStatement, DDLStatement, MIGRATION_NAME_REGEX, MigrationOptions, type Snapshot, type SnapshotColumn, type SnapshotColumnRef, type SnapshotEnum, type SnapshotSequence, type SnapshotTable, type SnapshotTableCheck, type SnapshotTableIndex, type SnapshotTablePrimaryKey, type SnapshotTableUnique, createEmptySnapshot, ddl, snapshot };
|
|
19
|
+
export { CustomStatement, DDLStatement, MIGRATION_NAME_REGEX, MigrationCheckBuilder, type MigrationCheckExprCallback, MigrationOptions, type Snapshot, type SnapshotColumn, type SnapshotColumnRef, type SnapshotEnum, type SnapshotSequence, type SnapshotTable, type SnapshotTableCheck, type SnapshotTableIndex, type SnapshotTablePrimaryKey, type SnapshotTableUnique, createEmptySnapshot, ddl, snapshot, sql };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { sql } from "../sql.mjs";
|
|
2
|
+
import { MigrationCheckBuilder } from "../constraints/check.mjs";
|
|
1
3
|
import { MIGRATION_NAME_REGEX } from "./consts.mjs";
|
|
2
4
|
import { CustomStatement, DDLStatement } from "./ddl/statement.mjs";
|
|
3
5
|
import { ddl } from "./ddl/index.mjs";
|
|
4
6
|
import { createEmptySnapshot, snapshot } from "./snapshot.mjs";
|
|
5
|
-
export { CustomStatement, DDLStatement, MIGRATION_NAME_REGEX, createEmptySnapshot, ddl, snapshot };
|
|
7
|
+
export { CustomStatement, DDLStatement, MIGRATION_NAME_REGEX, MigrationCheckBuilder, createEmptySnapshot, ddl, snapshot, sql };
|
package/dist/src/models.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { TableWithColumns } from "./table.mjs";
|
|
1
2
|
import { BigintColumn } from "./columns/bigint.mjs";
|
|
2
3
|
import { TimestampColumn } from "./columns/timestamp.mjs";
|
|
3
4
|
import { VarcharColumn } from "./columns/varchar.mjs";
|
|
4
|
-
import { TableWithColumns } from "./table.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/models.d.ts
|
|
7
7
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Query } from "./query.mjs";
|
|
2
1
|
import { Key } from "../types.mjs";
|
|
2
|
+
import { AnyColumn, TColsToLeftRight, TableColumn, TableWithColumns } from "../table.mjs";
|
|
3
3
|
import { QueryPromise } from "./query-promise.mjs";
|
|
4
4
|
import { BuildFilterExpression } from "../filters/index.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { Query } from "./query.mjs";
|
|
6
6
|
import { QueryExecutor } from "../connectors/common.mjs";
|
|
7
7
|
|
|
8
8
|
//#region src/query-builders/aggregates.d.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyColumn, TColsToLeftRight, TableWithColumns } from "../table.mjs";
|
|
2
2
|
import { QueryPromise } from "./query-promise.mjs";
|
|
3
3
|
import { BuildFilterExpression } from "../filters/index.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { Query } from "./query.mjs";
|
|
5
5
|
import { QueryExecutor } from "../connectors/common.mjs";
|
|
6
6
|
|
|
7
7
|
//#region src/query-builders/count.d.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Query } from "./query.mjs";
|
|
2
1
|
import { Key } from "../types.mjs";
|
|
2
|
+
import { AnyColumn, TColsToLeftRight, TableWithColumns } from "../table.mjs";
|
|
3
3
|
import { QueryPromise } from "./query-promise.mjs";
|
|
4
4
|
import { BuildFilterExpression } from "../filters/index.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { Query } from "./query.mjs";
|
|
6
6
|
import { QueryExecutor } from "../connectors/common.mjs";
|
|
7
7
|
|
|
8
8
|
//#region src/query-builders/delete.d.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Query } from "./query.mjs";
|
|
2
1
|
import { Key } from "../types.mjs";
|
|
2
|
+
import { AnyColumn, TColsToLeftRight, TableColumn, TableWithColumns } from "../table.mjs";
|
|
3
3
|
import { QueryPromise } from "./query-promise.mjs";
|
|
4
4
|
import { BuildFilterExpression } from "../filters/index.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { Query } from "./query.mjs";
|
|
6
6
|
import { QueryExecutor } from "../connectors/common.mjs";
|
|
7
7
|
|
|
8
8
|
//#region src/query-builders/distinct.d.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyColumn, TColsToLeftRight, TableWithColumns } from "../table.mjs";
|
|
2
2
|
import { QueryPromise } from "./query-promise.mjs";
|
|
3
3
|
import { BuildFilterExpression } from "../filters/index.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { Query } from "./query.mjs";
|
|
5
5
|
import { QueryExecutor } from "../connectors/common.mjs";
|
|
6
6
|
|
|
7
7
|
//#region src/query-builders/exists.d.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyColumn, TColsToLeftRight, TableWithColumns } from "../table.mjs";
|
|
2
2
|
import { QueryPromise } from "./query-promise.mjs";
|
|
3
3
|
import { BuildFilterExpression } from "../filters/index.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { Query } from "./query.mjs";
|
|
5
5
|
import { QueryExecutor } from "../connectors/common.mjs";
|
|
6
6
|
|
|
7
7
|
//#region src/query-builders/first.d.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Query } from "./query.mjs";
|
|
2
|
-
import { QueryPromise } from "./query-promise.mjs";
|
|
3
1
|
import { AnyColumn, TableWithColumns } from "../table.mjs";
|
|
2
|
+
import { QueryPromise } from "./query-promise.mjs";
|
|
3
|
+
import { Query } from "./query.mjs";
|
|
4
4
|
import { QueryExecutor } from "../connectors/common.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/query-builders/insert-returning.d.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Query } from "./query.mjs";
|
|
2
1
|
import { Key } from "../types.mjs";
|
|
3
|
-
import { QueryPromise } from "./query-promise.mjs";
|
|
4
2
|
import { AnyColumn, TableWithColumns } from "../table.mjs";
|
|
3
|
+
import { QueryPromise } from "./query-promise.mjs";
|
|
4
|
+
import { Query } from "./query.mjs";
|
|
5
5
|
import { QueryExecutor } from "../connectors/common.mjs";
|
|
6
6
|
|
|
7
7
|
//#region src/query-builders/insert.d.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Query } from "./query.mjs";
|
|
2
|
-
import { QueryPromise } from "./query-promise.mjs";
|
|
3
1
|
import { entityType } from "../symbols.mjs";
|
|
2
|
+
import { QueryPromise } from "./query-promise.mjs";
|
|
4
3
|
import { AnyDBorTX } from "../db.mjs";
|
|
4
|
+
import { Query } from "./query.mjs";
|
|
5
5
|
import { QueryExecutor } from "../connectors/common.mjs";
|
|
6
6
|
|
|
7
7
|
//#region src/query-builders/pre.d.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyColumn, AnyRelation, Fk, Many, Relations, StdRelations, TColsToLeftRight, TableWithColumns } from "../table.mjs";
|
|
2
2
|
import { OrderBy } from "./orderby-clause.mjs";
|
|
3
3
|
import { QueryPromise } from "./query-promise.mjs";
|
|
4
4
|
import { BuildFilterExpression } from "../filters/index.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { Query } from "./query.mjs";
|
|
6
6
|
import { QueryExecutor } from "../connectors/common.mjs";
|
|
7
7
|
|
|
8
8
|
//#region src/query-builders/rq.d.ts
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Query } from "./query.mjs";
|
|
2
1
|
import { Key, Prettify, SelfOrArray, UnionToIntersection, Valueof } from "../types.mjs";
|
|
2
|
+
import { AnyColumn, AnyTableWithColumns, BuildScmTblColumns, StdTableColumn, TColsToLeftRight, TableColumn, TableWithColumns } from "../table.mjs";
|
|
3
3
|
import { OrderBy } from "./orderby-clause.mjs";
|
|
4
4
|
import { QueryPromise } from "./query-promise.mjs";
|
|
5
5
|
import { BuildFilterExpression, StdCondition } from "../filters/index.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { Query } from "./query.mjs";
|
|
7
7
|
import { QueryExecutor } from "../connectors/common.mjs";
|
|
8
8
|
|
|
9
9
|
//#region src/query-builders/select.d.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Query } from "./query.mjs";
|
|
2
1
|
import { Key } from "../types.mjs";
|
|
2
|
+
import { AnyColumn, TColsToLeftRight, TableWithColumns } from "../table.mjs";
|
|
3
3
|
import { QueryPromise } from "./query-promise.mjs";
|
|
4
4
|
import { BuildFilterExpression } from "../filters/index.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { Query } from "./query.mjs";
|
|
6
6
|
import { QueryExecutor } from "../connectors/common.mjs";
|
|
7
7
|
|
|
8
8
|
//#region src/query-builders/update.d.ts
|
package/dist/src/sequence.d.mts
CHANGED
package/dist/src/sql.d.mts
CHANGED
package/dist/src/table.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { CamelToSnake, Key } from "./types.mjs";
|
|
2
1
|
import { entityType } from "./symbols.mjs";
|
|
2
|
+
import { CamelToSnake, Key } from "./types.mjs";
|
|
3
|
+
import { Column } from "./columns/common.mjs";
|
|
3
4
|
import { PrimaryKeyConstraint, PrimaryKeyConstraintFn } from "./constraints/primary-key.mjs";
|
|
4
5
|
import { UniqueConstraint, UniqueConstraintFn } from "./constraints/unique.mjs";
|
|
5
6
|
import { Index } from "./indexes.mjs";
|
|
6
|
-
import { Column } from "./columns/common.mjs";
|
|
7
7
|
import { Check, CheckBuilder, CheckExpr } from "./constraints/check.mjs";
|
|
8
8
|
|
|
9
9
|
//#region src/table.d.ts
|
package/package.json
CHANGED