durcno 1.0.0-alpha.12 → 1.0.0-alpha.14

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 (48) hide show
  1. package/README.md +1 -0
  2. package/dist/bin.cjs +7 -3
  3. package/dist/src/columns/common.d.mts +24 -2
  4. package/dist/src/columns/common.mjs +30 -1
  5. package/dist/src/columns/pgvector/index.d.mts +122 -0
  6. package/dist/src/columns/pgvector/index.mjs +195 -0
  7. package/dist/src/connectors/bun.mjs +1 -1
  8. package/dist/src/connectors/pg.mjs +1 -1
  9. package/dist/src/connectors/postgres.mjs +1 -1
  10. package/dist/src/constraints/check.d.mts +2 -2
  11. package/dist/src/constraints/check.mjs +1 -1
  12. package/dist/src/db.d.mts +1 -9
  13. package/dist/src/db.mjs +1 -11
  14. package/dist/src/filters/array.d.mts +16 -16
  15. package/dist/src/filters/index.d.mts +25 -25
  16. package/dist/src/filters/postgis.d.mts +1 -2
  17. package/dist/src/filters/string.d.mts +1 -2
  18. package/dist/src/functions/aggregate.d.mts +7 -7
  19. package/dist/src/functions/index.d.mts +3 -3
  20. package/dist/src/functions/numeric.d.mts +11 -11
  21. package/dist/src/functions/pgvector.d.mts +33 -0
  22. package/dist/src/functions/pgvector.mjs +38 -0
  23. package/dist/src/functions/string.d.mts +17 -17
  24. package/dist/src/index.d.mts +3 -1
  25. package/dist/src/index.mjs +3 -1
  26. package/dist/src/indexes.d.mts +5 -4
  27. package/dist/src/indexes.mjs +2 -1
  28. package/dist/src/migration/ddl/index.d.mts +1 -41
  29. package/dist/src/migration/ddl/index.mjs +1 -44
  30. package/dist/src/migration/ddl/indexes.d.mts +2 -2
  31. package/dist/src/migration/ddl/indexes.mjs +11 -2
  32. package/dist/src/migration/ddl/statement.d.mts +1 -4
  33. package/dist/src/migration/snapshot.d.mts +11 -2
  34. package/dist/src/migration/snapshot.mjs +26 -1
  35. package/dist/src/query-builders/insert.d.mts +5 -2
  36. package/dist/src/query-builders/insert.mjs +3 -2
  37. package/dist/src/query-builders/pre.d.mts +10 -3
  38. package/dist/src/query-builders/pre.mjs +11 -2
  39. package/dist/src/query-builders/rq.d.mts +39 -28
  40. package/dist/src/query-builders/rq.mjs +18 -10
  41. package/dist/src/query-builders/select.d.mts +4 -3
  42. package/dist/src/query-builders/select.mjs +12 -2
  43. package/dist/src/table.d.mts +5 -5
  44. package/package.json +2 -2
  45. package/dist/src/migration/ddl/enum.d.mts +0 -100
  46. package/dist/src/migration/ddl/enum.mjs +0 -148
  47. package/dist/src/query-builders/insert-returning.d.mts +0 -15
  48. package/dist/src/query-builders/insert-returning.mjs +0 -37
package/README.md CHANGED
@@ -26,6 +26,7 @@
26
26
  - **🔌 Multiple Drivers** — Support for `pg`, `postgres`, `bun`, and `pglite` drivers.
27
27
  - **🛡️ Zod Integration** — Built-in Zod validators for schema validation and type inference.
28
28
  - **🌍 PostGIS Support** — First-class geographic column types for spatial queries.
29
+ - **🔍 pgvector Support** — Vector similarity search with type-safe distance functions and indexes.
29
30
 
30
31
  ## Setup
31
32
 
package/dist/bin.cjs CHANGED
@@ -9411,7 +9411,9 @@ function generateMigration(prev, curr, direction, renamedTables = {}, renamedCol
9411
9411
  }
9412
9412
  statements.push(tableBuilder.join("\n"));
