durcno 1.0.0-alpha.4 → 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.
Files changed (51) hide show
  1. package/README.md +1 -1
  2. package/dist/bin.cjs +7 -17
  3. package/dist/src/columns/bigint.d.mts +6 -6
  4. package/dist/src/columns/bigint.mjs +4 -4
  5. package/dist/src/columns/bigserial.d.mts +6 -6
  6. package/dist/src/columns/bigserial.mjs +4 -4
  7. package/dist/src/columns/common.d.mts +1 -0
  8. package/dist/src/columns/postgis/geography/linestring.d.mts +1 -0
  9. package/dist/src/columns/postgis/geography/multilinestring.d.mts +1 -0
  10. package/dist/src/columns/postgis/geography/multipoint.d.mts +1 -0
  11. package/dist/src/columns/postgis/geography/multipolygon.d.mts +1 -0
  12. package/dist/src/columns/postgis/geography/point.d.mts +1 -0
  13. package/dist/src/columns/postgis/geography/polygon.d.mts +1 -0
  14. package/dist/src/constraints/check.d.mts +17 -5
  15. package/dist/src/constraints/check.mjs +51 -27
  16. package/dist/src/constraints/primary-key.d.mts +1 -0
  17. package/dist/src/constraints/unique.d.mts +1 -0
  18. package/dist/src/db.d.mts +16 -16
  19. package/dist/src/db.mjs +8 -8
  20. package/dist/src/filters/array.d.mts +0 -5
  21. package/dist/src/filters/array.mjs +5 -33
  22. package/dist/src/filters/custom.d.mts +0 -1
  23. package/dist/src/filters/index.d.mts +1 -17
  24. package/dist/src/filters/index.mjs +0 -64
  25. package/dist/src/index.d.mts +2 -10
  26. package/dist/src/indexes.d.mts +1 -0
  27. package/dist/src/logger.d.mts +8 -4
  28. package/dist/src/logger.mjs +8 -4
  29. package/dist/src/query-builders/aggregates.d.mts +3 -2
  30. package/dist/src/query-builders/aggregates.mjs +4 -2
  31. package/dist/src/query-builders/count.d.mts +2 -2
  32. package/dist/src/query-builders/count.mjs +4 -2
  33. package/dist/src/query-builders/delete.d.mts +1 -0
  34. package/dist/src/query-builders/delete.mjs +1 -2
  35. package/dist/src/query-builders/distinct.d.mts +3 -2
  36. package/dist/src/query-builders/distinct.mjs +4 -2
  37. package/dist/src/query-builders/exists.d.mts +2 -2
  38. package/dist/src/query-builders/exists.mjs +4 -2
  39. package/dist/src/query-builders/first.d.mts +2 -2
  40. package/dist/src/query-builders/first.mjs +4 -2
  41. package/dist/src/query-builders/insert.d.mts +1 -0
  42. package/dist/src/query-builders/insert.mjs +17 -27
  43. package/dist/src/query-builders/orderby-clause.d.mts +1 -0
  44. package/dist/src/query-builders/rq.mjs +4 -1
  45. package/dist/src/query-builders/select.d.mts +1 -0
  46. package/dist/src/query-builders/select.mjs +3 -3
  47. package/dist/src/query-builders/update.d.mts +1 -0
  48. package/dist/src/query-builders/update.mjs +1 -2
  49. package/dist/src/table.d.mts +1 -1
  50. package/dist/src/types.d.mts +8 -1
  51. package/package.json +1 -1
package/README.md CHANGED
@@ -40,7 +40,7 @@ npm exec durcno init
40
40
 
41
41
  Get started with Durcno by following our comprehensive documentation.
42
42
 
