durcno 1.0.0-alpha.5 → 1.0.0-alpha.6

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 CHANGED
@@ -12063,13 +12063,16 @@ var Column = class {
12063
12063
  };
12064
12064
 
12065
12065
  // src/constraints/check.ts
12066
+ function isExprColumnRef(value) {
12067
+ return typeof value === "object" && value !== null && value.type === "col";
12068
+ }
12066
12069
  function snapshotExprToSQL(expr) {
12067
12070
  if (expr.type === "raw") {
12068
12071
  return expr.sql;
12069
12072
  }
12070
12073
  if (expr.type === "comparison") {
12071
- const left = typeof expr.left === "string" ? `"${expr.left}"` : snapshotExprToSQL(expr.left);
12072
- const right = formatSnapshotValue(expr.right);
12074
+ const left = isExprColumnRef(expr.left) ? `"${expr.left.name}"` : snapshotExprToSQL(expr.left);
12075
+ const right = isExprColumnRef(expr.right) ? `"${expr.right.name}"` : expr.right;
12073
12076
  return `${left} ${expr.op} ${right}`;
12074
12077
  }
12075
12078
  if (expr.type === "logical") {
@@ -12078,24 +12081,11 @@ function snapshotExprToSQL(expr) {
12078
12081
  return wrappedParts.join(` ${expr.op} `);
12079
12082
  }
12080
12083
  if (expr.type === "function") {
12081
- const args = expr.args.map(
12082
- (a) => typeof a === "string" ? `"${a}"` : formatSnapshotValue(a)
12083
- );
12084
+ const args = expr.args.map((a) => isExprColumnRef(a) ? `"${a.name}"` : a);
12084
12085
  return `${expr.name}(${args.join(", ")})`;
12085
12086
  }
12086
12087
  throw new Error("Unknown expression type");
12087
12088
  }
12088
- function formatSnapshotValue(value) {
12089
- if (value === null) return "NULL";
12090
- if (Array.isArray(value)) {
12091
- const list = value.map((v) => formatSnapshotValue(v)).join(", ");
12092
- return `(${list})`;
12093
- }
12094
- if (typeof value === "string") return `'${value.replace(/'/g, "''")}'`;
12095
- if (typeof value === "number") return String(value);
12096
- if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
12097
- return String(value);
12098
- }
12099
12089
 
12100
12090
  // src/cli/utils.ts
12101
12091
  function getOrderedDependencies(items, dependencyMap) {
@@ -13508,7 +13498,7 @@ async function status(options) {
13508
13498
  }
13509
13499
 
13510
13500
  // src/cli/index.ts
13511
- program.version("1.0.0-alpha.4");
13501
+ program.version("1.0.0-alpha.5");
13512
13502
  var Options = {
13513
13503
  config: ["--config <path>", "Path to the config file"]
13514
13504
  };
@@ -3,18 +3,18 @@ import { Column, ColumnConfig } from "./common.mjs";
3
3
  import * as z from "zod";
4
4
 
5
5
  //#region src/columns/bigint.d.ts
6
- type BigintValType = number;
6
+ type BigintValType = bigint;
7
7
  type BigintConfig = ColumnConfig;
8
8
  declare class BigintColumn<TConfig extends BigintConfig> extends Column<TConfig, BigintValType> {
9
9
  static readonly id = "Column.Bigint";
10
10
  get sqlTypeScalar(): string;
11
11
  get sqlCastScalar(): null;
12
- get zodTypeScaler(): z.ZodCoercedNumber<unknown>;
13
- toDriverScalar(value: BigintValType | Sql | null): string | number | null;
14
- toSQLScalar(value: number | Sql | null): string;
15
- fromDriverScalar(value: number | string | null): BigintValType | null;
12
+ get zodTypeScaler(): z.ZodCoercedBigInt<unknown>;
13
+ toDriverScalar(value: BigintValType | Sql | null): string | null;
14
+ toSQLScalar(value: BigintValType | Sql | null): string;
15
+ fromDriverScalar(value: bigint | string | null): BigintValType | null;
16
16
  }
17
- /** Creates a `bigint` column. PostgreSQL 64-bit signed integer, maps to `number`. */
17
+ /** Creates a `bigint` column. PostgreSQL 64-bit signed integer, maps to `bigint`. */
18
18
  declare function bigint<TConfig extends BigintConfig>(config: TConfig): BigintColumn<TConfig>;
19
19
  //#endregion
20
20
  export { BigintColumn, bigint };
@@ -11,11 +11,11 @@ var BigintColumn = class extends Column {
11
11
  return null;
12
12
  }
13
13
  get zodTypeScaler() {
14
- return z.coerce.number();
14
+ return z.coerce.bigint();
15
15
  }
16
16
  toDriverScalar(value) {
17
17
  if (value === null) return null;
18
- return value instanceof Sql ? value.string : value;
18
+ return value instanceof Sql ? value.string : value.toString();
19
19
  }
20
20
  toSQLScalar(value) {
21
21
  if (value === null) return "NULL";
@@ -24,10 +24,10 @@ var BigintColumn = class extends Column {
24
24
  }
25
25
  fromDriverScalar(value) {
26
26
  if (value === null) return null;
27
- return typeof value === "string" ? parseInt(value, 10) : value;
27
+ return BigInt(value);
28
28
  }
29
29
  };
30
- /** Creates a `bigint` column. PostgreSQL 64-bit signed integer, maps to `number`. */
30
+ /** Creates a `bigint` column. PostgreSQL 64-bit signed integer, maps to `bigint`. */
31
31
  function bigint(config) {
32
32
  return new BigintColumn(config);
33
33
  }
@@ -3,7 +3,7 @@ import { Column, ColumnConfig } from "./common.mjs";
3
3
  import * as z from "zod";
4
4
 
5
5
  //#region src/columns/bigserial.d.ts
6
- type BigserialValType = number;
6
+ type BigserialValType = bigint;
7
7
  type BigserialConfig = Pick<ColumnConfig, "primaryKey" | "unique">;
8
8
  type BigserialInternalConfig<TConfig extends BigserialConfig> = TConfig & {
9
9
  generated: "BY DEFAULT";
@@ -14,12 +14,12 @@ declare class BigserialColumn<TConfig extends BigserialConfig> extends Column<Bi
14
14
  constructor(config: TConfig);
15
15
  get sqlTypeScalar(): string;
16
16
  get sqlCastScalar(): null;
17
- get zodTypeScaler(): z.ZodCoercedNumber<unknown>;
18
- toDriverScalar(value: BigserialValType | Sql | null): string | number | null;
19
- toSQLScalar(value: number | Sql | null): string;
20
- fromDriverScalar(value: number | string | null): BigserialValType | null;
17
+ get zodTypeScaler(): z.ZodCoercedBigInt<unknown>;
18
+ toDriverScalar(value: BigserialValType | Sql | null): string | null;
19
+ toSQLScalar(value: BigserialValType | Sql | null): string;
20
+ fromDriverScalar(value: BigserialValType | string | null): BigserialValType | null;
21
21
  }
22
- /** Creates a `bigserial` column. Auto-incrementing 64-bit integer, implicitly `NOT NULL`. Maps to `number`. */
22
+ /** Creates a `bigserial` column. Auto-incrementing 64-bit integer, implicitly `NOT NULL`. Maps to `bigint`. */
23
23
  declare function bigserial<TConfig extends BigserialConfig>(config: TConfig): BigserialColumn<TConfig>;
24
24
  //#endregion
25
25
  export { bigserial };
@@ -14,11 +14,11 @@ var BigserialColumn = class extends Column {
14
14
  return null;
15
15
  }
16
16
  get zodTypeScaler() {
17
- return z.coerce.number();
17
+ return z.coerce.bigint();
18
18
  }
19
19
  toDriverScalar(value) {
20
20
  if (value === null) return null;
21
- return value instanceof Sql ? value.string : value;
21
+ return value instanceof Sql ? value.string : value.toString();
22
22
  }
23
23
  toSQLScalar(value) {
24
24
  if (value === null) return "NULL";
@@ -27,10 +27,10 @@ var BigserialColumn = class extends Column {
27
27
  }
28
28
  fromDriverScalar(value) {
29
29
  if (value === null) return null;
30
- return typeof value === "string" ? parseInt(value, 10) : value;
30
+ return BigInt(value);
31
31
  }
32
32
  };
33
- /** Creates a `bigserial` column. Auto-incrementing 64-bit integer, implicitly `NOT NULL`. Maps to `number`. */
33
+ /** Creates a `bigserial` column. Auto-incrementing 64-bit integer, implicitly `NOT NULL`. Maps to `bigint`. */
34
34
  function bigserial(config) {
35
35
  return new BigserialColumn(config);
36
36
  }
@@ -29,11 +29,21 @@ type CheckExpr = ComparisonExpr | LogicalExpr | FunctionExpr | RawExpr;
29
29
  type SnapshotComparisonOp = "=" | "<>" | "<" | ">" | "<=" | ">=" | "IN" | "NOT IN";
30
30
  type SnapshotPatternOp = "LIKE" | "SIMILAR TO" | "~";
31
31
  type SnapshotLogicalOp = "AND" | "OR";
32
+ /**
33
+ * A tagged column reference stored in a snapshot expression.
34
+ * Stores the snake_case column name so it can be quoted correctly in SQL output.
35
+ */
36
+ interface ExprColumnRef {
37
+ type: "col";
38
+ /** Snake_case column name as used in PostgreSQL (e.g. `user_id`). */
39
+ name: string;
40
+ }
32
41
  interface SnapshotComparisonExpr {
33
42
  type: "comparison";
34
- left: string | SnapshotFunctionExpr;
43
+ left: ExprColumnRef | SnapshotFunctionExpr;
35
44
  op: SnapshotComparisonOp | SnapshotPatternOp;
36
- right: unknown;
45
+ /** Column ref, or a pre-rendered SQL string (incl. `(v1, v2)` for IN lists). */
46
+ right: ExprColumnRef | string;
37
47
  }
38
48
  interface SnapshotLogicalExpr {
39
49
  type: "logical";
@@ -43,7 +53,8 @@ interface SnapshotLogicalExpr {
43
53
  interface SnapshotFunctionExpr {
44
54
  type: "function";
45
55
  name: string;
46
- args: (string | unknown)[];
56
+ /** Column refs or pre-rendered SQL strings. */
57
+ args: (ExprColumnRef | string)[];
47
58
  }
48
59
  interface SnapshotRawExpr {
49
60
  type: "raw";
@@ -60,8 +71,8 @@ declare class CheckBuilder {
60
71
  like<TCol extends TableColumn<string, string, Key, AnyColumn>>(col: TCol, pattern: string): ComparisonExpr;
61
72
  similarTo<TCol extends TableColumn<string, string, Key, AnyColumn>>(col: TCol, pattern: string): ComparisonExpr;
62
73
  regex<TCol extends TableColumn<string, string, Key, AnyColumn>>(col: TCol, pattern: string): ComparisonExpr;
63
- in<TCol extends TableColumn<string, string, Key, AnyColumn>>(col: TCol, values: (TCol["ValType"] & (string | number))[]): ComparisonExpr;
64
- notIn<TCol extends TableColumn<string, string, Key, AnyColumn>>(col: TCol, values: (TCol["ValType"] & (string | number))[]): ComparisonExpr;
74
+ in<TCol extends TableColumn<string, string, Key, AnyColumn>>(col: TCol, values: TCol["ValType"][]): ComparisonExpr;
75
+ notIn<TCol extends TableColumn<string, string, Key, AnyColumn>>(col: TCol, values: TCol["ValType"][]): ComparisonExpr;
65
76
  and(...expressions: CheckExpr[]): LogicalExpr;
66
77
  or(...expressions: CheckExpr[]): LogicalExpr;
67
78
  length<TCol extends TableColumn<string, string, Key, AnyColumn>>(col: TCol): FunctionExpr;
@@ -218,35 +218,39 @@ var Check = class {
218
218
  function check(name, expr) {
219
219
  return new Check(name, expr);
220
220
  }
221
- function formatValue(value) {
221
+ /**
222
+ * Converts a raw JavaScript value to a SQL literal string.
223
+ * Used as a fallback when no column type context is available.
224
+ */
225
+ function formatUnknown(value) {
222
226
  if (value === null) return "NULL";
227
+ if (typeof value === "bigint") return value.toString();
223
228
  if (typeof value === "string") return `'${value.replace(/'/g, "''")}'`;
224
229
  if (typeof value === "number") return String(value);
225
230
  if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
226
- if (value instanceof Date) return `'${value.toISOString()}'`;
227
231
  return String(value);
228
232
  }
229
233
  function exprToSQL(expr) {
230
234
  if (expr.type === "raw") return expr.sql;
231
235
  if (expr.type === "comparison") {
232
236
  let left;
233
- if (isTableCol(expr.left)) left = `"${expr.left.name}"`;
237
+ if (isTableCol(expr.left)) left = `"${expr.left.nameSnake}"`;
234
238
  else if (expr.left.type === "function") left = exprToSQL(expr.left);
235
239
  else left = String(expr.left);
236
240
  if (expr.op === "IN" || expr.op === "NOT IN") {
237
241
  if (Array.isArray(expr.right)) {
238
- const list = expr.right.map((v) => isTableCol(v) ? `"${v.name}"` : formatValue(v)).join(", ");
242
+ const list = expr.right.map((v) => isTableCol(v) ? `"${v.nameSnake}"` : formatUnknown(v)).join(", ");
239
243
  return `${left} ${expr.op} (${list})`;
240
244
  }
241
- const singleRight = isTableCol(expr.right) ? `"${expr.right.name}"` : formatValue(expr.right);
245
+ const singleRight = isTableCol(expr.right) ? `"${expr.right.nameSnake}"` : formatUnknown(expr.right);
242
246
  return `${left} ${expr.op} (${singleRight})`;
243
247
  }
244
- const right = isTableCol(expr.right) ? `"${expr.right.name}"` : formatValue(expr.right);
248
+ const right = isTableCol(expr.right) ? `"${expr.right.nameSnake}"` : isTableCol(expr.left) ? expr.left.toSQL(expr.right) : formatUnknown(expr.right);
245
249
  return `${left} ${expr.op} ${right}`;
246
250
  }
247
251
  if (expr.type === "logical") return `(${expr.expressions.map((e) => exprToSQL(e)).join(` ${expr.op} `)})`;
248
252
  if (expr.type === "function") {
249
- const args = expr.args.map((arg) => isTableCol(arg) ? `"${arg.name}"` : formatValue(arg));
253
+ const args = expr.args.map((arg) => isTableCol(arg) ? `"${arg.nameSnake}"` : formatUnknown(arg));
250
254
  return `${expr.name}(${args.join(", ")})`;
251
255
  }
252
256
  throw new Error("Unknown expression type");
@@ -258,10 +262,24 @@ function exprToSnapshot(expr) {
258
262
  };
259
263
  if (expr.type === "comparison") {
260
264
  let left;
261
- if (isTableCol(expr.left)) left = expr.left.name;
262
- else if (expr.left.type === "function") left = exprToSnapshot(expr.left);
263
- else left = String(expr.left);
264
- const right = isTableCol(expr.right) ? expr.right.name : expr.right;
265
+ if (isTableCol(expr.left)) left = {
266
+ type: "col",
267
+ name: expr.left.nameSnake
268
+ };
269
+ else left = exprToSnapshot(expr.left);
270
+ let right;
271
+ if (isTableCol(expr.right)) right = {
272
+ type: "col",
273
+ name: expr.right.nameSnake
274
+ };
275
+ else if ((expr.op === "IN" || expr.op === "NOT IN") && Array.isArray(expr.right)) {
276
+ const refCol = isTableCol(expr.left) ? expr.left : void 0;
277
+ right = `(${expr.right.map((v) => {
278
+ if (isTableCol(v)) return `"${v.nameSnake}"`;
279
+ return refCol ? refCol.toSQL(v) : formatUnknown(v);
280
+ }).join(", ")})`;
281
+ } else if (isTableCol(expr.left)) right = expr.left.toSQL(expr.right);
282
+ else right = formatUnknown(expr.right);
265
283
  return {
266
284
  type: "comparison",
267
285
  left,
@@ -274,34 +292,40 @@ function exprToSnapshot(expr) {
274
292
  op: expr.op,
275
293
  expressions: expr.expressions.map((e) => exprToSnapshot(e))
276
294
  };
277
- if (expr.type === "function") return {
278
- type: "function",
279
- name: expr.name,
280
- args: expr.args.map((arg) => isTableCol(arg) ? arg.name : arg)
281
- };
295
+ if (expr.type === "function") {
296
+ const refCol = expr.args.find(isTableCol);
297
+ return {
298
+ type: "function",
299
+ name: expr.name,
300
+ args: expr.args.map((arg) => {
301
+ if (isTableCol(arg)) return {
302
+ type: "col",
303
+ name: arg.nameSnake
304
+ };
305
+ return refCol ? refCol.toSQL(arg) : formatUnknown(arg);
306
+ })
307
+ };
308
+ }
282
309
  throw new Error("Unknown expression type");
283
310
  }
311
+ /** Type guard for {@link ExprColumnRef}. */
312
+ function isExprColumnRef(value) {
313
+ return typeof value === "object" && value !== null && value.type === "col";
314
+ }
315
+ /** Convert a snapshot expression back to a SQL string. */
284
316
  function snapshotExprToSQL(expr) {
285
317
  if (expr.type === "raw") return expr.sql;
286
318
  if (expr.type === "comparison") {
287
- const left = typeof expr.left === "string" ? `"${expr.left}"` : snapshotExprToSQL(expr.left);
288
- const right = formatSnapshotValue(expr.right);
319
+ const left = isExprColumnRef(expr.left) ? `"${expr.left.name}"` : snapshotExprToSQL(expr.left);
320
+ const right = isExprColumnRef(expr.right) ? `"${expr.right.name}"` : expr.right;
289
321
  return `${left} ${expr.op} ${right}`;
290
322
  }
291
323
  if (expr.type === "logical") return expr.expressions.map((e) => snapshotExprToSQL(e)).map((p) => `(${p})`).join(` ${expr.op} `);
292
324
  if (expr.type === "function") {
293
- const args = expr.args.map((a) => typeof a === "string" ? `"${a}"` : formatSnapshotValue(a));
325
+ const args = expr.args.map((a) => isExprColumnRef(a) ? `"${a.name}"` : a);
294
326
  return `${expr.name}(${args.join(", ")})`;
295
327
  }
296
328
  throw new Error("Unknown expression type");
297
329
  }
298
- function formatSnapshotValue(value) {
299
- if (value === null) return "NULL";
300
- if (Array.isArray(value)) return `(${value.map((v) => formatSnapshotValue(v)).join(", ")})`;
301
- if (typeof value === "string") return `'${value.replace(/'/g, "''")}'`;
302
- if (typeof value === "number") return String(value);
303
- if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
304
- return String(value);
305
- }
306
330
  //#endregion
307
331
  export { CheckBuilder, check, snapshotExprToSQL };
@@ -18,7 +18,6 @@ declare class ArrayContainsFilter<TCol extends AnyTC, TVal extends ArrayElement<
18
18
  readonly left: TCol;
19
19
  readonly right: TVal[];
20
20
  constructor(column: TCol, values: TVal[]);
21
- toSQL(): string;
22
21
  toQuery(query: Query): void;
23
22
  }
24
23
  /**
@@ -37,7 +36,6 @@ declare class ArrayContainedByFilter<TCol extends AnyTC, TVal extends ArrayEleme
37
36
  readonly left: TCol;
38
37
  readonly right: TVal[];
39
38
  constructor(column: TCol, values: TVal[]);
40
- toSQL(): string;
41
39
  toQuery(query: Query): void;
42
40
  }
43
41
  /**
@@ -53,7 +51,6 @@ declare class ArrayOverlapsFilter<TCol extends AnyTC, TVal extends ArrayElement<
53
51
  readonly left: TCol;
54
52
  readonly right: TVal[];
55
53
  constructor(column: TCol, values: TVal[]);
56
- toSQL(): string;
57
54
  toQuery(query: Query): void;
58
55
  }
59
56
  /**
@@ -69,7 +66,6 @@ declare class ArrayHasFilter<TCol extends AnyTC, TVal extends ArrayElement<TCol[
69
66
  readonly left: TCol;
70
67
  readonly right: TVal;
71
68
  constructor(column: TCol, value: TVal);
72
- toSQL(): string;
73
69
  toQuery(query: Query): void;
74
70
  }
75
71
  /**
@@ -85,7 +81,6 @@ declare class ArrayAllFilter<TCol extends AnyTC, TVal extends ArrayElement<TCol[
85
81
  readonly left: TCol;
86
82
  readonly right: TVal;
87
83
  constructor(column: TCol, value: TVal);
88
- toSQL(): string;
89
84
  toQuery(query: Query): void;
90
85
  }
91
86
  /**
@@ -12,9 +12,6 @@ var ArrayContainsFilter = class extends Filter {
12
12
  this.left = column;
13
13
  this.right = values;
14
14
  }
15
- toSQL() {
16
- return `${this.left.fullName} @> ${this.left.toSQL(this.right)}::${this.left.sqlType}`;
17
- }
18
15
  toQuery(query) {
19
16
  query.sql += `${this.left.fullName} @> ${this.left.toSQL(this.right)}::${this.left.sqlType}`;
20
17
  }
@@ -41,9 +38,6 @@ var ArrayContainedByFilter = class extends Filter {
41
38
  this.left = column;
42
39
  this.right = values;
43
40
  }
44
- toSQL() {
45
- return `${this.left.fullName} <@ ${this.left.toSQL(this.right)}::${this.left.sqlType}`;
46
- }
47
41
  toQuery(query) {
48
42
  query.sql += `${this.left.fullName} <@ ${this.left.toSQL(this.right)}::${this.left.sqlType}`;
49
43
  }
@@ -67,9 +61,6 @@ var ArrayOverlapsFilter = class extends Filter {
67
61
  this.left = column;
68
62
  this.right = values;
69
63
  }
70
- toSQL() {
71
- return `${this.left.fullName} && ${this.left.toSQL(this.right)}::${this.left.sqlType}`;
72
- }
73
64
  toQuery(query) {
74
65
  query.sql += `${this.left.fullName} && ${this.left.toSQL(this.right)}::${this.left.sqlType}`;
75
66
  }
@@ -93,9 +84,6 @@ var ArrayHasFilter = class extends Filter {
93
84
  this.left = column;
94
85
  this.right = value;
95
86
  }
96
- toSQL() {
97
- return `${this.left.toSQLScalar(this.right)} = ANY(${this.left.fullName})`;
98
- }
99
87
  toQuery(query) {
100
88
  query.sql += `${this.left.toSQLScalar(this.right)} = ANY(${this.left.fullName})`;
101
89
  }
@@ -119,9 +107,6 @@ var ArrayAllFilter = class extends Filter {
119
107
  this.left = column;
120
108
  this.right = value;
121
109
  }
122
- toSQL() {
123
- return `${this.left.toSQLScalar(this.right)} = ALL(${this.left.fullName})`;
124
- }
125
110
  toQuery(query) {
126
111
  query.sql += `${this.left.toSQLScalar(this.right)} = ALL(${this.left.fullName})`;
127
112
  }
@@ -5,7 +5,6 @@ import { AnyColumn, TableColumn } from "../table.mjs";
5
5
  /** Abstract base class for SQL filter expressions used in `WHERE`/`ON` clauses. */
6
6
  declare abstract class Filter<TColumn extends TableColumn<any, any, any, AnyColumn>> {
7
7
  readonly $Columns: TColumn;
8
- abstract toSQL(): string;
9
8
  abstract toQuery(query: Query): void;
10
9
  }
11
10
  //#endregion
@@ -17,14 +17,12 @@ declare class EqualValCondition<CTSchema extends string, CTName extends string,
17
17
  readonly left: TableColumn<CTSchema, CTName, CName, Col>;
18
18
  readonly right: TRight;
19
19
  constructor(field: TableColumn<CTSchema, CTName, CName, Col>, right: TRight);
20
- toSQL(): string;
21
20
  toQuery(query: Query): void;
22
21
  }
23
22
  declare class EqualColCondition<C1TSchema extends string, C1TName extends string, C1Name extends Key, C1 extends AnyColumn, C2TSchema extends string, C2TName extends string, C2Name extends Key, C2 extends AnyColumn> {
24
23
  readonly left: TableColumn<C1TSchema, C1TName, C1Name, C1>;
25
24
  readonly right: TableColumn<C2TSchema, C2TName, C2Name, C2>;
26
25
  constructor(field: TableColumn<C1TSchema, C1TName, C1Name, C1>, right: TableColumn<C2TSchema, C2TName, C2Name, C2>);
27
- toSQL(): string;
28
26
  toQuery(query: Query): void;
29
27
  }
30
28
  declare function eq<CTSchema extends string, CTName extends string, CName extends Key, Col extends AnyColumn, TRight extends Col["ValType"]>(field: TableColumn<CTSchema, CTName, CName, Col>, right: TRight): EqualValCondition<CTSchema, CTName, CName, Col, TRight>;
@@ -34,14 +32,12 @@ declare class NotEqualValCondition<CTSchema extends string, CTName extends strin
34
32
  readonly left: TableColumn<CTSchema, CTName, CName, Col>;
35
33
  readonly right: TRight;
36
34
  constructor(field: TableColumn<CTSchema, CTName, CName, Col>, right: TRight);
37
- toSQL(): string;
38
35
  toQuery(query: Query): void;
39
36
  }
40
37
  declare class NotEqualColCondition<C1TSchema extends string, C1TName extends string, C1Name extends Key, C1 extends AnyColumn, C2TSchema extends string, C2TName extends string, C2Name extends Key, C2 extends AnyColumn> {
41
38
  readonly left: TableColumn<C1TSchema, C1TName, C1Name, C1>;
42
39
  readonly right: TableColumn<C2TSchema, C2TName, C2Name, C2>;
43
40
  constructor(field: TableColumn<C1TSchema, C1TName, C1Name, C1>, right: TableColumn<C2TSchema, C2TName, C2Name, C2>);
44
- toSQL(): string;
45
41
  toQuery(query: Query): void;
46
42
  }
47
43
  declare function ne<CTSchema extends string, CTName extends string, CName extends Key, Col extends AnyColumn, TRight extends Col["ValType"]>(field: TableColumn<CTSchema, CTName, CName, Col>, right: TRight): NotEqualValCondition<CTSchema, CTName, CName, Col, TRight>;
@@ -51,14 +47,12 @@ declare class GreaterEqualValCondition<CTSchema extends string, CTName extends s
51
47
  readonly left: TableColumn<CTSchema, CTName, CName, Col>;
52
48
  readonly right: TRight;
53
49
  constructor(field: TableColumn<CTSchema, CTName, CName, Col>, right: TRight);
54
- toSQL(): string;
55
50
  toQuery(query: Query): void;
56
51
  }
57
52
  declare class GreaterEqualColCondition<C1TSchema extends string, C1TName extends string, C1Name extends Key, C1 extends AnyColumn, C2TSchema extends string, C2TName extends string, C2Name extends Key, C2 extends AnyColumn> {
58
53
  readonly left: TableColumn<C1TSchema, C1TName, C1Name, C1>;
59
54
  readonly right: TableColumn<C2TSchema, C2TName, C2Name, C2>;
60
55
  constructor(field: TableColumn<C1TSchema, C1TName, C1Name, C1>, right: TableColumn<C2TSchema, C2TName, C2Name, C2>);
61
- toSQL(): string;
62
56
  toQuery(query: Query): void;
63
57
  }
64
58
  declare function gte<CTSchema extends string, CTName extends string, CName extends Key, Col extends AnyColumn, TRight extends Col["ValType"]>(field: TableColumn<CTSchema, CTName, CName, Col>, right: TRight): GreaterEqualValCondition<CTSchema, CTName, CName, Col, TRight>;
@@ -68,14 +62,12 @@ declare class GreaterThanValCondition<CTSchema extends string, CTName extends st
68
62
  readonly left: TableColumn<CTSchema, CTName, CName, Col>;
69
63
  readonly right: TRight;
70
64
  constructor(field: TableColumn<CTSchema, CTName, CName, Col>, right: TRight);
71
- toSQL(): string;
72
65
  toQuery(query: Query): void;
73
66
  }
74
67
  declare class GreaterThanColCondition<C1TSchema extends string, C1TName extends string, C1Name extends Key, C1 extends AnyColumn, C2TSchema extends string, C2TName extends string, C2Name extends Key, C2 extends AnyColumn> {
75
68
  readonly left: TableColumn<C1TSchema, C1TName, C1Name, C1>;
76
69
  readonly right: TableColumn<C2TSchema, C2TName, C2Name, C2>;
77
70
  constructor(field: TableColumn<C1TSchema, C1TName, C1Name, C1>, right: TableColumn<C2TSchema, C2TName, C2Name, C2>);
78
- toSQL(): string;
79
71
  toQuery(query: Query): void;
80
72
  }
81
73
  declare function gt<CTSchema extends string, CTName extends string, CName extends Key, Col extends AnyColumn, TRight extends Col["ValType"]>(field: TableColumn<CTSchema, CTName, CName, Col>, right: TRight): GreaterThanValCondition<CTSchema, CTName, CName, Col, TRight>;
@@ -85,14 +77,12 @@ declare class LessEqualValCondition<CTSchema extends string, CTName extends stri
85
77
  readonly left: TableColumn<CTSchema, CTName, CName, Col>;
86
78
  readonly right: TRight;
87
79
  constructor(field: TableColumn<CTSchema, CTName, CName, Col>, right: TRight);
88
- toSQL(): string;
89
80
  toQuery(query: Query): void;
90
81
  }
91
82
  declare class LessEqualColCondition<C1TSchema extends string, C1TName extends string, C1Name extends Key, C1 extends AnyColumn, C2TSchema extends string, C2TName extends string, C2Name extends Key, C2 extends AnyColumn> {
92
83
  readonly left: TableColumn<C1TSchema, C1TName, C1Name, C1>;
93
84
  readonly right: TableColumn<C2TSchema, C2TName, C2Name, C2>;
94
85
  constructor(field: TableColumn<C1TSchema, C1TName, C1Name, C1>, right: TableColumn<C2TSchema, C2TName, C2Name, C2>);
95
- toSQL(): string;
96
86
  toQuery(query: Query): void;
97
87
  }
98
88
  declare function lte<CTSchema extends string, CTName extends string, CName extends Key, Col extends AnyColumn, TRight extends Col["ValType"]>(field: TableColumn<CTSchema, CTName, CName, Col>, right: TRight): LessEqualValCondition<CTSchema, CTName, CName, Col, TRight>;
@@ -102,14 +92,12 @@ declare class LessThanValCondition<CTSchema extends string, CTName extends strin
102
92
  readonly left: TableColumn<CTSchema, CTName, CName, Col>;
103
93
  readonly right: TRight;
104
94
  constructor(field: TableColumn<CTSchema, CTName, CName, Col>, right: TRight);
105
- toSQL(): string;
106
95
  toQuery(query: Query): void;
107
96
  }
108
97
  declare class LessThanColCondition<C1TSchema extends string, C1TName extends string, C1Name extends Key, C1 extends AnyColumn, C2TSchema extends string, C2TName extends string, C2Name extends Key, C2 extends AnyColumn> {
109
98
  readonly left: TableColumn<C1TSchema, C1TName, C1Name, C1>;
110
99
  readonly right: TableColumn<C2TSchema, C2TName, C2Name, C2>;
111
100
  constructor(field: TableColumn<C1TSchema, C1TName, C1Name, C1>, right: TableColumn<C2TSchema, C2TName, C2Name, C2>);
112
- toSQL(): string;
113
101
  toQuery(query: Query): void;
114
102
  }
115
103
  declare function lt<CTSchema extends string, CTName extends string, CName extends Key, Col extends AnyColumn, TRight extends Col["ValType"]>(field: TableColumn<CTSchema, CTName, CName, Col>, right: TRight): LessThanValCondition<CTSchema, CTName, CName, Col, TRight>;
@@ -118,14 +106,12 @@ declare function lt<C1TSchema extends string, C1TName extends string, C1Name ext
118
106
  declare class IsNullCondition<CTSchema extends string, CTName extends string, CName extends Key, Col extends AnyColumn> {
119
107
  readonly field: TableColumn<CTSchema, CTName, CName, Col>;
120
108
  constructor(field: TableColumn<CTSchema, CTName, CName, Col>);
121
- toSQL(): string;
122
109
  toQuery(query: Query): void;
123
110
  }
124
111
  declare function isNull<CTSchema extends string, CTName extends string, CName extends Key, Col extends AnyColumn>(field: TableColumn<CTSchema, CTName, CName, Col>): IsNullCondition<CTSchema, CTName, CName, Col>;
125
112
  declare class IsNotNullCondition<CTSchema extends string, CTName extends string, CName extends Key, Col extends AnyColumn> {
126
113
  readonly field: TableColumn<CTSchema, CTName, CName, Col>;
127
114
  constructor(field: TableColumn<CTSchema, CTName, CName, Col>);
128
- toSQL(): string;
129
115
  toQuery(query: Query): void;
130
116
  }
131
117
  declare function isNotNull<CTSchema extends string, CTName extends string, CName extends Key, Col extends AnyColumn>(field: TableColumn<CTSchema, CTName, CName, Col>): IsNotNullCondition<CTSchema, CTName, CName, Col>;
@@ -134,21 +120,18 @@ declare class InCondition<CTSchema extends string, CTName extends string, CName
134
120
  readonly field: TableColumn<CTSchema, CTName, CName, Col>;
135
121
  readonly values: Col["ValType"][] | InSelectQuery<TArg, Col["ValType"]>;
136
122
  constructor(field: TableColumn<CTSchema, CTName, CName, Col>, values: Col["ValType"][] | InSelectQuery<TArg, Col["ValType"]>);
137
- toSQL(): string;
138
123
  toQuery(query: Query): void;
139
124
  }
140
125
  declare function isIn<CTSchema extends string, CTName extends string, CName extends Key, Col extends AnyColumn>(field: TableColumn<CTSchema, CTName, CName, Col>, values: Col["ValType"][] | InSelectQuery<boolean, Col["ValType"]>): InCondition<CTSchema, CTName, CName, Col, boolean>;
141
126
  declare class AndCondition<TConditions extends any[]> {
142
127
  readonly conditions: TConditions;
143
128
  constructor(...conditions: TConditions);
144
- toSQL(): string;
145
129
  toQuery(query: Query): void;
146
130
  }
147
131
  declare function and<TConditions extends any[]>(...conditions: TConditions): AndCondition<TConditions>;
148
132
  declare class OrCondition<TConditions extends any[]> {
149
133
  readonly conditions: TConditions;
150
134
  constructor(...conditions: TConditions);
151
- toSQL(): string;
152
135
  toQuery(query: Query): void;
153
136
  }
154
137
  declare function or<TConditions extends any[]>(...conditions: TConditions): OrCondition<TConditions>;
@@ -9,9 +9,6 @@ var EqualValCondition = class {
9
9
  this.left = field;
10
10
  this.right = right;
11
11
  }
12
- toSQL() {
13
- return `${this.left.fullName} = ${this.left.toSQL(this.right)}`;
14
- }
15
12
  toQuery(query) {
16
13
  query.sql += `${this.left.fullName} = `;
17
14
  if (is(this.right, Arg)) query.addArg(this.right);
@@ -25,9 +22,6 @@ var EqualColCondition = class {
25
22
  this.left = field;
26
23
  this.right = right;
27
24
  }
28
- toSQL() {
29
- return `${this.left.fullName} = ${this.right.fullName}`;
30
- }
31
25
  toQuery(query) {
32
26
  query.sql += `${this.left.fullName} = ${this.right.fullName}`;
33
27
  }
@@ -43,9 +37,6 @@ var NotEqualValCondition = class {
43
37
  this.left = field;
44
38
  this.right = right;
45
39
  }
46
- toSQL() {
47
- return `${this.left.fullName} != ${this.left.toSQL(this.right)}`;
48
- }
49
40
  toQuery(query) {
50
41
  query.sql += `${this.left.fullName} != `;
51
42
  if (is(this.right, Arg)) query.addArg(this.right);
@@ -59,9 +50,6 @@ var NotEqualColCondition = class {
59
50
  this.left = field;
60
51
  this.right = right;
61
52
  }
62
- toSQL() {
63
- return `${this.left.fullName} != ${this.right.fullName}`;
64
- }
65
53
  toQuery(query) {
66
54
  query.sql += `${this.left.fullName} != ${this.right.fullName}`;
67
55
  }
@@ -77,9 +65,6 @@ var GreaterEqualValCondition = class {
77
65
  this.left = field;
78
66
  this.right = right;
79
67
  }
80
- toSQL() {
81
- return `${this.left.fullName} >= ${this.left.toSQL(this.right)}`;
82
- }
83
68
  toQuery(query) {
84
69
  query.sql += `${this.left.fullName} >= `;
85
70
  if (is(this.right, Arg)) query.addArg(this.right);
@@ -93,9 +78,6 @@ var GreaterEqualColCondition = class {
93
78
  this.left = field;
94
79
  this.right = right;
95
80
  }
96
- toSQL() {
97
- return `${this.left.fullName} >= ${this.right.fullName}`;
98
- }
99
81
  toQuery(query) {
100
82
  query.sql += `${this.left.fullName} >= ${this.right.fullName}`;
101
83
  }
@@ -111,9 +93,6 @@ var GreaterThanValCondition = class {
111
93
  this.left = field;
112
94
  this.right = right;
113
95
  }
114
- toSQL() {
115
- return `${this.left.fullName} > ${this.left.toSQL(this.right)}`;
116
- }
117
96
  toQuery(query) {
118
97
  query.sql += `${this.left.fullName} > `;
119
98
  if (is(this.right, Arg)) query.addArg(this.right);
@@ -127,9 +106,6 @@ var GreaterThanColCondition = class {
127
106
  this.left = field;
128
107
  this.right = right;
129
108
  }
130
- toSQL() {
131
- return `${this.left.fullName} > ${this.right.fullName}`;
132
- }
133
109
  toQuery(query) {
134
110
  query.sql += `${this.left.fullName} > ${this.right.fullName}`;
135
111
  }
@@ -145,9 +121,6 @@ var LessEqualValCondition = class {
145
121
  this.left = field;
146
122
  this.right = right;
147
123
  }
148
- toSQL() {
149
- return `${this.left.fullName} <= ${this.left.toSQL(this.right)}`;
150
- }
151
124
  toQuery(query) {
152
125
  query.sql += `${this.left.fullName} <= `;
153
126
  if (is(this.right, Arg)) query.addArg(this.right);
@@ -161,9 +134,6 @@ var LessEqualColCondition = class {
161
134
  this.left = field;
162
135
  this.right = right;
163
136
  }
164
- toSQL() {
165
- return `${this.left.fullName} <= ${this.right.fullName}`;
166
- }
167
137
  toQuery(query) {
168
138
  query.sql += `${this.left.fullName} <= ${this.right.fullName}`;
169
139
  }
@@ -179,9 +149,6 @@ var LessThanValCondition = class {
179
149
  this.left = field;
180
150
  this.right = right;
181
151
  }
182
- toSQL() {
183
- return `${this.left.fullName} < ${this.left.toSQL(this.right)}`;
184
- }
185
152
  toQuery(query) {
186
153
  query.sql += `${this.left.fullName} < `;
187
154
  if (is(this.right, Arg)) query.addArg(this.right);
@@ -195,9 +162,6 @@ var LessThanColCondition = class {
195
162
  this.left = field;
196
163
  this.right = right;
197
164
  }
198
- toSQL() {
199
- return `${this.left.fullName} < ${this.right.fullName}`;
200
- }
201
165
  toQuery(query) {
202
166
  query.sql += `${this.left.fullName} < ${this.right.fullName}`;
203
167
  }
@@ -211,9 +175,6 @@ var IsNullCondition = class {
211
175
  constructor(field) {
212
176
  this.field = field;
213
177
  }
214
- toSQL() {
215
- return `${this.field.fullName} IS NULL`;
216
- }
217
178
  toQuery(query) {
218
179
  query.sql += `${this.field.fullName} IS NULL`;
219
180
  }
@@ -226,9 +187,6 @@ var IsNotNullCondition = class {
226
187
  constructor(field) {
227
188
  this.field = field;
228
189
  }
229
- toSQL() {
230
- return `${this.field.fullName} IS NOT NULL`;
231
- }
232
190
  toQuery(query) {
233
191
  query.sql += `${this.field.fullName} IS NOT NULL`;
234
192
  }
@@ -243,12 +201,6 @@ var InCondition = class {
243
201
  this.field = field;
244
202
  this.values = values;
245
203
  }
246
- toSQL() {
247
- if (Array.isArray(this.values)) {
248
- if (this.values.length === 0) return "FALSE";
249
- return `${this.field.fullName} IN (${this.values.map((v) => this.field.toSQL(v)).join(", ")})`;
250
- } else return `${this.field.fullName} IN (${this.values.toQuery()})`;
251
- }
252
204
  toQuery(query) {
253
205
  if (Array.isArray(this.values)) {
254
206
  if (this.values.length === 0) {
@@ -273,14 +225,6 @@ var AndCondition = class {
273
225
  constructor(...conditions) {
274
226
  this.conditions = conditions;
275
227
  }
276
- toSQL() {
277
- let sql = "";
278
- for (let i = 0; i < this.conditions.length; i++) {
279
- sql += this.conditions[i].toSQL();
280
- if (i < this.conditions.length - 1) sql += " AND ";
281
- }
282
- return sql;
283
- }
284
228
  toQuery(query) {
285
229
  for (let i = 0; i < this.conditions.length; i++) {
286
230
  this.conditions[i].toQuery(query);
@@ -296,14 +240,6 @@ var OrCondition = class {
296
240
  constructor(...conditions) {
297
241
  this.conditions = conditions;
298
242
  }
299
- toSQL() {
300
- let sql = "";
301
- for (let i = 0; i < this.conditions.length; i++) {
302
- sql += this.conditions[i].toSQL();
303
- if (i < this.conditions.length - 1) sql += " OR ";
304
- }
305
- return sql;
306
- }
307
243
  toQuery(query) {
308
244
  for (let i = 0; i < this.conditions.length; i++) {
309
245
  this.conditions[i].toQuery(query);
@@ -23,8 +23,7 @@ var AggregateQuery = class extends QueryPromise {
23
23
  query.sql += this.#$table._.fullName;
24
24
  if (this.#$where) {
25
25
  query.sql += " WHERE ";
26
- if (this.#$prepare) this.#$where.toQuery(query);
27
- else query.sql += this.#$where.toSQL();
26
+ this.#$where.toQuery(query);
28
27
  }
29
28
  return query;
30
29
  }
@@ -18,8 +18,7 @@ var CountQuery = class extends QueryPromise {
18
18
  query.sql += this.#$table._.fullName;
19
19
  if (this.#$where) {
20
20
  query.sql += " WHERE ";
21
- if (this.#$prepare) this.#$where.toQuery(query);
22
- else query.sql += this.#$where.toSQL();
21
+ this.#$where.toQuery(query);
23
22
  }
24
23
  return query;
25
24
  }
@@ -26,8 +26,7 @@ var DeleteQuery = class DeleteQuery extends QueryPromise {
26
26
  query.sql += this.#$table._.fullName;
27
27
  if (this.#$where) {
28
28
  query.sql += " WHERE ";
29
- if (this.#$prepare) this.#$where.toQuery(query);
30
- else query.sql += this.#$where.toSQL();
29
+ this.#$where.toQuery(query);
31
30
  }
32
31
  if (this.#$returning) {
33
32
  query.sql += " RETURNING ";
@@ -21,8 +21,7 @@ var DistinctQuery = class extends QueryPromise {
21
21
  query.sql += this.#$table._.fullName;
22
22
  if (this.#$where) {
23
23
  query.sql += " WHERE ";
24
- if (this.#$prepare) this.#$where.toQuery(query);
25
- else query.sql += this.#$where.toSQL();
24
+ this.#$where.toQuery(query);
26
25
  }
27
26
  query.sql += ` ORDER BY ${columnName}`;
28
27
  return query;
@@ -18,8 +18,7 @@ var ExistsQuery = class extends QueryPromise {
18
18
  query.sql += this.#$table._.fullName;
19
19
  if (this.#$where) {
20
20
  query.sql += " WHERE ";
21
- if (this.#$prepare) this.#$where.toQuery(query);
22
- else query.sql += this.#$where.toSQL();
21
+ this.#$where.toQuery(query);
23
22
  }
24
23
  query.sql += ")";
25
24
  return query;
@@ -19,8 +19,7 @@ var FirstQuery = class extends QueryPromise {
19
19
  query.sql += this.#$table._.fullName;
20
20
  if (this.#$where) {
21
21
  query.sql += " WHERE ";
22
- if (this.#$prepare) this.#$where.toQuery(query);
23
- else query.sql += this.#$where.toSQL();
22
+ this.#$where.toQuery(query);
24
23
  }
25
24
  query.sql += " LIMIT 1";
26
25
  return query;
@@ -64,7 +64,10 @@ var RelationQuery = class extends QueryPromise {
64
64
  if (relation) query.sql += buildRelationSubquery(key, this.#table._.name, o, relation, this.#allRelations);
65
65
  }
66
66
  }
67
- if (options.where) query.sql += ` WHERE ${options.where.toSQL()}`;
67
+ if (options.where) {
68
+ query.sql += " WHERE ";
69
+ options.where.toQuery(query);
70
+ }
68
71
  if (options.orderBy) {
69
72
  const orders = Array.isArray(options.orderBy) ? options.orderBy : [options.orderBy];
70
73
  query.sql += ` ORDER BY ${orders.map((o) => o.toSQL()).join(", ")}`;
@@ -75,12 +75,12 @@ var SelectQuery = class SelectQuery extends QueryPromise {
75
75
  query.sql += this.#table._.fullName;
76
76
  this.#$innerJoins?.forEach((innerJoin) => {
77
77
  const join = innerJoin;
78
- query.sql += ` INNER JOIN ${join.table._.fullName} ON ${join.on.toSQL()}`;
78
+ query.sql += ` INNER JOIN ${join.table._.fullName} ON `;
79
+ join.on.toQuery(query);
79
80
  });
80
81
  if (this.#$where) {
81
82
  query.sql += " WHERE ";
82
- if (this.#prepare) this.#$where.toQuery(query);
83
- else query.sql += this.#$where.toSQL();
83
+ this.#$where.toQuery(query);
84
84
  }
85
85
  if (this.#$orderBy) {
86
86
  const orders = Array.isArray(this.#$orderBy) ? this.#$orderBy : [this.#$orderBy];
@@ -58,8 +58,7 @@ var UpdateQuery = class UpdateQuery extends QueryPromise {
58
58
  query.sql += allFields.map((field, index) => `"${this.#table._.columns[field].nameSnake}" = ${this.#table._.columns[field].toSQL(allValues[index], { cast: true })}`).join(", ");
59
59
  if (this.#$where) {
60
60
  query.sql += ` WHERE `;
61
- if (this.#prepare) this.#$where.toQuery(query);
62
- else query.sql += this.#$where.toSQL();
61
+ this.#$where.toQuery(query);
63
62
  }
64
63
  if (this.#$returning) {
65
64
  query.sql += " RETURNING ";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "durcno",
3
- "version": "1.0.0-alpha.5",
3
+ "version": "1.0.0-alpha.6",
4
4
  "description": "A PostgreSQL Query Builder and Migration Manager for TypeScript, from the future.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://durcno.dev",