9413
9413
  for (const idx of Object.values(currTable.indexes)) {
9414
- const cols = idx.columns.map((c) => `"${c}"`).join(", ");
9414
+ const cols = idx.columns.map(
9415
+ (c) => c.opclass ? `["${c.name}", "${c.opclass}"]` : `"${c.name}"`
9416
+ ).join(", ");
9415
9417
  let indexStmt = `ddl.createIndex("${idx.name}").on("${currTable.schema}", "${currTable.name}", [${cols}]).using("${idx.type}")`;
9416
9418
  if (idx.unique) indexStmt += ".unique()";
9417
9419
  statements.push(indexStmt);
@@ -9531,7 +9533,9 @@ function generateAlterTableStmts(prevTable, currTable, tableName, curr, statemen
9531
9533
  for (const idxName in currTable.indexes) {
9532
9534
  if (!prevTable.indexes[idxName]) {
9533
9535
  const idx = currTable.indexes[idxName];
9534
- const cols = idx.columns.map((c) => `"${c}"`).join(", ");
9536
+ const cols = idx.columns.map(
9537
+ (c) => c.opclass ? `["${c.name}", "${c.opclass}"]` : `"${c.name}"`
9538
+ ).join(", ");
9535
9539
  let indexStmt = `ddl.createIndex("${idx.name}").on("${currTable.schema}", "${currTable.name}", [${cols}]).using("${idx.type}")`;
9536
9540
  if (idx.unique) indexStmt += ".unique()";
9537
9541
  statements.push(indexStmt);
@@ -10451,7 +10455,7 @@ async function status(options) {
10451
10455
  }
10452
10456
 
10453
10457
  // src/cli/index.ts
10454
- program.version("1.0.0-alpha.11");
10458
+ program.version("1.0.0-alpha.13");
10455
10459
  var Options = {
10456
10460
  config: ["--config <path>", "Path to the config file"]
10457
10461
  };
@@ -1,5 +1,7 @@
1
+ import { CheckExpression } from "../constraints/check.mjs";
1
2
  import { entityType } from "../symbols.mjs";
2
- import { StdTable, StdTableColumn } from "../table.mjs";
3
+ import { AnyColumn, StdTable, StdTableColumn } from "../table.mjs";
4
+ import { AnyFilter } from "../filters/index.mjs";
3
5
  import { Arg } from "../query-builders/pre.mjs";
4
6
  import { Query, QueryContext } from "../query-builders/query.mjs";
5
7
  import { Sql } from "../sql.mjs";
@@ -273,6 +275,13 @@ declare abstract class Column<TConfig extends ColumnConfig, TColVal, TPgType ext
273
275
  get hasReferences(): boolean;
274
276
  get getReferencesCol(): StdTableColumn | null;
275
277
  get getReferencesOnDelete(): OnDeleteAction | null;
278
+ /**
279
+ * Attaches a column-level CHECK constraint.
280
+ * SQL equivalent: `CONSTRAINT "{table}_{col}_check" CHECK (<expr>)`
281
+ * @param fn - Function receiving the column and returning a filter or SQL expression.
282
+ */
283
+ check(fn: (c: this) => CheckExpression<this>): this;
284
+ get getCheckFn(): ((c: StdTableColumn) => AnyFilter | Sql) | undefined;
276
285
  /**
277
286
  * Sets a function to be called during INSERT queries to generate a value.
278
287
  * @param fn - A function that returns the value to insert
@@ -299,6 +308,19 @@ declare abstract class Column<TConfig extends ColumnConfig, TColVal, TPgType ext
299
308
  * @returns an `Arg` instance with the type of this column
300
309
  */
301
310
  arg(): Arg<this["ValType"]>;
311
+ /**
312
+ * Applies an operator class to this column for index creation.
313
+ *
314
+ * @param opclass - The operator class to use (e.g., 'vector_l2_ops').
315
+ * @returns an IndexOn instance wrapping this column and its opclass.
316
+ */
317
+ opclass(opclass: string): IndexOn<this>;
318
+ }
319
+ declare class IndexOn<TCol extends AnyColumn = AnyColumn> {
320
+ readonly column: StdTableColumn<TCol>;
321
+ readonly opclassStr: string;
322
+ static readonly [entityType] = "IndexOn";
323
+ constructor(column: StdTableColumn<TCol>, opclassStr: string);
302
324
  }
303
325
  //#endregion
304
- export { Column, ColumnConfig, Dimension, GeneratedAlways, GeneratedByDefault, OnDeleteAction, array, notNull, primaryKey, tuple, unique };
326
+ export { Column, ColumnConfig, Dimension, GeneratedAlways, GeneratedByDefault, IndexOn, OnDeleteAction, Tuple, array, notNull, primaryKey, tuple, unique };
@@ -74,6 +74,7 @@ var Column = class {
74
74
  #generated;
75
75
  #generatedAs;
76
76
  #references;
77
+ #check;
77
78
  #name;
78
79
  #nameSql;
79
80
  #table;
@@ -334,6 +335,18 @@ var Column = class {
334
335
  return this.#references ? this.#references.onDelete : null;
335
336
  }
336
337
  /**
338
+ * Attaches a column-level CHECK constraint.
339
+ * SQL equivalent: `CONSTRAINT "{table}_{col}_check" CHECK (<expr>)`
340
+ * @param fn - Function receiving the column and returning a filter or SQL expression.
341
+ */
342
+ check(fn) {
343
+ this.#check = fn;
344
+ return this;
345
+ }
346
+ get getCheckFn() {
347
+ return this.#check;
348
+ }
349
+ /**
337
350
  * Sets a function to be called during INSERT queries to generate a value.
338
351
  * @param fn - A function that returns the value to insert
339
352
  * @returns HasInsertFn<this>
@@ -377,6 +390,22 @@ var Column = class {
377
390
  arg() {
378
391
  return new Arg(this.toDriver.bind(this), this.sqlCast);
379
392
  }
393
+ /**
394
+ * Applies an operator class to this column for index creation.
395
+ *
396
+ * @param opclass - The operator class to use (e.g., 'vector_l2_ops').
397
+ * @returns an IndexOn instance wrapping this column and its opclass.
398
+ */
399
+ opclass(opclass) {
400
+ return new IndexOn(this, opclass);
401
+ }
402
+ };
403
+ var IndexOn = class {
404
+ static [entityType] = "IndexOn";
405
+ constructor(column, opclassStr) {
406
+ this.column = column;
407
+ this.opclassStr = opclassStr;
408
+ }
380
409
  };
381
410
  //#endregion
382
- export { Column, Dimension, array, identity, notNull, primaryKey, tuple, unique };
411
+ export { Column, Dimension, IndexOn, array, identity, notNull, primaryKey, tuple, unique };
@@ -0,0 +1,122 @@
1
+ import { Column, ColumnConfig, Tuple } from "../common.mjs";
2
+ import { Sql } from "../../sql.mjs";
3
+ import * as z from "zod";
4
+
5
+ //#region src/columns/pgvector/index.d.ts
6
+ type VectorConfig = ColumnConfig & {
7
+ dimensions?: number;
8
+ };
9
+ /** Derives a fixed-length numeric tuple when `dimensions` is a number literal, otherwise `number[]`. */
10
+ type VectorValue<TConfig extends VectorConfig> = TConfig extends {
11
+ dimensions: infer D extends number;
12
+ } ? number extends D ? number[] : Tuple<number, D> : number[];
13
+ declare class VectorColumn<TConfig extends VectorConfig> extends Column<TConfig, VectorValue<TConfig>, "numeric"> {
14
+ #private;
15
+ static readonly id = "Column.Vector";
16
+ constructor(config: TConfig);
17
+ get sqlTypeScalar(): string;
18
+ get sqlCastScalar(): string;
19
+ get zodTypeScaler(): TConfig["dimensions"] extends number ? z.ZodTuple<Tuple<z.ZodNumber, TConfig["dimensions"]>, null> : z.ZodArray<z.ZodNumber>;
20
+ toDriverScalar(value: VectorValue<TConfig> | Sql | null): string | null;
21
+ toSQLScalar(value: VectorValue<TConfig> | Sql | null): string;
22
+ fromDriverScalar(value: unknown): VectorValue<TConfig> | null;
23
+ }
24
+ /**
25
+ * Creates a `vector` column. PostgreSQL pgvector dense vector type, maps to `number[]`.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * vector({ dimensions: 1536, notNull }) // vector(1536) NOT NULL
30
+ * ```
31
+ *
32
+ * @param config.dimensions - Fixed vector dimension length
33
+ */
34
+ declare function vector<const TConfig extends VectorConfig>(config?: TConfig): VectorColumn<TConfig>;
35
+ type HalfvecConfig = ColumnConfig & {
36
+ dimensions?: number;
37
+ };
38
+ /** Derives a fixed-length numeric tuple when `dimensions` is a number literal, otherwise `number[]`. */
39
+ type HalfvecValue<TConfig extends HalfvecConfig> = TConfig extends {
40
+ dimensions: infer D extends number;
41
+ } ? number extends D ? number[] : Tuple<number, D> : number[];
42
+ declare class HalfvecColumn<TConfig extends HalfvecConfig> extends Column<TConfig, HalfvecValue<TConfig>, "numeric"> {
43
+ #private;
44
+ static readonly id = "Column.Halfvec";
45
+ constructor(config: TConfig);
46
+ get sqlTypeScalar(): string;
47
+ get sqlCastScalar(): string;
48
+ get zodTypeScaler(): TConfig["dimensions"] extends number ? z.ZodTuple<Tuple<z.ZodNumber, TConfig["dimensions"]>, null> : z.ZodArray<z.ZodNumber>;
49
+ toDriverScalar(value: HalfvecValue<TConfig> | Sql | null): string | null;
50
+ toSQLScalar(value: HalfvecValue<TConfig> | Sql | null): string;
51
+ fromDriverScalar(value: unknown): HalfvecValue<TConfig> | null;
52
+ }
53
+ /**
54
+ * Creates a `halfvec` column. PostgreSQL pgvector half precision vector type, maps to `number[]`.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * halfvec({ dimensions: 1536, notNull }) // halfvec(1536) NOT NULL
59
+ * ```
60
+ *
61
+ * @param config.dimensions - Fixed vector dimension length
62
+ */
63
+ declare function halfvec<const TConfig extends HalfvecConfig>(config?: TConfig): HalfvecColumn<TConfig>;
64
+ type SparsevecConfig = ColumnConfig & {
65
+ dimensions?: number;
66
+ };
67
+ declare class SparsevecColumn<TConfig extends SparsevecConfig> extends Column<TConfig, string, "string"> {
68
+ #private;
69
+ static readonly id = "Column.Sparsevec";
70
+ constructor(config: TConfig);
71
+ get sqlTypeScalar(): string;
72
+ get sqlCastScalar(): string;
73
+ get zodTypeScaler(): z.ZodString;
74
+ toDriverScalar(value: string | Sql | null): string | null;
75
+ toSQLScalar(value: string | Sql | null): string;
76
+ fromDriverScalar(value: string | null): string | null;
77
+ }
78
+ /**
79
+ * Creates a `sparsevec` column. PostgreSQL pgvector sparse vector type, maps to `string`.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * sparsevec({ dimensions: 1000, notNull }) // sparsevec(1000) NOT NULL
84
+ * ```
85
+ *
86
+ * @param config.dimensions - Fixed vector dimension length
87
+ */
88
+ declare function sparsevec<const TConfig extends SparsevecConfig>(config?: TConfig): SparsevecColumn<TConfig>;
89
+ type BitConfig = ColumnConfig & {
90
+ length?: number;
91
+ };
92
+ declare class BitColumn<TConfig extends BitConfig> extends Column<TConfig, string, "string"> {
93
+ #private;
94
+ static readonly id = "Column.Bit";
95
+ constructor(config: TConfig);
96
+ get sqlTypeScalar(): string;
97
+ get sqlCastScalar(): string;
98
+ get zodTypeScaler(): z.ZodString;
99
+ toDriverScalar(value: string | Sql | null): string | null;
100
+ toSQLScalar(value: string | Sql | null): string;
101
+ fromDriverScalar(value: string | null): string | null;
102
+ }
103
+ /**
104
+ * Creates a `bit` column. PostgreSQL bit string type, maps to `string`.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * bit({ length: 16, notNull }) // bit(16) NOT NULL
109
+ * ```
110
+ *
111
+ * @param config.length - Fixed bit string length
112
+ */
113
+ declare function bit<const TConfig extends BitConfig>(config?: TConfig): BitColumn<TConfig>;
114
+ /** All pgvector column constructors grouped as a single object. */
115
+ declare const pgvector: {
116
+ vector: typeof vector;
117
+ halfvec: typeof halfvec;
118
+ sparsevec: typeof sparsevec;
119
+ bit: typeof bit;
120
+ };
121
+ //#endregion
122
+ export { pgvector };
@@ -0,0 +1,195 @@
1
+ import { Column } from "../common.mjs";
2
+ import { Sql } from "../../sql.mjs";
3
+ import * as z from "zod";
4
+ //#region src/columns/pgvector/index.ts
5
+ var VectorColumn = class extends Column {
6
+ static id = "Column.Vector";
7
+ #dimensions;
8
+ constructor(config) {
9
+ super(config);
10
+ this.#dimensions = config.dimensions;
11
+ }
12
+ get sqlTypeScalar() {
13
+ return this.#dimensions ? `vector(${this.#dimensions})` : "vector";
14
+ }
15
+ get sqlCastScalar() {
16
+ return this.sqlTypeScalar;
17
+ }
18
+ get zodTypeScaler() {
19
+ if (this.#dimensions === void 0) return z.array(z.number());
20
+ return z.tuple(Array.from({ length: this.#dimensions }, () => z.number()));
21
+ }
22
+ toDriverScalar(value) {
23
+ if (value === null) return null;
24
+ return value instanceof Sql ? value.string : `[${value.join(",")}]`;
25
+ }
26
+ toSQLScalar(value) {
27
+ if (value === null) return "NULL";
28
+ return value instanceof Sql ? value.string : `'[${value.join(",")}]'`;
29
+ }
30
+ fromDriverScalar(value) {
31
+ if (value === null) return null;
32
+ if (Array.isArray(value)) return value;
33
+ if (typeof value === "string") try {
34
+ return JSON.parse(value);
35
+ } catch {
36
+ return null;
37
+ }
38
+ return null;
39
+ }
40
+ };
41
+ /**
42
+ * Creates a `vector` column. PostgreSQL pgvector dense vector type, maps to `number[]`.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * vector({ dimensions: 1536, notNull }) // vector(1536) NOT NULL
47
+ * ```
48
+ *
49
+ * @param config.dimensions - Fixed vector dimension length
50
+ */
51
+ function vector(config = {}) {
52
+ return new VectorColumn(config);
53
+ }
54
+ var HalfvecColumn = class extends Column {
55
+ static id = "Column.Halfvec";
56
+ #dimensions;
57
+ constructor(config) {
58
+ super(config);
59
+ this.#dimensions = config.dimensions;
60
+ }
61
+ get sqlTypeScalar() {
62
+ return this.#dimensions ? `halfvec(${this.#dimensions})` : "halfvec";
63
+ }
64
+ get sqlCastScalar() {
65
+ return this.sqlTypeScalar;
66
+ }
67
+ get zodTypeScaler() {
68
+ if (this.#dimensions === void 0) return z.array(z.number());
69
+ return z.tuple(Array.from({ length: this.#dimensions }, () => z.number()));
70
+ }
71
+ toDriverScalar(value) {
72
+ if (value === null) return null;
73
+ return value instanceof Sql ? value.string : `[${value.join(",")}]`;
74
+ }
75
+ toSQLScalar(value) {
76
+ if (value === null) return "NULL";
77
+ return value instanceof Sql ? value.string : `'[${value.join(",")}]'`;
78
+ }
79
+ fromDriverScalar(value) {
80
+ if (value === null) return null;
81
+ if (Array.isArray(value)) return value;
82
+ if (typeof value === "string") try {
83
+ return JSON.parse(value);
84
+ } catch {
85
+ return null;
86
+ }
87
+ return null;
88
+ }
89
+ };
90
+ /**
91
+ * Creates a `halfvec` column. PostgreSQL pgvector half precision vector type, maps to `number[]`.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * halfvec({ dimensions: 1536, notNull }) // halfvec(1536) NOT NULL
96
+ * ```
97
+ *
98
+ * @param config.dimensions - Fixed vector dimension length
99
+ */
100
+ function halfvec(config = {}) {
101
+ return new HalfvecColumn(config);
102
+ }
103
+ var SparsevecColumn = class extends Column {
104
+ static id = "Column.Sparsevec";
105
+ #dimensions;
106
+ constructor(config) {
107
+ super(config);
108
+ this.#dimensions = config.dimensions;
109
+ }
110
+ get sqlTypeScalar() {
111
+ return this.#dimensions ? `sparsevec(${this.#dimensions})` : "sparsevec";
112
+ }
113
+ get sqlCastScalar() {
114
+ return this.sqlTypeScalar;
115
+ }
116
+ get zodTypeScaler() {
117
+ return z.string();
118
+ }
119
+ toDriverScalar(value) {
120
+ if (value === null) return null;
121
+ return value instanceof Sql ? value.string : value;
122
+ }
123
+ toSQLScalar(value) {
124
+ if (value === null) return "NULL";
125
+ return value instanceof Sql ? value.string : `'${value.replace(/'/g, "''")}'`;
126
+ }
127
+ fromDriverScalar(value) {
128
+ return value;
129
+ }
130
+ };
131
+ /**
132
+ * Creates a `sparsevec` column. PostgreSQL pgvector sparse vector type, maps to `string`.
133
+ *
134
+ * @example
135
+ * ```ts
136
+ * sparsevec({ dimensions: 1000, notNull }) // sparsevec(1000) NOT NULL
137
+ * ```
138
+ *
139
+ * @param config.dimensions - Fixed vector dimension length
140
+ */
141
+ function sparsevec(config = {}) {
142
+ return new SparsevecColumn(config);
143
+ }
144
+ var BitColumn = class extends Column {
145
+ static id = "Column.Bit";
146
+ #length;
147
+ constructor(config) {
148
+ super(config);
149
+ this.#length = config.length;
150
+ }
151
+ get sqlTypeScalar() {
152
+ return this.#length ? `bit(${this.#length})` : "bit";
153
+ }
154
+ get sqlCastScalar() {
155
+ return this.sqlTypeScalar;
156
+ }
157
+ get zodTypeScaler() {
158
+ let base = z.string().regex(/^[01]+$/);
159
+ if (this.#length !== void 0) base = base.length(this.#length);
160
+ return base;
161
+ }
162
+ toDriverScalar(value) {
163
+ if (value === null) return null;
164
+ return value instanceof Sql ? value.string : value;
165
+ }
166
+ toSQLScalar(value) {
167
+ if (value === null) return "NULL";
168
+ return value instanceof Sql ? value.string : `B'${value}'`;
169
+ }
170
+ fromDriverScalar(value) {
171
+ return value;
172
+ }
173
+ };
174
+ /**
175
+ * Creates a `bit` column. PostgreSQL bit string type, maps to `string`.
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * bit({ length: 16, notNull }) // bit(16) NOT NULL
180
+ * ```
181
+ *
182
+ * @param config.length - Fixed bit string length
183
+ */
184
+ function bit(config = {}) {
185
+ return new BitColumn(config);
186
+ }
187
+ /** All pgvector column constructors grouped as a single object. */
188
+ const pgvector = {
189
+ vector,
190
+ halfvec,
191
+ sparsevec,
192
+ bit
193
+ };
194
+ //#endregion
195
+ export { pgvector };
@@ -59,7 +59,7 @@ var BunPool = class extends $Pool {
59
59
  #pool;
60
60
  constructor(options) {
61
61
  super(options);
62
- this.#pool = new Bun.SQL(getUrlFromDbCredentials(options.dbCredentials), { max: options.pool?.max ?? 10 });
62
+ this.#pool = new Bun.SQL(getUrlFromDbCredentials(options.dbCredentials), { max: options.pool?.max ?? 5 });
63
63
  this.query = this.#pool.unsafe.bind(this.#pool);
64
64
  }
65
65
  async connect() {
@@ -66,7 +66,7 @@ var PgPool = class extends $Pool {
66
66
  super(options);
67
67
  this.#pool = new Pool({
68
68
  connectionString: getUrlFromDbCredentials(options.dbCredentials),
69
- max: options.pool?.max ?? 10
69
+ max: options.pool?.max ?? 5
70
70
  });
71
71
  this.query = this.#pool.query.bind(this.#pool);
72
72
  }
@@ -60,7 +60,7 @@ var PostgresPool = class extends $Pool {
60
60
  #sql;
61
61
  constructor(options) {
62
62
  super(options);
63
- this.#sql = postgresLib(getUrlFromDbCredentials(options.dbCredentials), { max: options.pool?.max ?? 10 });
63
+ this.#sql = postgresLib(getUrlFromDbCredentials(options.dbCredentials), { max: options.pool?.max ?? 5 });
64
64
  this.query = this.#sql.unsafe.bind(this.#sql);
65
65
  }
66
66
  async connect() {}
@@ -1,4 +1,4 @@
1
- import { TableAnyColumn } from "../table.mjs";
1
+ import { AnyColumn, TableAnyColumn } from "../table.mjs";
2
2
  import { AnyFilter, Filter } from "../filters/index.mjs";
3
3
  import { QueryContext } from "../query-builders/query.mjs";
4
4
  import { Sql } from "../sql.mjs";
@@ -8,7 +8,7 @@ import { Sql } from "../sql.mjs";
8
8
  * A check constraint expression that can be a filter condition or a raw SQL snippet.
9
9
  * Used in `checkConstraints` table extra to define `CHECK` constraints.
10
10
  */
11
- type CheckExpression<TScopeColumns extends TableAnyColumn> = Filter<TScopeColumns, false> | Sql;
11
+ type CheckExpression<TScopeColumns extends TableAnyColumn | AnyColumn> = Filter<TScopeColumns, false> | Sql;
12
12
  /** A CHECK constraint for a table, storing its name and filter/SQL expression. */
13
13
  declare class Check {
14
14
  #private;
@@ -34,7 +34,7 @@ var Check = class {
34
34
  * ```ts
35
35
  * table("public", "projects", { name: varchar({ length: 255 }) }, {
36
36
  * checkConstraints: (t, check) => [
37
- * check("check_projects_name_length", gte(sql`char_length(${t.name})`, 1)),
37
+ * check("check_projects_name_length", gte(length(t.name), 1)),
38
38
  * ],
39
39
  * });
40
40
  * ```
package/dist/src/db.d.mts CHANGED
@@ -10,7 +10,6 @@ import { DistinctQuery } from "./query-builders/distinct.mjs";
10
10
  import { ExistsQuery } from "./query-builders/exists.mjs";
11
11
  import { FirstQuery } from "./query-builders/first.mjs";
12
12
  import { InsertBuilder } from "./query-builders/insert.mjs";
13
- import { InsertReturningQuery } from "./query-builders/insert-returning.mjs";
14
13
  import { RawQuery } from "./query-builders/raw.mjs";
15
14
  import { RelationQueryBuilder } from "./query-builders/rq.mjs";
16
15
  import { UpdateBuilder } from "./query-builders/update.mjs";
@@ -124,13 +123,6 @@ declare class Base<TTName extends string, TTables extends Record<TTName, TableWi
124
123
  */
125
124
  $distinct<TTable extends TTables[keyof TTables], TColumn extends Valueof<TTable["_"]["columns"]>>(table: TTable, column: TColumn): DistinctQuery<TTable, TColumn, TColumn["ValTypeSelect"][], TPrepare>;
126
125
  $distinct<TTable extends TTables[keyof TTables], TColumn extends Valueof<TTable["_"]["columns"]>, TWhere extends FilterExpression<Valueof<TTable["_"]["columns"]>, TPrepare>>(table: TTable, column: TColumn, where: TWhere): DistinctQuery<TTable, TColumn, TColumn["ValTypeSelect"][], TPrepare>;
127
- /**
128
- * Insert a row and return the inserted row with all columns.
129
- * @param table The table to insert into
130
- * @param values The values to insert
131
- * @returns Promise<T> - the inserted row with all columns including generated values
132
- */
133
- $insertReturning<TTable extends TTables[keyof TTables]>(table: TTable, values: { [colName in keyof TTable["_"]["columns"] as TTable["_"]["columns"][colName]["ValTypeInsert"] extends never ? never : undefined extends TTable["_"]["columns"][colName]["ValTypeInsert"] ? never : colName]: TTable["_"]["columns"][colName]["ValTypeInsert"] } & { [colName in keyof TTable["_"]["columns"] as TTable["_"]["columns"][colName]["ValTypeInsert"] extends never ? never : undefined extends TTable["_"]["columns"][colName]["ValTypeInsert"] ? colName : never]?: Exclude<TTable["_"]["columns"][colName]["ValTypeInsert"], undefined> }): InsertReturningQuery<TTable, { [ColName in keyof TTable["_"]["columns"]]: TTable["_"]["columns"][ColName]["ValTypeSelect"] }>;
134
126
  /**
135
127
  * Start building a relational query for the specified table.
136
128
  *
@@ -148,7 +140,7 @@ declare class Base<TTName extends string, TTables extends Record<TTName, TableWi
148
140
  * @param table The table to query — must have relations registered via `relations()`.
149
141
  * @returns A `RelationQueryBuilder` with `.findMany()` and `.findFirst()` methods.
150
142
  */
151
- query<UTSchema extends string, UTName extends string, TColumns extends Record<string, AnyColumn>>(table: TableWithColumns<UTSchema, UTName, TColumns>): RelationQueryBuilder<UTSchema, UTName, TColumns, TAllRelations[`"${CamelToSnake<UTSchema>}"."${CamelToSnake<UTName>}"`], TAllRelations>;
143
+ query<UTSchema extends string, UTName extends string, TColumns extends Record<string, AnyColumn>>(table: TableWithColumns<UTSchema, UTName, TColumns>): RelationQueryBuilder<UTSchema, UTName, TColumns, TAllRelations[`"${CamelToSnake<UTSchema>}"."${CamelToSnake<UTName>}"`], TAllRelations, TPrepare>;
152
144
  /**
153
145
  * Execute a raw SQL query with optional parameter binding and custom result handler.
154
146
  * @param query The raw SQL query string with $1, $2, etc. placeholders for parameters
package/dist/src/db.mjs CHANGED
@@ -7,7 +7,6 @@ import { DistinctQuery } from "./query-builders/distinct.mjs";
7
7
  import { ExistsQuery } from "./query-builders/exists.mjs";
8
8
  import { FirstQuery } from "./query-builders/first.mjs";
9
9
  import { InsertBuilder } from "./query-builders/insert.mjs";
10
- import { InsertReturningQuery } from "./query-builders/insert-returning.mjs";
11
10
  import { RawQuery } from "./query-builders/raw.mjs";
12
11
  import { RelationQueryBuilder } from "./query-builders/rq.mjs";
13
12
  import { SelectBuilder } from "./query-builders/select.mjs";
@@ -91,15 +90,6 @@ var Base = class {
91
90
  return new DistinctQuery(table, column, where, this.#getExecutor(), this.$.pre);
92
91
  }
93
92
  /**
94
- * Insert a row and return the inserted row with all columns.
95
- * @param table The table to insert into
96
- * @param values The values to insert
97
- * @returns Promise<T> - the inserted row with all columns including generated values
98
- */
99
- $insertReturning(table, values) {
100
- return new InsertReturningQuery(table, values, this.#getExecutor());
101
- }
102
- /**
103
93
  * Start building a relational query for the specified table.
104
94
  *
105
95
  * Returns a builder with two methods:
@@ -117,7 +107,7 @@ var Base = class {
117
107
  * @returns A `RelationQueryBuilder` with `.findMany()` and `.findFirst()` methods.
118
108
  */
119
109
  query(table) {
120
- return new RelationQueryBuilder(table, this.#allRelations[table._.fullName], this.#allRelations, this.#getExecutor());
110
+ return new RelationQueryBuilder(table, this.#allRelations[table._.fullName], this.#allRelations, this.#getExecutor(), this.$.pre);
121
111
  }
122
112
  /**
123
113
  * Execute a raw SQL query with optional parameter binding and custom result handler.
@@ -1,4 +1,4 @@
1
- import { TableAnyColumn } from "../table.mjs";
1
+ import { AnyColumn } from "../table.mjs";
2
2
  import { Filter } from "./index.mjs";
3
3
  import { Arg, IsArg } from "../query-builders/pre.mjs";
4
4
  import { Query, QueryContext } from "../query-builders/query.mjs";
@@ -13,7 +13,7 @@ type ArrayElement<T> = T extends readonly (infer E)[] ? E extends readonly unkno
13
13
  * ArrayContains filter: col @> ARRAY[values]
14
14
  * Returns true if the array column contains all the specified values.
15
15
  */
16
- declare class ArrayContainsFilter<TCol extends TableAnyColumn, TValues extends ArrayElement<TCol["ValType"]>[] | Arg<TCol["ValType"]>> extends Filter<TCol, IsArg<TValues>> {
16
+ declare class ArrayContainsFilter<TCol extends AnyColumn, TValues extends ArrayElement<TCol["ValType"]>[] | Arg<TCol["ValType"]>> extends Filter<TCol, IsArg<TValues>> {
17
17
  readonly left: TCol;
18
18
  readonly values: TValues;
19
19
  constructor(column: TCol, values: TValues);
@@ -26,13 +26,13 @@ declare class ArrayContainsFilter<TCol extends TableAnyColumn, TValues extends A
26
26
  * @example
27
27
  * db.from(Posts).select().where(arrayContains(Posts.tags, ['typescript', 'postgres']))
28
28
  */
29
- declare function arrayContains<TCol extends TableAnyColumn, TValues extends ArrayElement<TCol["ValType"]>[]>(column: TCol, values: TValues): ArrayContainsFilter<TCol, TValues>;
30
- declare function arrayContains<TCol extends TableAnyColumn, TValues extends Arg<TCol["ValType"]>>(column: TCol, values: TValues): ArrayContainsFilter<TCol, TValues>;
29
+ declare function arrayContains<TCol extends AnyColumn, TValues extends ArrayElement<TCol["ValType"]>[]>(column: TCol, values: TValues): ArrayContainsFilter<TCol, TValues>;
30
+ declare function arrayContains<TCol extends AnyColumn, TValues extends Arg<TCol["ValType"]>>(column: TCol, values: TValues): ArrayContainsFilter<TCol, TValues>;
31
31
  /**
32
32
  * ArrayContainedBy filter: col <@ ARRAY[values]
33
33
  * Returns true if the array column is contained by (is a subset of) the specified values.
34
34
  */
35
- declare class ArrayContainedByFilter<TCol extends TableAnyColumn, TValues extends ArrayElement<TCol["ValType"]>[] | Arg<TCol["ValType"]>> extends Filter<TCol, IsArg<TValues>> {
35
+ declare class ArrayContainedByFilter<TCol extends AnyColumn, TValues extends ArrayElement<TCol["ValType"]>[] | Arg<TCol["ValType"]>> extends Filter<TCol, IsArg<TValues>> {
36
36
  readonly left: TCol;
37
37
  readonly values: TValues;
38
38
  constructor(column: TCol, values: TValues);
@@ -42,13 +42,13 @@ declare class ArrayContainedByFilter<TCol extends TableAnyColumn, TValues extend
42
42
  * Creates a condition that checks if an array column is contained by the specified values.
43
43
  * SQL: column <@ ARRAY[values]
44
44
  */
45
- declare function arrayContainedBy<TCol extends TableAnyColumn, TValues extends ArrayElement<TCol["ValType"]>[]>(column: TCol, values: TValues): ArrayContainedByFilter<TCol, TValues>;
46
- declare function arrayContainedBy<TCol extends TableAnyColumn, TValues extends Arg<TCol["ValType"]>>(column: TCol, values: TValues): ArrayContainedByFilter<TCol, TValues>;
45
+ declare function arrayContainedBy<TCol extends AnyColumn, TValues extends ArrayElement<TCol["ValType"]>[]>(column: TCol, values: TValues): ArrayContainedByFilter<TCol, TValues>;
46
+ declare function arrayContainedBy<TCol extends AnyColumn, TValues extends Arg<TCol["ValType"]>>(column: TCol, values: TValues): ArrayContainedByFilter<TCol, TValues>;
47
47
  /**
48
48
  * ArrayOverlaps filter: col && ARRAY[values]
49
49
  * Returns true if the arrays have any elements in common.
50
50
  */
51
- declare class ArrayOverlapsFilter<TCol extends TableAnyColumn, TValues extends ArrayElement<TCol["ValType"]>[] | Arg<TCol["ValType"]>> extends Filter<TCol, IsArg<TValues>> {
51
+ declare class ArrayOverlapsFilter<TCol extends AnyColumn, TValues extends ArrayElement<TCol["ValType"]>[] | Arg<TCol["ValType"]>> extends Filter<TCol, IsArg<TValues>> {
52
52
  readonly left: TCol;
53
53
  readonly right: TValues;
54
54
  constructor(column: TCol, values: TValues);
@@ -58,13 +58,13 @@ declare class ArrayOverlapsFilter<TCol extends TableAnyColumn, TValues extends A
58
58
  * Creates a condition that checks if an array column overlaps with the specified values.
59
59
  * SQL: column && ARRAY[values]
60
60
  */
61
- declare function arrayOverlaps<TCol extends TableAnyColumn, TValues extends ArrayElement<TCol["ValType"]>[]>(column: TCol, values: TValues): ArrayOverlapsFilter<TCol, TValues>;
62
- declare function arrayOverlaps<TCol extends TableAnyColumn, TValues extends Arg<TCol["ValType"]>>(column: TCol, values: TValues): ArrayOverlapsFilter<TCol, TValues>;
61
+ declare function arrayOverlaps<TCol extends AnyColumn, TValues extends ArrayElement<TCol["ValType"]>[]>(column: TCol, values: TValues): ArrayOverlapsFilter<TCol, TValues>;
62
+ declare function arrayOverlaps<TCol extends AnyColumn, TValues extends Arg<TCol["ValType"]>>(column: TCol, values: TValues): ArrayOverlapsFilter<TCol, TValues>;
63
63
  /**
64
64
  * ArrayHas filter: value = ANY(col)
65
65
  * Returns true if the value exists in the array column.
66
66
  */
67
- declare class ArrayHasFilter<TCol extends TableAnyColumn, TRight extends ArrayElement<TCol["ValType"]> | Arg<ArrayElement<TCol["ValType"]>>> extends Filter<TCol, IsArg<TRight>> {
67
+ declare class ArrayHasFilter<TCol extends AnyColumn, TRight extends ArrayElement<TCol["ValType"]> | Arg<ArrayElement<TCol["ValType"]>>> extends Filter<TCol, IsArg<TRight>> {
68
68
  readonly left: TCol;
69
69
  readonly value: TRight;
70
70
  constructor(column: TCol, value: TRight);
@@ -74,13 +74,13 @@ declare class ArrayHasFilter<TCol extends TableAnyColumn, TRight extends ArrayEl
74
74
  * Creates a condition that checks if a value exists in an array column.
75
75
  * SQL: value = ANY(column)
76
76
  */
77
- declare function arrayHas<TCol extends TableAnyColumn, TRight extends ArrayElement<TCol["ValType"]>>(column: TCol, value: TRight): ArrayHasFilter<TCol, TRight>;
78
- declare function arrayHas<TCol extends TableAnyColumn, TRight extends Arg<ArrayElement<TCol["ValType"]>>>(column: TCol, value: TRight): ArrayHasFilter<TCol, TRight>;
77
+ declare function arrayHas<TCol extends AnyColumn, TRight extends ArrayElement<TCol["ValType"]>>(column: TCol, value: TRight): ArrayHasFilter<TCol, TRight>;
78
+ declare function arrayHas<TCol extends AnyColumn, TRight extends Arg<ArrayElement<TCol["ValType"]>>>(column: TCol, value: TRight): ArrayHasFilter<TCol, TRight>;
79
79
  /**
80
80
  * ArrayAll filter: value = ALL(col)
81
81
  * Returns true if all elements in the array column equal the value.
82
82
  */
83
- declare class ArrayAllFilter<TCol extends TableAnyColumn, TRight extends ArrayElement<TCol["ValType"]> | Arg<ArrayElement<TCol["ValType"]>>> extends Filter<TCol, IsArg<TRight>> {
83
+ declare class ArrayAllFilter<TCol extends AnyColumn, TRight extends ArrayElement<TCol["ValType"]> | Arg<ArrayElement<TCol["ValType"]>>> extends Filter<TCol, IsArg<TRight>> {
84
84
  readonly left: TCol;
85
85
  readonly value: TRight;
86
86
  constructor(column: TCol, value: TRight);
@@ -90,7 +90,7 @@ declare class ArrayAllFilter<TCol extends TableAnyColumn, TRight extends ArrayEl
90
90
  * Creates a condition that checks if all elements in an array column equal a value.
91
91
  * SQL: value = ALL(column)
92
92
  */
93
- declare function arrayAll<TCol extends TableAnyColumn, TRight extends ArrayElement<TCol["ValType"]>>(column: TCol, value: TRight): ArrayAllFilter<TCol, TRight>;
94
- declare function arrayAll<TCol extends TableAnyColumn, TRight extends Arg<ArrayElement<TCol["ValType"]>>>(column: TCol, value: TRight): ArrayAllFilter<TCol, TRight>;
93
+ declare function arrayAll<TCol extends AnyColumn, TRight extends ArrayElement<TCol["ValType"]>>(column: TCol, value: TRight): ArrayAllFilter<TCol, TRight>;
94
+ declare function arrayAll<TCol extends AnyColumn, TRight extends Arg<ArrayElement<TCol["ValType"]>>>(column: TCol, value: TRight): ArrayAllFilter<TCol, TRight>;
95
95
  //#endregion
96
96
  export { arrayAll, arrayContainedBy, arrayContains, arrayHas, arrayOverlaps };