43
- **[Read the Documentation](https://durcno.dev/docs)**
43
+ **[Read the Documentation](https://durcno.dev/docs/latest/intro)**
44
44
 
45
45
  > [!WARNING]
46
46
  > Durcno is currently in the alpha stage.
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.3");
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
  }
@@ -1,3 +1,4 @@
1
+ import { Key } from "../types.mjs";
1
2
  import { Sql } from "../sql.mjs";
2
3
  import { entityType } from "../symbols.mjs";
3
4
  import { Arg } from "../query-builders/pre.mjs";
@@ -1,3 +1,4 @@
1
+ import { SelfOrReadonly } from "../../../types.mjs";
1
2
  import { Sql } from "../../../sql.mjs";
2
3
  import { Column, ColumnConfig } from "../../common.mjs";
3
4
  import * as z from "zod";
@@ -1,3 +1,4 @@
1
+ import { SelfOrReadonly } from "../../../types.mjs";
1
2
  import { Sql } from "../../../sql.mjs";
2
3
  import { Column, ColumnConfig } from "../../common.mjs";
3
4
  import * as z from "zod";
@@ -1,3 +1,4 @@
1
+ import { SelfOrReadonly } from "../../../types.mjs";
1
2
  import { Sql } from "../../../sql.mjs";
2
3
  import { Column, ColumnConfig } from "../../common.mjs";
3
4
  import * as z from "zod";
@@ -1,3 +1,4 @@
1
+ import { SelfOrReadonly } from "../../../types.mjs";
1
2
  import { Sql } from "../../../sql.mjs";
2
3
  import { Column, ColumnConfig } from "../../common.mjs";
3
4
  import * as z from "zod";
@@ -1,3 +1,4 @@
1
+ import { SelfOrReadonly } from "../../../types.mjs";
1
2
  import { Sql } from "../../../sql.mjs";
2
3
  import { Column, ColumnConfig } from "../../common.mjs";
3
4
  import * as z from "zod";
@@ -1,3 +1,4 @@
1
+ import { SelfOrReadonly } from "../../../types.mjs";
1
2
  import { Sql } from "../../../sql.mjs";
2
3
  import { Column, ColumnConfig } from "../../common.mjs";
3
4
  import * as z from "zod";
@@ -1,3 +1,4 @@
1
+ import { Key } from "../types.mjs";
1
2
  import { AnyColumn, TableColumn } from "../table.mjs";
2
3
 
3
4
  //#region src/constraints/check.d.ts
@@ -28,11 +29,21 @@ type CheckExpr = ComparisonExpr | LogicalExpr | FunctionExpr | RawExpr;
28
29
  type SnapshotComparisonOp = "=" | "<>" | "<" | ">" | "<=" | ">=" | "IN" | "NOT IN";
29
30
  type SnapshotPatternOp = "LIKE" | "SIMILAR TO" | "~";
30
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
+ }
31
41
  interface SnapshotComparisonExpr {
32
42
  type: "comparison";
33
- left: string | SnapshotFunctionExpr;
43
+ left: ExprColumnRef | SnapshotFunctionExpr;
34
44
  op: SnapshotComparisonOp | SnapshotPatternOp;
35
- right: unknown;
45
+ /** Column ref, or a pre-rendered SQL string (incl. `(v1, v2)` for IN lists). */
46
+ right: ExprColumnRef | string;
36
47
  }
