pqb 0.27.6 → 0.27.7

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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { ExpressionTypeMethod, Expression, RawSQLBase, isTemplateLiteralArgs, ColumnTypeBase, setColumnData, pushColumnData, emptyObject, quoteObjectKey, toArray, singleQuote, addCode, objectHasValues, singleQuoteArray, columnDefaultArgumentToCode, columnErrorMessagesToCode, isExpression, dateDataToCode, joinTruthy, arrayDataToCode, noop, getValueKey, emptyArray, callWithThis, setParserToQuery, applyTransforms, isRawSQL, pushOrNewArray, pushOrNewArrayToObject, numberDataToCode, stringDataToCode, getDefaultLanguage, setDefaultNowFn, setDefaultLanguage, makeTimestampsHelpers, setCurrentColumnName, setAdapterConnectRetry, isObjectEmpty, applyMixins, toSnakeCase, snakeCaseKey } from 'orchid-core';
1
+ import { ExpressionTypeMethod, Expression, RawSQLBase, isTemplateLiteralArgs, ColumnTypeBase, setColumnData, pushColumnData, emptyObject, quoteObjectKey, toArray, singleQuote, addCode, singleQuoteArray, objectHasValues, columnDefaultArgumentToCode, columnErrorMessagesToCode, isExpression, dateDataToCode, joinTruthy, arrayDataToCode, noop, getValueKey, emptyArray, callWithThis, setParserToQuery, applyTransforms, isRawSQL, pushOrNewArray, pushOrNewArrayToObject, numberDataToCode, stringDataToCode, getDefaultLanguage, setDefaultNowFn, setDefaultLanguage, makeTimestampsHelpers, setCurrentColumnName, setAdapterConnectRetry, isObjectEmpty, applyMixins, toSnakeCase, snakeCaseKey } from 'orchid-core';
2
2
  import pg from 'pg';
3
3
  import { inspect } from 'node:util';
4
4
  import { AsyncLocalStorage } from 'node:async_hooks';
