durcno 1.0.0-alpha.6 → 1.0.0-alpha.8
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 +3 -2
- 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/connectors/common.d.mts +4 -4
- 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 +9 -9
- package/dist/src/logger.d.mts +3 -3
- 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 +17 -4
- package/dist/src/query-builders/rq.mjs +44 -81
- 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 +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,8 +22,9 @@
|
|
|
22
22
|
|
|
23
23
|
- **🔗 Relation Mapping** — Intuitive `many`, `one`, and `fk` relations with full type inference.
|
|
24
24
|
- **🦾 Robust Migrations** — Auto-generated, reversible, and squashable migrations for production applications.
|
|
25
|
-
-
|
|
25
|
+
- **⚡ Zero Runtime Overhead** — Thin abstraction layer that compiles to efficient SQL.
|
|
26
26
|
- **🔌 Multiple Drivers** — Support for `pg`, `postgres`, `bun`, and `pglite` drivers.
|
|
27
|
+
- **🛡️ Zod Integration** — Built-in Zod validators for schema validation and type inference.
|
|
27
28
|
- **🌍 PostGIS Support** — First-class geographic column types for spatial queries.
|
|
28
29
|
|
|
29
30
|
## Setup
|
|
@@ -40,7 +41,7 @@ npm exec durcno init
|
|
|
40
41
|
|
|
41
42
|
Get started with Durcno by following our comprehensive documentation.
|
|
42
43
|
|
|
43
|
-
**[
|
|
44
|
+
**[Getting Started | Durcno](https://durcno.dev/docs/latest/getting-started)**
|
|
44
45
|
|
|
45
46
|
> [!WARNING]
|
|
46
47
|
> Durcno is currently in the alpha stage.
|
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.7");
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { QueryLogger } from "../logger.mjs";
|
|
2
2
|
import { Query } from "../query-builders/query.mjs";
|
|
3
3
|
import { MigrationOptions } from "../migration/index.mjs";
|
|
4
4
|
import { ConnectionOptions } from "node:tls";
|
|
@@ -43,7 +43,7 @@ type ConnectorOptions = {
|
|
|
43
43
|
* When set, all executed queries will be logged at the `info` level with
|
|
44
44
|
* structured `{ sql, arguments }` metadata.
|
|
45
45
|
*/
|
|
46
|
-
logger?:
|
|
46
|
+
logger?: QueryLogger;
|
|
47
47
|
};
|
|
48
48
|
/**
|
|
49
49
|
* Abstract base class for all database connectors.
|
|
@@ -83,7 +83,7 @@ declare abstract class Connector {
|
|
|
83
83
|
/** Connection pool size override (can be mutated by CLI commands before `getPool()` is called). */
|
|
84
84
|
pool?: ConnectorOptions["pool"];
|
|
85
85
|
/** Optional logger instance for query logging. */
|
|
86
|
-
logger?:
|
|
86
|
+
logger?: QueryLogger;
|
|
87
87
|
constructor(options: ConnectorOptions);
|
|
88
88
|
/**
|
|
89
89
|
* Creates a single-connection client.
|
|
@@ -116,7 +116,7 @@ declare abstract class $QueryExecutor {
|
|
|
116
116
|
/** The connector options used to create this executor. */
|
|
117
117
|
options: ConnectorOptions;
|
|
118
118
|
/** Optional logger instance for query logging. */
|
|
119
|
-
logger?:
|
|
119
|
+
logger?: QueryLogger;
|
|
120
120
|
constructor(options: ConnectorOptions);
|
|
121
121
|
/**
|
|
122
122
|
* Executes a SQL query with optional parameterized arguments.
|
|
@@ -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 };
|