pqb 0.36.7 → 0.36.9

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
@@ -456,7 +456,7 @@ const combineCodeElements = (input) => {
456
456
  }
457
457
  return output;
458
458
  };
459
- const columnsShapeToCode = (shape, t) => {
459
+ const columnsShapeToCode = (ctx, shape) => {
460
460
  const hasTimestamps = "createdAt" in shape && isDefaultTimeStamp(shape.createdAt) && "updatedAt" in shape && isDefaultTimeStamp(shape.updatedAt);
461
461
  const code = [];
462
462
  for (const key in shape) {
@@ -469,7 +469,7 @@ const columnsShapeToCode = (shape, t) => {
469
469
  code.push(
470
470
  ...combineCodeElements([
471
471
  `${orchidCore.quoteObjectKey(key)}: `,
472
- ...orchidCore.toArray(shape[key].toCode(t)),
472
+ ...orchidCore.toArray(shape[key].toCode(ctx, key)),
473
473
  ","
474
474
  ])
475
475
  );
@@ -477,7 +477,7 @@ const columnsShapeToCode = (shape, t) => {
477
477
  column.data.name = name;
478
478
  }
479
479
  if (hasTimestamps) {
480
- code.push(`...${t}.timestamps(),`);
480
+ code.push(`...${ctx.t}.timestamps(),`);
481
481
  }
482
482
  return code;
483
483
  };
@@ -745,8 +745,8 @@ const columnIndexesToCode = (indexes) => {
745
745
  }
746
746
  return code;
747
747
  };
748
- const columnCheckToCode = (t, { sql, name }) => {
749
- return `.check(${sql.toCode(t)}${name ? `, { name: '${name}' }` : ""})`;
748
+ const columnCheckToCode = (ctx, { sql, name }, columnName) => {
749
+ return `.check(${sql.toCode(ctx.t)}${name && name !== `${ctx.table}_${columnName}_check` ? `, { name: '${name}' }` : ""})`;
750
750
  };
751
751
  const identityToCode = (identity, dataType) => {
752
752
  const code = [];
@@ -777,11 +777,14 @@ const identityToCode = (identity, dataType) => {
777
777
  orchidCore.addCode(code, ")");
778
778
  return code;
779
779
  };
780
- const columnCode = (type, t, code, migration, data = type.data, skip) => {
780
+ const columnCode = (type, ctx, key, code, data = type.data, skip) => {
781
+ var _a;
781
782
  code = orchidCore.toArray(code);
782
- let prepend = `${t}.`;
783
- if (data.name) {
784
- prepend += `name(${orchidCore.singleQuote(data.name)}).`;
783
+ let prepend = `${ctx.t}.`;
784
+ const keyName = ctx.snakeCase ? orchidCore.toSnakeCase(key) : key;
785
+ const name = (_a = data.name) != null ? _a : keyName;
786
+ if (name !== keyName) {
787
+ prepend += `name(${orchidCore.singleQuote(name)}).`;
785
788
  }
786
789
  if (typeof code[0] === "string") {
787
790
  code[0] = `${prepend}${code[0]}`;
@@ -795,7 +798,10 @@ const columnCode = (type, t, code, migration, data = type.data, skip) => {
795
798
  );
796
799
  }
797
800
  if (data.foreignKeys) {
798
- for (const part of columnForeignKeysToCode(data.foreignKeys, migration)) {
801
+ for (const part of columnForeignKeysToCode(
802
+ data.foreignKeys,
803
+ ctx.migration
804
+ )) {
799
805
  orchidCore.addCode(code, part);
800
806
  }
801
807
  }
@@ -808,9 +814,12 @@ const columnCode = (type, t, code, migration, data = type.data, skip) => {
808
814
  if (type.parseFn && !("hideFromCode" in type.parseFn))
809
815
  orchidCore.addCode(code, `.parse(${type.parseFn.toString()})`);
810
816
  if (data.as)
811
- orchidCore.addCode(code, `.as(${data.as.toCode(t)})`);
812
- if (data.default !== void 0 && (!migration || typeof data.default !== "function")) {
813
- orchidCore.addCode(code, `.default(${orchidCore.columnDefaultArgumentToCode(t, data.default)})`);
817
+ orchidCore.addCode(code, `.as(${data.as.toCode(ctx, key)})`);
818
+ if (data.default !== void 0 && (!ctx.migration || typeof data.default !== "function")) {
819
+ orchidCore.addCode(
820
+ code,
821
+ `.default(${orchidCore.columnDefaultArgumentToCode(ctx.t, data.default)})`
822
+ );
814
823
  }
815
824
  if (data.indexes) {
816
825
  for (const part of columnIndexesToCode(data.indexes)) {
@@ -820,7 +829,7 @@ const columnCode = (type, t, code, migration, data = type.data, skip) => {
820
829
  if (data.comment)
821
830
  orchidCore.addCode(code, `.comment(${orchidCore.singleQuote(data.comment)})`);
822
831
  if (data.check) {
823
- orchidCore.addCode(code, columnCheckToCode(t, data.check));
832
+ orchidCore.addCode(code, columnCheckToCode(ctx, data.check, name));
824
833
  }
825
834
  if (data.errors) {
826
835
  for (const part of orchidCore.columnErrorMessagesToCode(data.errors)) {
@@ -1074,13 +1083,13 @@ class DecimalColumn extends ColumnType {
1074
1083
  this.data.numericScale = numericScale;
1075
1084
  this.data.alias = "decimal";
1076
1085
  }
1077
- toCode(t, m) {
1086
+ toCode(ctx, key) {
1078
1087
  const { numericPrecision, numericScale } = this.data;
1079
1088
  return columnCode(
1080
1089
  this,
1081
- t,
1082
- `decimal(${numericPrecision || ""}${numericScale ? `, ${numericScale}` : ""})`,
1083
- m
1090
+ ctx,
1091
+ key,
1092
+ `decimal(${numericPrecision || ""}${numericScale ? `, ${numericScale}` : ""})`
1084
1093
  );
1085
1094
  }
1086
1095
  toSQL() {
@@ -1092,15 +1101,18 @@ class DecimalColumn extends ColumnType {
1092
1101
  }
1093
1102
  }
1094
1103
  const skipNumberMethods = { int: true };
1095
- const intToCode = (column, t, alias, m) => {
1104
+ const intToCode = (column, ctx, key, alias) => {
1096
1105
  let code;
1097
1106
  if (column.data.identity) {
1098
1107
  code = identityToCode(column.data.identity, alias);
1099
1108
  } else {
1100
1109
  code = [`${alias}()`];
1101
1110
  }
1102
- orchidCore.addCode(code, orchidCore.numberDataToCode(column.data, m, skipNumberMethods));
1103
- return columnCode(column, t, code, m);
1111
+ orchidCore.addCode(
1112
+ code,
1113
+ orchidCore.numberDataToCode(column.data, ctx.migration, skipNumberMethods)
1114
+ );
1115
+ return columnCode(column, ctx, key, code);
1104
1116
  };
1105
1117
  class SmallIntColumn extends IntegerBaseColumn {
1106
1118
  constructor(schema) {
@@ -1109,8 +1121,8 @@ class SmallIntColumn extends IntegerBaseColumn {
1109
1121
  this.parseItem = parseInt;
1110
1122
  this.data.alias = "smallint";
1111
1123
  }
1112
- toCode(t, m) {
1113
- return intToCode(this, t, "smallint", m);
1124
+ toCode(ctx, key) {
1125
+ return intToCode(this, ctx, key, "smallint");
1114
1126
  }
1115
1127
  identity(options = {}) {
1116
1128
  return orchidCore.setColumnData(this, "identity", options);
@@ -1123,8 +1135,8 @@ class IntegerColumn extends IntegerBaseColumn {
1123
1135
  this.parseItem = parseInt;
1124
1136
  this.data.alias = "integer";
1125
1137
  }
1126
- toCode(t, m) {
1127
- return intToCode(this, t, "integer", m);
1138
+ toCode(ctx, key) {
1139
+ return intToCode(this, ctx, key, "integer");
1128
1140
  }
1129
1141
  identity(options = {}) {
1130
1142
  return orchidCore.setColumnData(this, "identity", options);
@@ -1136,8 +1148,8 @@ class BigIntColumn extends NumberAsStringBaseColumn {
1136
1148
  this.dataType = "int8";
1137
1149
  this.data.alias = "bigint";
1138
1150
  }
1139
- toCode(t, m) {
1140
- return intToCode(this, t, "bigint", m);
1151
+ toCode(ctx, key) {
1152
+ return intToCode(this, ctx, key, "bigint");
1141
1153
  }
1142
1154
  identity(options = {}) {
1143
1155
  return orchidCore.setColumnData(this, "identity", options);
@@ -1150,8 +1162,13 @@ class RealColumn extends NumberBaseColumn {
1150
1162
  this.parseItem = parseFloat;
1151
1163
  this.data.alias = "real";
1152
1164
  }
1153
- toCode(t, m) {
1154
- return columnCode(this, t, `real()${orchidCore.numberDataToCode(this.data, m)}`, m);
1165
+ toCode(ctx, key) {
1166
+ return columnCode(
1167
+ this,
1168
+ ctx,
1169
+ key,
1170
+ `real()${orchidCore.numberDataToCode(this.data, ctx.migration)}`
1171
+ );
1155
1172
  }
1156
1173
  }
1157
1174
  class DoublePrecisionColumn extends NumberAsStringBaseColumn {
@@ -1160,8 +1177,8 @@ class DoublePrecisionColumn extends NumberAsStringBaseColumn {
1160
1177
  this.dataType = "float8";
1161
1178
  this.data.alias = "doublePrecision";
1162
1179
  }
1163
- toCode(t, m) {
1164
- return columnCode(this, t, `doublePrecision()`, m);
1180
+ toCode(ctx, key) {
1181
+ return columnCode(this, ctx, key, `doublePrecision()`);
1165
1182
  }
1166
1183
  }
1167
1184
  class SmallSerialColumn extends IntegerBaseColumn {
@@ -1175,12 +1192,16 @@ class SmallSerialColumn extends IntegerBaseColumn {
1175
1192
  toSQL() {
1176
1193
  return "smallserial";
1177
1194
  }
1178
- toCode(t, m) {
1195
+ toCode(ctx, key) {
1179
1196
  return columnCode(
1180
1197
  this,
1181
- t,
1182
- `smallSerial()${orchidCore.numberDataToCode(this.data, m, skipNumberMethods)}`,
1183
- m
1198
+ ctx,
1199
+ key,
1200
+ `smallSerial()${orchidCore.numberDataToCode(
1201
+ this.data,
1202
+ ctx.migration,
1203
+ skipNumberMethods
1204
+ )}`
1184
1205
  );
1185
1206
  }
1186
1207
  }
@@ -1195,12 +1216,16 @@ class SerialColumn extends IntegerBaseColumn {
1195
1216
  toSQL() {
1196
1217
  return "serial";
1197
1218
  }
1198
- toCode(t, m) {
1219
+ toCode(ctx, key) {
1199
1220
  return columnCode(
1200
1221
  this,
1201
- t,
1202
- `serial()${orchidCore.numberDataToCode(this.data, m, skipNumberMethods)}`,
1203
- m
1222
+ ctx,
1223
+ key,
1224
+ `serial()${orchidCore.numberDataToCode(
1225
+ this.data,
1226
+ ctx.migration,
1227
+ skipNumberMethods
1228
+ )}`
1204
1229
  );
1205
1230
  }
1206
1231
  }
@@ -1213,8 +1238,8 @@ class BigSerialColumn extends NumberAsStringBaseColumn {
1213
1238
  toSQL() {
1214
1239
  return "bigserial";
1215
1240
  }
1216
- toCode(t, m) {
1217
- return columnCode(this, t, `bigSerial()`, m);
1241
+ toCode(ctx, key) {
1242
+ return columnCode(this, ctx, key, `bigSerial()`);
1218
1243
  }
1219
1244
  }
1220
1245
 
@@ -1257,13 +1282,13 @@ class VarCharColumn extends LimitedTextBaseColumn {
1257
1282
  super(...arguments);
1258
1283
  this.dataType = "varchar";
1259
1284
  }
1260
- toCode(t, m) {
1285
+ toCode(ctx, key) {
1261
1286
  const { maxChars } = this.data;
1262
1287
  return columnCode(
1263
1288
  this,
1264
- t,
1265
- `varchar(${maxChars != null ? maxChars : ""})${orchidCore.stringDataToCode(this.data, m)}`,
1266
- m
1289
+ ctx,
1290
+ key,
1291
+ `varchar(${maxChars != null ? maxChars : ""})${orchidCore.stringDataToCode(this.data, ctx.migration)}`
1267
1292
  );
1268
1293
  }
1269
1294
  }
@@ -1271,19 +1296,19 @@ class StringColumn extends VarCharColumn {
1271
1296
  constructor(schema, limit = 255) {
1272
1297
  super(schema, limit);
1273
1298
  }
1274
- toCode(t, m) {
1299
+ toCode(ctx, key) {
1275
1300
  let max = this.data.maxChars;
1276
1301
  if (max === 255)
1277
1302
  max = void 0;
1278
1303
  return columnCode(
1279
1304
  this,
1280
- t,
1281
- `string(${max != null ? max : ""})${orchidCore.stringDataToCode(this.data, m)}`,
1282
- m
1305
+ ctx,
1306
+ key,
1307
+ `string(${max != null ? max : ""})${orchidCore.stringDataToCode(this.data, ctx.migration)}`
1283
1308
  );
1284
1309
  }
1285
1310
  }
1286
- const textColumnToCode = (column, t, m) => {
1311
+ const textColumnToCode = (column, ctx, key) => {
1287
1312
  const data = __spreadValues$i({}, column.data);
1288
1313
  let args = "";
1289
1314
  const hasMax = data.maxArg !== void 0 && data.max === data.maxArg;
@@ -1301,9 +1326,9 @@ const textColumnToCode = (column, t, m) => {
1301
1326
  }
1302
1327
  return columnCode(
1303
1328
  column,
1304
- t,
1305
- `${column.dataType}(${args})${orchidCore.stringDataToCode(data, m)}`,
1306
- m
1329
+ ctx,
1330
+ key,
1331
+ `${column.dataType}(${args})${orchidCore.stringDataToCode(data, ctx.migration)}`
1307
1332
  );
1308
1333
  };
1309
1334
  class TextColumn extends TextBaseColumn {
@@ -1311,8 +1336,8 @@ class TextColumn extends TextBaseColumn {
1311
1336
  super(schema, schema.stringSchema());
1312
1337
  this.dataType = "text";
1313
1338
  }
1314
- toCode(t, m) {
1315
- return textColumnToCode(this, t, m);
1339
+ toCode(ctx, key) {
1340
+ return textColumnToCode(this, ctx, key);
1316
1341
  }
1317
1342
  }
1318
1343
  class ByteaColumn extends ColumnType {
@@ -1321,8 +1346,8 @@ class ByteaColumn extends ColumnType {
1321
1346
  this.dataType = "bytea";
1322
1347
  this.operators = Operators.text;
1323
1348
  }
1324
- toCode(t, m) {
1325
- return columnCode(this, t, `bytea()`, m);
1349
+ toCode(ctx, key) {
1350
+ return columnCode(this, ctx, key, `bytea()`);
1326
1351
  }
1327
1352
  }
1328
1353
  class PointColumn extends ColumnType {
@@ -1331,8 +1356,8 @@ class PointColumn extends ColumnType {
1331
1356
  this.dataType = "point";
1332
1357
  this.operators = Operators.text;
1333
1358
  }
1334
- toCode(t, m) {
1335
- return columnCode(this, t, `point()`, m);
1359
+ toCode(ctx, key) {
1360
+ return columnCode(this, ctx, key, `point()`);
1336
1361
  }
1337
1362
  }
1338
1363
  class LineColumn extends ColumnType {
@@ -1341,8 +1366,8 @@ class LineColumn extends ColumnType {
1341
1366
  this.dataType = "line";
1342
1367
  this.operators = Operators.text;
1343
1368
  }
1344
- toCode(t, m) {
1345
- return columnCode(this, t, `line()`, m);
1369
+ toCode(ctx, key) {
1370
+ return columnCode(this, ctx, key, `line()`);
1346
1371
  }
1347
1372
  }
1348
1373
  class LsegColumn extends ColumnType {
@@ -1351,8 +1376,8 @@ class LsegColumn extends ColumnType {
1351
1376
  this.dataType = "lseg";
1352
1377
  this.operators = Operators.text;
1353
1378
  }
1354
- toCode(t, m) {
1355
- return columnCode(this, t, `lseg()`, m);
1379
+ toCode(ctx, key) {
1380
+ return columnCode(this, ctx, key, `lseg()`);
1356
1381
  }
1357
1382
  }
1358
1383
  class BoxColumn extends ColumnType {
@@ -1361,8 +1386,8 @@ class BoxColumn extends ColumnType {
1361
1386
  this.dataType = "box";
1362
1387
  this.operators = Operators.text;
1363
1388
  }
1364
- toCode(t, m) {
1365
- return columnCode(this, t, `box()`, m);
1389
+ toCode(ctx, key) {
1390
+ return columnCode(this, ctx, key, `box()`);
1366
1391
  }
1367
1392
  }
1368
1393
  class PathColumn extends ColumnType {
@@ -1371,8 +1396,8 @@ class PathColumn extends ColumnType {
1371
1396
  this.dataType = "path";
1372
1397
  this.operators = Operators.text;
1373
1398
  }
1374
- toCode(t, m) {
1375
- return columnCode(this, t, `path()`, m);
1399
+ toCode(ctx, key) {
1400
+ return columnCode(this, ctx, key, `path()`);
1376
1401
  }
1377
1402
  }
1378
1403
  class PolygonColumn extends ColumnType {
@@ -1381,8 +1406,8 @@ class PolygonColumn extends ColumnType {
1381
1406
  this.dataType = "polygon";
1382
1407
  this.operators = Operators.text;
1383
1408
  }
1384
- toCode(t, m) {
1385
- return columnCode(this, t, `polygon()`, m);
1409
+ toCode(ctx, key) {
1410
+ return columnCode(this, ctx, key, `polygon()`);
1386
1411
  }
1387
1412
  }
1388
1413
  class CircleColumn extends ColumnType {
@@ -1391,8 +1416,8 @@ class CircleColumn extends ColumnType {
1391
1416
  this.dataType = "circle";
1392
1417
  this.operators = Operators.text;
1393
1418
  }
1394
- toCode(t, m) {
1395
- return columnCode(this, t, `circle()`, m);
1419
+ toCode(ctx, key) {
1420
+ return columnCode(this, ctx, key, `circle()`);
1396
1421
  }
1397
1422
  }
1398
1423
  class MoneyColumn extends NumberBaseColumn {
@@ -1408,8 +1433,8 @@ class MoneyColumn extends NumberBaseColumn {
1408
1433
  }
1409
1434
  );
1410
1435
  }
1411
- toCode(t, m) {
1412
- return columnCode(this, t, `money()`, m);
1436
+ toCode(ctx, key) {
1437
+ return columnCode(this, ctx, key, `money()`);
1413
1438
  }
1414
1439
  }
1415
1440
  class CidrColumn extends ColumnType {
@@ -1418,8 +1443,8 @@ class CidrColumn extends ColumnType {
1418
1443
  this.dataType = "cidr";
1419
1444
  this.operators = Operators.text;
1420
1445
  }
1421
- toCode(t, m) {
1422
- return columnCode(this, t, `cidr()`, m);
1446
+ toCode(ctx, key) {
1447
+ return columnCode(this, ctx, key, `cidr()`);
1423
1448
  }
1424
1449
  }
1425
1450
  class InetColumn extends ColumnType {
@@ -1428,8 +1453,8 @@ class InetColumn extends ColumnType {
1428
1453
  this.dataType = "inet";
1429
1454
  this.operators = Operators.text;
1430
1455
  }
1431
- toCode(t, m) {
1432
- return columnCode(this, t, `inet()`, m);
1456
+ toCode(ctx, key) {
1457
+ return columnCode(this, ctx, key, `inet()`);
1433
1458
  }
1434
1459
  }
1435
1460
  class MacAddrColumn extends ColumnType {
@@ -1438,8 +1463,8 @@ class MacAddrColumn extends ColumnType {
1438
1463
  this.dataType = "macaddr";
1439
1464
  this.operators = Operators.text;
1440
1465
  }
1441
- toCode(t, m) {
1442
- return columnCode(this, t, `macaddr()`, m);
1466
+ toCode(ctx, key) {
1467
+ return columnCode(this, ctx, key, `macaddr()`);
1443
1468
  }
1444
1469
  }
1445
1470
  class MacAddr8Column extends ColumnType {
@@ -1448,8 +1473,8 @@ class MacAddr8Column extends ColumnType {
1448
1473
  this.dataType = "macaddr8";
1449
1474
  this.operators = Operators.text;
1450
1475
  }
1451
- toCode(t, m) {
1452
- return columnCode(this, t, `macaddr8()`, m);
1476
+ toCode(ctx, key) {
1477
+ return columnCode(this, ctx, key, `macaddr8()`);
1453
1478
  }
1454
1479
  }
1455
1480
  class BitColumn extends ColumnType {
@@ -1459,9 +1484,9 @@ class BitColumn extends ColumnType {
1459
1484
  this.operators = Operators.text;
1460
1485
  this.data.length = length;
1461
1486
  }
1462
- toCode(t, m) {
1487
+ toCode(ctx, key) {
1463
1488
  const { length } = this.data;
1464
- return columnCode(this, t, `bit(${length})`, m);
1489
+ return columnCode(this, ctx, key, `bit(${length})`);
1465
1490
  }
1466
1491
  toSQL() {
1467
1492
  return orchidCore.joinTruthy(
@@ -1478,9 +1503,9 @@ class BitVaryingColumn extends ColumnType {
1478
1503
  this.data.length = length;
1479
1504
  this.data.alias = "bitVarying";
1480
1505
  }
1481
- toCode(t, m) {
1506
+ toCode(ctx, key) {
1482
1507
  const { length } = this.data;
1483
- return columnCode(this, t, `bitVarying(${length != null ? length : ""})`, m);
1508
+ return columnCode(this, ctx, key, `bitVarying(${length != null ? length : ""})`);
1484
1509
  }
1485
1510
  toSQL() {
1486
1511
  return orchidCore.joinTruthy(
@@ -1496,8 +1521,8 @@ class TsVectorColumn extends ColumnType {
1496
1521
  this.dataType = "tsvector";
1497
1522
  this.operators = Operators.text;
1498
1523
  }
1499
- toCode(t, m) {
1500
- return columnCode(this, t, `tsvector()`, m);
1524
+ toCode(ctx, key) {
1525
+ return columnCode(this, ctx, key, `tsvector()`);
1501
1526
  }
1502
1527
  /**
1503
1528
  * For `tsvector` column type, it can also accept language (optional) and columns:
@@ -1559,8 +1584,8 @@ class TsQueryColumn extends ColumnType {
1559
1584
  this.dataType = "tsquery";
1560
1585
  this.operators = Operators.text;
1561
1586
  }
1562
- toCode(t, m) {
1563
- return columnCode(this, t, `tsquery()`, m);
1587
+ toCode(ctx, key) {
1588
+ return columnCode(this, ctx, key, `tsquery()`);
1564
1589
  }
1565
1590
  }
1566
1591
  const uuidDefaultSQL = "gen_random_uuid()";
@@ -1580,13 +1605,13 @@ class UUIDColumn extends ColumnType {
1580
1605
  column.data.default = uuidDefault;
1581
1606
  return column;
1582
1607
  }
1583
- toCode(t, m) {
1608
+ toCode(ctx, key) {
1584
1609
  const { data } = this;
1585
1610
  return columnCode(
1586
1611
  this,
1587
- t,
1612
+ ctx,
1613
+ key,
1588
1614
  `uuid()`,
1589
- m,
1590
1615
  // don't output the default default
1591
1616
  data.default instanceof orchidCore.RawSQLBase && data.default._sql === uuidDefaultSQL ? __spreadProps$8(__spreadValues$i({}, data), { default: void 0 }) : data
1592
1617
  );
@@ -1598,8 +1623,8 @@ class XMLColumn extends ColumnType {
1598
1623
  this.dataType = "xml";
1599
1624
  this.operators = Operators.text;
1600
1625
  }
1601
- toCode(t, m) {
1602
- return columnCode(this, t, `xml()`, m);
1626
+ toCode(ctx, key) {
1627
+ return columnCode(this, ctx, key, `xml()`);
1603
1628
  }
1604
1629
  }
1605
1630
  class CitextColumn extends TextBaseColumn {
@@ -1607,8 +1632,8 @@ class CitextColumn extends TextBaseColumn {
1607
1632
  super(schema, schema.stringSchema());
1608
1633
  this.dataType = "citext";
1609
1634
  }
1610
- toCode(t, m) {
1611
- return textColumnToCode(this, t, m);
1635
+ toCode(ctx, key) {
1636
+ return textColumnToCode(this, ctx, key);
1612
1637
  }
1613
1638
  }
1614
1639
 
@@ -1635,12 +1660,12 @@ class DateColumn extends DateBaseColumn {
1635
1660
  super(...arguments);
1636
1661
  this.dataType = "date";
1637
1662
  }
1638
- toCode(t, m) {
1663
+ toCode(ctx, key) {
1639
1664
  return columnCode(
1640
1665
  this,
1641
- t,
1642
- `date()${orchidCore.dateDataToCode(this.data, m)}`,
1643
- m,
1666
+ ctx,
1667
+ key,
1668
+ `date()${orchidCore.dateDataToCode(this.data, ctx.migration)}`,
1644
1669
  this.data,
1645
1670
  skipDateMethodsFromToCode
1646
1671
  );
@@ -1667,7 +1692,7 @@ class DateTimeTzBaseClass extends DateTimeBaseClass {
1667
1692
  );
1668
1693
  }
1669
1694
  }
1670
- const timestampToCode = (self, t, m) => {
1695
+ const timestampToCode = (self, ctx, key) => {
1671
1696
  const { dateTimePrecision: p } = self.data;
1672
1697
  const { defaultTimestamp } = self.data;
1673
1698
  if (defaultTimestamp) {
@@ -1678,9 +1703,9 @@ const timestampToCode = (self, t, m) => {
1678
1703
  self.data.modifyQuery = void 0;
1679
1704
  const code = columnCode(
1680
1705
  self,
1681
- t,
1682
- `timestamps${noTz}(${p && p !== 6 ? p : ""}).${defaultTimestamp}${orchidCore.dateDataToCode(self.data, m)}`,
1683
- m,
1706
+ ctx,
1707
+ key,
1708
+ `timestamps${noTz}(${p && p !== 6 ? p : ""}).${defaultTimestamp}${orchidCore.dateDataToCode(self.data, ctx.migration)}`,
1684
1709
  self.data,
1685
1710
  skipDateMethodsFromToCode
1686
1711
  );
@@ -1690,9 +1715,9 @@ const timestampToCode = (self, t, m) => {
1690
1715
  } else {
1691
1716
  return columnCode(
1692
1717
  self,
1693
- t,
1694
- `${self instanceof TimestampColumn ? "timestampNoTZ" : "timestamp"}(${p && p !== 6 ? p : ""})${orchidCore.dateDataToCode(self.data, m)}`,
1695
- m,
1718
+ ctx,
1719
+ key,
1720
+ `${self instanceof TimestampColumn ? "timestampNoTZ" : "timestamp"}(${p && p !== 6 ? p : ""})${orchidCore.dateDataToCode(self.data, ctx.migration)}`,
1696
1721
  self.data,
1697
1722
  skipDateMethodsFromToCode
1698
1723
  );
@@ -1703,8 +1728,8 @@ class TimestampColumn extends DateTimeBaseClass {
1703
1728
  super(...arguments);
1704
1729
  this.dataType = "timestamp";
1705
1730
  }
1706
- toCode(t, m) {
1707
- return timestampToCode(this, t, m);
1731
+ toCode(ctx, key) {
1732
+ return timestampToCode(this, ctx, key);
1708
1733
  }
1709
1734
  }
1710
1735
  class TimestampTZColumn extends DateTimeTzBaseClass {
@@ -1713,8 +1738,8 @@ class TimestampTZColumn extends DateTimeTzBaseClass {
1713
1738
  this.dataType = "timestamptz";
1714
1739
  this.baseDataType = "timestamp";
1715
1740
  }
1716
- toCode(t, m) {
1717
- return timestampToCode(this, t, m);
1741
+ toCode(ctx, key) {
1742
+ return timestampToCode(this, ctx, key);
1718
1743
  }
1719
1744
  }
1720
1745
  class TimeColumn extends ColumnType {
@@ -1724,13 +1749,16 @@ class TimeColumn extends ColumnType {
1724
1749
  this.operators = Operators.time;
1725
1750
  this.data.dateTimePrecision = dateTimePrecision;
1726
1751
  }
1727
- toCode(t, m) {
1752
+ toCode(ctx, key) {
1728
1753
  const { dateTimePrecision } = this.data;
1729
1754
  return columnCode(
1730
1755
  this,
1731
- t,
1732
- `time(${dateTimePrecision || ""})${orchidCore.dateDataToCode(this.data, m)}`,
1733
- m,
1756
+ ctx,
1757
+ key,
1758
+ `time(${dateTimePrecision || ""})${orchidCore.dateDataToCode(
1759
+ this.data,
1760
+ ctx.migration
1761
+ )}`,
1734
1762
  this.data,
1735
1763
  skipDateMethodsFromToCode
1736
1764
  );
@@ -1744,13 +1772,13 @@ class IntervalColumn extends ColumnType {
1744
1772
  this.data.fields = fields;
1745
1773
  this.data.precision = precision;
1746
1774
  }
1747
- toCode(t, m) {
1775
+ toCode(ctx, key) {
1748
1776
  const { fields, precision } = this.data;
1749
1777
  return columnCode(
1750
1778
  this,
1751
- t,
1779
+ ctx,
1780
+ key,
1752
1781
  `interval(${[fields && `'${fields}'`, precision && String(precision)].filter((part) => part).join(", ")})`,
1753
- m,
1754
1782
  this.data,
1755
1783
  skipDateMethodsFromToCode
1756
1784
  );
@@ -1772,8 +1800,8 @@ class BooleanColumn extends ColumnType {
1772
1800
  this.parseItem = (input) => input[0] === "t";
1773
1801
  this.data.alias = "boolean";
1774
1802
  }
1775
- toCode(t, m) {
1776
- return columnCode(this, t, "boolean()", m);
1803
+ toCode(ctx, key) {
1804
+ return columnCode(this, ctx, key, "boolean()");
1777
1805
  }
1778
1806
  }
1779
1807
 
@@ -1785,8 +1813,8 @@ class JSONColumn extends ColumnType {
1785
1813
  this.dataType = "jsonb";
1786
1814
  this.operators = Operators.json;
1787
1815
  }
1788
- toCode(t, m) {
1789
- return columnCode(this, t, `json()`, m, this.data, toCodeSkip);
1816
+ toCode(ctx, key) {
1817
+ return columnCode(this, ctx, key, `json()`, this.data, toCodeSkip);
1790
1818
  }
1791
1819
  }
1792
1820
  JSONColumn.prototype.encodeFn = encodeFn;
@@ -1796,8 +1824,8 @@ class JSONTextColumn extends ColumnType {
1796
1824
  this.dataType = "json";
1797
1825
  this.operators = Operators.text;
1798
1826
  }
1799
- toCode(t, m) {
1800
- return columnCode(this, t, `jsonText()`, m, this.data, toCodeSkip);
1827
+ toCode(ctx, key) {
1828
+ return columnCode(this, ctx, key, `jsonText()`, this.data, toCodeSkip);
1801
1829
  }
1802
1830
  }
1803
1831
 
@@ -2900,9 +2928,9 @@ class EnumColumn extends ColumnType {
2900
2928
  this.dataType = "enum";
2901
2929
  this.inputSchema = this.outputSchema = this.querySchema = schemaType;
2902
2930
  }
2903
- toCode(t, m) {
2904
- const options = m ? "" : `, [${this.options.map((option) => `'${option}'`).join(", ")}]`;
2905
- return columnCode(this, t, `enum('${this.enumName}'${options})`, m);
2931
+ toCode(ctx, key) {
2932
+ const options = ctx.migration ? "" : `, [${this.options.map((option) => `'${option}'`).join(", ")}]`;
2933
+ return columnCode(this, ctx, key, `enum('${this.enumName}'${options})`);
2906
2934
  }
2907
2935
  toSQL() {
2908
2936
  const name = this.enumName;
@@ -2941,21 +2969,21 @@ class ArrayColumn extends ColumnType {
2941
2969
  toSQL() {
2942
2970
  return this.data.item.toSQL() + "[]".repeat(this.data.arrayDims);
2943
2971
  }
2944
- toCode(t, m) {
2972
+ toCode(ctx, key) {
2945
2973
  let open = "array(";
2946
2974
  let close = ")";
2947
2975
  for (let i = 1; i < this.data.arrayDims; i++) {
2948
- open += `${t}.array(`;
2976
+ open += `${ctx.t}.array(`;
2949
2977
  close += ")";
2950
2978
  }
2951
2979
  const code = [open];
2952
2980
  const { item } = this.data;
2953
2981
  const { isNullable } = item.data;
2954
2982
  delete item.data.isNullable;
2955
- orchidCore.addCode(code, item.toCode(t));
2983
+ orchidCore.addCode(code, item.toCode(ctx, key));
2956
2984
  item.data.isNullable = isNullable;
2957
- orchidCore.addCode(code, `${close}${orchidCore.arrayDataToCode(this.data, m)}`);
2958
- return columnCode(this, t, code, m);
2985
+ orchidCore.addCode(code, `${close}${orchidCore.arrayDataToCode(this.data, ctx.migration)}`);
2986
+ return columnCode(this, ctx, key, code);
2959
2987
  }
2960
2988
  }
2961
2989
  const parseArray = (input, pos, len, entries, nested, item) => {
@@ -5971,8 +5999,8 @@ class CustomTypeColumn extends ColumnType {
5971
5999
  this.operators = Operators.any;
5972
6000
  this.data.isOfCustomType = true;
5973
6001
  }
5974
- toCode(t, m) {
5975
- return columnCode(this, t, `type(${orchidCore.singleQuote(this.dataType)})`, m);
6002
+ toCode(ctx, key) {
6003
+ return columnCode(this, ctx, key, `type(${orchidCore.singleQuote(this.dataType)})`);
5976
6004
  }
5977
6005
  as(column) {
5978
6006
  const c = orchidCore.setColumnData(
@@ -5987,8 +6015,8 @@ class CustomTypeColumn extends ColumnType {
5987
6015
  }
5988
6016
  }
5989
6017
  class DomainColumn extends CustomTypeColumn {
5990
- toCode(t, m) {
5991
- return columnCode(this, t, `domain(${orchidCore.singleQuote(this.dataType)})`, m);
6018
+ toCode(ctx, key) {
6019
+ return columnCode(this, ctx, key, `domain(${orchidCore.singleQuote(this.dataType)})`);
5992
6020
  }
5993
6021
  }
5994
6022