@@ -139,9 +139,12 @@ class ColumnType extends ColumnTypeBase {
139
139
  * // primary key can be used by `find` later:
140
140
  * db.table.find('97ba9e78-7510-415a-9c03-23d440aec443');
141
141
  * ```
142
+ *
143
+ * @param options - to specify a constraint name
142
144
  */
143
- primaryKey() {
144
- return setColumnData(this, "isPrimaryKey", true);
145
+ primaryKey(options) {
146
+ var _a;
147
+ return setColumnData(this, "primaryKey", (_a = options == null ? void 0 : options.name) != null ? _a : true);
145
148
  }
146
149
  foreignKey(fnOrTable, column, options = emptyObject) {
147
150
  const item = typeof fnOrTable === "string" ? __spreadValues$h({ table: fnOrTable, columns: [column] }, options) : __spreadValues$h({ fn: fnOrTable, columns: [column] }, options);
@@ -154,9 +157,9 @@ class ColumnType extends ColumnTypeBase {
154
157
  return pushColumnData(this, "indexes", options);
155
158
  }
156
159
  /**
157
- * `searchIndex` is designed for full text search.
160
+ * `searchIndex` is designed for [full text search](/guide/text-search).
158
161
  *
159
- * 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`.
162
+ * 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.
160
163
  *
161
164
  * ```ts
162
165
  * import { change } from '../dbScript';
@@ -164,8 +167,8 @@ class ColumnType extends ColumnTypeBase {
164
167
  * change(async (db) => {
165
168
  * await db.createTable('table', (t) => ({
166
169
  * id: t.identity().primaryKey(),
167
- * title: t.string(),
168
- * body: t.string(),
170
+ * title: t.text(),
171
+ * body: t.text(),
169
172
  * ...t.searchIndex(['title', 'body']),
170
173
  * }));
171
174
  * });
@@ -174,10 +177,10 @@ class ColumnType extends ColumnTypeBase {
174
177
  * Produces the following index ('english' is a default language, see [full text search](/guide/text-search.html#language) for changing it):
175
178
  *
176
179
  * ```sql
177
- * CREATE INDEX "table_title_body_idx" ON "table" USING GIN (to_tsvector('english', concat_ws(' ', "title", "body")))
180
+ * CREATE INDEX "table_title_body_idx" ON "table" USING GIN (to_tsvector('english', "title" || ' ' || "body"))
178
181
  * ```
179
182
  *
180
- * Also, it works well with a generated `tsvector` column:
183
+ * You can set different search weights (`A` to `D`) on different columns inside the index:
181
184
  *
182
185
  * ```ts
183
186
  * import { change } from '../dbScript';
@@ -185,8 +188,63 @@ class ColumnType extends ColumnTypeBase {
185
188
  * change(async (db) => {
186
189
  * await db.createTable('table', (t) => ({
187
190
  * id: t.identity().primaryKey(),
188
- * title: t.string(),
189
- * body: t.string(),
191
+ * title: t.text(),
192
+ * body: t.text(),
193
+ * ...t.searchIndex([
194
+ * { column: 'title', weight: 'A' },
195
+ * { column: 'body', weight: 'B' },
196
+ * ]),
197
+ * }));
198
+ * });
199
+ * ```
200
+ *
201
+ * When the table has localized columns,
202
+ * you can define different indexes for different languages by setting the `language` parameter:
203
+ *
204
+ * ```ts
205
+ * import { change } from '../dbScript';
206
+ *
207
+ * change(async (db) => {
208
+ * await db.createTable('table', (t) => ({
209
+ * id: t.identity().primaryKey(),
210
+ * titleEn: t.text(),
211
+ * bodyEn: t.text(),
212
+ * titleFr: t.text(),
213
+ * bodyFr: t.text(),
214
+ * ...t.searchIndex(['titleEn', 'bodyEn'], { language: 'english' }),
215
+ * ...t.searchIndex(['titleFr', 'bodyFr'], { language: 'french' }),
216
+ * }));
217
+ * });
218
+ * ```
219
+ *
220
+ * Alternatively, different table records may correspond to a single language,
221
+ * then you can define a search index that relies on a language column by using `languageColumn` parameter:
222
+ *
223
+ * ```ts
224
+ * import { change } from '../dbScript';
225
+ *
226
+ * change(async (db) => {
227
+ * await db.createTable('table', (t) => ({
228
+ * id: t.identity().primaryKey(),
229
+ * lang: t.type('regconfig'),
230
+ * title: t.text(),
231
+ * body: t.text(),
232
+ * ...t.searchIndex(['title', 'body'], { languageColumn: 'lang' }),
233
+ * }));
234
+ * });
235
+ * ```
236
+ *
237
+ * 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,
238
+ * and to set a `searchIndex` on it:
239
+ *
240
+ * ```ts
241
+ * import { change } from '../dbScript';
242
+ *
243
+ * change(async (db) => {
244
+ * await db.createTable('table', (t) => ({
245
+ * id: t.identity().primaryKey(),
246
+ * title: t.text(),
247
+ * body: t.text(),
190
248
  * generatedTsVector: t.tsvector().generated(['title', 'body']).searchIndex(),
191
249
  * }));
192
250
  * });
@@ -267,14 +325,21 @@ const knownDefaults = {
267
325
  };
268
326
  const simplifyColumnDefault = (value) => {
269
327
  if (typeof value === "string") {
270
- const lower = value.toLowerCase();
271
- return new RawSQL(knownDefaults[lower] || value);
328
+ return new RawSQL([
329
+ [knownDefaults[value.toLowerCase()] || value]
330
+ ]);
272
331
  }
273
332
  return;
274
333
  };
275
334
  const instantiateColumn = (typeFn, params) => {
276
335
  const column = typeFn();
336
+ const { dateTimePrecision } = params;
277
337
  Object.assign(column.data, __spreadProps$a(__spreadValues$g({}, params), {
338
+ dateTimePrecision: (
339
+ // 0 is default for date, 6 is default for timestamp
340
+ dateTimePrecision && dateTimePrecision !== 6 ? dateTimePrecision : void 0
341
+ ),
342
+ collate: params.collate,
278
343
  default: simplifyColumnDefault(params.default)
279
344
  }));
280
345
  return column;
@@ -315,7 +380,7 @@ const combineCodeElements = (input) => {
315
380
  }
316
381
  return output;
317
382
  };
318
- const columnsShapeToCode = (shape, tableData, t) => {
383
+ const columnsShapeToCode = (shape, tableData, t, m) => {
319
384
  const hasTimestamps = "createdAt" in shape && isDefaultTimeStamp(shape.createdAt) && "updatedAt" in shape && isDefaultTimeStamp(shape.updatedAt);
320
385
  const code = [];
321
386
  for (const key in shape) {
@@ -343,19 +408,33 @@ const columnsShapeToCode = (shape, tableData, t) => {
343
408
  }
344
409
  if (constraints) {
345
410
  for (const item of constraints) {
346
- code.push(...constraintToCode(item, t));
411
+ code.push(...constraintToCode(item, t, m));
347
412
  }
348
413
  }
349
414
  return code;
350
415
  };
351
416
  const primaryKeyToCode = (primaryKey, t) => {
417
+ return `...${primaryKeyInnerToCode(primaryKey, t)},`;
418
+ };
419
+ const primaryKeyInnerToCode = (primaryKey, t) => {
352
420
  var _a;
353
421
  const name = (_a = primaryKey.options) == null ? void 0 : _a.name;
354
- return `...${t}.primaryKey([${primaryKey.columns.map(singleQuote).join(", ")}]${name ? `, { name: ${singleQuote(name)} }` : ""}),`;
422
+ return `${t}.primaryKey([${primaryKey.columns.map(singleQuote).join(", ")}]${name ? `, { name: ${singleQuote(name)} }` : ""})`;
355
423
  };
356
424
  const indexToCode = (index, t) => {
425
+ const code = indexInnerToCode(index, t);
426
+ code[0] = `...${code[0]}`;
427
+ const last = code[code.length - 1];
428
+ if (typeof last === "string" && !last.endsWith(","))
429
+ addCode(code, ",");
430
+ return code;
431
+ };
432
+ const indexInnerToCode = (index, t) => {
357
433
  const code = [];
358
- code.push(`...${t}.index(`);
434
+ code.push(
435
+ `${t}.${index.options.tsVector ? "searchIndex" : index.options.unique ? "unique" : "index"}(`
436
+ );
437
+ const columnOptions = ["collate", "opclass", "order", "weight"];
359
438
  const columnsMultiline = index.columns.some((column) => {
360
439
  for (const key in column) {
361
440
  if (key !== "column" && column[key] !== void 0)
@@ -367,13 +446,13 @@ const indexToCode = (index, t) => {
367
446
  const objects = [];
368
447
  for (const column of index.columns) {
369
448
  const expr = "column" in column ? column.column : column.expression;
370
- let hasOptions2 = false;
449
+ let hasOptions = false;
371
450
  for (const key in column) {
372
- if (key !== "column" && key !== "expression") {
373
- hasOptions2 = true;
451
+ if (key !== "column") {
452
+ hasOptions = true;
374
453
  }
375
454
  }
376
- if (!hasOptions2) {
455
+ if (!hasOptions) {
377
456
  objects.push(`${singleQuote(expr)},`);
378
457
  } else {
379
458
  const props = [
@@ -381,14 +460,11 @@ const indexToCode = (index, t) => {
381
460
  expr
382
461
  )},`
383
462
  ];
384
- if (column.collate !== void 0) {
385
- props.push(`collate: ${singleQuote(column.collate)},`);
386
- }
387
- if (column.opclass !== void 0) {
388
- props.push(`opclass: ${singleQuote(column.opclass)},`);
389
- }
390
- if (column.order !== void 0) {
391
- props.push(`order: ${singleQuote(column.order)},`);
463
+ for (const key of columnOptions) {
464
+ const value = column[key];
465
+ if (value !== void 0) {
466
+ props.push(`${key}: ${singleQuote(value)},`);
467
+ }
392
468
  }
393
469
  objects.push("{", props, "},");
394
470
  }
@@ -400,8 +476,22 @@ const indexToCode = (index, t) => {
400
476
  `[${index.columns.map((it) => singleQuote(it.column)).join(", ")}]`
401
477
  );
402
478
  }
403
- const hasOptions = objectHasValues(index.options);
404
- if (hasOptions) {
479
+ const indexOptionsKeys = [
480
+ "name",
481
+ "using",
482
+ "nullsNotDistinct",
483
+ "include",
484
+ "with",
485
+ "tablespace",
486
+ "where",
487
+ "language",
488
+ "languageColumn",
489
+ "dropMode"
490
+ ];
491
+ if (index.options.tsVector && index.options.unique) {
492
+ indexOptionsKeys.unshift("unique");
493
+ }
494
+ if (indexOptionsKeys.some((key) => index.options[key])) {
405
495
  if (columnsMultiline) {
406
496
  const columns = code[code.length - 1];
407
497
  columns[columns.length - 1] += ",";
@@ -410,7 +500,7 @@ const indexToCode = (index, t) => {
410
500
  addCode(code, ", {");
411
501
  }
412
502
  const options = [];
413
- for (const key in index.options) {
503
+ for (const key of indexOptionsKeys) {
414
504
  const value = index.options[key];
415
505
  if (value === null || value === void 0)
416
506
  continue;
@@ -428,25 +518,35 @@ const indexToCode = (index, t) => {
428
518
  if (columnsMultiline) {
429
519
  code.push("),");
430
520
  } else {
431
- addCode(code, "),");
521
+ addCode(code, ")");
432
522
  }
433
523
  return code;
434
524
  };
435
- const constraintToCode = (item, t) => {
525
+ const constraintToCode = (item, t, m) => {
526
+ const code = constraintInnerToCode(item, t, m);
527
+ code[0] = `...${code[0]}`;
528
+ const last = code[code.length - 1];
529
+ if (typeof last === "string" && !last.endsWith(","))
530
+ code[code.length - 1] += ",";
531
+ return code;
532
+ };
533
+ const constraintInnerToCode = (item, t, m) => {
436
534
  const kind = getConstraintKind(item);
437
535
  if (kind === "foreignKey" && item.references) {
438
536
  return [
439
- `...${t}.foreignKey(`,
440
- referencesArgsToCode(item.references, item.name),
537
+ `${t}.foreignKey(`,
538
+ referencesArgsToCode(item.references, item.name, m),
441
539
  "),"
442
540
  ];
443
541
  } else if (kind === "check" && item.check) {
444
- return [`...${t}.check(${item.check.toCode(t)}),`];
542
+ return [
543
+ `${t}.check(${item.check.toCode(t)}${item.name ? `, { name: '${item.name}' }` : ""})`
544
+ ];
445
545
  } else {
446
- return [`...${t}.constraint({`, constraintPropsToCode(t, item), "}),"];
546
+ return [`${t}.constraint({`, constraintPropsToCode(t, item, m), "}),"];
447
547
  }
448
548
  };
449
- const constraintPropsToCode = (t, item) => {
549
+ const constraintPropsToCode = (t, item, m) => {
450
550
  const props = [];
451
551
  if (item.name) {
452
552
  props.push(`name: ${singleQuote(item.name)},`);
@@ -454,7 +554,7 @@ const constraintPropsToCode = (t, item) => {
454
554
  if (item.references) {
455
555
  props.push(
456
556
  `references: [`,
457
- referencesArgsToCode(item.references, false),
557
+ referencesArgsToCode(item.references, false, m),
458
558
  "],"
459
559
  );
460
560
  }
@@ -468,9 +568,13 @@ const referencesArgsToCode = ({
468
568
  fnOrTable,
469
569
  foreignColumns,
470
570
  options
471
- }, name = (options == null ? void 0 : options.name) || false) => {
571
+ }, name = (options == null ? void 0 : options.name) || false, m) => {
472
572
  const args = [];
473
573
  args.push(`${singleQuoteArray(columns)},`);
574
+ if (m && typeof fnOrTable !== "string") {
575
+ const { schema, table } = new (fnOrTable())();
576
+ fnOrTable = schema ? `${schema}.${table}` : table;
577
+ }
474
578
  args.push(
475
579
  `${typeof fnOrTable === "string" ? singleQuote(fnOrTable) : fnOrTable.toString()},`
476
580
  );
@@ -490,24 +594,27 @@ const referencesArgsToCode = ({
490
594
  }
491
595
  return args;
492
596
  };
493
- const columnForeignKeysToCode = (foreignKeys) => {
597
+ const columnForeignKeysToCode = (foreignKeys, migration) => {
494
598
  const code = [];
495
599
  for (const foreignKey of foreignKeys) {
496
600
  addCode(code, `.foreignKey(`);
497
- for (const part of foreignKeyArgumentToCode(foreignKey)) {
601
+ for (const part of foreignKeyArgumentToCode(foreignKey, migration)) {
498
602
  addCode(code, part);
499
603
  }
500
604
  addCode(code, ")");
501
605
  }
502
606
  return code;
503
607
  };
504
- const foreignKeyArgumentToCode = (foreignKey) => {
608
+ const foreignKeyArgumentToCode = (foreignKey, migration) => {
505
609
  const code = [];
506
- if ("fn" in foreignKey) {
507
- code.push(foreignKey.fn.toString());
508
- } else {
509
- code.push(singleQuote(foreignKey.table));
610
+ let fnOrTable = "fn" in foreignKey ? foreignKey.fn : foreignKey.table;
611
+ if (migration && typeof fnOrTable !== "string") {
612
+ const { schema, table } = new (fnOrTable())();
613
+ fnOrTable = schema ? `${schema}.${table}` : table;
510
614
  }
615
+ code.push(
616
+ typeof fnOrTable === "string" ? singleQuote(fnOrTable) : fnOrTable.toString()
617
+ );
511
618
  addCode(code, `, ${singleQuote(foreignKey.columns[0])}`);
512
619
  const hasOptions = foreignKey.name || foreignKey.match || foreignKey.onUpdate || foreignKey.onDelete;
513
620
  if (hasOptions) {
@@ -562,8 +669,8 @@ const columnIndexesToCode = (indexes) => {
562
669
  }
563
670
  return code;
564
671
  };
565
- const columnCheckToCode = (t, check) => {
566
- return `.check(${check.toCode(t)})`;
672
+ const columnCheckToCode = (t, { sql, options }) => {
673
+ return `.check(${sql.toCode(t)}${(options == null ? void 0 : options.name) ? `, { name: '${options.name}' }` : ""})`;
567
674
  };
568
675
  const identityToCode = (identity, dataType) => {
569
676
  const code = [];
@@ -575,16 +682,18 @@ const identityToCode = (identity, dataType) => {
575
682
  const props = [];
576
683
  if (identity.always)
577
684
  props.push(`always: true,`);
578
- if (identity.incrementBy)
579
- props.push(`incrementBy: ${identity.incrementBy},`);
580
- if (identity.startWith)
581
- props.push(`startWith: ${identity.startWith},`);
685
+ if (identity.increment && identity.increment !== 1)
686
+ props.push(`increment: ${identity.increment},`);
687
+ if (identity.start && identity.start !== 1)
688
+ props.push(`start: ${identity.start},`);
582
689
  if (identity.min)
583
690
  props.push(`min: ${identity.min},`);
584
691
  if (identity.max)
585
692
  props.push(`max: ${identity.max},`);
586
- if (identity.cache)
693
+ if (identity.cache && identity.cache !== 1)
587
694
  props.push(`cache: ${identity.cache},`);
695
+ if (identity.cycle)
696
+ props.push(`cycle: true,`);
588
697
  if (props.length) {
589
698
  addCode(code, "{");
590
699
  code.push(props, "}");
@@ -592,7 +701,7 @@ const identityToCode = (identity, dataType) => {
592
701
  addCode(code, ")");
593
702
  return code;
594
703
  };
595
- const columnCode = (type, t, code, data = type.data, skip) => {
704
+ const columnCode = (type, t, code, migration, data = type.data, skip) => {
596
705
  code = toArray(code);
597
706
  let prepend = `${t}.`;
598
707
  if (data.name) {
@@ -603,10 +712,14 @@ const columnCode = (type, t, code, data = type.data, skip) => {
603
712
  } else {
604
713
  code[0].unshift(prepend);
605
714
  }
606
- if (data.isPrimaryKey)
607
- addCode(code, ".primaryKey()");
715
+ if (data.primaryKey) {
716
+ addCode(
717
+ code,
718
+ `.primaryKey(${data.primaryKey === true ? "" : `{ name: '${data.primaryKey}' }`})`
719
+ );
720
+ }
608
721
  if (data.foreignKeys) {
609
- for (const part of columnForeignKeysToCode(data.foreignKeys)) {
722
+ for (const part of columnForeignKeysToCode(data.foreignKeys, migration)) {
610
723
  addCode(code, part);
611
724
  }
612
725
  }
@@ -620,7 +733,7 @@ const columnCode = (type, t, code, data = type.data, skip) => {
620
733
  addCode(code, `.parse(${type.parseFn.toString()})`);
621
734
  if (data.as)
622
735
  addCode(code, `.as(${data.as.toCode(t)})`);
623
- if (data.default !== void 0) {
736
+ if (data.default !== void 0 && (!migration || typeof data.default !== "function")) {
624
737
  addCode(code, `.default(${columnDefaultArgumentToCode(t, data.default)})`);
625
738
  }
626
739
  if (data.indexes) {
@@ -822,8 +935,8 @@ class JSONColumn extends ColumnType {
822
935
  this.dataType = "jsonb";
823
936
  this.operators = Operators.json;
824
937
  }
825
- toCode(t) {
826
- return columnCode(this, t, `json()`, this.data, toCodeSkip);
938
+ toCode(t, m) {
939
+ return columnCode(this, t, `json()`, m, this.data, toCodeSkip);
827
940
  }
828
941
  }
829
942
  JSONColumn.prototype.encodeFn = JSON.stringify;
@@ -833,8 +946,8 @@ class JSONTextColumn extends ColumnType {
833
946
  this.dataType = "json";
834
947
  this.operators = Operators.text;
835
948
  }
836
- toCode(t) {
837
- return columnCode(this, t, `jsonText()`, this.data, toCodeSkip);
949
+ toCode(t, m) {
950
+ return columnCode(this, t, `jsonText()`, m, this.data, toCodeSkip);
838
951
  }
839
952
  }
840
953
 
@@ -1604,11 +1717,12 @@ class DateColumn extends DateBaseColumn {
1604
1717
  super(...arguments);
1605
1718
  this.dataType = "date";
1606
1719
  }
1607
- toCode(t) {
1720
+ toCode(t, m) {
1608
1721
  return columnCode(
1609
1722
  this,
1610
1723
  t,
1611
- `date()${dateDataToCode(this.data)}`,
1724
+ `date()${dateDataToCode(this.data, m)}`,
1725
+ m,
1612
1726
  this.data,
1613
1727
  skipDateMethodsFromToCode
1614
1728
  );
@@ -1635,7 +1749,7 @@ class DateTimeTzBaseClass extends DateTimeBaseClass {
1635
1749
  );
1636
1750
  }
1637
1751
  }
1638
- const timestampToCode = (self, t) => {
1752
+ const timestampToCode = (self, t, m) => {
1639
1753
  const { dateTimePrecision: p } = self.data;
1640
1754
  const { defaultTimestamp } = self.data;
1641
1755
  if (defaultTimestamp) {
@@ -1647,7 +1761,8 @@ const timestampToCode = (self, t) => {
1647
1761
  const code = columnCode(
1648
1762
  self,
1649
1763
  t,
1650
- `timestamps${noTz}(${p && p !== 6 ? p : ""}).${defaultTimestamp}${dateDataToCode(self.data)}`,
1764
+ `timestamps${noTz}(${p && p !== 6 ? p : ""}).${defaultTimestamp}${dateDataToCode(self.data, m)}`,
1765
+ m,
1651
1766
  self.data,
1652
1767
  skipDateMethodsFromToCode
1653
1768
  );
@@ -1658,7 +1773,8 @@ const timestampToCode = (self, t) => {
1658
1773
  return columnCode(
1659
1774
  self,
1660
1775
  t,
1661
- `${self instanceof TimestampColumn ? "timestampNoTZ" : "timestamp"}(${p && p !== 6 ? p : ""})${dateDataToCode(self.data)}`,
1776
+ `${self instanceof TimestampColumn ? "timestampNoTZ" : "timestamp"}(${p && p !== 6 ? p : ""})${dateDataToCode(self.data, m)}`,
1777
+ m,
1662
1778
  self.data,
1663
1779
  skipDateMethodsFromToCode
1664
1780
  );
@@ -1669,8 +1785,8 @@ class TimestampColumn extends DateTimeBaseClass {
1669
1785
  super(...arguments);
1670
1786
  this.dataType = "timestamp";
1671
1787
  }
1672
- toCode(t) {
1673
- return timestampToCode(this, t);
1788
+ toCode(t, m) {
1789
+ return timestampToCode(this, t, m);
1674
1790
  }
1675
1791
  }
1676
1792
  class TimestampTZColumn extends DateTimeTzBaseClass {
@@ -1679,8 +1795,8 @@ class TimestampTZColumn extends DateTimeTzBaseClass {
1679
1795
  this.dataType = "timestamptz";
1680
1796
  this.baseDataType = "timestamp";
1681
1797
  }
1682
- toCode(t) {
1683
- return timestampToCode(this, t);
1798
+ toCode(t, m) {
1799
+ return timestampToCode(this, t, m);
1684
1800
  }
1685
1801
  }
1686
1802
  class TimeColumn extends ColumnType {
@@ -1690,12 +1806,13 @@ class TimeColumn extends ColumnType {
1690
1806
  this.operators = Operators.time;
1691
1807
  this.data.dateTimePrecision = dateTimePrecision;
1692
1808
  }
1693
- toCode(t) {
1809
+ toCode(t, m) {
1694
1810
  const { dateTimePrecision } = this.data;
1695
1811
  return columnCode(
1696
1812
  this,
1697
1813
  t,
1698
- `time(${dateTimePrecision || ""})${dateDataToCode(this.data)}`,
1814
+ `time(${dateTimePrecision || ""})${dateDataToCode(this.data, m)}`,
1815
+ m,
1699
1816
  this.data,
1700
1817
  skipDateMethodsFromToCode
1701
1818
  );
@@ -1709,12 +1826,13 @@ class IntervalColumn extends ColumnType {
1709
1826
  this.data.fields = fields;
1710
1827
  this.data.precision = precision;
1711
1828
  }
1712
- toCode(t) {
1829
+ toCode(t, m) {
1713
1830
  const { fields, precision } = this.data;
1714
1831
  return columnCode(
1715
1832
  this,
1716
1833
  t,
1717
1834
  `interval(${[fields && `'${fields}'`, precision && String(precision)].filter((part) => part).join(", ")})`,
1835
+ m,
1718
1836
  this.data,
1719
1837
  skipDateMethodsFromToCode
1720
1838
  );
@@ -1737,9 +1855,9 @@ class EnumColumn extends ColumnType {
1737
1855
  this.dataType = "enum";
1738
1856
  this.inputSchema = this.outputSchema = this.querySchema = schemaType;
1739
1857
  }
1740
- toCode(t, migration) {
1741
- const options = migration ? "" : `, [${this.options.map((option) => `'${option}'`).join(", ")}]`;
1742
- return columnCode(this, t, `enum('${this.enumName}'${options})`);
1858
+ toCode(t, m) {
1859
+ const options = m ? "" : `, [${this.options.map((option) => `'${option}'`).join(", ")}]`;
1860
+ return columnCode(this, t, `enum('${this.enumName}'${options})`, m);
1743
1861
  }
1744
1862
  toSQL() {
1745
1863
  const name = this.enumName;
@@ -1771,15 +1889,16 @@ class ArrayColumn extends ColumnType {
1771
1889
  }
1772
1890
  );
1773
1891
  this.data.item = item;
1892
+ this.data.name = item.data.name;
1774
1893
  }
1775
1894
  toSQL() {
1776
1895
  return `${this.data.item.toSQL()}[]`;
1777
1896
  }
1778
- toCode(t) {
1897
+ toCode(t, m) {
1779
1898
  const code = ["array("];
1780
1899
  addCode(code, this.data.item.toCode(t));
1781
- addCode(code, `)${arrayDataToCode(this.data)}`);
1782
- return columnCode(this, t, code);
1900
+ addCode(code, `)${arrayDataToCode(this.data, m)}`);
1901
+ return columnCode(this, t, code, m);
1783
1902
  }
1784
1903
  }
1785
1904
  const parseArray = (input, pos, len, entries, nested, item) => {
@@ -4062,16 +4181,18 @@ class DecimalColumn extends ColumnType {
4062
4181
  constructor(schema, numericPrecision, numericScale) {
4063
4182
  super(schema, schema.stringSchema());
4064
4183
  this.operators = Operators.number;
4065
- this.dataType = "decimal";
4184
+ this.dataType = "numeric";
4066
4185
  this.data.numericPrecision = numericPrecision;
4067
4186
  this.data.numericScale = numericScale;
4187
+ this.data.alias = "decimal";
4068
4188
  }
4069
- toCode(t) {
4189
+ toCode(t, m) {
4070
4190
  const { numericPrecision, numericScale } = this.data;
4071
4191
  return columnCode(
4072
4192
  this,
4073
4193
  t,
4074
- `decimal(${numericPrecision || ""}${numericScale ? `, ${numericScale}` : ""})`
4194
+ `decimal(${numericPrecision || ""}${numericScale ? `, ${numericScale}` : ""})`,
4195
+ m
4075
4196
  );
4076
4197
  }
4077
4198
  toSQL() {
@@ -4083,49 +4204,52 @@ class DecimalColumn extends ColumnType {
4083
4204
  }
4084
4205
  }
4085
4206
  const skipNumberMethods = { int: true };
4086
- const intToCode = (column, t) => {
4207
+ const intToCode = (column, t, alias, m) => {
4087
4208
  let code;
4088
4209
  if (column.data.identity) {
4089
- code = identityToCode(column.data.identity, column.dataType);
4210
+ code = identityToCode(column.data.identity, alias);
4090
4211
  } else {
4091
- code = [`${column.dataType}()`];
4212
+ code = [`${alias}()`];
4092
4213
  }
4093
- addCode(code, numberDataToCode(column.data, skipNumberMethods));
4094
- return columnCode(column, t, code);
4214
+ addCode(code, numberDataToCode(column.data, m, skipNumberMethods));
4215
+ return columnCode(column, t, code, m);
4095
4216
  };
4096
4217
  class SmallIntColumn extends IntegerBaseColumn {
4097
- constructor() {
4098
- super(...arguments);
4099
- this.dataType = "smallint";
4218
+ constructor(schema) {
4219
+ super(schema);
4220
+ this.dataType = "int2";
4100
4221
  this.parseItem = parseInt;
4222
+ this.data.alias = "smallint";
4101
4223
  }
4102
- toCode(t) {
4103
- return intToCode(this, t);
4224
+ toCode(t, m) {
4225
+ return intToCode(this, t, "smallint", m);
4104
4226
  }
4105
4227
  identity(options = {}) {
4106
4228
  return setColumnData(this, "identity", options);
4107
4229
  }
4108
4230
  }
4109
4231
  class IntegerColumn extends IntegerBaseColumn {
4110
- constructor() {
4111
- super(...arguments);
4112
- this.dataType = "integer";
4232
+ constructor(schema) {
4233
+ super(schema);
4234
+ this.dataType = "int4";
4113
4235
  this.parseItem = parseInt;
4236
+ this.data.alias = "integer";
4114
4237
  }
4115
- toCode(t) {
4116
- return intToCode(this, t);
4238
+ toCode(t, m) {
4239
+ return intToCode(this, t, "integer", m);
4117
4240
  }
4118
4241
  identity(options = {}) {
4119
4242
  return setColumnData(this, "identity", options);
4120
4243
  }
4121
4244
  }
4122
4245
  class BigIntColumn extends NumberAsStringBaseColumn {
4123
- constructor() {
4124
- super(...arguments);
4125
- this.dataType = "bigint";
4246
+ constructor(schema) {
4247
+ super(schema);
4248
+ this.dataType = "int8";
4249
+ this.data.alias = "bigint";
4126
4250
  }
4127
- toCode(t) {
4128
- return intToCode(this, t);
4251
+ toCode(t, m) {
4252
+ return intToCode(this, t, "bigint", m);
4129
4253
  }
4130
4254
  identity(options = {}) {
4131
4255
  return setColumnData(this, "identity", options);
@@ -4134,68 +4258,75 @@ class BigIntColumn extends NumberAsStringBaseColumn {
4134
4258
  class RealColumn extends NumberBaseColumn {
4135
4259
  constructor(schema) {
4136
4260
  super(schema, schema.number());
4137
- this.dataType = "real";
4261
+ this.dataType = "float4";
4138
4262
  this.parseItem = parseFloat;
4263
+ this.data.alias = "real";
4139
4264
  }
4140
- toCode(t) {
4141
- return columnCode(this, t, `real()${numberDataToCode(this.data)}`);
4265
+ toCode(t, m) {
4266
+ return columnCode(this, t, `real()${numberDataToCode(this.data, m)}`, m);
4142
4267
  }
4143
4268
  }
4144
4269
  class DoublePrecisionColumn extends NumberAsStringBaseColumn {
4145
- constructor() {
4146
- super(...arguments);
4147
- this.dataType = "double precision";
4270
+ constructor(schema) {
4271
+ super(schema);
4272
+ this.dataType = "float8";
4273
+ this.data.alias = "doublePrecision";
4148
4274
  }
4149
- toCode(t) {
4150
- return columnCode(this, t, `doublePrecision()`);
4275
+ toCode(t, m) {
4276
+ return columnCode(this, t, `doublePrecision()`, m);
4151
4277
  }
4152
4278
  }
4153
4279
  class SmallSerialColumn extends IntegerBaseColumn {
4154
4280
  constructor(schema) {
4155
4281
  super(schema);
4156
- this.dataType = "smallint";
4282
+ this.dataType = "int2";
4157
4283
  this.parseItem = parseInt;
4158
4284
  this.data.int = true;
4285
+ this.data.alias = "smallSerial";
4159
4286
  }
4160
4287
  toSQL() {
4161
4288
  return "smallserial";
4162
4289
  }
4163
- toCode(t) {
4290
+ toCode(t, m) {
4164
4291
  return columnCode(
4165
4292
  this,
4166
4293
  t,
4167
- `smallSerial()${numberDataToCode(this.data, skipNumberMethods)}`
4294
+ `smallSerial()${numberDataToCode(this.data, m, skipNumberMethods)}`,
4295
+ m
4168
4296
  );
4169
4297
  }
4170
4298
  }
4171
4299
  class SerialColumn extends IntegerBaseColumn {
4172
4300
  constructor(schema) {
4173
4301
  super(schema);
4174
- this.dataType = "integer";
4302
+ this.dataType = "int4";
4175
4303
  this.parseItem = parseInt;
4176
4304
  this.data.int = true;
4305
+ this.data.alias = "serial";
4177
4306
  }
4178
4307
  toSQL() {
4179
4308
  return "serial";
4180
4309
  }
4181
- toCode(t) {
4310
+ toCode(t, m) {
4182
4311
  return columnCode(
4183
4312
  this,
4184
4313
  t,
4185
- `serial()${numberDataToCode(this.data, skipNumberMethods)}`
4314
+ `serial()${numberDataToCode(this.data, m, skipNumberMethods)}`,
4315
+ m
4186
4316
  );
4187
4317
  }
4188
4318
  }
4189
4319
  class BigSerialColumn extends NumberAsStringBaseColumn {
4190
- constructor() {
4191
- super(...arguments);
4192
- this.dataType = "bigint";
4320
+ constructor(schema) {
4321
+ super(schema);
4322
+ this.dataType = "int8";
4323
+ this.data.alias = "bigint";
4193
4324
  }
4194
4325
  toSQL() {
4195
4326
  return "bigserial";
4196
4327
  }
4197
- toCode(t) {
4198
- return columnCode(this, t, `bigSerial()`);
4328
+ toCode(t, m) {
4329
+ return columnCode(this, t, `bigSerial()`, m);
4199
4330
  }
4200
4331
  }
4201
4332
 
@@ -4244,12 +4375,13 @@ class VarCharColumn extends LimitedTextBaseColumn {
4244
4375
  super(...arguments);
4245
4376
  this.dataType = "varchar";
4246
4377
  }
4247
- toCode(t) {
4378
+ toCode(t, m) {
4248
4379
  const { maxChars } = this.data;
4249
4380
  return columnCode(
4250
4381
  this,
4251
4382
  t,
4252
- `varchar(${maxChars != null ? maxChars : ""})${stringDataToCode(this.data)}`
4383
+ `varchar(${maxChars != null ? maxChars : ""})${stringDataToCode(this.data, m)}`,
4384
+ m
4253
4385
  );
4254
4386
  }
4255
4387
  }
@@ -4257,14 +4389,15 @@ class StringColumn extends VarCharColumn {
4257
4389
  constructor(schema, limit = 255) {
4258
4390
  super(schema, limit);
4259
4391
  }
4260
- toCode(t) {
4392
+ toCode(t, m) {
4261
4393
  let max = this.data.maxChars;
4262
4394
  if (max === 255)
4263
4395
  max = void 0;
4264
4396
  return columnCode(
4265
4397
  this,
4266
4398
  t,
4267
- `string(${max != null ? max : ""})${stringDataToCode(this.data)}`
4399
+ `string(${max != null ? max : ""})${stringDataToCode(this.data, m)}`,
4400
+ m
4268
4401
  );
4269
4402
  }
4270
4403
  }
@@ -4273,12 +4406,13 @@ class CharColumn extends LimitedTextBaseColumn {
4273
4406
  super(...arguments);
4274
4407
  this.dataType = "char";
4275
4408
  }
4276
- toCode(t) {
4409
+ toCode(t, m) {
4277
4410
  const { maxChars } = this.data;
4278
4411
  return columnCode(
4279
4412
  this,
4280
4413
  t,
4281
- `char(${maxChars != null ? maxChars : ""})${stringDataToCode(this.data)}`
4414
+ `char(${maxChars != null ? maxChars : ""})${stringDataToCode(this.data, m)}`,
4415
+ m
4282
4416
  );
4283
4417
  }
4284
4418
  }
@@ -4290,7 +4424,7 @@ const setTextColumnData = (column, minArg, maxArg) => {
4290
4424
  }
4291
4425
  }
4292
4426
  };
4293
- const textColumnToCode = (column, t) => {
4427
+ const textColumnToCode = (column, t, m) => {
4294
4428
  const data = __spreadValues$9({}, column.data);
4295
4429
  let args = "";
4296
4430
  const hasMax = data.maxArg !== void 0 && data.max === data.maxArg;
@@ -4309,7 +4443,8 @@ const textColumnToCode = (column, t) => {
4309
4443
  return columnCode(
4310
4444
  column,
4311
4445
  t,
4312
- `${column.dataType}(${args})${stringDataToCode(data)}`
4446
+ `${column.dataType}(${args})${stringDataToCode(data, m)}`,
4447
+ m
4313
4448
  );
4314
4449
  };
4315
4450
  const minMaxToSchema = (schema, min, max) => min ? max ? schema.stringMinMax(min, max) : schema.stringMin(min) : schema.stringSchema();
@@ -4319,8 +4454,8 @@ class TextColumn extends TextBaseColumn {
4319
4454
  this.dataType = "text";
4320
4455
  setTextColumnData(this, min, max);
4321
4456
  }
4322
- toCode(t) {
4323
- return textColumnToCode(this, t);
4457
+ toCode(t, m) {
4458
+ return textColumnToCode(this, t, m);
4324
4459
  }
4325
4460
  }
4326
4461
  class ByteaColumn extends ColumnType {
@@ -4329,8 +4464,8 @@ class ByteaColumn extends ColumnType {
4329
4464
  this.dataType = "bytea";
4330
4465
  this.operators = Operators.text;
4331
4466
  }
4332
- toCode(t) {
4333
- return columnCode(this, t, `bytea()`);
4467
+ toCode(t, m) {
4468
+ return columnCode(this, t, `bytea()`, m);
4334
4469
  }
4335
4470
  }
4336
4471
  class PointColumn extends ColumnType {
@@ -4339,8 +4474,8 @@ class PointColumn extends ColumnType {
4339
4474
  this.dataType = "point";
4340
4475
  this.operators = Operators.text;
4341
4476
  }
4342
- toCode(t) {
4343
- return columnCode(this, t, `point()`);
4477
+ toCode(t, m) {
4478
+ return columnCode(this, t, `point()`, m);
4344
4479
  }
4345
4480
  }
4346
4481
  class LineColumn extends ColumnType {
@@ -4349,8 +4484,8 @@ class LineColumn extends ColumnType {
4349
4484
  this.dataType = "line";
4350
4485
  this.operators = Operators.text;
4351
4486
  }
4352
- toCode(t) {
4353
- return columnCode(this, t, `line()`);
4487
+ toCode(t, m) {
4488
+ return columnCode(this, t, `line()`, m);
4354
4489
  }
4355
4490
  }
4356
4491
  class LsegColumn extends ColumnType {
@@ -4359,8 +4494,8 @@ class LsegColumn extends ColumnType {
4359
4494
  this.dataType = "lseg";
4360
4495
  this.operators = Operators.text;
4361
4496
  }
4362
- toCode(t) {
4363
- return columnCode(this, t, `lseg()`);
4497
+ toCode(t, m) {
4498
+ return columnCode(this, t, `lseg()`, m);
4364
4499
  }
4365
4500
  }
4366
4501
  class BoxColumn extends ColumnType {
@@ -4369,8 +4504,8 @@ class BoxColumn extends ColumnType {
4369
4504
  this.dataType = "box";
4370
4505
  this.operators = Operators.text;
4371
4506
  }
4372
- toCode(t) {
4373
- return columnCode(this, t, `box()`);
4507
+ toCode(t, m) {
4508
+ return columnCode(this, t, `box()`, m);
4374
4509
  }
4375
4510
  }
4376
4511
  class PathColumn extends ColumnType {
@@ -4379,8 +4514,8 @@ class PathColumn extends ColumnType {
4379
4514
  this.dataType = "path";
4380
4515
  this.operators = Operators.text;
4381
4516
  }
4382
- toCode(t) {
4383
- return columnCode(this, t, `path()`);
4517
+ toCode(t, m) {
4518
+ return columnCode(this, t, `path()`, m);
4384
4519
  }
4385
4520
  }
4386
4521
  class PolygonColumn extends ColumnType {
@@ -4389,8 +4524,8 @@ class PolygonColumn extends ColumnType {
4389
4524
  this.dataType = "polygon";
4390
4525
  this.operators = Operators.text;
4391
4526
  }
4392
- toCode(t) {
4393
- return columnCode(this, t, `polygon()`);
4527
+ toCode(t, m) {
4528
+ return columnCode(this, t, `polygon()`, m);
4394
4529
  }
4395
4530
  }
4396
4531
  class CircleColumn extends ColumnType {
@@ -4399,8 +4534,8 @@ class CircleColumn extends ColumnType {
4399
4534
  this.dataType = "circle";
4400
4535
  this.operators = Operators.text;
4401
4536
  }
4402
- toCode(t) {
4403
- return columnCode(this, t, `circle()`);
4537
+ toCode(t, m) {
4538
+ return columnCode(this, t, `circle()`, m);
4404
4539
  }
4405
4540
  }
4406
4541
  class MoneyColumn extends NumberBaseColumn {
@@ -4416,8 +4551,8 @@ class MoneyColumn extends NumberBaseColumn {
4416
4551
  }
4417
4552
  );
4418
4553
  }
4419
- toCode(t) {
4420
- return columnCode(this, t, `money()`);
4554
+ toCode(t, m) {
4555
+ return columnCode(this, t, `money()`, m);
4421
4556
  }
4422
4557
  }
4423
4558
  class CidrColumn extends ColumnType {
@@ -4426,8 +4561,8 @@ class CidrColumn extends ColumnType {
4426
4561
  this.dataType = "cidr";
4427
4562
  this.operators = Operators.text;
4428
4563
  }
4429
- toCode(t) {
4430
- return columnCode(this, t, `cidr()`);
4564
+ toCode(t, m) {
4565
+ return columnCode(this, t, `cidr()`, m);
4431
4566
  }
4432
4567
  }
4433
4568
  class InetColumn extends ColumnType {
@@ -4436,8 +4571,8 @@ class InetColumn extends ColumnType {
4436
4571
  this.dataType = "inet";
4437
4572
  this.operators = Operators.text;
4438
4573
  }
4439
- toCode(t) {
4440
- return columnCode(this, t, `inet()`);
4574
+ toCode(t, m) {
4575
+ return columnCode(this, t, `inet()`, m);
4441
4576
  }
4442
4577
  }
4443
4578
  class MacAddrColumn extends ColumnType {
@@ -4446,8 +4581,8 @@ class MacAddrColumn extends ColumnType {
4446
4581
  this.dataType = "macaddr";
4447
4582
  this.operators = Operators.text;
4448
4583
  }
4449
- toCode(t) {
4450
- return columnCode(this, t, `macaddr()`);
4584
+ toCode(t, m) {
4585
+ return columnCode(this, t, `macaddr()`, m);
4451
4586
  }
4452
4587
  }
4453
4588
  class MacAddr8Column extends ColumnType {
@@ -4456,8 +4591,8 @@ class MacAddr8Column extends ColumnType {
4456
4591
  this.dataType = "macaddr8";
4457
4592
  this.operators = Operators.text;
4458
4593
  }
4459
- toCode(t) {
4460
- return columnCode(this, t, `macaddr8()`);
4594
+ toCode(t, m) {
4595
+ return columnCode(this, t, `macaddr8()`, m);
4461
4596
  }
4462
4597
  }
4463
4598
  class BitColumn extends ColumnType {
@@ -4467,9 +4602,9 @@ class BitColumn extends ColumnType {
4467
4602
  this.operators = Operators.text;
4468
4603
  this.data.length = length;
4469
4604
  }
4470
- toCode(t) {
4605
+ toCode(t, m) {
4471
4606
  const { length } = this.data;
4472
- return columnCode(this, t, `bit(${length})`);
4607
+ return columnCode(this, t, `bit(${length})`, m);
4473
4608
  }
4474
4609
  toSQL() {
4475
4610
  return joinTruthy(
@@ -4481,13 +4616,14 @@ class BitColumn extends ColumnType {
4481
4616
  class BitVaryingColumn extends ColumnType {
4482
4617
  constructor(schema, length) {
4483
4618
  super(schema, schema.bit(length));
4484
- this.dataType = "bit varying";
4619
+ this.dataType = "varbit";
4485
4620
  this.operators = Operators.text;
4486
4621
  this.data.length = length;
4622
+ this.data.alias = "bitVarying";
4487
4623
  }
4488
- toCode(t) {
4624
+ toCode(t, m) {
4489
4625
  const { length } = this.data;
4490
- return columnCode(this, t, `bitVarying(${length != null ? length : ""})`);
4626
+ return columnCode(this, t, `bitVarying(${length != null ? length : ""})`, m);
4491
4627
  }
4492
4628
  toSQL() {
4493
4629
  return joinTruthy(
@@ -4503,8 +4639,8 @@ class TsVectorColumn extends ColumnType {
4503
4639
  this.dataType = "tsvector";
4504
4640
  this.operators = Operators.text;
4505
4641
  }
4506
- toCode(t) {
4507
- return columnCode(this, t, `tsvector()`);
4642
+ toCode(t, m) {
4643
+ return columnCode(this, t, `tsvector()`, m);
4508
4644
  }
4509
4645
  /**
4510
4646
  * For `tsvector` column type, it can also accept language (optional) and columns:
@@ -4534,14 +4670,17 @@ class TsVectorColumn extends ColumnType {
4534
4670
  const first = args[0];
4535
4671
  if (typeof first === "string" || !("raw" in first)) {
4536
4672
  const target = typeof first === "string" ? args[1] : first;
4673
+ const language = typeof first === "string" ? first : this.defaultLanguage;
4537
4674
  let sql;
4538
4675
  if (Array.isArray(target)) {
4539
4676
  const columns = target.length === 1 ? `"${target[0]}"` : target.map((column) => `coalesce("${column}", '')`).join(` || ' ' || `);
4540
- sql = `to_tsvector('${typeof first === "string" ? first : this.defaultLanguage}', ${columns})`;
4677
+ sql = `to_tsvector('${language}', ${columns})`;
4541
4678
  } else {
4542
4679
  for (const key in target) {
4543
- sql = (sql ? sql + " || " : "") + `setweight(to_tsvector(coalesce("${key}", '')), '${target[key]}')`;
4680
+ sql = (sql ? sql + " || " : "(") + `setweight(to_tsvector('${language}', coalesce("${key}", '')), '${target[key]}')`;
4544
4681
  }
4682
+ if (sql)
4683
+ sql += ")";
4545
4684
  }
4546
4685
  const arr = [sql];
4547
4686
  arr.raw = arr;
@@ -4556,8 +4695,8 @@ class TsQueryColumn extends ColumnType {
4556
4695
  this.dataType = "tsquery";
4557
4696
  this.operators = Operators.text;
4558
4697
  }
4559
- toCode(t) {
4560
- return columnCode(this, t, `tsquery()`);
4698
+ toCode(t, m) {
4699
+ return columnCode(this, t, `tsquery()`, m);
4561
4700
  }
4562
4701
  }
4563
4702
  const uuidDefaultSQL = "gen_random_uuid()";
@@ -4574,12 +4713,13 @@ class UUIDColumn extends ColumnType {
4574
4713
  column.data.default = uuidDefault;
4575
4714
  return column;
4576
4715
  }
4577
- toCode(t) {
4716
+ toCode(t, m) {
4578
4717
  const { data } = this;
4579
4718
  return columnCode(
4580
4719
  this,
4581
4720
  t,
4582
4721
  `uuid()`,
4722
+ m,
4583
4723
  // don't output the default default
4584
4724
  data.default instanceof RawSQLBase && data.default._sql === uuidDefaultSQL ? __spreadProps$5(__spreadValues$9({}, data), { default: void 0 }) : data
4585
4725
  );
@@ -4591,8 +4731,8 @@ class XMLColumn extends ColumnType {
4591
4731
  this.dataType = "xml";
4592
4732
  this.operators = Operators.text;
4593
4733
  }
4594
- toCode(t) {
4595
- return columnCode(this, t, `xml()`);
4734
+ toCode(t, m) {
4735
+ return columnCode(this, t, `xml()`, m);
4596
4736
  }
4597
4737
  }
4598
4738
  class CitextColumn extends TextBaseColumn {
@@ -4601,20 +4741,21 @@ class CitextColumn extends TextBaseColumn {
4601
4741
  this.dataType = "citext";
4602
4742
  setTextColumnData(this, min, max);
4603
4743
  }
4604
- toCode(t) {
4605
- return textColumnToCode(this, t);
4744
+ toCode(t, m) {
4745
+ return textColumnToCode(this, t, m);
4606
4746
  }
4607
4747
  }
4608
4748
 
4609
4749
  class BooleanColumn extends ColumnType {
4610
4750
  constructor(schema) {
4611
4751
  super(schema, schema.boolean());
4612
- this.dataType = "boolean";
4752
+ this.dataType = "bool";
4613
4753
  this.operators = Operators.boolean;
4614
4754
  this.parseItem = (input) => input[0] === "t";
4755
+ this.data.alias = "boolean";
4615
4756
  }
4616
- toCode(t) {
4617
- return columnCode(this, t, "boolean()");
4757
+ toCode(t, m) {
4758
+ return columnCode(this, t, "boolean()", m);
4618
4759
  }
4619
4760
  }
4620
4761
 
@@ -4630,8 +4771,8 @@ class CustomTypeColumn extends ColumnType {
4630
4771
  this.operators = Operators.any;
4631
4772
  this.data.isOfCustomType = true;
4632
4773
  }
4633
- toCode(t) {
4634
- return columnCode(this, t, `type(${singleQuote(this.dataType)})`);
4774
+ toCode(t, m) {
4775
+ return columnCode(this, t, `type(${singleQuote(this.dataType)})`, m);
4635
4776
  }
4636
4777
  as(column) {
4637
4778
  const c = setColumnData(
@@ -4646,8 +4787,8 @@ class CustomTypeColumn extends ColumnType {
4646
4787
  }
4647
4788
  }
4648
4789
  class DomainColumn extends CustomTypeColumn {
4649
- toCode(t) {
4650
- return columnCode(this, t, `domain(${singleQuote(this.dataType)})`);
4790
+ toCode(t, m) {
4791
+ return columnCode(this, t, `domain(${singleQuote(this.dataType)})`, m);
4651
4792
  }
4652
4793
  }
4653
4794
 
@@ -4826,7 +4967,7 @@ const makeColumnTypes = (schema) => {
4826
4967
  * See {@link ColumnType.searchIndex}
4827
4968
  */
4828
4969
  searchIndex(columns, options) {
4829
- return this.index(columns, __spreadProps$4(__spreadValues$8({}, options), { tsVector: true }));
4970
+ return this.index(columns, __spreadProps$4(__spreadValues$8({ using: "gin" }, options), { tsVector: true }));
4830
4971
  },
4831
4972
  constraint({ name, references, check, dropMode }) {
4832
4973
  var _a;
@@ -4857,11 +4998,11 @@ const makeColumnTypes = (schema) => {
4857
4998
  });
4858
4999
  return emptyObject;
4859
5000
  },
4860
- check(check) {
5001
+ check(check, options) {
4861
5002
  var _a;
4862
- ((_a = tableData.constraints) != null ? _a : tableData.constraints = []).push({
5003
+ ((_a = tableData.constraints) != null ? _a : tableData.constraints = []).push(__spreadProps$4(__spreadValues$8({}, options), {
4863
5004
  check
4864
- });
5005
+ }));
4865
5006
  return emptyObject;
4866
5007
  }
4867
5008
  }, makeTimestampsHelpers(makeRegexToFindInSql));
@@ -4980,6 +5121,8 @@ for (const key in types.builtins) {
4980
5121
  delete defaultTypeParsers[id];
4981
5122
  });
4982
5123
  const returnArg = (arg) => arg;
5124
+ const rollbackSql$1 = { text: "ROLLBACK" };
5125
+ const commitSql$1 = { text: "COMMIT" };
4983
5126
  class Adapter {
4984
5127
  constructor(_a) {
4985
5128
  var _b = _a, { types: types2 = defaultTypeParsers } = _b, config = __objRest$1(_b, ["types"]);
@@ -5021,7 +5164,7 @@ class Adapter {
5021
5164
  arrays(query, types2) {
5022
5165
  return performQuery$1(this, query, types2, "array");
5023
5166
  }
5024
- async transaction(begin, cb) {
5167
+ async transaction(begin, cb, end = commitSql$1) {
5025
5168
  const client = await this.connect();
5026
5169
  try {
5027
5170
  await setSearchPath(client, this.schema);
@@ -5030,10 +5173,10 @@ class Adapter {
5030
5173
  try {
5031
5174
  result = await cb(new TransactionAdapter(this, client, this.types));
5032
5175
  } catch (err) {
5033
- await performQueryOnClient(client, { text: "ROLLBACK" }, this.types);
5176
+ await performQueryOnClient(client, rollbackSql$1, this.types);
5034
5177
  throw err;
5035
5178
  }
5036
- await performQueryOnClient(client, { text: "COMMIT" }, this.types);
5179
+ await performQueryOnClient(client, end, this.types);
5037
5180
  return result;
5038
5181
  } finally {
5039
5182
  client.release();
@@ -7951,7 +8094,7 @@ const makeMessage = (colors, timeColor, time, sqlColor, sql, valuesColor, values
7951
8094
  const elapsed = process.hrtime(time);
7952
8095
  const formattedTime = `(${elapsed[0] ? `${elapsed[0]}s ` : ""}${(elapsed[1] / 1e6).toFixed(1)}ms)`;
7953
8096
  const result = `${colors ? timeColor(formattedTime) : formattedTime} ${colors ? sqlColor(sql) : sql}`;
7954
- if (!values.length) {
8097
+ if (!(values == null ? void 0 : values.length)) {
7955
8098
  return result;
7956
8099
  }
7957
8100
  const formattedValues = `[${values.map(quote).join(", ")}]`;
@@ -10909,21 +11052,23 @@ var __objRest = (source, exclude) => {
10909
11052
  };
10910
11053
  const anyShape = {};
10911
11054
  class Db {
10912
- constructor(adapter, queryBuilder, table = void 0, shape = anyShape, columnTypes, transactionStorage, options) {
11055
+ constructor(adapter, queryBuilder, table = void 0, shape = anyShape, columnTypes, transactionStorage, options, tableData = getTableData()) {
10913
11056
  this.adapter = adapter;
10914
11057
  this.queryBuilder = queryBuilder;
10915
11058
  this.table = table;
10916
11059
  this.shape = shape;
10917
11060
  this.columnTypes = columnTypes;
11061
+ this.tableData = tableData;
10918
11062
  var _a, _b;
10919
11063
  const self = this;
10920
11064
  const { softDelete } = options;
10921
11065
  const scopes = options.scopes || softDelete ? {} : emptyObject;
10922
- const tableData = getTableData();
10923
11066
  this.internal = __spreadProps(__spreadValues({}, tableData), {
10924
11067
  transactionStorage,
10925
11068
  scopes,
10926
- snakeCase: options.snakeCase
11069
+ snakeCase: options.snakeCase,
11070
+ noPrimaryKey: options.noPrimaryKey === "ignore",
11071
+ comment: options.comment
10927
11072
  });
10928
11073
  this.baseQuery = this;
10929
11074
  const logger = options.logger || console;
@@ -10991,7 +11136,7 @@ class Db {
10991
11136
  this.q.schema = options.schema;
10992
11137
  }
10993
11138
  this.primaryKeys = Object.keys(shape).filter(
10994
- (key) => shape[key].data.isPrimaryKey
11139
+ (key) => shape[key].data.primaryKey
10995
11140
  );
10996
11141
  const primaryKeysFromData = (_b = getTableData().primaryKey) == null ? void 0 : _b.columns;
10997
11142
  if (primaryKeysFromData)
@@ -11187,16 +11332,13 @@ const createDb = (_a) => {
11187
11332
  ct[snakeCaseKey] = true;
11188
11333
  }
11189
11334
  const transactionStorage = new AsyncLocalStorage();
11190
- const qb = new Db(
11335
+ const qb = _initQueryBuilder(
11191
11336
  adapter,
11192
- void 0,
11193
- void 0,
11194
- anyShape,
11195
11337
  ct,
11196
11338
  transactionStorage,
11197
- commonOptions
11339
+ commonOptions,
11340
+ options
11198
11341
  );
11199
- qb.queryBuilder = qb;
11200
11342
  const tableConstructor = (table, shape, options2) => new Db(
11201
11343
  adapter,
11202
11344
  qb,
@@ -11215,6 +11357,33 @@ const createDb = (_a) => {
11215
11357
  }
11216
11358
  return db;
11217
11359
  };
11360
+ const _initQueryBuilder = (adapter, columnTypes, transactionStorage, commonOptions, options) => {
11361
+ const qb = new Db(
11362
+ adapter,
11363
+ void 0,
11364
+ void 0,
11365
+ anyShape,
11366
+ columnTypes,
11367
+ transactionStorage,
11368
+ commonOptions,
11369
+ emptyObject
11370
+ );
11371
+ if (options.extensions) {
11372
+ const arr = [];
11373
+ for (const x of options.extensions) {
11374
+ if (typeof x === "string") {
11375
+ arr.push({ name: x });
11376
+ } else {
11377
+ for (const key in x) {
11378
+ arr.push({ name: key, version: x[key] });
11379
+ }
11380
+ }
11381
+ }
11382
+ qb.internal.extensions = arr;
11383
+ }
11384
+ qb.internal.domains = options.domains;
11385
+ return qb.queryBuilder = qb;
11386
+ };
11218
11387
 
11219
11388
  class Rollback extends Error {
11220
11389
  }
@@ -11347,5 +11516,5 @@ function copyTableData(query, arg) {
11347
11516
  return q;
11348
11517
  }
11349
11518
 
11350
- export { Adapter, AggregateMethods, ArrayColumn, AsMethods, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, Create, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, Delete, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, FnExpression, For, From, Having, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, JsonMethods, JsonModifiers, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnMethods, Operators, OrchidOrmError, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, QueryBase, QueryError, QueryGet, QueryHooks, QueryLog, QueryMethods, QueryUpsertOrCreate, RawSQL, RawSqlMethods, RealColumn, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransactionAdapter, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, With, XMLColumn, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotSql, _queryWhereSql, addComputedColumns, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, constraintPropsToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, extendQuery, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getConstraintKind, getQueryAs, getShapeFromSelect, getTableData, handleResult, identityToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logColors, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeExpression, makeFnExpression, makeRegexToFindInSql, makeSQL, newTableData, parseRecord, parseResult, primaryKeyToCode, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, quote, quoteString, raw, referencesArgsToCode, resetTableData, resolveSubQueryCallback, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlQueryArgsToExpression, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
11519
+ export { Adapter, AggregateMethods, ArrayColumn, AsMethods, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, Create, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, Delete, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, FnExpression, For, From, Having, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, JsonMethods, JsonModifiers, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnMethods, Operators, OrchidOrmError, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, QueryBase, QueryError, QueryGet, QueryHooks, QueryLog, QueryMethods, QueryUpsertOrCreate, RawSQL, RawSqlMethods, RealColumn, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransactionAdapter, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, With, XMLColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotSql, _queryWhereSql, addComputedColumns, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, constraintInnerToCode, constraintPropsToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, extendQuery, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getConstraintKind, getQueryAs, getShapeFromSelect, getTableData, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logColors, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeExpression, makeFnExpression, makeRegexToFindInSql, makeSQL, newTableData, parseRecord, parseResult, primaryKeyInnerToCode, primaryKeyToCode, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, quote, quoteString, raw, referencesArgsToCode, resetTableData, resolveSubQueryCallback, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlQueryArgsToExpression, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
11351
11520
  //# sourceMappingURL=index.mjs.map