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