37
48
  interface SnapshotLogicalExpr {
38
49
  type: "logical";
@@ -42,7 +53,8 @@ interface SnapshotLogicalExpr {
42
53
  interface SnapshotFunctionExpr {
43
54
  type: "function";
44
55
  name: string;
45
- args: (string | unknown)[];
56
+ /** Column refs or pre-rendered SQL strings. */
57
+ args: (ExprColumnRef | string)[];
46
58
  }
47
59
  interface SnapshotRawExpr {
48
60
  type: "raw";
@@ -59,8 +71,8 @@ declare class CheckBuilder {
59
71
  like<TCol extends TableColumn<string, string, Key, AnyColumn>>(col: TCol, pattern: string): ComparisonExpr;
60
72
  similarTo<TCol extends TableColumn<string, string, Key, AnyColumn>>(col: TCol, pattern: string): ComparisonExpr;
61
73
  regex<TCol extends TableColumn<string, string, Key, AnyColumn>>(col: TCol, pattern: string): ComparisonExpr;
62
- in<TCol extends TableColumn<string, string, Key, AnyColumn>>(col: TCol, values: (TCol["ValType"] & (string | number))[]): ComparisonExpr;
63
- 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;
64
76
  and(...expressions: CheckExpr[]): LogicalExpr;
65
77
  or(...expressions: CheckExpr[]): LogicalExpr;
66
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 };
@@ -1,3 +1,4 @@
1
+ import { Key } from "../types.mjs";
1
2
  import { AnyColumn, AnyTableWithColumns, TableColumn } from "../table.mjs";
2
3
 
3
4
  //#region src/constraints/primary-key.d.ts
@@ -1,3 +1,4 @@
1
+ import { Key } from "../types.mjs";
1
2
  import { AnyColumn, AnyTableWithColumns, TableColumn } from "../table.mjs";
2
3
 
3
4
  //#region src/constraints/unique.d.ts
package/dist/src/db.d.mts CHANGED
@@ -60,24 +60,24 @@ declare class Base<TTName extends string, TTables extends Record<TTName, TableWi
60
60
  * @param where Optional where clause to filter rows
61
61
  * @returns Promise<number> - the count of matching rows
62
62
  */
63
- $count<TTable extends TTables[keyof TTables]>(table: TTable): CountQuery<TTable>;
64
- $count<TTable extends TTables[keyof TTables], TWhere extends BuildFilterExpression<TColsToLeftRight<TTable["_"]["columns"]>>>(table: TTable, where: TWhere): CountQuery<TTable>;
63
+ $count<TTable extends TTables[keyof TTables]>(table: TTable): CountQuery<TTable, TPrepare>;
64
+ $count<TTable extends TTables[keyof TTables], TWhere extends BuildFilterExpression<TColsToLeftRight<TTable["_"]["columns"]>, TPrepare>>(table: TTable, where: TWhere): CountQuery<TTable, TPrepare>;
65
65
  /**
66
66
  * Check if any rows exist in a table, optionally filtered by a where clause.
67
67
  * @param table The table to check
68
68
  * @param where Optional where clause to filter rows
69
69
  * @returns Promise<boolean> - true if at least one row exists
70
70
  */
71
- $exists<TTable extends TTables[keyof TTables]>(table: TTable): ExistsQuery<TTable>;
72
- $exists<TTable extends TTables[keyof TTables], TWhere extends BuildFilterExpression<TColsToLeftRight<TTable["_"]["columns"]>>>(table: TTable, where: TWhere): ExistsQuery<TTable>;
71
+ $exists<TTable extends TTables[keyof TTables]>(table: TTable): ExistsQuery<TTable, TPrepare>;
72
+ $exists<TTable extends TTables[keyof TTables], TWhere extends BuildFilterExpression<TColsToLeftRight<TTable["_"]["columns"]>, TPrepare>>(table: TTable, where: TWhere): ExistsQuery<TTable, TPrepare>;
73
73
  /**
74
74
  * Get the first row from a table, optionally filtered by a where clause.
75
75
  * @param table The table to query
76
76
  * @param where Optional where clause to filter rows
77
77
  * @returns Promise<T | null> - the first row or null if no rows match
78
78
  */
79
- $first<TTable extends TTables[keyof TTables]>(table: TTable): FirstQuery<TTable>;
80
- $first<TTable extends TTables[keyof TTables], TWhere extends BuildFilterExpression<TColsToLeftRight<TTable["_"]["columns"]>>>(table: TTable, where: TWhere): FirstQuery<TTable>;
79
+ $first<TTable extends TTables[keyof TTables]>(table: TTable): FirstQuery<TTable, TPrepare>;
80
+ $first<TTable extends TTables[keyof TTables], TWhere extends BuildFilterExpression<TColsToLeftRight<TTable["_"]["columns"]>, TPrepare>>(table: TTable, where: TWhere): FirstQuery<TTable, TPrepare>;
81
81
  /**
82
82
  * Calculate the sum of a numeric column.
83
83
  * @param table The table to query
@@ -85,8 +85,8 @@ declare class Base<TTName extends string, TTables extends Record<TTName, TableWi
85
85
  * @param where Optional where clause to filter rows
86
86
  * @returns Promise<number | null> - the sum or null if no rows match
87
87
  */
88
- $sum<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]]>(table: TTable, column: TColumn): AggregateQuery<TTable, TColumn, number | null>;
89
- $sum<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]], TWhere extends BuildFilterExpression<TColsToLeftRight<TTable["_"]["columns"]>>>(table: TTable, column: TColumn, where: TWhere): AggregateQuery<TTable, TColumn, number | null>;
88
+ $sum<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]]>(table: TTable, column: TColumn): AggregateQuery<TTable, TColumn, number | null, TPrepare>;
89
+ $sum<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]], TWhere extends BuildFilterExpression<TColsToLeftRight<TTable["_"]["columns"]>, TPrepare>>(table: TTable, column: TColumn, where: TWhere): AggregateQuery<TTable, TColumn, number | null, TPrepare>;
90
90
  /**
91
91
  * Calculate the average of a numeric column.
92
92
  * @param table The table to query
@@ -94,8 +94,8 @@ declare class Base<TTName extends string, TTables extends Record<TTName, TableWi
94
94
  * @param where Optional where clause to filter rows
95
95
  * @returns Promise<number | null> - the average or null if no rows match
96
96
  */
