pqb 0.27.6 → 0.28.0

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/index.js CHANGED
@@ -101,10 +101,23 @@ const countSelect = [new RawSQL("count(*)")];
101
101
  function sqlQueryArgsToExpression(args) {
102
102
  return Array.isArray(args[0]) ? new RawSQL(args) : args[0];
103
103
  }
104
+ const sqlFn = (...args) => {
105
+ const arg = args[0];
106
+ if (Array.isArray(arg)) {
107
+ return new RawSQL(args);
108
+ }
109
+ if (typeof args[0] === "string") {
110
+ return new RawSQL(args[0]);
111
+ }
112
+ if (args[1] !== void 0) {
113
+ return new RawSQL(args[1], arg);
114
+ }
115
+ return (...args2) => new RawSQL(args2, arg);
116
+ };
104
117
 
105
118
  var __defProp$h = Object.defineProperty;
106
- var __defProps$b = Object.defineProperties;
107
- var __getOwnPropDescs$b = Object.getOwnPropertyDescriptors;
119
+ var __defProps$9 = Object.defineProperties;
120
+ var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
108
121
  var __getOwnPropSymbols$i = Object.getOwnPropertySymbols;
109
122
  var __hasOwnProp$i = Object.prototype.hasOwnProperty;
110
123
  var __propIsEnum$i = Object.prototype.propertyIsEnumerable;
@@ -120,7 +133,7 @@ var __spreadValues$h = (a, b) => {
120
133
  }
121
134
  return a;
122
135
  };