97
- $avg<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]]>(table: TTable, column: TColumn): AggregateQuery<TTable, TColumn, number | null>;
98
- $avg<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]], TWhere extends BuildFilterExpression<TColsToLeftRight<TTable["_"]["columns"]>>>(table: TTable, column: TColumn, where: TWhere): AggregateQuery<TTable, TColumn, number | null>;
97
+ $avg<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]]>(table: TTable, column: TColumn): AggregateQuery<TTable, TColumn, number | null, TPrepare>;
98
+ $avg<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]], TWhere extends BuildFilterExpression<TColsToLeftRight<TTable["_"]["columns"]>, TPrepare>>(table: TTable, column: TColumn, where: TWhere): AggregateQuery<TTable, TColumn, number | null, TPrepare>;
99
99
  /**
100
100
  * Find the minimum value of a column.
101
101
  * @param table The table to query
@@ -103,8 +103,8 @@ declare class Base<TTName extends string, TTables extends Record<TTName, TableWi
103
103
  * @param where Optional where clause to filter rows
104
104
  * @returns Promise<number | null> - the minimum value or null if no rows match
105
105
  */
106
- $min<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]]>(table: TTable, column: TColumn): AggregateQuery<TTable, TColumn, number | null>;
107
- $min<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]], TWhere extends BuildFilterExpression<TColsToLeftRight<TTable["_"]["columns"]>>>(table: TTable, column: TColumn, where: TWhere): AggregateQuery<TTable, TColumn, number | null>;
106
+ $min<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]]>(table: TTable, column: TColumn): AggregateQuery<TTable, TColumn, number | null, TPrepare>;
107
+ $min<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]], TWhere extends BuildFilterExpression<TColsToLeftRight<TTable["_"]["columns"]>, TPrepare>>(table: TTable, column: TColumn, where: TWhere): AggregateQuery<TTable, TColumn, number | null, TPrepare>;
108
108
  /**
109
109
  * Find the maximum value of a column.
110
110
  * @param table The table to query
@@ -112,8 +112,8 @@ declare class Base<TTName extends string, TTables extends Record<TTName, TableWi
112
112
  * @param where Optional where clause to filter rows
113
113
  * @returns Promise<number | null> - the maximum value or null if no rows match
114
114
  */
115
- $max<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]]>(table: TTable, column: TColumn): AggregateQuery<TTable, TColumn, number | null>;
116
- $max<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]], TWhere extends BuildFilterExpression<TColsToLeftRight<TTable["_"]["columns"]>>>(table: TTable, column: TColumn, where: TWhere): AggregateQuery<TTable, TColumn, number | null>;
115
+ $max<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]]>(table: TTable, column: TColumn): AggregateQuery<TTable, TColumn, number | null, TPrepare>;
116
+ $max<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]], TWhere extends BuildFilterExpression<TColsToLeftRight<TTable["_"]["columns"]>, TPrepare>>(table: TTable, column: TColumn, where: TWhere): AggregateQuery<TTable, TColumn, number | null, TPrepare>;
117
117
  /**
118
118
  * Get distinct values of a column.
119
119
  * @param table The table to query
@@ -121,8 +121,8 @@ declare class Base<TTName extends string, TTables extends Record<TTName, TableWi
121
121
  * @param where Optional where clause to filter rows
122
122
  * @returns Promise<T[]> - array of distinct values
123
123
  */
124
- $distinct<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]]>(table: TTable, column: TColumn): DistinctQuery<TTable, TColumn, TColumn["ValTypeSelect"][]>;
125
- $distinct<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]], TWhere extends BuildFilterExpression<TColsToLeftRight<TTable["_"]["columns"]>>>(table: TTable, column: TColumn, where: TWhere): DistinctQuery<TTable, TColumn, TColumn["ValTypeSelect"][]>;
124
+ $distinct<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]]>(table: TTable, column: TColumn): DistinctQuery<TTable, TColumn, TColumn["ValTypeSelect"][], TPrepare>;
125
+ $distinct<TTable extends TTables[keyof TTables], TColumn extends TTable["_"]["columns"][keyof TTable["_"]["columns"]], TWhere extends BuildFilterExpression<TColsToLeftRight<TTable["_"]["columns"]>, TPrepare>>(table: TTable, column: TColumn, where: TWhere): DistinctQuery<TTable, TColumn, TColumn["ValTypeSelect"][], TPrepare>;
126
126
  /**
127
127
  * Insert a row and return the inserted row with all columns.
128
128
  * @param table The table to insert into
package/dist/src/db.mjs CHANGED
@@ -67,28 +67,28 @@ var Base = class {
67
67
  return new DeleteQuery(table, void 0, void 0, this.#getExecutor(), this.$.pre);
68
68
  }
69
69
  $count(table, where) {
70
- return new CountQuery(table, where, this.#getExecutor());
70
+ return new CountQuery(table, where, this.#getExecutor(), this.$.pre);
71
71
  }
72
72
  $exists(table, where) {
73
- return new ExistsQuery(table, where, this.#getExecutor());
73
+ return new ExistsQuery(table, where, this.#getExecutor(), this.$.pre);
74
74
  }
75
75
  $first(table, where) {
76
- return new FirstQuery(table, where, this.#getExecutor());
76
+ return new FirstQuery(table, where, this.#getExecutor(), this.$.pre);
77
77
  }
78
78
  $sum(table, column, where) {
79
- return new AggregateQuery(table, column, "SUM", where, this.#getExecutor());
79
+ return new AggregateQuery(table, column, "SUM", where, this.#getExecutor(), this.$.pre);
80
80
  }
81
81
  $avg(table, column, where) {
82
- return new AggregateQuery(table, column, "AVG", where, this.#getExecutor());
82
+ return new AggregateQuery(table, column, "AVG", where, this.#getExecutor(), this.$.pre);
83
83
  }
84
84
  $min(table, column, where) {
85
- return new AggregateQuery(table, column, "MIN", where, this.#getExecutor());
85
+ return new AggregateQuery(table, column, "MIN", where, this.#getExecutor(), this.$.pre);
86
86
  }
87
87
  $max(table, column, where) {
88
- return new AggregateQuery(table, column, "MAX", where, this.#getExecutor());
88
+ return new AggregateQuery(table, column, "MAX", where, this.#getExecutor(), this.$.pre);
89
89
  }
90
90
  $distinct(table, column, where) {
91
- return new DistinctQuery(table, column, where, this.#getExecutor());
91
+ return new DistinctQuery(table, column, where, this.#getExecutor(), this.$.pre);
92
92
  }
93
93
  /**
94
94
  * Insert a row and return the inserted row with all columns.
@@ -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
  /**