123
- var __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
136
+ var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
124
137
  class ColumnType extends orchidCore.ColumnTypeBase {
125
138
  /**
126
139
  * Mark the column as a primary key.
@@ -135,30 +148,90 @@ class ColumnType extends orchidCore.ColumnTypeBase {
135
148
  * readonly table = 'table';
136
149
  * columns = this.setColumns((t) => ({
137
150
  * id: t.uuid().primaryKey(),
151
+ * // database-level name can be passed:
152
+ * id: t.uuid().primaryKey('primary_key_name'),
138
153
  * }));
139
154
  * }
140
155
  *
141
156
  * // primary key can be used by `find` later:
142
157
  * db.table.find('97ba9e78-7510-415a-9c03-23d440aec443');
143
158
  * ```
159
+ *
160
+ * @param name - to specify a constraint name
144
161
  */
145
- primaryKey() {
146
- return orchidCore.setColumnData(this, "isPrimaryKey", true);
162
+ primaryKey(name) {
163
+ return orchidCore.setColumnData(this, "primaryKey", name != null ? name : true);
147
164
  }
148
165
  foreignKey(fnOrTable, column, options = orchidCore.emptyObject) {
149
- const item = typeof fnOrTable === "string" ? __spreadValues$h({ table: fnOrTable, columns: [column] }, options) : __spreadValues$h({ fn: fnOrTable, columns: [column] }, options);
150
- return orchidCore.pushColumnData(this, "foreignKeys", item);
166
+ return orchidCore.pushColumnData(this, "foreignKeys", {
167
+ fnOrTable,
168
+ foreignColumns: [column],
169
+ options
170
+ });
151
171
  }
152
172
  toSQL() {
153
173
  return this.dataType;
154
174
  }
155
- index(options = {}) {
156
- return orchidCore.pushColumnData(this, "indexes", options);
175
+ /**
176
+ * Add an index to the column.
177
+ *
178
+ * ```ts
179
+ * import { change } from '../dbScript';
180
+ *
181
+ * change(async (db) => {
182
+ * await db.createTable('table', (t) => ({
183
+ * // add an index to the name column with default settings:
184
+ * name: t.text().index(),
185
+ * // options are described below:
186
+ * name: t.text().index({ ...options }),
187
+ * // with a database-level name:
188
+ * name: t.text().index('custom_index_name'),
189
+ * // with name and options:
190
+ * name: t.text().index('custom_index_name', { ...options }),
191
+ * }));
192
+ * });
193
+ * ```
194
+ *
195
+ * Possible options are:
196
+ *
197
+ * ```ts
198
+ * type IndexOptions = {
199
+ * // NULLS NOT DISTINCT: availabe in Postgres 15+, makes sense only for unique index
200
+ * nullsNotDistinct?: true;
201
+ * // index algorithm to use such as GIST, GIN
202
+ * using?: string;
203
+ * // specify collation:
204
+ * collate?: string;
205
+ * // see `opclass` in the Postgres document for creating the index
206
+ * opclass?: string;
207
+ * // specify index order such as ASC NULLS FIRST, DESC NULLS LAST
208
+ * order?: string;
209
+ * // include columns to an index to optimize specific queries
210
+ * include?: MaybeArray<string>;
211
+ * // see "storage parameters" in the Postgres document for creating an index, for example, 'fillfactor = 70'
212
+ * with?: string;
213
+ * // The tablespace in which to create the index. If not specified, default_tablespace is consulted, or temp_tablespaces for indexes on temporary tables.
214
+ * tablespace?: string;
215
+ * // WHERE clause to filter records for the index
216
+ * where?: string;
217
+ * // mode is for dropping the index
218
+ * mode?: 'CASCADE' | 'RESTRICT';
219
+ * };
220
+ * ```
221
+ *
222
+ * @param args
223
+ */
224
+ index(...args) {
225
+ var _a;
226
+ return orchidCore.pushColumnData(this, "indexes", {
227
+ options: (_a = typeof args[0] === "string" ? args[1] : args[0]) != null ? _a : orchidCore.emptyObject,
228
+ name: typeof args[0] === "string" ? args[0] : void 0
229
+ });
157
230
  }
158
231
  /**
159
- * `searchIndex` is designed for full text search.
232
+ * `searchIndex` is designed for [full text search](/guide/text-search).
160
233
  *
161
- * It can accept the same options as a regular `index`, but it is `USING GIN` by default, and it is concatenating columns into a `tsvector`.
234
+ * It can accept the same options as a regular `index`, but it is `USING GIN` by default, and it is concatenating columns into a `tsvector` database type.
162
235
  *
163
236
  * ```ts
164
237
  * import { change } from '../dbScript';
@@ -166,8 +239,8 @@ class ColumnType extends orchidCore.ColumnTypeBase {
166
239
  * change(async (db) => {
167
240
  * await db.createTable('table', (t) => ({
168
241
  * id: t.identity().primaryKey(),
169
- * title: t.string(),
170
- * body: t.string(),
242
+ * title: t.text(),
243
+ * body: t.text(),
171
244
  * ...t.searchIndex(['title', 'body']),
172
245
  * }));
173
246
  * });
@@ -176,10 +249,29 @@ class ColumnType extends orchidCore.ColumnTypeBase {
176
249
  * Produces the following index ('english' is a default language, see [full text search](/guide/text-search.html#language) for changing it):
177
250
  *
178
251
  * ```sql
179
- * CREATE INDEX "table_title_body_idx" ON "table" USING GIN (to_tsvector('english', concat_ws(' ', "title", "body")))
252
+ * CREATE INDEX "table_title_body_idx" ON "table" USING GIN (to_tsvector('english', "title" || ' ' || "body"))
253
+ * ```
254
+ *
255
+ * You can set different search weights (`A` to `D`) on different columns inside the index:
256
+ *
257
+ * ```ts
258
+ * import { change } from '../dbScript';
259
+ *
260
+ * change(async (db) => {
261
+ * await db.createTable('table', (t) => ({
262
+ * id: t.identity().primaryKey(),
263
+ * title: t.text(),
264
+ * body: t.text(),
265
+ * ...t.searchIndex([
266
+ * { column: 'title', weight: 'A' },
267
+ * { column: 'body', weight: 'B' },
268
+ * ]),
269
+ * }));
270
+ * });
180
271
  * ```
181
272
  *
182
- * Also, it works well with a generated `tsvector` column:
273
+ * When the table has localized columns,
274
+ * you can define different indexes for different languages by setting the `language` parameter:
183
275
  *
184
276
  * ```ts
185
277
  * import { change } from '../dbScript';
@@ -187,8 +279,44 @@ class ColumnType extends orchidCore.ColumnTypeBase {
187
279
  * change(async (db) => {
188
280
  * await db.createTable('table', (t) => ({
189
281
  * id: t.identity().primaryKey(),
190
- * title: t.string(),
191
- * body: t.string(),
282
+ * titleEn: t.text(),
283
+ * bodyEn: t.text(),
284
+ * titleFr: t.text(),
285
+ * bodyFr: t.text(),
286
+ * ...t.searchIndex(['titleEn', 'bodyEn'], { language: 'english' }),
287
+ * ...t.searchIndex(['titleFr', 'bodyFr'], { language: 'french' }),
288
+ * }));
289
+ * });
290
+ * ```
291
+ *
292
+ * Alternatively, different table records may correspond to a single language,
293
+ * then you can define a search index that relies on a language column by using `languageColumn` parameter:
294
+ *
295
+ * ```ts
296
+ * import { change } from '../dbScript';
297
+ *
298
+ * change(async (db) => {
299
+ * await db.createTable('table', (t) => ({
300
+ * id: t.identity().primaryKey(),
301
+ * lang: t.type('regconfig'),
302
+ * title: t.text(),
303
+ * body: t.text(),
304
+ * ...t.searchIndex(['title', 'body'], { languageColumn: 'lang' }),
305
+ * }));
306
+ * });
307
+ * ```
308
+ *
309
+ * It can be more efficient to use a [generated](/guide/migration-column-methods.html#generated-column) column instead of indexing text column in the way described above,
310
+ * and to set a `searchIndex` on it:
311
+ *
312
+ * ```ts
313
+ * import { change } from '../dbScript';
314
+ *
315
+ * change(async (db) => {
316
+ * await db.createTable('table', (t) => ({
317
+ * id: t.identity().primaryKey(),
318
+ * title: t.text(),
319
+ * body: t.text(),
192
320
  * generatedTsVector: t.tsvector().generated(['title', 'body']).searchIndex(),
193
321
  * }));
194
322
  * });
@@ -202,11 +330,19 @@ class ColumnType extends orchidCore.ColumnTypeBase {
202
330
  *
203
331
  * @param options - index options
204
332
  */
205
- searchIndex(options) {
206
- return orchidCore.pushColumnData(this, "indexes", __spreadValues$h(__spreadValues$h({}, options), this.dataType === "tsvector" ? { using: "GIN" } : { tsVector: true }));
333
+ searchIndex(...args) {
334
+ return orchidCore.pushColumnData(this, "indexes", {
335
+ options: __spreadValues$h(__spreadValues$h({}, typeof args[0] === "string" ? args[1] : args[0]), this.dataType === "tsvector" ? { using: "GIN" } : { tsVector: true }),
336
+ name: typeof args[0] === "string" ? args[0] : void 0
337
+ });
207
338
  }
208
- unique(options = {}) {
209
- return orchidCore.pushColumnData(this, "indexes", __spreadProps$b(__spreadValues$h({}, options), { unique: true }));
339
+ unique(...args) {
340
+ return orchidCore.pushColumnData(this, "indexes", {
341
+ options: __spreadProps$9(__spreadValues$h({}, typeof args[0] === "string" ? args[1] : args[0]), {
342
+ unique: true
343
+ }),
344
+ name: typeof args[0] === "string" ? args[0] : void 0
345
+ });
210
346
  }
211
347
  comment(comment) {
212
348
  return orchidCore.setColumnData(this, "comment", comment);
@@ -245,8 +381,8 @@ class ColumnType extends orchidCore.ColumnTypeBase {
245
381
  }
246
382
 
247
383
  var __defProp$g = Object.defineProperty;
248
- var __defProps$a = Object.defineProperties;
249
- var __getOwnPropDescs$a = Object.getOwnPropertyDescriptors;
384
+ var __defProps$8 = Object.defineProperties;
385
+ var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
250
386
  var __getOwnPropSymbols$h = Object.getOwnPropertySymbols;
251
387
  var __hasOwnProp$h = Object.prototype.hasOwnProperty;
252
388
  var __propIsEnum$h = Object.prototype.propertyIsEnumerable;
@@ -262,34 +398,32 @@ var __spreadValues$g = (a, b) => {
262
398
  }
263
399
  return a;
264
400
  };
265
- var __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
401
+ var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
266
402
  const knownDefaults = {
267
403
  current_timestamp: "now()",
268
404
  "transaction_timestamp()": "now()"
269
405
  };
270
406
  const simplifyColumnDefault = (value) => {
271
407
  if (typeof value === "string") {
272
- const lower = value.toLowerCase();
273
- return new RawSQL(knownDefaults[lower] || value);
408
+ return new RawSQL([
409
+ [knownDefaults[value.toLowerCase()] || value]
410
+ ]);
274
411
  }
275
412
  return;
276
413
  };
277
414
  const instantiateColumn = (typeFn, params) => {
278
415
  const column = typeFn();
279
- Object.assign(column.data, __spreadProps$a(__spreadValues$g({}, params), {
416
+ const { dateTimePrecision } = params;
417
+ Object.assign(column.data, __spreadProps$8(__spreadValues$g({}, params), {
418
+ dateTimePrecision: (
419
+ // 0 is default for date, 6 is default for timestamp
420
+ dateTimePrecision && dateTimePrecision !== 6 ? dateTimePrecision : void 0
421
+ ),
422
+ collate: params.collate,
280
423
  default: simplifyColumnDefault(params.default)
281
424
  }));
282
425
  return column;
283
426
  };
284
- const getConstraintKind = (it) => {
285
- let num = 0;
286
- for (const key in it) {
287
- if ((key === "references" || key === "check") && it[key] !== void 0) {
288
- num++;
289
- }
290
- }
291
- return num === 1 ? it.references ? "foreignKey" : "check" : "constraint";
292
- };
293
427
 
294
428
  const isDefaultTimeStamp = (item) => {
295
429
  if (item.dataType !== "timestamptz")
@@ -317,7 +451,7 @@ const combineCodeElements = (input) => {
317
451
  }
318
452
  return output;
319
453
  };
320
- const columnsShapeToCode = (shape, tableData, t) => {
454
+ const columnsShapeToCode = (shape, t) => {
321
455
  const hasTimestamps = "createdAt" in shape && isDefaultTimeStamp(shape.createdAt) && "updatedAt" in shape && isDefaultTimeStamp(shape.updatedAt);
322
456
  const code = [];
323
457
  for (const key in shape) {
@@ -334,30 +468,64 @@ const columnsShapeToCode = (shape, tableData, t) => {
334
468
  if (hasTimestamps) {
335
469
  code.push(`...${t}.timestamps(),`);
336
470
  }
337
- const { primaryKey, indexes, constraints } = tableData;
338
- if (primaryKey) {
339
- code.push(primaryKeyToCode(primaryKey, t));
471
+ return code;
472
+ };
473
+ const pushTableDataCode = (code, ast) => {
474
+ const lines = [];
475
+ if (ast.primaryKey) {
476
+ lines.push([primaryKeyInnerToCode(ast.primaryKey, "t") + ","]);
340
477
  }
341
- if (indexes) {
342
- for (const index of indexes) {
343
- code.push(...indexToCode(index, t));
478
+ if (ast.indexes) {
479
+ for (const index of ast.indexes) {
480
+ lines.push(indexToCode(index, "t"));
344
481
  }
345
482
  }
346
- if (constraints) {
347
- for (const item of constraints) {
348
- code.push(...constraintToCode(item, t));
483
+ if (ast.constraints) {
484
+ for (const constraint of ast.constraints) {
485
+ lines.push(constraintToCode(constraint, "t", true));
349
486
  }
350
487
  }
488
+ if (lines.length > 1) {
489
+ code.push("(t) => [", ...lines, "],");
490
+ } else if (lines[0].length === 1 && typeof lines[0][0] === "string") {
491
+ code.push("(t) => " + lines[0][0]);
492
+ } else {
493
+ code.push("(t) => ", lines[0]);
494
+ }
351
495
  return code;
352
496
  };
353
- const primaryKeyToCode = (primaryKey, t) => {
354
- var _a;
355
- const name = (_a = primaryKey.options) == null ? void 0 : _a.name;
356
- return `...${t}.primaryKey([${primaryKey.columns.map(orchidCore.singleQuote).join(", ")}]${name ? `, { name: ${orchidCore.singleQuote(name)} }` : ""}),`;
497
+ const primaryKeyInnerToCode = (primaryKey, t) => {
498
+ const name = primaryKey.name;
499
+ return `${t}.primaryKey([${primaryKey.columns.map(orchidCore.singleQuote).join(", ")}]${name ? `, ${orchidCore.singleQuote(name)}` : ""})`;
500
+ };
501
+ const indexToCode = (index, t, prefix) => {
502
+ const code = indexInnerToCode(index, t);
503
+ if (prefix)
504
+ code[0] = prefix + code[0];
505
+ const last = code[code.length - 1];
506
+ if (typeof last === "string" && !last.endsWith(","))
507
+ orchidCore.addCode(code, ",");
508
+ return code;
357
509
  };
358
- const indexToCode = (index, t) => {
510
+ const indexInnerToCode = (index, t) => {
359
511
  const code = [];
360
- code.push(`...${t}.index(`);
512
+ code.push(
513
+ `${t}.${index.options.tsVector ? "searchIndex" : index.options.unique ? "unique" : "index"}(`
514
+ );
515
+ const columnOptions = ["collate", "opclass", "order", "weight"];
516
+ const indexOptionsKeys = [
517
+ index.options.tsVector ? "unique" : void 0,
518
+ "using",
519
+ "nullsNotDistinct",
520
+ "include",
521
+ "with",
522
+ "tablespace",
523
+ "where",
524
+ "language",
525
+ "languageColumn",
526
+ "dropMode"
527
+ ];
528
+ const hasOptions = indexOptionsKeys.some((key) => key && index.options[key]);
361
529
  const columnsMultiline = index.columns.some((column) => {
362
530
  for (const key in column) {
363
531
  if (key !== "column" && column[key] !== void 0)
@@ -371,7 +539,7 @@ const indexToCode = (index, t) => {
371
539
  const expr = "column" in column ? column.column : column.expression;
372
540
  let hasOptions2 = false;
373
541
  for (const key in column) {
374
- if (key !== "column" && key !== "expression") {
542
+ if (key !== "column") {
375
543
  hasOptions2 = true;
376
544
  }
377
545
  }
@@ -383,36 +551,38 @@ const indexToCode = (index, t) => {
383
551
  expr
384
552
  )},`
385
553
  ];
386
- if (column.collate !== void 0) {
387
- props.push(`collate: ${orchidCore.singleQuote(column.collate)},`);
388
- }
389
- if (column.opclass !== void 0) {
390
- props.push(`opclass: ${orchidCore.singleQuote(column.opclass)},`);
391
- }
392
- if (column.order !== void 0) {
393
- props.push(`order: ${orchidCore.singleQuote(column.order)},`);
554
+ for (const key of columnOptions) {
555
+ const value = column[key];
556
+ if (value !== void 0) {
557
+ props.push(`${key}: ${orchidCore.singleQuote(value)},`);
558
+ }
394
559
  }
395
560
  objects.push("{", props, "},");
396
561
  }
397
562
  }
398
- code.push(["[", objects, "]"]);
563
+ code.push(["[", objects, hasOptions || index.name ? "]," : "]"]);
564
+ if (index.name) {
565
+ orchidCore.addCode(code, ` ${orchidCore.singleQuote(index.name)},`);
566
+ }
399
567
  } else {
400
568
  orchidCore.addCode(
401
569
  code,
402
570
  `[${index.columns.map((it) => orchidCore.singleQuote(it.column)).join(", ")}]`
403
571
  );
572
+ if (index.name) {
573
+ orchidCore.addCode(code, `, ${orchidCore.singleQuote(index.name)}`);
574
+ }
404
575
  }
405
- const hasOptions = orchidCore.objectHasValues(index.options);
406
576
  if (hasOptions) {
407
577
  if (columnsMultiline) {
408
- const columns = code[code.length - 1];
409
- columns[columns.length - 1] += ",";
410
578
  code.push(["{"]);
411
579
  } else {
412
580
  orchidCore.addCode(code, ", {");
413
581
  }
414
582
  const options = [];
415
- for (const key in index.options) {
583
+ for (const key of indexOptionsKeys) {
584
+ if (!key)
585
+ continue;
416
586
  const value = index.options[key];
417
587
  if (value === null || value === void 0)
418
588
  continue;
@@ -430,49 +600,43 @@ const indexToCode = (index, t) => {
430
600
  if (columnsMultiline) {
431
601
  code.push("),");
432
602
  } else {
433
- orchidCore.addCode(code, "),");
603
+ orchidCore.addCode(code, ")");
434
604
  }
435
605
  return code;
436
606
  };
437
- const constraintToCode = (item, t) => {
438
- const kind = getConstraintKind(item);
439
- if (kind === "foreignKey" && item.references) {
607
+ const constraintToCode = (item, t, m, prefix) => {
608
+ const code = constraintInnerToCode(item, t, m);
609
+ if (prefix)
610
+ code[0] = prefix + code[0];
611
+ const last = code[code.length - 1];
612
+ if (typeof last === "string" && !last.endsWith(","))
613
+ code[code.length - 1] += ",";
614
+ return code;
615
+ };
616
+ const constraintInnerToCode = (item, t, m) => {
617
+ if (item.references) {
440
618
  return [
441
- `...${t}.foreignKey(`,
442
- referencesArgsToCode(item.references, item.name),
619
+ `${t}.foreignKey(`,
620
+ referencesArgsToCode(item.references, item.name, m),
443
621
  "),"
444
622
  ];
445
- } else if (kind === "check" && item.check) {
446
- return [`...${t}.check(${item.check.toCode(t)}),`];
447
- } else {
448
- return [`...${t}.constraint({`, constraintPropsToCode(t, item), "}),"];
449
- }
450
- };
451
- const constraintPropsToCode = (t, item) => {
452
- const props = [];
453
- if (item.name) {
454
- props.push(`name: ${orchidCore.singleQuote(item.name)},`);
455
- }
456
- if (item.references) {
457
- props.push(
458
- `references: [`,
459
- referencesArgsToCode(item.references, false),
460
- "],"
461
- );
462
- }
463
- if (item.check) {
464
- props.push(`check: ${item.check.toCode(t)},`);
465
623
  }
466
- return props;
624
+ return [
625
+ `${t}.check(${item.check.toCode(t)}${item.name ? `, ${orchidCore.singleQuote(item.name)}` : ""})`
626
+ ];
467
627
  };
468
628
  const referencesArgsToCode = ({
469
629
  columns,
470
630
  fnOrTable,
471
631
  foreignColumns,
472
632
  options
473
- }, name = (options == null ? void 0 : options.name) || false) => {
633
+ }, name = (options == null ? void 0 : options.name) || false, m) => {
474
634
  const args = [];
475
635
  args.push(`${orchidCore.singleQuoteArray(columns)},`);
636
+ if (m && typeof fnOrTable !== "string") {
637
+ const { schema, table } = new (fnOrTable())();
638
+ fnOrTable = schema ? `${schema}.${table}` : table;
639
+ }
476
640
  args.push(
477
641
  `${typeof fnOrTable === "string" ? orchidCore.singleQuote(fnOrTable) : fnOrTable.toString()},`
478
642
  );
@@ -492,36 +656,42 @@ const referencesArgsToCode = ({
492
656
  }
493
657
  return args;
494
658
  };
495
- const columnForeignKeysToCode = (foreignKeys) => {
659
+ const columnForeignKeysToCode = (foreignKeys, migration) => {
496
660
  const code = [];
497
661
  for (const foreignKey of foreignKeys) {
498
662
  orchidCore.addCode(code, `.foreignKey(`);
499
- for (const part of foreignKeyArgumentToCode(foreignKey)) {
663
+ for (const part of foreignKeyArgumentToCode(foreignKey, migration)) {
500
664
  orchidCore.addCode(code, part);
501
665
  }
502
666
  orchidCore.addCode(code, ")");
503
667
  }
504
668
  return code;
505
669
  };
506
- const foreignKeyArgumentToCode = (foreignKey) => {
670
+ const foreignKeyArgumentToCode = ({
671
+ fnOrTable,
672
+ foreignColumns,
673
+ options = orchidCore.emptyObject
674
+ }, migration) => {
507
675
  const code = [];
508
- if ("fn" in foreignKey) {
509
- code.push(foreignKey.fn.toString());
510
- } else {
511
- code.push(orchidCore.singleQuote(foreignKey.table));
676
+ if (migration && typeof fnOrTable !== "string") {
677
+ const { schema, table } = new (fnOrTable())();
678
+ fnOrTable = schema ? `${schema}.${table}` : table;
512
679
  }
513
- orchidCore.addCode(code, `, ${orchidCore.singleQuote(foreignKey.columns[0])}`);
514
- const hasOptions = foreignKey.name || foreignKey.match || foreignKey.onUpdate || foreignKey.onDelete;
680
+ code.push(
681
+ typeof fnOrTable === "string" ? orchidCore.singleQuote(fnOrTable) : fnOrTable.toString()
682
+ );
683
+ orchidCore.addCode(code, `, ${orchidCore.singleQuote(foreignColumns[0])}`);
684
+ const hasOptions = options.name || options.match || options.onUpdate || options.onDelete;
515
685
  if (hasOptions) {
516
686
  const arr = [];
517
- if (foreignKey.name)
518
- arr.push(`name: ${orchidCore.singleQuote(foreignKey.name)},`);
519
- if (foreignKey.match)
520
- arr.push(`match: ${orchidCore.singleQuote(foreignKey.match)},`);
521
- if (foreignKey.onUpdate)
522
- arr.push(`onUpdate: ${orchidCore.singleQuote(foreignKey.onUpdate)},`);
523
- if (foreignKey.onDelete)
524
- arr.push(`onDelete: ${orchidCore.singleQuote(foreignKey.onDelete)},`);
687
+ if (options.name)
688
+ arr.push(`name: ${orchidCore.singleQuote(options.name)},`);
689
+ if (options.match)
690
+ arr.push(`match: ${orchidCore.singleQuote(options.match)},`);
691
+ if (options.onUpdate)
692
+ arr.push(`onUpdate: ${orchidCore.singleQuote(options.onUpdate)},`);
693
+ if (options.onDelete)
694
+ arr.push(`onDelete: ${orchidCore.singleQuote(options.onDelete)},`);
525
695
  orchidCore.addCode(code, ", {");
526
696
  code.push(arr);
527
697
  orchidCore.addCode(code, "}");
@@ -530,31 +700,31 @@ const foreignKeyArgumentToCode = (foreignKey) => {
530
700
  };
531
701
  const columnIndexesToCode = (indexes) => {
532
702
  const code = [];
533
- for (const index of indexes) {
534
- orchidCore.addCode(code, `.${index.unique ? "unique" : "index"}(`);
703
+ for (const { options, name } of indexes) {
704
+ orchidCore.addCode(code, `.${options.unique ? "unique" : "index"}(`);
535
705
  const arr = [];
536
- if (index.collate)
537
- arr.push(`collate: ${orchidCore.singleQuote(index.collate)},`);
538
- if (index.opclass)
539
- arr.push(`opclass: ${orchidCore.singleQuote(index.opclass)},`);
540
- if (index.order)
541
- arr.push(`order: ${orchidCore.singleQuote(index.order)},`);
542
- if (index.name)
543
- arr.push(`name: ${orchidCore.singleQuote(index.name)},`);
544
- if (index.using)
545
- arr.push(`using: ${orchidCore.singleQuote(index.using)},`);
546
- if (index.include)
706
+ if (options.collate)
707
+ arr.push(`collate: ${orchidCore.singleQuote(options.collate)},`);
708
+ if (options.opclass)
709
+ arr.push(`opclass: ${orchidCore.singleQuote(options.opclass)},`);
710
+ if (options.order)
711
+ arr.push(`order: ${orchidCore.singleQuote(options.order)},`);
712
+ if (name)
713
+ arr.push(`name: ${orchidCore.singleQuote(name)},`);
714
+ if (options.using)
715
+ arr.push(`using: ${orchidCore.singleQuote(options.using)},`);
716
+ if (options.include)
547
717
  arr.push(
548
- `include: ${typeof index.include === "string" ? orchidCore.singleQuote(index.include) : `[${index.include.map(orchidCore.singleQuote).join(", ")}]`},`
718
+ `include: ${typeof options.include === "string" ? orchidCore.singleQuote(options.include) : `[${options.include.map(orchidCore.singleQuote).join(", ")}]`},`
549
719
  );
550
- if (index.nullsNotDistinct)
720
+ if (options.nullsNotDistinct)
551
721
  arr.push(`nullsNotDistinct: true,`);
552
- if (index.with)
553
- arr.push(`with: ${orchidCore.singleQuote(index.with)},`);
554
- if (index.tablespace)
555
- arr.push(`tablespace: ${orchidCore.singleQuote(index.tablespace)},`);
556
- if (index.where)
557
- arr.push(`where: ${orchidCore.singleQuote(index.where)},`);
722
+ if (options.with)
723
+ arr.push(`with: ${orchidCore.singleQuote(options.with)},`);
724
+ if (options.tablespace)
725
+ arr.push(`tablespace: ${orchidCore.singleQuote(options.tablespace)},`);
726
+ if (options.where)
727
+ arr.push(`where: ${orchidCore.singleQuote(options.where)},`);
558
728
  if (arr.length) {
559
729
  orchidCore.addCode(code, "{");
560
730
  orchidCore.addCode(code, arr);
@@ -564,8 +734,8 @@ const columnIndexesToCode = (indexes) => {
564
734
  }
565
735
  return code;
566
736
  };
567
- const columnCheckToCode = (t, check) => {
568
- return `.check(${check.toCode(t)})`;
737
+ const columnCheckToCode = (t, { sql, name }) => {
738
+ return `.check(${sql.toCode(t)}${name ? `, { name: '${name}' }` : ""})`;
569
739
  };
570
740
  const identityToCode = (identity, dataType) => {
571
741
  const code = [];
@@ -577,16 +747,18 @@ const identityToCode = (identity, dataType) => {
577
747
  const props = [];
578
748
  if (identity.always)
579
749
  props.push(`always: true,`);
580
- if (identity.incrementBy)
581
- props.push(`incrementBy: ${identity.incrementBy},`);
582
- if (identity.startWith)
583
- props.push(`startWith: ${identity.startWith},`);
750
+ if (identity.increment && identity.increment !== 1)
751
+ props.push(`increment: ${identity.increment},`);
752
+ if (identity.start && identity.start !== 1)
753
+ props.push(`start: ${identity.start},`);
584
754
  if (identity.min)
585
755
  props.push(`min: ${identity.min},`);
586
756
  if (identity.max)
587
757
  props.push(`max: ${identity.max},`);
588
- if (identity.cache)
758
+ if (identity.cache && identity.cache !== 1)
589
759
  props.push(`cache: ${identity.cache},`);
760
+ if (identity.cycle)
761
+ props.push(`cycle: true,`);
590
762
  if (props.length) {
591
763
  orchidCore.addCode(code, "{");
592
764
  code.push(props, "}");
@@ -594,7 +766,7 @@ const identityToCode = (identity, dataType) => {
594
766
  orchidCore.addCode(code, ")");
595
767
  return code;
596
768
  };
597
- const columnCode = (type, t, code, data = type.data, skip) => {
769
+ const columnCode = (type, t, code, migration, data = type.data, skip) => {
598
770
  code = orchidCore.toArray(code);
599
771
  let prepend = `${t}.`;
600
772
  if (data.name) {
@@ -605,10 +777,14 @@ const columnCode = (type, t, code, data = type.data, skip) => {
605
777
  } else {
606
778
  code[0].unshift(prepend);
607
779
  }
608
- if (data.isPrimaryKey)
609
- orchidCore.addCode(code, ".primaryKey()");
780
+ if (data.primaryKey) {
781
+ orchidCore.addCode(
782
+ code,
783
+ `.primaryKey(${data.primaryKey === true ? "" : orchidCore.singleQuote(data.primaryKey)})`
784
+ );
785
+ }
610
786
  if (data.foreignKeys) {
611
- for (const part of columnForeignKeysToCode(data.foreignKeys)) {
787
+ for (const part of columnForeignKeysToCode(data.foreignKeys, migration)) {
612
788
  orchidCore.addCode(code, part);
613
789
  }
614
790
  }
@@ -622,7 +798,7 @@ const columnCode = (type, t, code, data = type.data, skip) => {
622
798
  orchidCore.addCode(code, `.parse(${type.parseFn.toString()})`);
623
799
  if (data.as)
624
800
  orchidCore.addCode(code, `.as(${data.as.toCode(t)})`);
625
- if (data.default !== void 0) {
801
+ if (data.default !== void 0 && (!migration || typeof data.default !== "function")) {
626
802
  orchidCore.addCode(code, `.default(${orchidCore.columnDefaultArgumentToCode(t, data.default)})`);
627
803
  }
628
804
  if (data.indexes) {
@@ -824,8 +1000,8 @@ class JSONColumn extends ColumnType {
824
1000
  this.dataType = "jsonb";
825
1001
  this.operators = Operators.json;
826
1002
  }
827
- toCode(t) {
828
- return columnCode(this, t, `json()`, this.data, toCodeSkip);
1003
+ toCode(t, m) {
1004
+ return columnCode(this, t, `json()`, m, this.data, toCodeSkip);
829
1005
  }
830
1006
  }
831
1007
  JSONColumn.prototype.encodeFn = JSON.stringify;
@@ -835,8 +1011,8 @@ class JSONTextColumn extends ColumnType {
835
1011
  this.dataType = "json";
836
1012
  this.operators = Operators.text;
837
1013
  }
838
- toCode(t) {
839
- return columnCode(this, t, `jsonText()`, this.data, toCodeSkip);
1014
+ toCode(t, m) {
1015
+ return columnCode(this, t, `jsonText()`, m, this.data, toCodeSkip);
840
1016
  }
841
1017
  }
842
1018
 
@@ -1092,8 +1268,8 @@ const pushIn = (ctx, query, ands, quotedAs, arg) => {
1092
1268
  };
1093
1269
 
1094
1270
  var __defProp$f = Object.defineProperty;
1095
- var __defProps$9 = Object.defineProperties;
1096
- var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
1271
+ var __defProps$7 = Object.defineProperties;
1272
+ var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
1097
1273
  var __getOwnPropSymbols$g = Object.getOwnPropertySymbols;
1098
1274
  var __hasOwnProp$g = Object.prototype.hasOwnProperty;
1099
1275
  var __propIsEnum$g = Object.prototype.propertyIsEnumerable;
@@ -1109,7 +1285,7 @@ var __spreadValues$f = (a, b) => {
1109
1285
  }
1110
1286
  return a;
1111
1287
  };
1112
- var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
1288
+ var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
1113
1289
  const processJoinItem = (ctx, table, query, args, quotedAs) => {
1114
1290
  let target;
1115
1291
  let on;
@@ -1171,8 +1347,8 @@ const processJoinItem = (ctx, table, query, args, quotedAs) => {
1171
1347
  const whereSql = whereToSql(
1172
1348
  ctx,
1173
1349
  q,
1174
- __spreadProps$9(__spreadValues$f({}, q.q), {
1175
- joinedShapes: __spreadProps$9(__spreadValues$f(__spreadValues$f({}, query.joinedShapes), q.q.joinedShapes), {
1350
+ __spreadProps$7(__spreadValues$f({}, q.q), {
1351
+ joinedShapes: __spreadProps$7(__spreadValues$f(__spreadValues$f({}, query.joinedShapes), q.q.joinedShapes), {
1176
1352
  [table.q.as || table.table]: table.q.shape
1177
1353
  })
1178
1354
  }),
@@ -1329,8 +1505,8 @@ const getIsJoinSubQuery = (query) => {
1329
1505
  };
1330
1506
 
1331
1507
  var __defProp$e = Object.defineProperty;
1332
- var __defProps$8 = Object.defineProperties;
1333
- var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
1508
+ var __defProps$6 = Object.defineProperties;
1509
+ var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
1334
1510
  var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
1335
1511
  var __hasOwnProp$f = Object.prototype.hasOwnProperty;
1336
1512
  var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
@@ -1346,7 +1522,7 @@ var __spreadValues$e = (a, b) => {
1346
1522
  }
1347
1523
  return a;
1348
1524
  };
1349
- var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
1525
+ var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
1350
1526
  const processJoinArgs = (joinTo, first, args, joinSubQuery) => {
1351
1527
  var _a;
1352
1528
  if (typeof first === "string") {
@@ -1378,7 +1554,7 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery) => {
1378
1554
  logger: joinToQ.logger
1379
1555
  };
1380
1556
  j.baseQuery = j;
1381
- const joinedShapes = __spreadProps$8(__spreadValues$e({}, joinToQ.joinedShapes), {
1557
+ const joinedShapes = __spreadProps$6(__spreadValues$e({}, joinToQ.joinedShapes), {
1382
1558
  [joinToQ.as || joinTo.table]: joinTo.shape
1383
1559
  });
1384
1560
  const r = args[0](
@@ -1405,7 +1581,7 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery) => {
1405
1581
  pushQueryArray(q, "or", query.or);
1406
1582
  }
1407
1583
  }
1408
- const joinedShapes = __spreadProps$8(__spreadValues$e({}, joinTo.q.joinedShapes), {
1584
+ const joinedShapes = __spreadProps$6(__spreadValues$e({}, joinTo.q.joinedShapes), {
1409
1585
  [joinTo.q.as || joinTo.table]: joinTo.shape
1410
1586
  });
1411
1587
  const r = args[0](
@@ -1434,8 +1610,8 @@ const makeJoinQueryBuilder = (joinedQuery, joinedShapes, joinTo) => {
1434
1610
  };
1435
1611
 
1436
1612
  var __defProp$d = Object.defineProperty;
1437
- var __defProps$7 = Object.defineProperties;
1438
- var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
1613
+ var __defProps$5 = Object.defineProperties;
1614
+ var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
1439
1615
  var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
1440
1616
  var __hasOwnProp$e = Object.prototype.hasOwnProperty;
1441
1617
  var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
@@ -1451,7 +1627,7 @@ var __spreadValues$d = (a, b) => {
1451
1627
  }
1452
1628
  return a;
1453
1629
  };
1454
- var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
1630
+ var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
1455
1631
  const _join = (q, require2, type, first, args) => {
1456
1632
  var _a, _b;
1457
1633
  let joinKey;
@@ -1552,7 +1728,7 @@ const _joinLateral = (self, type, arg, cb, as) => {
1552
1728
  const t = Object.create(q.queryBuilder);
1553
1729
  t.table = arg;
1554
1730
  t.shape = shape;
1555
- t.q = __spreadProps$7(__spreadValues$d({}, t.q), {
1731
+ t.q = __spreadProps$5(__spreadValues$d({}, t.q), {
1556
1732
  shape
1557
1733
  });
1558
1734
  t.baseQuery = t;
@@ -1606,11 +1782,12 @@ class DateColumn extends DateBaseColumn {
1606
1782
  super(...arguments);
1607
1783
  this.dataType = "date";
1608
1784
  }
1609
- toCode(t) {
1785
+ toCode(t, m) {
1610
1786
  return columnCode(
1611
1787
  this,
1612
1788
  t,
1613
- `date()${orchidCore.dateDataToCode(this.data)}`,
1789
+ `date()${orchidCore.dateDataToCode(this.data, m)}`,
1790
+ m,
1614
1791
  this.data,
1615
1792
  skipDateMethodsFromToCode
1616
1793
  );
@@ -1637,7 +1814,7 @@ class DateTimeTzBaseClass extends DateTimeBaseClass {
1637
1814
  );
1638
1815
  }
1639
1816
  }
1640
- const timestampToCode = (self, t) => {
1817
+ const timestampToCode = (self, t, m) => {
1641
1818
  const { dateTimePrecision: p } = self.data;
1642
1819
  const { defaultTimestamp } = self.data;
1643
1820
  if (defaultTimestamp) {
@@ -1649,7 +1826,8 @@ const timestampToCode = (self, t) => {
1649
1826
  const code = columnCode(
1650
1827
  self,
1651
1828
  t,
1652
- `timestamps${noTz}(${p && p !== 6 ? p : ""}).${defaultTimestamp}${orchidCore.dateDataToCode(self.data)}`,
1829
+ `timestamps${noTz}(${p && p !== 6 ? p : ""}).${defaultTimestamp}${orchidCore.dateDataToCode(self.data, m)}`,
1830
+ m,
1653
1831
  self.data,
1654
1832
  skipDateMethodsFromToCode
1655
1833
  );
@@ -1660,7 +1838,8 @@ const timestampToCode = (self, t) => {
1660
1838
  return columnCode(
1661
1839
  self,
1662
1840
  t,
1663
- `${self instanceof TimestampColumn ? "timestampNoTZ" : "timestamp"}(${p && p !== 6 ? p : ""})${orchidCore.dateDataToCode(self.data)}`,
1841
+ `${self instanceof TimestampColumn ? "timestampNoTZ" : "timestamp"}(${p && p !== 6 ? p : ""})${orchidCore.dateDataToCode(self.data, m)}`,
1842
+ m,
1664
1843
  self.data,
1665
1844
  skipDateMethodsFromToCode
1666
1845
  );
@@ -1671,8 +1850,8 @@ class TimestampColumn extends DateTimeBaseClass {
1671
1850
  super(...arguments);
1672
1851
  this.dataType = "timestamp";
1673
1852
  }
1674
- toCode(t) {
1675
- return timestampToCode(this, t);
1853
+ toCode(t, m) {
1854
+ return timestampToCode(this, t, m);
1676
1855
  }
1677
1856
  }
1678
1857
  class TimestampTZColumn extends DateTimeTzBaseClass {
@@ -1681,8 +1860,8 @@ class TimestampTZColumn extends DateTimeTzBaseClass {
1681
1860
  this.dataType = "timestamptz";
1682
1861
  this.baseDataType = "timestamp";
1683
1862
  }
1684
- toCode(t) {
1685
- return timestampToCode(this, t);
1863
+ toCode(t, m) {
1864
+ return timestampToCode(this, t, m);
1686
1865
  }
1687
1866
  }
1688
1867
  class TimeColumn extends ColumnType {
@@ -1692,12 +1871,13 @@ class TimeColumn extends ColumnType {
1692
1871
  this.operators = Operators.time;
1693
1872
  this.data.dateTimePrecision = dateTimePrecision;
1694
1873
  }
1695
- toCode(t) {
1874
+ toCode(t, m) {
1696
1875
  const { dateTimePrecision } = this.data;
1697
1876
  return columnCode(
1698
1877
  this,
1699
1878
  t,
1700
- `time(${dateTimePrecision || ""})${orchidCore.dateDataToCode(this.data)}`,
1879
+ `time(${dateTimePrecision || ""})${orchidCore.dateDataToCode(this.data, m)}`,
1880
+ m,
1701
1881
  this.data,
1702
1882
  skipDateMethodsFromToCode
1703
1883
  );
@@ -1711,12 +1891,13 @@ class IntervalColumn extends ColumnType {
1711
1891
  this.data.fields = fields;
1712
1892
  this.data.precision = precision;
1713
1893
  }
1714
- toCode(t) {
1894
+ toCode(t, m) {
1715
1895
  const { fields, precision } = this.data;
1716
1896
  return columnCode(
1717
1897
  this,
1718
1898
  t,
1719
1899
  `interval(${[fields && `'${fields}'`, precision && String(precision)].filter((part) => part).join(", ")})`,
1900
+ m,
1720
1901
  this.data,
1721
1902
  skipDateMethodsFromToCode
1722
1903
  );
@@ -1739,9 +1920,9 @@ class EnumColumn extends ColumnType {
1739
1920
  this.dataType = "enum";
1740
1921
  this.inputSchema = this.outputSchema = this.querySchema = schemaType;
1741
1922
  }
1742
- toCode(t, migration) {
1743
- const options = migration ? "" : `, [${this.options.map((option) => `'${option}'`).join(", ")}]`;
1744
- return columnCode(this, t, `enum('${this.enumName}'${options})`);
1923
+ toCode(t, m) {
1924
+ const options = m ? "" : `, [${this.options.map((option) => `'${option}'`).join(", ")}]`;
1925
+ return columnCode(this, t, `enum('${this.enumName}'${options})`, m);
1745
1926
  }
1746
1927
  toSQL() {
1747
1928
  const name = this.enumName;
@@ -1773,15 +1954,16 @@ class ArrayColumn extends ColumnType {
1773
1954
  }
1774
1955
  );
1775
1956
  this.data.item = item;
1957
+ this.data.name = item.data.name;
1776
1958
  }
1777
1959
  toSQL() {
1778
1960
  return `${this.data.item.toSQL()}[]`;
1779
1961
  }
1780
- toCode(t) {
1962
+ toCode(t, m) {
1781
1963
  const code = ["array("];
1782
1964
  orchidCore.addCode(code, this.data.item.toCode(t));
1783
- orchidCore.addCode(code, `)${orchidCore.arrayDataToCode(this.data)}`);
1784
- return columnCode(this, t, code);
1965
+ orchidCore.addCode(code, `)${orchidCore.arrayDataToCode(this.data, m)}`);
1966
+ return columnCode(this, t, code, m);
1785
1967
  }
1786
1968
  }
1787
1969
  const parseArray = (input, pos, len, entries, nested, item) => {
@@ -3197,29 +3379,11 @@ const pushInsertSql = (ctx, q, query, quotedAs) => {
3197
3379
  ""
3198
3380
  )})`
3199
3381
  );
3200
- } else {
3382
+ } else if ("toSQL" in expr) {
3201
3383
  ctx.sql.push(expr.toSQL(ctx, quotedAs));
3384
+ } else {
3385
+ ctx.sql.push(`ON CONSTRAINT "${expr.constraint}"`);
3202
3386
  }
3203
- } else if (type === "merge") {
3204
- const { indexes } = q.internal;
3205
- const quotedUniques = columns.reduce((arr, key, i) => {
3206
- var _a2, _b2;
3207
- const unique = (
3208
- // check column index
3209
- ((_b2 = ((_a2 = shape[key]) == null ? void 0 : _a2.data).indexes) == null ? void 0 : _b2.some(
3210
- (index) => index.unique
3211
- )) || // check table composite indexes
3212
- (indexes == null ? void 0 : indexes.some(
3213
- (index) => index.columns.some(
3214
- (item) => "column" in item && item.column === key
3215
- )
3216
- ))
3217
- );
3218
- if (unique)
3219
- arr.push(quotedColumns[i]);
3220
- return arr;
3221
- }, []);
3222
- ctx.sql.push(`(${quotedUniques.join(", ")})`);
3223
3387
  }
3224
3388
  if (type === "ignore") {
3225
3389
  ctx.sql.push("DO NOTHING");
@@ -3893,10 +4057,27 @@ const extendQuery = (q, methods) => {
3893
4057
  cloned.q = getClonedQueryData(q.q);
3894
4058
  return cloned;
3895
4059
  };
4060
+ const getPrimaryKeys = (q) => {
4061
+ var _a, _b;
4062
+ return (_b = (_a = q.internal).primaryKeys) != null ? _b : _a.primaryKeys = collectPrimaryKeys(q);
4063
+ };
4064
+ const collectPrimaryKeys = (q) => {
4065
+ const primaryKeys = [];
4066
+ const { shape } = q.q;
4067
+ for (const key in shape) {
4068
+ if (shape[key].data.primaryKey) {
4069
+ primaryKeys.push(key);
4070
+ }
4071
+ }
4072
+ if (q.internal.primaryKeys) {
4073
+ primaryKeys.push(...q.internal.primaryKeys);
4074
+ }
4075
+ return primaryKeys;
4076
+ };
3896
4077
 
3897
4078
  var __defProp$a = Object.defineProperty;
3898
- var __defProps$6 = Object.defineProperties;
3899
- var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
4079
+ var __defProps$4 = Object.defineProperties;
4080
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
3900
4081
  var __getOwnPropSymbols$b = Object.getOwnPropertySymbols;
3901
4082
  var __hasOwnProp$b = Object.prototype.hasOwnProperty;
3902
4083
  var __propIsEnum$b = Object.prototype.propertyIsEnumerable;
@@ -3912,7 +4093,7 @@ var __spreadValues$a = (a, b) => {
3912
4093
  }
3913
4094
  return a;
3914
4095
  };
3915
- var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
4096
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
3916
4097
  function setQueryOperators(query, operators) {
3917
4098
  const q = query.q;
3918
4099
  if (q.operators) {
@@ -3971,7 +4152,7 @@ const base = {
3971
4152
  (key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteValue(value, ctx, quotedAs)}`
3972
4153
  )
3973
4154
  };
3974
- const boolean = __spreadProps$6(__spreadValues$a({}, base), {
4155
+ const boolean = __spreadProps$4(__spreadValues$a({}, base), {
3975
4156
  and: make(
3976
4157
  (key, value, ctx, quotedAs) => `${key} AND ${value.q.expr.toSQL(ctx, quotedAs)}`
3977
4158
  ),
@@ -3979,7 +4160,7 @@ const boolean = __spreadProps$6(__spreadValues$a({}, base), {
3979
4160
  (key, value, ctx, quotedAs) => `(${key}) OR (${value.q.expr.toSQL(ctx, quotedAs)})`
3980
4161
  )
3981
4162
  });
3982
- const numeric = __spreadProps$6(__spreadValues$a({}, base), {
4163
+ const numeric = __spreadProps$4(__spreadValues$a({}, base), {
3983
4164
  lt: make(
3984
4165
  (key, value, ctx, quotedAs) => `${key} < ${quoteValue(value, ctx, quotedAs)}`
3985
4166
  ),
@@ -4000,7 +4181,7 @@ const numeric = __spreadProps$6(__spreadValues$a({}, base), {
4000
4181
  )}`
4001
4182
  )
4002
4183
  });
4003
- const text = __spreadProps$6(__spreadValues$a({}, base), {
4184
+ const text = __spreadProps$4(__spreadValues$a({}, base), {
4004
4185
  contains: make(
4005
4186
  (key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${quoteValue(value, ctx, quotedAs)} || '%'`
4006
4187
  ),
@@ -4020,7 +4201,7 @@ const text = __spreadProps$6(__spreadValues$a({}, base), {
4020
4201
  (key, value, ctx, quotedAs) => `${key} LIKE '%' || ${quoteValue(value, ctx, quotedAs)}`
4021
4202
  )
4022
4203
  });
4023
- const json = __spreadProps$6(__spreadValues$a({}, base), {
4204
+ const json = __spreadProps$4(__spreadValues$a({}, base), {
4024
4205
  jsonPath: make(
4025
4206
  (key, [path, op, value], ctx, quotedAs) => `jsonb_path_query_first(${key}, '${path}') #>> '{}' ${op} ${value === null ? "null" : quoteValue(value, ctx, quotedAs, true)}`
4026
4207
  ),
@@ -4064,16 +4245,18 @@ class DecimalColumn extends ColumnType {
4064
4245
  constructor(schema, numericPrecision, numericScale) {
4065
4246
  super(schema, schema.stringSchema());
4066
4247
  this.operators = Operators.number;
4067
- this.dataType = "decimal";
4248
+ this.dataType = "numeric";
4068
4249
  this.data.numericPrecision = numericPrecision;
4069
4250
  this.data.numericScale = numericScale;
4251
+ this.data.alias = "decimal";
4070
4252
  }
4071
- toCode(t) {
4253
+ toCode(t, m) {
4072
4254
  const { numericPrecision, numericScale } = this.data;
4073
4255
  return columnCode(
4074
4256
  this,
4075
4257
  t,
4076
- `decimal(${numericPrecision || ""}${numericScale ? `, ${numericScale}` : ""})`
4258
+ `decimal(${numericPrecision || ""}${numericScale ? `, ${numericScale}` : ""})`,
4259
+ m
4077
4260
  );
4078
4261
  }
4079
4262
  toSQL() {
@@ -4085,49 +4268,52 @@ class DecimalColumn extends ColumnType {
4085
4268
  }
4086
4269
  }
4087
4270
  const skipNumberMethods = { int: true };
4088
- const intToCode = (column, t) => {
4271
+ const intToCode = (column, t, alias, m) => {
4089
4272
  let code;
4090
4273
  if (column.data.identity) {
4091
- code = identityToCode(column.data.identity, column.dataType);
4274
+ code = identityToCode(column.data.identity, alias);
4092
4275
  } else {
4093
- code = [`${column.dataType}()`];
4276
+ code = [`${alias}()`];
4094
4277
  }
4095
- orchidCore.addCode(code, orchidCore.numberDataToCode(column.data, skipNumberMethods));
4096
- return columnCode(column, t, code);
4278
+ orchidCore.addCode(code, orchidCore.numberDataToCode(column.data, m, skipNumberMethods));
4279
+ return columnCode(column, t, code, m);
4097
4280
  };
4098
4281
  class SmallIntColumn extends IntegerBaseColumn {
4099
- constructor() {
4100
- super(...arguments);
4101
- this.dataType = "smallint";
4282
+ constructor(schema) {
4283
+ super(schema);
4284
+ this.dataType = "int2";
4102
4285
  this.parseItem = parseInt;
4286
+ this.data.alias = "smallint";
4103
4287
  }
4104
- toCode(t) {
4105
- return intToCode(this, t);
4288
+ toCode(t, m) {
4289
+ return intToCode(this, t, "smallint", m);
4106
4290
  }
4107
4291
  identity(options = {}) {
4108
4292
  return orchidCore.setColumnData(this, "identity", options);
4109
4293
  }
4110
4294
  }
4111
4295
  class IntegerColumn extends IntegerBaseColumn {
4112
- constructor() {
4113
- super(...arguments);
4114
- this.dataType = "integer";
4296
+ constructor(schema) {
4297
+ super(schema);
4298
+ this.dataType = "int4";
4115
4299
  this.parseItem = parseInt;
4300
+ this.data.alias = "integer";
4116
4301
  }
4117
- toCode(t) {
4118
- return intToCode(this, t);
4302
+ toCode(t, m) {
4303
+ return intToCode(this, t, "integer", m);
4119
4304
  }
4120
4305
  identity(options = {}) {
4121
4306
  return orchidCore.setColumnData(this, "identity", options);
4122
4307
  }
4123
4308
  }
4124
4309
  class BigIntColumn extends NumberAsStringBaseColumn {
4125
- constructor() {
4126
- super(...arguments);
4127
- this.dataType = "bigint";
4310
+ constructor(schema) {
4311
+ super(schema);
4312
+ this.dataType = "int8";
4313
+ this.data.alias = "bigint";
4128
4314
  }
4129
- toCode(t) {
4130
- return intToCode(this, t);
4315
+ toCode(t, m) {
4316
+ return intToCode(this, t, "bigint", m);
4131
4317
  }
4132
4318
  identity(options = {}) {
4133
4319
  return orchidCore.setColumnData(this, "identity", options);
@@ -4136,74 +4322,81 @@ class BigIntColumn extends NumberAsStringBaseColumn {
4136
4322
  class RealColumn extends NumberBaseColumn {
4137
4323
  constructor(schema) {
4138
4324
  super(schema, schema.number());
4139
- this.dataType = "real";
4325
+ this.dataType = "float4";
4140
4326
  this.parseItem = parseFloat;
4327
+ this.data.alias = "real";
4141
4328
  }
4142
- toCode(t) {
4143
- return columnCode(this, t, `real()${orchidCore.numberDataToCode(this.data)}`);
4329
+ toCode(t, m) {
4330
+ return columnCode(this, t, `real()${orchidCore.numberDataToCode(this.data, m)}`, m);
4144
4331
  }
4145
4332
  }
4146
4333
  class DoublePrecisionColumn extends NumberAsStringBaseColumn {
4147
- constructor() {
4148
- super(...arguments);
4149
- this.dataType = "double precision";
4334
+ constructor(schema) {
4335
+ super(schema);
4336
+ this.dataType = "float8";
4337
+ this.data.alias = "doublePrecision";
4150
4338
  }
4151
- toCode(t) {
4152
- return columnCode(this, t, `doublePrecision()`);
4339
+ toCode(t, m) {
4340
+ return columnCode(this, t, `doublePrecision()`, m);
4153
4341
  }
4154
4342
  }
4155
4343
  class SmallSerialColumn extends IntegerBaseColumn {
4156
4344
  constructor(schema) {
4157
4345
  super(schema);
4158
- this.dataType = "smallint";
4346
+ this.dataType = "int2";
4159
4347
  this.parseItem = parseInt;
4160
4348
  this.data.int = true;
4349
+ this.data.alias = "smallSerial";
4161
4350
  }
4162
4351
  toSQL() {
4163
4352
  return "smallserial";
4164
4353
  }
4165
- toCode(t) {
4354
+ toCode(t, m) {
4166
4355
  return columnCode(
4167
4356
  this,
4168
4357
  t,
4169
- `smallSerial()${orchidCore.numberDataToCode(this.data, skipNumberMethods)}`
4358
+ `smallSerial()${orchidCore.numberDataToCode(this.data, m, skipNumberMethods)}`,
4359
+ m
4170
4360
  );
4171
4361
  }
4172
4362
  }
4173
4363
  class SerialColumn extends IntegerBaseColumn {
4174
4364
  constructor(schema) {
4175
4365
  super(schema);
4176
- this.dataType = "integer";
4366
+ this.dataType = "int4";
4177
4367
  this.parseItem = parseInt;
4178
4368
  this.data.int = true;
4369
+ this.data.alias = "serial";
4179
4370
  }
4180
4371
  toSQL() {
4181
4372
  return "serial";
4182
4373
  }
4183
- toCode(t) {
4374
+ toCode(t, m) {
4184
4375
  return columnCode(
4185
4376
  this,
4186
4377
  t,
4187
- `serial()${orchidCore.numberDataToCode(this.data, skipNumberMethods)}`
4378
+ `serial()${orchidCore.numberDataToCode(this.data, m, skipNumberMethods)}`,
4379
+ m
4188
4380
  );
4189
4381
  }
4190
4382
  }
4191
4383
  class BigSerialColumn extends NumberAsStringBaseColumn {
4192
- constructor() {
4193
- super(...arguments);
4194
- this.dataType = "bigint";
4384
+ constructor(schema) {
4385
+ super(schema);
4386
+ this.dataType = "int8";
4387
+ this.data.alias = "bigint";
4195
4388
  }
4196
4389
  toSQL() {
4197
4390
  return "bigserial";
4198
4391
  }
4199
- toCode(t) {
4200
- return columnCode(this, t, `bigSerial()`);
4392
+ toCode(t, m) {
4393
+ return columnCode(this, t, `bigSerial()`, m);
4201
4394
  }
4202
4395
  }
4203
4396
 
4204
4397
  var __defProp$9 = Object.defineProperty;
4205
- var __defProps$5 = Object.defineProperties;
4206
- var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
4398
+ var __defProps$3 = Object.defineProperties;
4399
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
4207
4400
  var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
4208
4401
  var __hasOwnProp$a = Object.prototype.hasOwnProperty;
4209
4402
  var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
@@ -4219,7 +4412,7 @@ var __spreadValues$9 = (a, b) => {
4219
4412
  }
4220
4413
  return a;
4221
4414
  };
4222
- var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
4415
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
4223
4416
  class TextBaseColumn extends ColumnType {
4224
4417
  constructor(schema, schemaType = schema.stringSchema()) {
4225
4418
  super(schema, schemaType);
@@ -4246,12 +4439,13 @@ class VarCharColumn extends LimitedTextBaseColumn {
4246
4439
  super(...arguments);
4247
4440
  this.dataType = "varchar";
4248
4441
  }
4249
- toCode(t) {
4442
+ toCode(t, m) {
4250
4443
  const { maxChars } = this.data;
4251
4444
  return columnCode(
4252
4445
  this,
4253
4446
  t,
4254
- `varchar(${maxChars != null ? maxChars : ""})${orchidCore.stringDataToCode(this.data)}`
4447
+ `varchar(${maxChars != null ? maxChars : ""})${orchidCore.stringDataToCode(this.data, m)}`,
4448
+ m
4255
4449
  );
4256
4450
  }
4257
4451
  }
@@ -4259,14 +4453,15 @@ class StringColumn extends VarCharColumn {
4259
4453
  constructor(schema, limit = 255) {
4260
4454
  super(schema, limit);
4261
4455
  }
4262
- toCode(t) {
4456
+ toCode(t, m) {
4263
4457
  let max = this.data.maxChars;
4264
4458
  if (max === 255)
4265
4459
  max = void 0;
4266
4460
  return columnCode(
4267
4461
  this,
4268
4462
  t,
4269
- `string(${max != null ? max : ""})${orchidCore.stringDataToCode(this.data)}`
4463
+ `string(${max != null ? max : ""})${orchidCore.stringDataToCode(this.data, m)}`,
4464
+ m
4270
4465
  );
4271
4466
  }
4272
4467
  }
@@ -4275,12 +4470,13 @@ class CharColumn extends LimitedTextBaseColumn {
4275
4470
  super(...arguments);
4276
4471
  this.dataType = "char";
4277
4472
  }
4278
- toCode(t) {
4473
+ toCode(t, m) {
4279
4474
  const { maxChars } = this.data;
4280
4475
  return columnCode(
4281
4476
  this,
4282
4477
  t,
4283
- `char(${maxChars != null ? maxChars : ""})${orchidCore.stringDataToCode(this.data)}`
4478
+ `char(${maxChars != null ? maxChars : ""})${orchidCore.stringDataToCode(this.data, m)}`,
4479
+ m
4284
4480
  );
4285
4481
  }
4286
4482
  }
@@ -4292,7 +4488,7 @@ const setTextColumnData = (column, minArg, maxArg) => {
4292
4488
  }
4293
4489
  }
4294
4490
  };
4295
- const textColumnToCode = (column, t) => {
4491
+ const textColumnToCode = (column, t, m) => {
4296
4492
  const data = __spreadValues$9({}, column.data);
4297
4493
  let args = "";
4298
4494
  const hasMax = data.maxArg !== void 0 && data.max === data.maxArg;
@@ -4311,7 +4507,8 @@ const textColumnToCode = (column, t) => {
4311
4507
  return columnCode(
4312
4508
  column,
4313
4509
  t,
4314
- `${column.dataType}(${args})${orchidCore.stringDataToCode(data)}`
4510
+ `${column.dataType}(${args})${orchidCore.stringDataToCode(data, m)}`,
4511
+ m
4315
4512
  );
4316
4513
  };
4317
4514
  const minMaxToSchema = (schema, min, max) => min ? max ? schema.stringMinMax(min, max) : schema.stringMin(min) : schema.stringSchema();
@@ -4321,8 +4518,8 @@ class TextColumn extends TextBaseColumn {
4321
4518
  this.dataType = "text";
4322
4519
  setTextColumnData(this, min, max);
4323
4520
  }
4324
- toCode(t) {
4325
- return textColumnToCode(this, t);
4521
+ toCode(t, m) {
4522
+ return textColumnToCode(this, t, m);
4326
4523
  }
4327
4524
  }
4328
4525
  class ByteaColumn extends ColumnType {
@@ -4331,8 +4528,8 @@ class ByteaColumn extends ColumnType {
4331
4528
  this.dataType = "bytea";
4332
4529
  this.operators = Operators.text;
4333
4530
  }
4334
- toCode(t) {
4335
- return columnCode(this, t, `bytea()`);
4531
+ toCode(t, m) {
4532
+ return columnCode(this, t, `bytea()`, m);
4336
4533
  }
4337
4534
  }
4338
4535
  class PointColumn extends ColumnType {
@@ -4341,8 +4538,8 @@ class PointColumn extends ColumnType {
4341
4538
  this.dataType = "point";
4342
4539
  this.operators = Operators.text;
4343
4540
  }
4344
- toCode(t) {
4345
- return columnCode(this, t, `point()`);
4541
+ toCode(t, m) {
4542
+ return columnCode(this, t, `point()`, m);
4346
4543
  }
4347
4544
  }
4348
4545
  class LineColumn extends ColumnType {
@@ -4351,8 +4548,8 @@ class LineColumn extends ColumnType {
4351
4548
  this.dataType = "line";
4352
4549
  this.operators = Operators.text;
4353
4550
  }
4354
- toCode(t) {
4355
- return columnCode(this, t, `line()`);
4551
+ toCode(t, m) {
4552
+ return columnCode(this, t, `line()`, m);
4356
4553
  }
4357
4554
  }
4358
4555
  class LsegColumn extends ColumnType {
@@ -4361,8 +4558,8 @@ class LsegColumn extends ColumnType {
4361
4558
  this.dataType = "lseg";
4362
4559
  this.operators = Operators.text;
4363
4560
  }
4364
- toCode(t) {
4365
- return columnCode(this, t, `lseg()`);
4561
+ toCode(t, m) {
4562
+ return columnCode(this, t, `lseg()`, m);
4366
4563
  }
4367
4564
  }
4368
4565
  class BoxColumn extends ColumnType {
@@ -4371,8 +4568,8 @@ class BoxColumn extends ColumnType {
4371
4568
  this.dataType = "box";
4372
4569
  this.operators = Operators.text;
4373
4570
  }
4374
- toCode(t) {
4375
- return columnCode(this, t, `box()`);
4571
+ toCode(t, m) {
4572
+ return columnCode(this, t, `box()`, m);
4376
4573
  }
4377
4574
  }
4378
4575
  class PathColumn extends ColumnType {
@@ -4381,8 +4578,8 @@ class PathColumn extends ColumnType {
4381
4578
  this.dataType = "path";
4382
4579
  this.operators = Operators.text;
4383
4580
  }
4384
- toCode(t) {
4385
- return columnCode(this, t, `path()`);
4581
+ toCode(t, m) {
4582
+ return columnCode(this, t, `path()`, m);
4386
4583
  }
4387
4584
  }
4388
4585
  class PolygonColumn extends ColumnType {
@@ -4391,8 +4588,8 @@ class PolygonColumn extends ColumnType {
4391
4588
  this.dataType = "polygon";
4392
4589
  this.operators = Operators.text;
4393
4590
  }
4394
- toCode(t) {
4395
- return columnCode(this, t, `polygon()`);
4591
+ toCode(t, m) {
4592
+ return columnCode(this, t, `polygon()`, m);
4396
4593
  }
4397
4594
  }
4398
4595
  class CircleColumn extends ColumnType {
@@ -4401,8 +4598,8 @@ class CircleColumn extends ColumnType {
4401
4598
  this.dataType = "circle";
4402
4599
  this.operators = Operators.text;
4403
4600
  }
4404
- toCode(t) {
4405
- return columnCode(this, t, `circle()`);
4601
+ toCode(t, m) {
4602
+ return columnCode(this, t, `circle()`, m);
4406
4603
  }
4407
4604
  }
4408
4605
  class MoneyColumn extends NumberBaseColumn {
@@ -4418,8 +4615,8 @@ class MoneyColumn extends NumberBaseColumn {
4418
4615
  }
4419
4616
  );
4420
4617
  }
4421
- toCode(t) {
4422
- return columnCode(this, t, `money()`);
4618
+ toCode(t, m) {
4619
+ return columnCode(this, t, `money()`, m);
4423
4620
  }
4424
4621
  }
4425
4622
  class CidrColumn extends ColumnType {
@@ -4428,8 +4625,8 @@ class CidrColumn extends ColumnType {
4428
4625
  this.dataType = "cidr";
4429
4626
  this.operators = Operators.text;
4430
4627
  }
4431
- toCode(t) {
4432
- return columnCode(this, t, `cidr()`);
4628
+ toCode(t, m) {
4629
+ return columnCode(this, t, `cidr()`, m);
4433
4630
  }
4434
4631
  }
4435
4632
  class InetColumn extends ColumnType {
@@ -4438,8 +4635,8 @@ class InetColumn extends ColumnType {
4438
4635
  this.dataType = "inet";
4439
4636
  this.operators = Operators.text;
4440
4637
  }
4441
- toCode(t) {
4442
- return columnCode(this, t, `inet()`);
4638
+ toCode(t, m) {
4639
+ return columnCode(this, t, `inet()`, m);
4443
4640
  }
4444
4641
  }
4445
4642
  class MacAddrColumn extends ColumnType {
@@ -4448,8 +4645,8 @@ class MacAddrColumn extends ColumnType {
4448
4645
  this.dataType = "macaddr";
4449
4646
  this.operators = Operators.text;
4450
4647
  }
4451
- toCode(t) {
4452
- return columnCode(this, t, `macaddr()`);
4648
+ toCode(t, m) {
4649
+ return columnCode(this, t, `macaddr()`, m);
4453
4650
  }
4454
4651
  }
4455
4652
  class MacAddr8Column extends ColumnType {
@@ -4458,8 +4655,8 @@ class MacAddr8Column extends ColumnType {
4458
4655
  this.dataType = "macaddr8";
4459
4656
  this.operators = Operators.text;
4460
4657
  }
4461
- toCode(t) {
4462
- return columnCode(this, t, `macaddr8()`);
4658
+ toCode(t, m) {
4659
+ return columnCode(this, t, `macaddr8()`, m);
4463
4660
  }
4464
4661
  }
4465
4662
  class BitColumn extends ColumnType {
@@ -4469,9 +4666,9 @@ class BitColumn extends ColumnType {
4469
4666
  this.operators = Operators.text;
4470
4667
  this.data.length = length;
4471
4668
  }
4472
- toCode(t) {
4669
+ toCode(t, m) {
4473
4670
  const { length } = this.data;
4474
- return columnCode(this, t, `bit(${length})`);
4671
+ return columnCode(this, t, `bit(${length})`, m);
4475
4672
  }
4476
4673
  toSQL() {
4477
4674
  return orchidCore.joinTruthy(
@@ -4483,13 +4680,14 @@ class BitColumn extends ColumnType {
4483
4680
  class BitVaryingColumn extends ColumnType {
4484
4681
  constructor(schema, length) {
4485
4682
  super(schema, schema.bit(length));
4486
- this.dataType = "bit varying";
4683
+ this.dataType = "varbit";
4487
4684
  this.operators = Operators.text;
4488
4685
  this.data.length = length;
4686
+ this.data.alias = "bitVarying";
4489
4687
  }
4490
- toCode(t) {
4688
+ toCode(t, m) {
4491
4689
  const { length } = this.data;
4492
- return columnCode(this, t, `bitVarying(${length != null ? length : ""})`);
4690
+ return columnCode(this, t, `bitVarying(${length != null ? length : ""})`, m);
4493
4691
  }
4494
4692
  toSQL() {
4495
4693
  return orchidCore.joinTruthy(
@@ -4505,8 +4703,8 @@ class TsVectorColumn extends ColumnType {
4505
4703
  this.dataType = "tsvector";
4506
4704
  this.operators = Operators.text;
4507
4705
  }
4508
- toCode(t) {
4509
- return columnCode(this, t, `tsvector()`);
4706
+ toCode(t, m) {
4707
+ return columnCode(this, t, `tsvector()`, m);
4510
4708
  }
4511
4709
  /**
4512
4710
  * For `tsvector` column type, it can also accept language (optional) and columns:
@@ -4536,14 +4734,17 @@ class TsVectorColumn extends ColumnType {
4536
4734
  const first = args[0];
4537
4735
  if (typeof first === "string" || !("raw" in first)) {
4538
4736
  const target = typeof first === "string" ? args[1] : first;
4737
+ const language = typeof first === "string" ? first : this.defaultLanguage;
4539
4738
  let sql;
4540
4739
  if (Array.isArray(target)) {
4541
4740
  const columns = target.length === 1 ? `"${target[0]}"` : target.map((column) => `coalesce("${column}", '')`).join(` || ' ' || `);
4542
- sql = `to_tsvector('${typeof first === "string" ? first : this.defaultLanguage}', ${columns})`;
4741
+ sql = `to_tsvector('${language}', ${columns})`;
4543
4742
  } else {
4544
4743
  for (const key in target) {
4545
- sql = (sql ? sql + " || " : "") + `setweight(to_tsvector(coalesce("${key}", '')), '${target[key]}')`;
4744
+ sql = (sql ? sql + " || " : "(") + `setweight(to_tsvector('${language}', coalesce("${key}", '')), '${target[key]}')`;
4546
4745
  }
4746
+ if (sql)
4747
+ sql += ")";
4547
4748
  }
4548
4749
  const arr = [sql];
4549
4750
  arr.raw = arr;
@@ -4558,8 +4759,8 @@ class TsQueryColumn extends ColumnType {
4558
4759
  this.dataType = "tsquery";
4559
4760
  this.operators = Operators.text;
4560
4761
  }
4561
- toCode(t) {
4562
- return columnCode(this, t, `tsquery()`);
4762
+ toCode(t, m) {
4763
+ return columnCode(this, t, `tsquery()`, m);
4563
4764
  }
4564
4765
  }
4565
4766
  const uuidDefaultSQL = "gen_random_uuid()";
@@ -4570,20 +4771,24 @@ class UUIDColumn extends ColumnType {
4570
4771
  this.dataType = "uuid";
4571
4772
  this.operators = Operators.text;
4572
4773
  }
4573
- primaryKey() {
4574
- const column = super.primaryKey();
4774
+ /**
4775
+ * see {@link ColumnType.primaryKey}
4776
+ */
4777
+ primaryKey(name) {
4778
+ const column = super.primaryKey(name);
4575
4779
  if (!column.data.default)
4576
4780
  column.data.default = uuidDefault;
4577
4781
  return column;
4578
4782
  }
4579
- toCode(t) {
4783
+ toCode(t, m) {
4580
4784
  const { data } = this;
4581
4785
  return columnCode(
4582
4786
  this,
4583
4787
  t,
4584
4788
  `uuid()`,
4789
+ m,
4585
4790
  // don't output the default default
4586
- data.default instanceof orchidCore.RawSQLBase && data.default._sql === uuidDefaultSQL ? __spreadProps$5(__spreadValues$9({}, data), { default: void 0 }) : data
4791
+ data.default instanceof orchidCore.RawSQLBase && data.default._sql === uuidDefaultSQL ? __spreadProps$3(__spreadValues$9({}, data), { default: void 0 }) : data
4587
4792
  );
4588
4793
  }
4589
4794
  }
@@ -4593,8 +4798,8 @@ class XMLColumn extends ColumnType {
4593
4798
  this.dataType = "xml";
4594
4799
  this.operators = Operators.text;
4595
4800
  }
4596
- toCode(t) {
4597
- return columnCode(this, t, `xml()`);
4801
+ toCode(t, m) {
4802
+ return columnCode(this, t, `xml()`, m);
4598
4803
  }
4599
4804
  }
4600
4805
  class CitextColumn extends TextBaseColumn {
@@ -4603,20 +4808,21 @@ class CitextColumn extends TextBaseColumn {
4603
4808
  this.dataType = "citext";
4604
4809
  setTextColumnData(this, min, max);
4605
4810
  }
4606
- toCode(t) {
4607
- return textColumnToCode(this, t);
4811
+ toCode(t, m) {
4812
+ return textColumnToCode(this, t, m);
4608
4813
  }
4609
4814
  }
4610
4815
 
4611
4816
  class BooleanColumn extends ColumnType {
4612
4817
  constructor(schema) {
4613
4818
  super(schema, schema.boolean());
4614
- this.dataType = "boolean";
4819
+ this.dataType = "bool";
4615
4820
  this.operators = Operators.boolean;
4616
4821
  this.parseItem = (input) => input[0] === "t";
4822
+ this.data.alias = "boolean";
4617
4823
  }
4618
- toCode(t) {
4619
- return columnCode(this, t, "boolean()");
4824
+ toCode(t, m) {
4825
+ return columnCode(this, t, "boolean()", m);
4620
4826
  }
4621
4827
  }
4622
4828
 
@@ -4632,8 +4838,8 @@ class CustomTypeColumn extends ColumnType {
4632
4838
  this.operators = Operators.any;
4633
4839
  this.data.isOfCustomType = true;
4634
4840
  }
4635
- toCode(t) {
4636
- return columnCode(this, t, `type(${orchidCore.singleQuote(this.dataType)})`);
4841
+ toCode(t, m) {
4842
+ return columnCode(this, t, `type(${orchidCore.singleQuote(this.dataType)})`, m);
4637
4843
  }
4638
4844
  as(column) {
4639
4845
  const c = orchidCore.setColumnData(
@@ -4648,14 +4854,12 @@ class CustomTypeColumn extends ColumnType {
4648
4854
  }
4649
4855
  }
4650
4856
  class DomainColumn extends CustomTypeColumn {
4651
- toCode(t) {
4652
- return columnCode(this, t, `domain(${orchidCore.singleQuote(this.dataType)})`);
4857
+ toCode(t, m) {
4858
+ return columnCode(this, t, `domain(${orchidCore.singleQuote(this.dataType)})`, m);
4653
4859
  }
4654
4860
  }
4655
4861
 
4656
4862
  var __defProp$8 = Object.defineProperty;
4657
- var __defProps$4 = Object.defineProperties;
4658
- var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
4659
4863
  var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
4660
4864
  var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
4661
4865
  var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
@@ -4671,19 +4875,11 @@ var __spreadValues$8 = (a, b) => {
4671
4875
  }
4672
4876
  return a;
4673
4877
  };
4674
- var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
4675
- const newTableData = () => ({});
4676
- let tableData = newTableData();
4677
- const getTableData = () => tableData;
4678
- const resetTableData = (data = newTableData()) => {
4679
- tableData = data;
4680
- };
4681
- const getColumnTypes = (types, fn, nowSQL, language, data = newTableData()) => {
4878
+ const getColumnTypes = (types, fn, nowSQL, language) => {
4682
4879
  if (nowSQL)
4683
4880
  orchidCore.setDefaultNowFn(nowSQL);
4684
4881
  if (language)
4685
4882
  orchidCore.setDefaultLanguage(language);
4686
- resetTableData(data);
4687
4883
  return fn(types);
4688
4884
  };
4689
4885
  const makeColumnTypes = (schema) => {
@@ -4695,20 +4891,7 @@ const makeColumnTypes = (schema) => {
4695
4891
  orchidCore.setCurrentColumnName(name);
4696
4892
  return this;
4697
4893
  },
4698
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4699
- sql(...args) {
4700
- const arg = args[0];
4701
- if (Array.isArray(arg)) {
4702
- return new RawSQL(args);
4703
- }
4704
- if (typeof args[0] === "string") {
4705
- return new RawSQL(args[0]);
4706
- }
4707
- if (args[1] !== void 0) {
4708
- return new RawSQL(args[1], arg);
4709
- }
4710
- return (...args2) => new RawSQL(args2, arg);
4711
- },
4894
+ sql: sqlFn,
4712
4895
  smallint: schema.smallint,
4713
4896
  integer: schema.integer,
4714
4897
  bigint: schema.bigint,
@@ -4805,66 +4988,6 @@ const makeColumnTypes = (schema) => {
4805
4988
  },
4806
4989
  domain(dataType) {
4807
4990
  return new DomainColumn(schema, dataType);
4808
- },
4809
- primaryKey(columns, options) {
4810
- tableData.primaryKey = { columns, options };
4811
- return orchidCore.emptyObject;
4812
- },
4813
- index(columns, options = {}) {
4814
- var _a;
4815
- const index = {
4816
- columns: orchidCore.toArray(columns).map(
4817
- (column) => typeof column === "string" ? { column } : column
4818
- ),
4819
- options
4820
- };
4821
- ((_a = tableData.indexes) != null ? _a : tableData.indexes = []).push(index);
4822
- return orchidCore.emptyObject;
4823
- },
4824
- unique(columns, options) {
4825
- return this.index(columns, __spreadProps$4(__spreadValues$8({}, options), { unique: true }));
4826
- },
4827
- /**
4828
- * See {@link ColumnType.searchIndex}
4829
- */
4830
- searchIndex(columns, options) {
4831
- return this.index(columns, __spreadProps$4(__spreadValues$8({}, options), { tsVector: true }));
4832
- },
4833
- constraint({ name, references, check, dropMode }) {
4834
- var _a;
4835
- ((_a = tableData.constraints) != null ? _a : tableData.constraints = []).push({
4836
- name,
4837
- references: references ? {
4838
- columns: references[0],
4839
- fnOrTable: references[1],
4840
- foreignColumns: references[2],
4841
- options: references[3]
4842
- } : void 0,
4843
- check,
4844
- dropMode
4845
- });
4846
- return orchidCore.emptyObject;
4847
- },
4848
- foreignKey(columns, fnOrTable, foreignColumns, options) {
4849
- var _a;
4850
- ((_a = tableData.constraints) != null ? _a : tableData.constraints = []).push({
4851
- name: options == null ? void 0 : options.name,
4852
- references: {
4853
- columns,
4854
- fnOrTable,
4855
- foreignColumns,
4856
- options
4857
- },
4858
- dropMode: options == null ? void 0 : options.dropMode
4859
- });
4860
- return orchidCore.emptyObject;
4861
- },
4862
- check(check) {
4863
- var _a;
4864
- ((_a = tableData.constraints) != null ? _a : tableData.constraints = []).push({
4865
- check
4866
- });
4867
- return orchidCore.emptyObject;
4868
4991
  }
4869
4992
  }, orchidCore.makeTimestampsHelpers(makeRegexToFindInSql));
4870
4993
  };
@@ -4982,6 +5105,8 @@ for (const key in types.builtins) {
4982
5105
  delete defaultTypeParsers[id];
4983
5106
  });
4984
5107
  const returnArg = (arg) => arg;
5108
+ const rollbackSql$1 = { text: "ROLLBACK" };
5109
+ const commitSql$1 = { text: "COMMIT" };
4985
5110
  class Adapter {
4986
5111
  constructor(_a) {
4987
5112
  var _b = _a, { types: types2 = defaultTypeParsers } = _b, config = __objRest$1(_b, ["types"]);
@@ -5023,7 +5148,7 @@ class Adapter {
5023
5148
  arrays(query, types2) {
5024
5149
  return performQuery$1(this, query, types2, "array");
5025
5150
  }
5026
- async transaction(begin, cb) {
5151
+ async transaction(begin, cb, end = commitSql$1) {
5027
5152
  const client = await this.connect();
5028
5153
  try {
5029
5154
  await setSearchPath(client, this.schema);
@@ -5032,10 +5157,10 @@ class Adapter {
5032
5157
  try {
5033
5158
  result = await cb(new TransactionAdapter(this, client, this.types));
5034
5159
  } catch (err) {
5035
- await performQueryOnClient(client, { text: "ROLLBACK" }, this.types);
5160
+ await performQueryOnClient(client, rollbackSql$1, this.types);
5036
5161
  throw err;
5037
5162
  }
5038
- await performQueryOnClient(client, { text: "COMMIT" }, this.types);
5163
+ await performQueryOnClient(client, end, this.types);
5039
5164
  return result;
5040
5165
  } finally {
5041
5166
  client.release();
@@ -5109,8 +5234,8 @@ class TransactionAdapter {
5109
5234
  }
5110
5235
 
5111
5236
  var __defProp$7 = Object.defineProperty;
5112
- var __defProps$3 = Object.defineProperties;
5113
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
5237
+ var __defProps$2 = Object.defineProperties;
5238
+ var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
5114
5239
  var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
5115
5240
  var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
5116
5241
  var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
@@ -5126,7 +5251,7 @@ var __spreadValues$7 = (a, b) => {
5126
5251
  }
5127
5252
  return a;
5128
5253
  };
5129
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
5254
+ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
5130
5255
  class FnExpression extends orchidCore.Expression {
5131
5256
  /**
5132
5257
  * @param q - query object.
@@ -5183,7 +5308,7 @@ class FnExpression extends orchidCore.Expression {
5183
5308
  sql.push(" ");
5184
5309
  if (options.order) {
5185
5310
  pushOrderBySql(
5186
- __spreadProps$3(__spreadValues$7({}, ctx), { sql }),
5311
+ __spreadProps$2(__spreadValues$7({}, ctx), { sql }),
5187
5312
  this.q.q,
5188
5313
  quotedAs,
5189
5314
  orchidCore.toArray(options.order)
@@ -6114,9 +6239,9 @@ class Create {
6114
6239
  * password: '1234',
6115
6240
  * });
6116
6241
  *
6117
- * // When using `.onConflict().ignore()`,
6242
+ * // When using `.onConflictIgnore()`,
6118
6243
  * // the record may be not created and the `createdCount` will be 0.
6119
- * const createdCount = await db.table.insert(data).onConflict().ignore();
6244
+ * const createdCount = await db.table.insert(data).onConflictIgnore();
6120
6245
  *
6121
6246
  * await db.table.create({
6122
6247
  * // raw SQL
@@ -6330,32 +6455,44 @@ class Create {
6330
6455
  return _queryDefaults(this.clone(), data);
6331
6456
  }
6332
6457
  /**
6333
- * A modifier for creating queries that specify alternative behavior in the case of a conflict.
6334
- * A conflict occurs when a table has a `PRIMARY KEY` or a `UNIQUE` index on a column
6335
- * (or a composite index on a set of columns) and a row being created has the same value as a row
6336
- * that already exists in the table in this column(s).
6337
- * The default behavior in case of conflict is to raise an error and abort the query.
6458
+ * By default, violating unique constraint will cause the creative query to throw,
6459
+ * you can define what to do on a conflict: to ignore it, or to merge the existing record with a new data.
6460
+ *
6461
+ * A conflict occurs when a table has a primary key or a unique index on a column,
6462
+ * or a composite primary key unique index on a set of columns,
6463
+ * and a row being created has the same value as a row that already exists in the table in this column(s).
6464
+ *
6465
+ * Use `onConflictIgnore()` to suppress the error and continue without updating the record,
6466
+ * or `onConflict(['uniqueColumn']).merge()` to update the record with a new data.
6338
6467
  *
6339
- * Use `onConflict` to either ignore the error by using `.onConflict().ignore()`,
6340
- * or to update the existing row with new data (perform an "UPSERT") by using `.onConflict().merge()`.
6468
+ * `onConflict` only accepts column names that are defined in `primaryKey` or `unique` in the table definition.
6469
+ * To specify a constraint, its name also must be explicitly set in `primaryKey` or `unique` in the table code.
6470
+ *
6471
+ * Postgres has a limitation that a single `INSERT` query can have only a single `ON CONFLICT` clause that can target only a single unique constraint
6472
+ * for updating the record.
6473
+ *
6474
+ * If your table has multiple potential reasons for unique constraint violation, such as username and email columns in a user table,
6475
+ * consider using [upsert](#upsert) instead.
6341
6476
  *
6342
6477
  * ```ts
6343
6478
  * // leave `onConflict` without argument to ignore or merge on any conflict
6344
- * db.table.create(data).onConflict().ignore();
6479
+ * db.table.create(data).onConflictIgnore();
6345
6480
  *
6346
6481
  * // single column:
6347
- * db.table.create(data).onConfict('email');
6482
+ * db.table.create(data).onConfict('email').merge();
6348
6483
  *
6349
6484
  * // array of columns:
6350
- * db.table.create(data).onConfict(['email', 'name']);
6485
+ * db.table.create(data).onConfict(['email', 'name']).merge();
6351
6486
  *
6352
- * // raw expression:
6353
- * db.table.create(data).onConfict(db.table.sql`(email) where condition`);
6354
- * ```
6487
+ * // constraint name
6488
+ * db.table.create(data).onConfict({ constraint: 'unique_index_name' }).merge();
6355
6489
  *
6356
- * ::: info
6357
- * The column(s) given to the `onConflict` must either be the table's PRIMARY KEY or have a UNIQUE index on them, or the query will fail to execute.
6358
- * When specifying multiple columns, they must be a composite PRIMARY KEY or have a composite UNIQUE index.
6490
+ * // raw SQL expression:
6491
+ * db.table
6492
+ * .create(data)
6493
+ * .onConfict(db.table.sql`(email) where condition`)
6494
+ * .merge();
6495
+ * ```
6359
6496
  *
6360
6497
  * You can use the db.table.sql function in onConflict.
6361
6498
  * It can be useful to specify a condition when you have a partial index:
@@ -6372,29 +6509,17 @@ class Create {
6372
6509
  * .ignore();
6373
6510
  * ```
6374
6511
  *
6375
- * :::
6376
- *
6377
- * See the documentation on the .ignore() and .merge() methods for more details.
6378
- *
6379
6512
  * @param arg - optionally provide an array of columns
6380
6513
  */
6381
6514
  onConflict(arg) {
6382
6515
  return new OnConflictQueryBuilder(this, arg);
6383
6516
  }
6384
- }
6385
- class OnConflictQueryBuilder {
6386
- constructor(query, onConflict) {
6387
- this.query = query;
6388
- this.onConflict = onConflict;
6389
- }
6390
6517
  /**
6391
- * Available only after `onConflict`.
6392
- *
6393
- * `ignore` modifies a create query, and causes it to be silently dropped without an error if a conflict occurs.
6518
+ * Use `onConflictIgnore` to suppress unique constraint violation error when creating a record.
6394
6519
  *
6395
- * Adds the `ON CONFLICT (columns) DO NOTHING` clause to the insert statement.
6520
+ * Adds `ON CONFLICT (columns) DO NOTHING` clause to the insert statement, columns are optional.
6396
6521
  *
6397
- * It produces `ON CONFLICT DO NOTHING` when no `onConflict` argument provided.
6522
+ * Can also accept a constraint name.
6398
6523
  *
6399
6524
  * ```ts
6400
6525
  * db.table
@@ -6402,40 +6527,39 @@ class OnConflictQueryBuilder {
6402
6527
  * email: 'ignore@example.com',
6403
6528
  * name: 'John Doe',
6404
6529
  * })
6405
- * .onConflict('email')
6406
- * .ignore();
6530
+ * // on any conflict:
6531
+ * .onConflictIgnore()
6532
+ * // or, for a specific column:
6533
+ * .onConflictIgnore('email')
6534
+ * // or, for a specific constraint:
6535
+ * .onConflictIgnore({ constraint: 'unique_index_name' });
6407
6536
  * ```
6408
6537
  *
6409
- *
6410
- * When there is a conflict, nothing can be returned from the database, that's why `ignore` has to add `| undefined` part to the response type.
6411
- *
6412
- * `create` returns a full record by default, it becomes `RecordType | undefined` after applying `ignore`.
6538
+ * When there is a conflict, nothing can be returned from the database, so `onConflictIgnore` adds `| undefined` part to the response type.
6413
6539
  *
6414
6540
  * ```ts
6415
6541
  * const maybeRecord: RecordType | undefined = await db.table
6416
6542
  * .create(data)
6417
- * .onConflict()
6418
- * .ignore();
6543
+ * .onConflictIgnore();
6419
6544
  *
6420
6545
  * const maybeId: number | undefined = await db.table
6421
6546
  * .get('id')
6422
6547
  * .create(data)
6423
- * .onConflict()
6424
- * .ignore();
6548
+ * .onConflictIgnore();
6425
6549
  * ```
6426
6550
  *
6427
- * When creating many records, only the created records will be returned. If no records were created, array will be empty:
6551
+ * When creating multiple records, only created records will be returned. If no records were created, array will be empty:
6428
6552
  *
6429
6553
  * ```ts
6430
6554
  * // array can be empty
6431
- * const arr = await db.table.createMany([data, data, data]).onConflict().ignore();
6555
+ * const arr = await db.table.createMany([data, data, data]).onConflictIgnore();
6432
6556
  * ```
6433
6557
  */
6434
- ignore() {
6435
- const q = this.query;
6558
+ onConflictIgnore(arg) {
6559
+ const q = this.clone();
6436
6560
  q.q.onConflict = {
6437
6561
  type: "ignore",
6438
- expr: this.onConflict
6562
+ expr: arg
6439
6563
  };
6440
6564
  if (q.q.returnType === "oneOrThrow") {
6441
6565
  q.q.returnType = "one";
@@ -6444,23 +6568,27 @@ class OnConflictQueryBuilder {
6444
6568
  }
6445
6569
  return q;
6446
6570
  }
6571
+ }
6572
+ class OnConflictQueryBuilder {
6573
+ constructor(query, onConflict) {
6574
+ this.query = query;
6575
+ this.onConflict = onConflict;
6576
+ }
6447
6577
  /**
6448
- * Available only after `onConflict`.
6449
- *
6450
- * Modifies a create query, to turn it into an 'upsert' operation.
6578
+ * Available only after [onConflict](#onconflict).
6451
6579
  *
6452
6580
  * Adds an `ON CONFLICT (columns) DO UPDATE` clause to the insert statement.
6453
6581
  *
6454
- * When no `onConflict` argument provided,
6455
- * it will automatically collect all table columns that have unique index and use them as a conflict target.
6456
- *
6457
6582
  * ```ts
6458
6583
  * db.table
6459
6584
  * .create({
6460
6585
  * email: 'ignore@example.com',
6461
6586
  * name: 'John Doe',
6462
6587
  * })
6588
+ * // for a specific column:
6463
6589
  * .onConflict('email')
6590
+ * // or, for a specific constraint:
6591
+ * .onConflict({ constraint: 'unique_constraint_name' })
6464
6592
  * .merge();
6465
6593
  * ```
6466
6594
  *
@@ -6491,15 +6619,15 @@ class OnConflictQueryBuilder {
6491
6619
  * updatedAt: timestamp,
6492
6620
  * })
6493
6621
  * .onConflict('email')
6494
- * // string argument for a single column:
6622
+ * // update only a single column
6495
6623
  * .merge('email')
6496
- * // array of strings for multiple columns:
6624
+ * // or, update multiple columns
6497
6625
  * .merge(['email', 'name', 'updatedAt']);
6498
6626
  * ```
6499
6627
  *
6500
- * It is also possible to specify data to update separately from the data to create.
6628
+ * It's possible to specify data to update separately from the data to create.
6501
6629
  * This is useful if you want to make an update with different data than in creating.
6502
- * For example, you may want to change a value if the row already exists:
6630
+ * For example, changing a value if the row already exists:
6503
6631
  *
6504
6632
  * ```ts
6505
6633
  * const timestamp = Date.now();
@@ -6517,7 +6645,7 @@ class OnConflictQueryBuilder {
6517
6645
  * });
6518
6646
  * ```
6519
6647
  *
6520
- * It is also possible to add a WHERE clause to conditionally update only the matching rows:
6648
+ * You can use `where` to update only the matching rows:
6521
6649
  *
6522
6650
  * ```ts
6523
6651
  * const timestamp = Date.now();
@@ -6537,7 +6665,7 @@ class OnConflictQueryBuilder {
6537
6665
  * .where({ updatedAt: { lt: timestamp } });
6538
6666
  * ```
6539
6667
  *
6540
- * `merge` also accepts raw expression:
6668
+ * `merge` can take a raw SQL expression:
6541
6669
  *
6542
6670
  * ```ts
6543
6671
  * db.table
@@ -7773,10 +7901,7 @@ class JsonModifiers {
7773
7901
  options
7774
7902
  ]
7775
7903
  };
7776
- return Object.assign(
7777
- pushQueryValue(q, "select", json),
7778
- json
7779
- );
7904
+ return Object.assign(pushQueryValue(q, "select", json), json);
7780
7905
  }
7781
7906
  /**
7782
7907
  * Return a JSON value/object/array where a given value is inserted at the given JSON path. Value can be a single value or JSON object. If a value exists at the given path, the value is not replaced.
@@ -7824,10 +7949,7 @@ class JsonModifiers {
7824
7949
  options
7825
7950
  ]
7826
7951
  };
7827
- return Object.assign(
7828
- pushQueryValue(q, "select", json),
7829
- json
7830
- );
7952
+ return Object.assign(pushQueryValue(q, "select", json), json);
7831
7953
  }
7832
7954
  /**
7833
7955
  * Return a JSON value/object/array where a given value is removed at the given JSON path.
@@ -7866,10 +7988,7 @@ class JsonModifiers {
7866
7988
  path
7867
7989
  ]
7868
7990
  };
7869
- return Object.assign(
7870
- pushQueryValue(q, "select", json),
7871
- json
7872
- );
7991
+ return Object.assign(pushQueryValue(q, "select", json), json);
7873
7992
  }
7874
7993
  /**
7875
7994
  * Selects a value from JSON data using a JSON path.
@@ -7915,10 +8034,7 @@ class JsonModifiers {
7915
8034
  const json = {
7916
8035
  __json: ["pathQuery", as, type, column, path, options]
7917
8036
  };
7918
- return Object.assign(
7919
- pushQueryValue(q, "select", json),
7920
- json
7921
- );
8037
+ return Object.assign(pushQueryValue(q, "select", json), json);
7922
8038
  }
7923
8039
  }
7924
8040
  class JsonMethods {
@@ -7935,10 +8051,7 @@ class JsonMethods {
7935
8051
  * @param coalesce
7936
8052
  */
7937
8053
  json(coalesce) {
7938
- return queryJson(
7939
- this.clone(),
7940
- coalesce
7941
- );
8054
+ return queryJson(this.clone(), coalesce);
7942
8055
  }
7943
8056
  }
7944
8057
 
@@ -7953,7 +8066,7 @@ const makeMessage = (colors, timeColor, time, sqlColor, sql, valuesColor, values
7953
8066
  const elapsed = process.hrtime(time);
7954
8067
  const formattedTime = `(${elapsed[0] ? `${elapsed[0]}s ` : ""}${(elapsed[1] / 1e6).toFixed(1)}ms)`;
7955
8068
  const result = `${colors ? timeColor(formattedTime) : formattedTime} ${colors ? sqlColor(sql) : sql}`;
7956
- if (!values.length) {
8069
+ if (!(values == null ? void 0 : values.length)) {
7957
8070
  return result;
7958
8071
  }
7959
8072
  const formattedValues = `[${values.map(quote).join(", ")}]`;
@@ -8065,8 +8178,8 @@ class MergeQueryMethods {
8065
8178
  }
8066
8179
 
8067
8180
  var __defProp$4 = Object.defineProperty;
8068
- var __defProps$2 = Object.defineProperties;
8069
- var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
8181
+ var __defProps$1 = Object.defineProperties;
8182
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
8070
8183
  var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
8071
8184
  var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
8072
8185
  var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
@@ -8082,7 +8195,7 @@ var __spreadValues$4 = (a, b) => {
8082
8195
  }
8083
8196
  return a;
8084
8197
  };
8085
- var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
8198
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
8086
8199
  class With {
8087
8200
  /**
8088
8201
  * Add Common Table Expression (CTE) to the query.
@@ -8157,7 +8270,7 @@ class With {
8157
8270
  const query = typeof last === "function" ? last(q.queryBuilder) : last;
8158
8271
  const shape = args.length === 4 ? args[2] : orchidCore.isExpression(query) ? args[1] : query.q.shape;
8159
8272
  if ((options == null ? void 0 : options.columns) === true) {
8160
- options = __spreadProps$2(__spreadValues$4({}, options), {
8273
+ options = __spreadProps$1(__spreadValues$4({}, options), {
8161
8274
  columns: Object.keys(shape)
8162
8275
  });
8163
8276
  }
@@ -9099,9 +9212,9 @@ const _queryUpdate = (query, arg) => {
9099
9212
  if (queries) {
9100
9213
  q.patchResult = async (_, queryResult) => {
9101
9214
  await Promise.all(queries.map(orchidCore.callWithThis, queryResult));
9102
- if (ctx.updateData) {
9215
+ if (ctx.collect) {
9103
9216
  const t = query.baseQuery.clone();
9104
- const keys = query.primaryKeys;
9217
+ const { keys } = ctx.collect;
9105
9218
  _queryWhereIn(
9106
9219
  t,
9107
9220
  keys,
@@ -9109,10 +9222,10 @@ const _queryUpdate = (query, arg) => {
9109
9222
  );
9110
9223
  _queryUpdate(
9111
9224
  t,
9112
- ctx.updateData
9225
+ ctx.collect.data
9113
9226
  );
9114
9227
  for (const row of queryResult.rows) {
9115
- Object.assign(row, ctx.updateData);
9228
+ Object.assign(row, ctx.collect.data);
9116
9229
  }
9117
9230
  }
9118
9231
  };
@@ -9545,8 +9658,8 @@ class Transaction {
9545
9658
  }
9546
9659
 
9547
9660
  var __defProp$2 = Object.defineProperty;
9548
- var __defProps$1 = Object.defineProperties;
9549
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
9661
+ var __defProps = Object.defineProperties;
9662
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
9550
9663
  var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
9551
9664
  var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
9552
9665
  var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
@@ -9562,7 +9675,7 @@ var __spreadValues$2 = (a, b) => {
9562
9675
  }
9563
9676
  return a;
9564
9677
  };
9565
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
9678
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
9566
9679
  class Headline extends orchidCore.Expression {
9567
9680
  constructor(q, source, params) {
9568
9681
  super();
@@ -9784,7 +9897,7 @@ class SearchMethods {
9784
9897
  const q = this.clone();
9785
9898
  if (!arg.as) {
9786
9899
  const as = saveSearchAlias(q, "@q", "joinedShapes");
9787
- arg = __spreadProps$1(__spreadValues$2({}, arg), {
9900
+ arg = __spreadProps(__spreadValues$2({}, arg), {
9788
9901
  as
9789
9902
  });
9790
9903
  }
@@ -10373,20 +10486,11 @@ class QueryMethods {
10373
10486
  );
10374
10487
  }
10375
10488
  /**
10376
- * The `find` method is available only for tables which has exactly one primary key.
10377
- * And also it can accept raw SQL template literal, then the primary key is not required.
10378
- *
10379
- * Finds a record by id, throws {@link NotFoundError} if not found:
10489
+ * Finds a single record by the primary key (id), throws [NotFoundError](/guide/error-handling.html) if not found.
10490
+ * Not available if the table has no or multiple primary keys.
10380
10491
  *
10381
10492
  * ```ts
10382
- * await db.table.find(1);
10383
- * ```
10384
- *
10385
- * ```ts
10386
- * await db.user.find`
10387
- * age = ${age} AND
10388
- * name = ${name}
10389
- * `;
10493
+ * const result: TableType = await db.table.find(1);
10390
10494
  * ```
10391
10495
  *
10392
10496
  * @param value - primary key value to find by
@@ -10402,7 +10506,7 @@ class QueryMethods {
10402
10506
  return _queryTake(
10403
10507
  _queryWhere(q, [
10404
10508
  {
10405
- [q.singlePrimaryKey]: value
10509
+ [q.internal.singlePrimaryKey]: value
10406
10510
  }
10407
10511
  ])
10408
10512
  );
@@ -10424,8 +10528,8 @@ class QueryMethods {
10424
10528
  return _queryTake(_queryWhereSql(q, args));
10425
10529
  }
10426
10530
  /**
10427
- * Find a single record by the primary key (id), adds `LIMIT 1`.
10428
- * Returns `undefined` when not found.
10531
+ * Finds a single record by the primary key (id), returns `undefined` when not found.
10532
+ * Not available if the table has no or multiple primary keys.
10429
10533
  *
10430
10534
  * ```ts
10431
10535
  * const result: TableType | undefined = await db.table.find(123);
@@ -10455,40 +10559,40 @@ class QueryMethods {
10455
10559
  );
10456
10560
  }
10457
10561
  /**
10458
- * The same as `where(conditions).take()`, takes the same arguments as {@link Where.where}, it will filter records and add a `LIMIT 1`.
10459
- * Throws `NotFoundError` if not found.
10562
+ * Finds a single unique record, throws [NotFoundError](/guide/error-handling.html) if not found.
10563
+ * It accepts values of primary keys or unique indexes defined on the table.
10564
+ * `findBy`'s argument type is a union of all possible sets of unique conditions.
10565
+ *
10566
+ * You can use `where(...).take()` for non-unique conditions.
10460
10567
  *
10461
10568
  * ```ts
10462
- * const result: TableType = await db.table.findBy({ key: 'value' });
10463
- * // is equivalent to:
10464
- * db.table.where({ key: 'value' }).take()
10569
+ * await db.table.findBy({ key: 'value' });
10465
10570
  * ```
10466
10571
  *
10467
- * @param args - `where` conditions
10572
+ * @param uniqueColumnValues - is derived from primary keys and unique indexes in the table
10468
10573
  */
10469
- findBy(...args) {
10470
- return _queryFindBy(
10471
- this.clone(),
10472
- args
10473
- );
10574
+ findBy(uniqueColumnValues) {
10575
+ return _queryFindBy(this.clone(), [
10576
+ uniqueColumnValues
10577
+ ]);
10474
10578
  }
10475
10579
  /**
10476
- * The same as `where(conditions).takeOptional()`, it will filter records and add a `LIMIT 1`.
10477
- * Returns `undefined` when not found.
10580
+ * Finds a single unique record, returns `undefined` if not found.
10581
+ * It accepts values of primary keys or unique indexes defined on the table.
10582
+ * `findBy`'s argument type is a union of all possible sets of unique conditions.
10583
+ *
10584
+ * You can use `where(...).takeOptional()` for non-unique conditions.
10478
10585
  *
10479
10586
  * ```ts
10480
- * const result: TableType | undefined = await db.table.findByOptional({
10481
- * key: 'value',
10482
- * });
10587
+ * await db.table.findByOptional({ key: 'value' });
10483
10588
  * ```
10484
10589
  *
10485
- * @param args - `where` conditions
10590
+ * @param uniqueColumnValues - is derived from primary keys and unique indexes in the table
10486
10591
  */
10487
- findByOptional(...args) {
10488
- return _queryFindByOptional(
10489
- this.clone(),
10490
- args
10491
- );
10592
+ findByOptional(uniqueColumnValues) {
10593
+ return _queryFindByOptional(this.clone(), [
10594
+ uniqueColumnValues
10595
+ ]);
10492
10596
  }
10493
10597
  /**
10494
10598
  * Specifies the schema to be used as a prefix of a table name.
@@ -10634,9 +10738,9 @@ class QueryMethods {
10634
10738
  * Order by raw SQL expression.
10635
10739
  *
10636
10740
  * ```ts
10637
- * db.table.order`raw sql`;
10741
+ * db.table.orderSql`raw sql`;
10638
10742
  * // or
10639
- * db.table.order(db.table.sql`raw sql`);
10743
+ * db.table.orderSql(db.table.sql`raw sql`);
10640
10744
  * ```
10641
10745
  *
10642
10746
  * @param args - SQL expression
@@ -10878,9 +10982,86 @@ orchidCore.applyMixins(QueryMethods, [
10878
10982
  SoftDeleteMethods
10879
10983
  ]);
10880
10984
 
10985
+ const makeIndex = (columns, first, second) => {
10986
+ if (typeof first === "string") {
10987
+ const options = second != null ? second : {};
10988
+ return {
10989
+ index: { columns, options, name: first }
10990
+ };
10991
+ } else {
10992
+ const options = first != null ? first : {};
10993
+ return {
10994
+ index: { columns, options }
10995
+ };
10996
+ }
10997
+ };
10998
+ const tableDataMethods = {
10999
+ primaryKey(columns, name) {
11000
+ return { primaryKey: { columns, name } };
11001
+ },
11002
+ unique(columns, ...[first, second]) {
11003
+ const input = makeIndex(columns, first, second);
11004
+ input.index.options.unique = true;
11005
+ return input;
11006
+ },
11007
+ index: makeIndex,
11008
+ searchIndex(columns, ...[first, second]) {
11009
+ var _a, _b;
11010
+ const input = makeIndex(columns, first, second);
11011
+ (_b = (_a = input.index.options).using) != null ? _b : _a.using = "gin";
11012
+ input.index.options.tsVector = true;
11013
+ return input;
11014
+ },
11015
+ foreignKey(columns, fnOrTable, foreignColumns, options) {
11016
+ return {
11017
+ constraint: {
11018
+ name: options == null ? void 0 : options.name,
11019
+ references: { columns, fnOrTable, foreignColumns, options }
11020
+ }
11021
+ };
11022
+ },
11023
+ check(check, name) {
11024
+ return { constraint: { check, name } };
11025
+ },
11026
+ sql: sqlFn
11027
+ };
11028
+ const parseTableData = (dataFn) => {
11029
+ const tableData = {};
11030
+ if (dataFn) {
11031
+ const input = dataFn(tableDataMethods);
11032
+ if (Array.isArray(input)) {
11033
+ for (const item of input) {
11034
+ parseTableDataInput(tableData, item);
11035
+ }
11036
+ } else {
11037
+ parseTableDataInput(tableData, input);
11038
+ }
11039
+ }
11040
+ return tableData;
11041
+ };
11042
+ const parseTableDataInput = (tableData, item) => {
11043
+ var _a, _b, _c, _d;
11044
+ if (item.primaryKey) {
11045
+ tableData.primaryKey = item.primaryKey;
11046
+ } else if (item.index) {
11047
+ const index = item.index;
11048
+ for (let i = index.columns.length - 1; i >= 0; i--) {
11049
+ if (typeof index.columns[i] === "string") {
11050
+ index.columns[i] = {
11051
+ column: index.columns[i]
11052
+ };
11053
+ }
11054
+ }
11055
+ ((_a = tableData.indexes) != null ? _a : tableData.indexes = []).push(item.index);
11056
+ } else if (item.constraint) {
11057
+ ((_b = tableData.constraints) != null ? _b : tableData.constraints = []).push(item.constraint);
11058
+ if ((_d = (_c = item.constraint.references) == null ? void 0 : _c.options) == null ? void 0 : _d.dropMode) {
11059
+ item.constraint.dropMode = item.constraint.references.options.dropMode;
11060
+ }
11061
+ }
11062
+ };
11063
+
10881
11064
  var __defProp = Object.defineProperty;
10882
- var __defProps = Object.defineProperties;
10883
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
10884
11065
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
10885
11066
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10886
11067
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -10896,7 +11077,6 @@ var __spreadValues = (a, b) => {
10896
11077
  }
10897
11078
  return a;
10898
11079
  };
10899
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
10900
11080
  var __objRest = (source, exclude) => {
10901
11081
  var target = {};
10902
11082
  for (var prop in source)
@@ -10911,22 +11091,24 @@ var __objRest = (source, exclude) => {
10911
11091
  };
10912
11092
  const anyShape = {};
10913
11093
  class Db {
10914
- constructor(adapter, queryBuilder, table = void 0, shape = anyShape, columnTypes, transactionStorage, options) {
11094
+ constructor(adapter, queryBuilder, table = void 0, shape = anyShape, columnTypes, transactionStorage, options, tableData = orchidCore.emptyObject) {
10915
11095
  this.adapter = adapter;
10916
11096
  this.queryBuilder = queryBuilder;
10917
11097
  this.table = table;
10918
11098
  this.shape = shape;
10919
11099
  this.columnTypes = columnTypes;
10920
- var _a, _b;
11100
+ var _a;
10921
11101
  const self = this;
10922
11102
  const { softDelete } = options;
10923
11103
  const scopes = options.scopes || softDelete ? {} : orchidCore.emptyObject;
10924
- const tableData = getTableData();
10925
- this.internal = __spreadProps(__spreadValues({}, tableData), {
11104
+ this.internal = {
10926
11105
  transactionStorage,
10927
11106
  scopes,
10928
- snakeCase: options.snakeCase
10929
- });
11107
+ snakeCase: options.snakeCase,
11108
+ noPrimaryKey: options.noPrimaryKey === "ignore",
11109
+ comment: options.comment,
11110
+ tableData
11111
+ };
10930
11112
  this.baseQuery = this;
10931
11113
  const logger = options.logger || console;
10932
11114
  const parsers = {};
@@ -10987,20 +11169,21 @@ class Db {
10987
11169
  log: logParamToLogObject(logger, options.log),
10988
11170
  autoPreparedStatements: (_a = options.autoPreparedStatements) != null ? _a : false,
10989
11171
  parsers: hasParsers ? parsers : void 0,
10990
- language: options.language
11172
+ language: options.language,
11173
+ schema: options == null ? void 0 : options.schema
10991
11174
  };
10992
- if (options == null ? void 0 : options.schema) {
10993
- this.q.schema = options.schema;
11175
+ let shapeHasPrimaryKey;
11176
+ for (const key in shape) {
11177
+ if (shape[key].data.primaryKey) {
11178
+ shapeHasPrimaryKey = true;
11179
+ if (this.internal.singlePrimaryKey) {
11180
+ this.internal.singlePrimaryKey = void 0;
11181
+ break;
11182
+ }
11183
+ this.internal.singlePrimaryKey = key;
11184
+ }
10994
11185
  }
10995
- this.primaryKeys = Object.keys(shape).filter(
10996
- (key) => shape[key].data.isPrimaryKey
10997
- );
10998
- const primaryKeysFromData = (_b = getTableData().primaryKey) == null ? void 0 : _b.columns;
10999
- if (primaryKeysFromData)
11000
- this.primaryKeys.push(...primaryKeysFromData);
11001
- if (this.primaryKeys.length === 1) {
11002
- this.singlePrimaryKey = this.primaryKeys[0];
11003
- } else if (this.primaryKeys.length === 0 && shape !== anyShape && options.noPrimaryKey !== "ignore") {
11186
+ if (!shapeHasPrimaryKey && !tableData.primaryKey && shape !== anyShape && options.noPrimaryKey !== "ignore") {
11004
11187
  const message = `Table ${table} has no primary key`;
11005
11188
  if (options.noPrimaryKey === "error")
11006
11189
  throw new Error(message);
@@ -11189,24 +11372,22 @@ const createDb = (_a) => {
11189
11372
  ct[orchidCore.snakeCaseKey] = true;
11190
11373
  }
11191
11374
  const transactionStorage = new node_async_hooks.AsyncLocalStorage();
11192
- const qb = new Db(
11375
+ const qb = _initQueryBuilder(
11193
11376
  adapter,
11194
- void 0,
11195
- void 0,
11196
- anyShape,
11197
11377
  ct,
11198
11378
  transactionStorage,
11199
- commonOptions
11379
+ commonOptions,
11380
+ options
11200
11381
  );
11201
- qb.queryBuilder = qb;
11202
- const tableConstructor = (table, shape, options2) => new Db(
11382
+ const tableConstructor = (table, shape, dataFn, options2) => new Db(
11203
11383
  adapter,
11204
11384
  qb,
11205
11385
  table,
11206
11386
  typeof shape === "function" ? getColumnTypes(ct, shape, nowSQL, options2 == null ? void 0 : options2.language) : shape,
11207
11387
  ct,
11208
11388
  transactionStorage,
11209
- __spreadValues(__spreadValues({}, commonOptions), options2)
11389
+ __spreadValues(__spreadValues({}, commonOptions), options2),
11390
+ parseTableData(dataFn)
11210
11391
  );
11211
11392
  const db = Object.assign(tableConstructor, qb, {
11212
11393
  adapter,
@@ -11217,6 +11398,32 @@ const createDb = (_a) => {
11217
11398
  }
11218
11399
  return db;
11219
11400
  };
11401
+ const _initQueryBuilder = (adapter, columnTypes, transactionStorage, commonOptions, options) => {
11402
+ const qb = new Db(
11403
+ adapter,
11404
+ void 0,
11405
+ void 0,
11406
+ anyShape,
11407
+ columnTypes,
11408
+ transactionStorage,
11409
+ commonOptions
11410
+ );
11411
+ if (options.extensions) {
11412
+ const arr = [];
11413
+ for (const x of options.extensions) {
11414
+ if (typeof x === "string") {
11415
+ arr.push({ name: x });
11416
+ } else {
11417
+ for (const key in x) {
11418
+ arr.push({ name: key, version: x[key] });
11419
+ }
11420
+ }
11421
+ }
11422
+ qb.internal.extensions = arr;
11423
+ }
11424
+ qb.internal.domains = options.domains;
11425
+ return qb.queryBuilder = qb;
11426
+ };
11220
11427
 
11221
11428
  class Rollback extends Error {
11222
11429
  }
@@ -11449,6 +11656,7 @@ exports.VirtualColumn = VirtualColumn;
11449
11656
  exports.Where = Where;
11450
11657
  exports.With = With;
11451
11658
  exports.XMLColumn = XMLColumn;
11659
+ exports._initQueryBuilder = _initQueryBuilder;
11452
11660
  exports._queryAfterSaveCommit = _queryAfterSaveCommit;
11453
11661
  exports._queryAll = _queryAll;
11454
11662
  exports._queryAs = _queryAs;
@@ -11516,7 +11724,7 @@ exports.columnCode = columnCode;
11516
11724
  exports.columnForeignKeysToCode = columnForeignKeysToCode;
11517
11725
  exports.columnIndexesToCode = columnIndexesToCode;
11518
11726
  exports.columnsShapeToCode = columnsShapeToCode;
11519
- exports.constraintPropsToCode = constraintPropsToCode;
11727
+ exports.constraintInnerToCode = constraintInnerToCode;
11520
11728
  exports.constraintToCode = constraintToCode;
11521
11729
  exports.copyTableData = copyTableData;
11522
11730
  exports.countSelect = countSelect;
@@ -11527,12 +11735,12 @@ exports.foreignKeyArgumentToCode = foreignKeyArgumentToCode;
11527
11735
  exports.getClonedQueryData = getClonedQueryData;
11528
11736
  exports.getColumnInfo = getColumnInfo;
11529
11737
  exports.getColumnTypes = getColumnTypes;
11530
- exports.getConstraintKind = getConstraintKind;
11738
+ exports.getPrimaryKeys = getPrimaryKeys;
11531
11739
  exports.getQueryAs = getQueryAs;
11532
11740
  exports.getShapeFromSelect = getShapeFromSelect;
11533
- exports.getTableData = getTableData;
11534
11741
  exports.handleResult = handleResult;
11535
11742
  exports.identityToCode = identityToCode;
11743
+ exports.indexInnerToCode = indexInnerToCode;
11536
11744
  exports.indexToCode = indexToCode;
11537
11745
  exports.instantiateColumn = instantiateColumn;
11538
11746
  exports.isDefaultTimeStamp = isDefaultTimeStamp;
@@ -11547,16 +11755,18 @@ exports.makeExpression = makeExpression;
11547
11755
  exports.makeFnExpression = makeFnExpression;
11548
11756
  exports.makeRegexToFindInSql = makeRegexToFindInSql;
11549
11757
  exports.makeSQL = makeSQL;
11550
- exports.newTableData = newTableData;
11551
11758
  exports.parseRecord = parseRecord;
11552
11759
  exports.parseResult = parseResult;
11553
- exports.primaryKeyToCode = primaryKeyToCode;
11760
+ exports.parseTableData = parseTableData;
11761
+ exports.parseTableDataInput = parseTableDataInput;
11762
+ exports.primaryKeyInnerToCode = primaryKeyInnerToCode;
11554
11763
  exports.processSelectArg = processSelectArg;
11555
11764
  exports.pushLimitSQL = pushLimitSQL;
11556
11765
  exports.pushQueryArray = pushQueryArray;
11557
11766
  exports.pushQueryOn = pushQueryOn;
11558
11767
  exports.pushQueryOrOn = pushQueryOrOn;
11559
11768
  exports.pushQueryValue = pushQueryValue;
11769
+ exports.pushTableDataCode = pushTableDataCode;
11560
11770
  exports.queryFrom = queryFrom;
11561
11771
  exports.queryFromSql = queryFromSql;
11562
11772
  exports.queryJson = queryJson;
@@ -11567,14 +11777,15 @@ exports.quote = quote;
11567
11777
  exports.quoteString = quoteString;
11568
11778
  exports.raw = raw;
11569
11779
  exports.referencesArgsToCode = referencesArgsToCode;
11570
- exports.resetTableData = resetTableData;
11571
11780
  exports.resolveSubQueryCallback = resolveSubQueryCallback;
11572
11781
  exports.saveSearchAlias = saveSearchAlias;
11573
11782
  exports.setParserForSelectedString = setParserForSelectedString;
11574
11783
  exports.setQueryObjectValue = setQueryObjectValue;
11575
11784
  exports.setQueryOperators = setQueryOperators;
11576
11785
  exports.simplifyColumnDefault = simplifyColumnDefault;
11786
+ exports.sqlFn = sqlFn;
11577
11787
  exports.sqlQueryArgsToExpression = sqlQueryArgsToExpression;
11788
+ exports.tableDataMethods = tableDataMethods;
11578
11789
  exports.templateLiteralToSQL = templateLiteralToSQL;
11579
11790
  exports.testTransaction = testTransaction;
11580
11791
  exports.throwIfNoWhere = throwIfNoWhere;