pqb 0.40.0 → 0.40.2
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 +35 -22
- package/dist/index.js +231 -226
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +230 -226
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -921,7 +921,7 @@ const makeVarArg = (_op) => {
|
|
|
921
921
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
922
922
|
);
|
|
923
923
|
};
|
|
924
|
-
const quoteValue
|
|
924
|
+
const quoteValue = (arg, ctx, quotedAs, jsonArray) => {
|
|
925
925
|
if (arg && typeof arg === "object") {
|
|
926
926
|
if (!jsonArray && Array.isArray(arg)) {
|
|
927
927
|
return `(${arg.map((value) => orchidCore.addValue(ctx.values, value)).join(", ")})`;
|
|
@@ -953,16 +953,16 @@ const quoteLikeValue = (arg, ctx, quotedAs, jsonArray) => {
|
|
|
953
953
|
};
|
|
954
954
|
const base = {
|
|
955
955
|
equals: make(
|
|
956
|
-
(key, value, ctx, quotedAs) => value === null ? `${key} IS NULL` : `${key} = ${quoteValue
|
|
956
|
+
(key, value, ctx, quotedAs) => value === null ? `${key} IS NULL` : `${key} = ${quoteValue(value, ctx, quotedAs)}`
|
|
957
957
|
),
|
|
958
958
|
not: make(
|
|
959
|
-
(key, value, ctx, quotedAs) => value === null ? `${key} IS NOT NULL` : `${key} <> ${quoteValue
|
|
959
|
+
(key, value, ctx, quotedAs) => value === null ? `${key} IS NOT NULL` : `${key} <> ${quoteValue(value, ctx, quotedAs)}`
|
|
960
960
|
),
|
|
961
961
|
in: make(
|
|
962
|
-
(key, value, ctx, quotedAs) => `${key} IN ${quoteValue
|
|
962
|
+
(key, value, ctx, quotedAs) => `${key} IN ${quoteValue(value, ctx, quotedAs)}`
|
|
963
963
|
),
|
|
964
964
|
notIn: make(
|
|
965
|
-
(key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteValue
|
|
965
|
+
(key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteValue(value, ctx, quotedAs)}`
|
|
966
966
|
)
|
|
967
967
|
};
|
|
968
968
|
const boolean = __spreadProps$b(__spreadValues$k({}, base), {
|
|
@@ -975,19 +975,19 @@ const boolean = __spreadProps$b(__spreadValues$k({}, base), {
|
|
|
975
975
|
});
|
|
976
976
|
const numeric = __spreadProps$b(__spreadValues$k({}, base), {
|
|
977
977
|
lt: make(
|
|
978
|
-
(key, value, ctx, quotedAs) => `${key} < ${quoteValue
|
|
978
|
+
(key, value, ctx, quotedAs) => `${key} < ${quoteValue(value, ctx, quotedAs)}`
|
|
979
979
|
),
|
|
980
980
|
lte: make(
|
|
981
|
-
(key, value, ctx, quotedAs) => `${key} <= ${quoteValue
|
|
981
|
+
(key, value, ctx, quotedAs) => `${key} <= ${quoteValue(value, ctx, quotedAs)}`
|
|
982
982
|
),
|
|
983
983
|
gt: make(
|
|
984
|
-
(key, value, ctx, quotedAs) => `${key} > ${quoteValue
|
|
984
|
+
(key, value, ctx, quotedAs) => `${key} > ${quoteValue(value, ctx, quotedAs)}`
|
|
985
985
|
),
|
|
986
986
|
gte: make(
|
|
987
|
-
(key, value, ctx, quotedAs) => `${key} >= ${quoteValue
|
|
987
|
+
(key, value, ctx, quotedAs) => `${key} >= ${quoteValue(value, ctx, quotedAs)}`
|
|
988
988
|
),
|
|
989
989
|
between: make(
|
|
990
|
-
(key, [from, to], ctx, quotedAs) => `${key} BETWEEN ${quoteValue
|
|
990
|
+
(key, [from, to], ctx, quotedAs) => `${key} BETWEEN ${quoteValue(from, ctx, quotedAs)} AND ${quoteValue(
|
|
991
991
|
to,
|
|
992
992
|
ctx,
|
|
993
993
|
quotedAs
|
|
@@ -1041,10 +1041,10 @@ const json = __spreadProps$b(__spreadValues$k({}, base), {
|
|
|
1041
1041
|
{ _op: jsonPathQueryOp }
|
|
1042
1042
|
),
|
|
1043
1043
|
jsonSupersetOf: make(
|
|
1044
|
-
(key, value, ctx, quotedAs) => `${key} @> ${quoteValue
|
|
1044
|
+
(key, value, ctx, quotedAs) => `${key} @> ${quoteValue(value, ctx, quotedAs, true)}`
|
|
1045
1045
|
),
|
|
1046
1046
|
jsonSubsetOf: make(
|
|
1047
|
-
(key, value, ctx, quotedAs) => `${key} <@ ${quoteValue
|
|
1047
|
+
(key, value, ctx, quotedAs) => `${key} <@ ${quoteValue(value, ctx, quotedAs, true)}`
|
|
1048
1048
|
),
|
|
1049
1049
|
jsonSet: makeVarArg(
|
|
1050
1050
|
(key, [path, value], ctx) => `jsonb_set(${key}, ${encodeJsonPath(ctx, path)}, ${orchidCore.addValue(
|
|
@@ -1079,193 +1079,6 @@ const Operators = {
|
|
|
1079
1079
|
array: base
|
|
1080
1080
|
};
|
|
1081
1081
|
|
|
1082
|
-
class NumberBaseColumn extends ColumnType {
|
|
1083
|
-
constructor() {
|
|
1084
|
-
super(...arguments);
|
|
1085
|
-
this.operators = Operators.number;
|
|
1086
|
-
}
|
|
1087
|
-
}
|
|
1088
|
-
class IntegerBaseColumn extends NumberBaseColumn {
|
|
1089
|
-
constructor(schema) {
|
|
1090
|
-
super(schema, schema.int());
|
|
1091
|
-
this.data.int = true;
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
class NumberAsStringBaseColumn extends ColumnType {
|
|
1095
|
-
constructor(schema) {
|
|
1096
|
-
super(schema, schema.stringSchema());
|
|
1097
|
-
this.operators = Operators.number;
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
class DecimalColumn extends NumberAsStringBaseColumn {
|
|
1101
|
-
constructor(schema, numericPrecision, numericScale) {
|
|
1102
|
-
super(schema);
|
|
1103
|
-
this.operators = Operators.number;
|
|
1104
|
-
this.dataType = "numeric";
|
|
1105
|
-
this.data.numericPrecision = numericPrecision;
|
|
1106
|
-
this.data.numericScale = numericScale;
|
|
1107
|
-
this.data.alias = "decimal";
|
|
1108
|
-
}
|
|
1109
|
-
toCode(ctx, key) {
|
|
1110
|
-
const { numericPrecision, numericScale } = this.data;
|
|
1111
|
-
return columnCode(
|
|
1112
|
-
this,
|
|
1113
|
-
ctx,
|
|
1114
|
-
key,
|
|
1115
|
-
`decimal(${numericPrecision || ""}${numericScale ? `, ${numericScale}` : ""})`
|
|
1116
|
-
);
|
|
1117
|
-
}
|
|
1118
|
-
toSQL() {
|
|
1119
|
-
const { numericPrecision, numericScale } = this.data;
|
|
1120
|
-
return orchidCore.joinTruthy(
|
|
1121
|
-
this.dataType,
|
|
1122
|
-
numericPrecision ? numericScale ? `(${numericPrecision}, ${numericScale})` : `(${numericPrecision})` : void 0
|
|
1123
|
-
);
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
const skipNumberMethods = { int: true };
|
|
1127
|
-
const intToCode = (column, ctx, key, alias) => {
|
|
1128
|
-
let code;
|
|
1129
|
-
if (column.data.identity) {
|
|
1130
|
-
code = identityToCode(column.data.identity, alias);
|
|
1131
|
-
} else {
|
|
1132
|
-
code = [`${alias}()`];
|
|
1133
|
-
}
|
|
1134
|
-
orchidCore.addCode(
|
|
1135
|
-
code,
|
|
1136
|
-
orchidCore.numberDataToCode(column.data, ctx.migration, skipNumberMethods)
|
|
1137
|
-
);
|
|
1138
|
-
return columnCode(column, ctx, key, code);
|
|
1139
|
-
};
|
|
1140
|
-
class SmallIntColumn extends IntegerBaseColumn {
|
|
1141
|
-
constructor(schema) {
|
|
1142
|
-
super(schema);
|
|
1143
|
-
this.dataType = "int2";
|
|
1144
|
-
this.parseItem = parseInt;
|
|
1145
|
-
this.data.alias = "smallint";
|
|
1146
|
-
}
|
|
1147
|
-
toCode(ctx, key) {
|
|
1148
|
-
return intToCode(this, ctx, key, "smallint");
|
|
1149
|
-
}
|
|
1150
|
-
identity(options = {}) {
|
|
1151
|
-
return orchidCore.setColumnData(this, "identity", options);
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
class IntegerColumn extends IntegerBaseColumn {
|
|
1155
|
-
constructor(schema) {
|
|
1156
|
-
super(schema);
|
|
1157
|
-
this.dataType = "int4";
|
|
1158
|
-
this.parseItem = parseInt;
|
|
1159
|
-
this.data.alias = "integer";
|
|
1160
|
-
}
|
|
1161
|
-
toCode(ctx, key) {
|
|
1162
|
-
return intToCode(this, ctx, key, "integer");
|
|
1163
|
-
}
|
|
1164
|
-
identity(options = {}) {
|
|
1165
|
-
return orchidCore.setColumnData(this, "identity", options);
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
class BigIntColumn extends NumberAsStringBaseColumn {
|
|
1169
|
-
constructor(schema) {
|
|
1170
|
-
super(schema);
|
|
1171
|
-
this.dataType = "int8";
|
|
1172
|
-
this.data.alias = "bigint";
|
|
1173
|
-
}
|
|
1174
|
-
toCode(ctx, key) {
|
|
1175
|
-
return intToCode(this, ctx, key, "bigint");
|
|
1176
|
-
}
|
|
1177
|
-
identity(options = {}) {
|
|
1178
|
-
return orchidCore.setColumnData(this, "identity", options);
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
class RealColumn extends NumberBaseColumn {
|
|
1182
|
-
constructor(schema) {
|
|
1183
|
-
super(schema, schema.number());
|
|
1184
|
-
this.dataType = "float4";
|
|
1185
|
-
this.parseItem = parseFloat;
|
|
1186
|
-
this.data.alias = "real";
|
|
1187
|
-
}
|
|
1188
|
-
toCode(ctx, key) {
|
|
1189
|
-
return columnCode(
|
|
1190
|
-
this,
|
|
1191
|
-
ctx,
|
|
1192
|
-
key,
|
|
1193
|
-
`real()${orchidCore.numberDataToCode(this.data, ctx.migration)}`
|
|
1194
|
-
);
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
class DoublePrecisionColumn extends NumberAsStringBaseColumn {
|
|
1198
|
-
constructor(schema) {
|
|
1199
|
-
super(schema);
|
|
1200
|
-
this.dataType = "float8";
|
|
1201
|
-
this.data.alias = "doublePrecision";
|
|
1202
|
-
}
|
|
1203
|
-
toCode(ctx, key) {
|
|
1204
|
-
return columnCode(this, ctx, key, `doublePrecision()`);
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
class SmallSerialColumn extends IntegerBaseColumn {
|
|
1208
|
-
constructor(schema) {
|
|
1209
|
-
super(schema);
|
|
1210
|
-
this.dataType = "int2";
|
|
1211
|
-
this.parseItem = parseInt;
|
|
1212
|
-
this.data.int = true;
|
|
1213
|
-
this.data.alias = "smallSerial";
|
|
1214
|
-
}
|
|
1215
|
-
toSQL() {
|
|
1216
|
-
return "smallserial";
|
|
1217
|
-
}
|
|
1218
|
-
toCode(ctx, key) {
|
|
1219
|
-
return columnCode(
|
|
1220
|
-
this,
|
|
1221
|
-
ctx,
|
|
1222
|
-
key,
|
|
1223
|
-
`smallSerial()${orchidCore.numberDataToCode(
|
|
1224
|
-
this.data,
|
|
1225
|
-
ctx.migration,
|
|
1226
|
-
skipNumberMethods
|
|
1227
|
-
)}`
|
|
1228
|
-
);
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
class SerialColumn extends IntegerBaseColumn {
|
|
1232
|
-
constructor(schema) {
|
|
1233
|
-
super(schema);
|
|
1234
|
-
this.dataType = "int4";
|
|
1235
|
-
this.parseItem = parseInt;
|
|
1236
|
-
this.data.int = true;
|
|
1237
|
-
this.data.alias = "serial";
|
|
1238
|
-
}
|
|
1239
|
-
toSQL() {
|
|
1240
|
-
return "serial";
|
|
1241
|
-
}
|
|
1242
|
-
toCode(ctx, key) {
|
|
1243
|
-
return columnCode(
|
|
1244
|
-
this,
|
|
1245
|
-
ctx,
|
|
1246
|
-
key,
|
|
1247
|
-
`serial()${orchidCore.numberDataToCode(
|
|
1248
|
-
this.data,
|
|
1249
|
-
ctx.migration,
|
|
1250
|
-
skipNumberMethods
|
|
1251
|
-
)}`
|
|
1252
|
-
);
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
class BigSerialColumn extends NumberAsStringBaseColumn {
|
|
1256
|
-
constructor(schema) {
|
|
1257
|
-
super(schema);
|
|
1258
|
-
this.dataType = "int8";
|
|
1259
|
-
this.data.alias = "bigint";
|
|
1260
|
-
}
|
|
1261
|
-
toSQL() {
|
|
1262
|
-
return "bigserial";
|
|
1263
|
-
}
|
|
1264
|
-
toCode(ctx, key) {
|
|
1265
|
-
return columnCode(this, ctx, key, `bigSerial()`);
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
1082
|
var __defProp$j = Object.defineProperty;
|
|
1270
1083
|
var __defProps$a = Object.defineProperties;
|
|
1271
1084
|
var __getOwnPropDescs$a = Object.getOwnPropertyDescriptors;
|
|
@@ -1449,13 +1262,14 @@ class CircleColumn extends ColumnType {
|
|
|
1449
1262
|
return columnCode(this, ctx, key, `circle()`);
|
|
1450
1263
|
}
|
|
1451
1264
|
}
|
|
1452
|
-
class MoneyColumn extends
|
|
1265
|
+
class MoneyColumn extends ColumnType {
|
|
1453
1266
|
constructor(schema) {
|
|
1454
1267
|
super(schema, schema.stringSchema());
|
|
1455
1268
|
this.dataType = "money";
|
|
1269
|
+
this.operators = Operators.number;
|
|
1456
1270
|
this.parseFn = Object.assign(
|
|
1457
1271
|
function(input) {
|
|
1458
|
-
return parseFloat(input.replace(/,/g, "").replace(/\$/g, ""));
|
|
1272
|
+
return input === null ? input : parseFloat(input.replace(/,/g, "").replace(/\$/g, ""));
|
|
1459
1273
|
},
|
|
1460
1274
|
{
|
|
1461
1275
|
hideFromCode: true
|
|
@@ -3021,6 +2835,8 @@ class ArrayColumn extends ColumnType {
|
|
|
3021
2835
|
this.operators = Operators.array;
|
|
3022
2836
|
this.parseFn = Object.assign(
|
|
3023
2837
|
(source) => {
|
|
2838
|
+
if (!source)
|
|
2839
|
+
return source;
|
|
3024
2840
|
const entries = [];
|
|
3025
2841
|
parsePostgresArray(source, entries, this.data.item.parseItem);
|
|
3026
2842
|
return entries;
|
|
@@ -3109,6 +2925,193 @@ const parsePostgresArray = (source, entries, transform) => {
|
|
|
3109
2925
|
return pos;
|
|
3110
2926
|
};
|
|
3111
2927
|
|
|
2928
|
+
class NumberBaseColumn extends ColumnType {
|
|
2929
|
+
constructor() {
|
|
2930
|
+
super(...arguments);
|
|
2931
|
+
this.operators = Operators.number;
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
class IntegerBaseColumn extends NumberBaseColumn {
|
|
2935
|
+
constructor(schema) {
|
|
2936
|
+
super(schema, schema.int());
|
|
2937
|
+
this.data.int = true;
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
class NumberAsStringBaseColumn extends ColumnType {
|
|
2941
|
+
constructor(schema) {
|
|
2942
|
+
super(schema, schema.stringSchema());
|
|
2943
|
+
this.operators = Operators.number;
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2946
|
+
class DecimalColumn extends NumberAsStringBaseColumn {
|
|
2947
|
+
constructor(schema, numericPrecision, numericScale) {
|
|
2948
|
+
super(schema);
|
|
2949
|
+
this.operators = Operators.number;
|
|
2950
|
+
this.dataType = "numeric";
|
|
2951
|
+
this.data.numericPrecision = numericPrecision;
|
|
2952
|
+
this.data.numericScale = numericScale;
|
|
2953
|
+
this.data.alias = "decimal";
|
|
2954
|
+
}
|
|
2955
|
+
toCode(ctx, key) {
|
|
2956
|
+
const { numericPrecision, numericScale } = this.data;
|
|
2957
|
+
return columnCode(
|
|
2958
|
+
this,
|
|
2959
|
+
ctx,
|
|
2960
|
+
key,
|
|
2961
|
+
`decimal(${numericPrecision || ""}${numericScale ? `, ${numericScale}` : ""})`
|
|
2962
|
+
);
|
|
2963
|
+
}
|
|
2964
|
+
toSQL() {
|
|
2965
|
+
const { numericPrecision, numericScale } = this.data;
|
|
2966
|
+
return orchidCore.joinTruthy(
|
|
2967
|
+
this.dataType,
|
|
2968
|
+
numericPrecision ? numericScale ? `(${numericPrecision}, ${numericScale})` : `(${numericPrecision})` : void 0
|
|
2969
|
+
);
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
const skipNumberMethods = { int: true };
|
|
2973
|
+
const intToCode = (column, ctx, key, alias) => {
|
|
2974
|
+
let code;
|
|
2975
|
+
if (column.data.identity) {
|
|
2976
|
+
code = identityToCode(column.data.identity, alias);
|
|
2977
|
+
} else {
|
|
2978
|
+
code = [`${alias}()`];
|
|
2979
|
+
}
|
|
2980
|
+
orchidCore.addCode(
|
|
2981
|
+
code,
|
|
2982
|
+
orchidCore.numberDataToCode(column.data, ctx.migration, skipNumberMethods)
|
|
2983
|
+
);
|
|
2984
|
+
return columnCode(column, ctx, key, code);
|
|
2985
|
+
};
|
|
2986
|
+
class SmallIntColumn extends IntegerBaseColumn {
|
|
2987
|
+
constructor(schema) {
|
|
2988
|
+
super(schema);
|
|
2989
|
+
this.dataType = "int2";
|
|
2990
|
+
this.parseItem = parseInt;
|
|
2991
|
+
this.data.alias = "smallint";
|
|
2992
|
+
}
|
|
2993
|
+
toCode(ctx, key) {
|
|
2994
|
+
return intToCode(this, ctx, key, "smallint");
|
|
2995
|
+
}
|
|
2996
|
+
identity(options = {}) {
|
|
2997
|
+
return orchidCore.setColumnData(this, "identity", options);
|
|
2998
|
+
}
|
|
2999
|
+
}
|
|
3000
|
+
class IntegerColumn extends IntegerBaseColumn {
|
|
3001
|
+
constructor(schema) {
|
|
3002
|
+
super(schema);
|
|
3003
|
+
this.dataType = "int4";
|
|
3004
|
+
this.parseItem = parseInt;
|
|
3005
|
+
this.data.alias = "integer";
|
|
3006
|
+
}
|
|
3007
|
+
toCode(ctx, key) {
|
|
3008
|
+
return intToCode(this, ctx, key, "integer");
|
|
3009
|
+
}
|
|
3010
|
+
identity(options = {}) {
|
|
3011
|
+
return orchidCore.setColumnData(this, "identity", options);
|
|
3012
|
+
}
|
|
3013
|
+
}
|
|
3014
|
+
class BigIntColumn extends NumberAsStringBaseColumn {
|
|
3015
|
+
constructor(schema) {
|
|
3016
|
+
super(schema);
|
|
3017
|
+
this.dataType = "int8";
|
|
3018
|
+
this.data.alias = "bigint";
|
|
3019
|
+
}
|
|
3020
|
+
toCode(ctx, key) {
|
|
3021
|
+
return intToCode(this, ctx, key, "bigint");
|
|
3022
|
+
}
|
|
3023
|
+
identity(options = {}) {
|
|
3024
|
+
return orchidCore.setColumnData(this, "identity", options);
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
class RealColumn extends NumberBaseColumn {
|
|
3028
|
+
constructor(schema) {
|
|
3029
|
+
super(schema, schema.number());
|
|
3030
|
+
this.dataType = "float4";
|
|
3031
|
+
this.parseItem = parseFloat;
|
|
3032
|
+
this.data.alias = "real";
|
|
3033
|
+
}
|
|
3034
|
+
toCode(ctx, key) {
|
|
3035
|
+
return columnCode(
|
|
3036
|
+
this,
|
|
3037
|
+
ctx,
|
|
3038
|
+
key,
|
|
3039
|
+
`real()${orchidCore.numberDataToCode(this.data, ctx.migration)}`
|
|
3040
|
+
);
|
|
3041
|
+
}
|
|
3042
|
+
}
|
|
3043
|
+
class DoublePrecisionColumn extends NumberAsStringBaseColumn {
|
|
3044
|
+
constructor(schema) {
|
|
3045
|
+
super(schema);
|
|
3046
|
+
this.dataType = "float8";
|
|
3047
|
+
this.data.alias = "doublePrecision";
|
|
3048
|
+
}
|
|
3049
|
+
toCode(ctx, key) {
|
|
3050
|
+
return columnCode(this, ctx, key, `doublePrecision()`);
|
|
3051
|
+
}
|
|
3052
|
+
}
|
|
3053
|
+
class SmallSerialColumn extends IntegerBaseColumn {
|
|
3054
|
+
constructor(schema) {
|
|
3055
|
+
super(schema);
|
|
3056
|
+
this.dataType = "int2";
|
|
3057
|
+
this.parseItem = parseInt;
|
|
3058
|
+
this.data.int = true;
|
|
3059
|
+
this.data.alias = "smallSerial";
|
|
3060
|
+
}
|
|
3061
|
+
toSQL() {
|
|
3062
|
+
return "smallserial";
|
|
3063
|
+
}
|
|
3064
|
+
toCode(ctx, key) {
|
|
3065
|
+
return columnCode(
|
|
3066
|
+
this,
|
|
3067
|
+
ctx,
|
|
3068
|
+
key,
|
|
3069
|
+
`smallSerial()${orchidCore.numberDataToCode(
|
|
3070
|
+
this.data,
|
|
3071
|
+
ctx.migration,
|
|
3072
|
+
skipNumberMethods
|
|
3073
|
+
)}`
|
|
3074
|
+
);
|
|
3075
|
+
}
|
|
3076
|
+
}
|
|
3077
|
+
class SerialColumn extends IntegerBaseColumn {
|
|
3078
|
+
constructor(schema) {
|
|
3079
|
+
super(schema);
|
|
3080
|
+
this.dataType = "int4";
|
|
3081
|
+
this.parseItem = parseInt;
|
|
3082
|
+
this.data.int = true;
|
|
3083
|
+
this.data.alias = "serial";
|
|
3084
|
+
}
|
|
3085
|
+
toSQL() {
|
|
3086
|
+
return "serial";
|
|
3087
|
+
}
|
|
3088
|
+
toCode(ctx, key) {
|
|
3089
|
+
return columnCode(
|
|
3090
|
+
this,
|
|
3091
|
+
ctx,
|
|
3092
|
+
key,
|
|
3093
|
+
`serial()${orchidCore.numberDataToCode(
|
|
3094
|
+
this.data,
|
|
3095
|
+
ctx.migration,
|
|
3096
|
+
skipNumberMethods
|
|
3097
|
+
)}`
|
|
3098
|
+
);
|
|
3099
|
+
}
|
|
3100
|
+
}
|
|
3101
|
+
class BigSerialColumn extends NumberAsStringBaseColumn {
|
|
3102
|
+
constructor(schema) {
|
|
3103
|
+
super(schema);
|
|
3104
|
+
this.dataType = "int8";
|
|
3105
|
+
this.data.alias = "bigint";
|
|
3106
|
+
}
|
|
3107
|
+
toSQL() {
|
|
3108
|
+
return "bigserial";
|
|
3109
|
+
}
|
|
3110
|
+
toCode(ctx, key) {
|
|
3111
|
+
return columnCode(this, ctx, key, `bigSerial()`);
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
|
|
3112
3115
|
const parseDateToNumber = (value) => value ? Date.parse(value) : value;
|
|
3113
3116
|
const parseDateToDate = (value) => value ? new Date(value) : value;
|
|
3114
3117
|
parseDateToNumber.hideFromCode = parseDateToDate.hideFromCode = true;
|
|
@@ -3179,25 +3182,26 @@ const defaultSchemaConfig = {
|
|
|
3179
3182
|
timestamp: (precision) => new TimestampTZColumn(defaultSchemaConfig, precision)
|
|
3180
3183
|
};
|
|
3181
3184
|
|
|
3182
|
-
const
|
|
3185
|
+
const escape = (value, migration, nested) => {
|
|
3183
3186
|
const type = typeof value;
|
|
3184
3187
|
if (type === "number" || type === "bigint")
|
|
3185
3188
|
return String(value);
|
|
3186
3189
|
else if (type === "string")
|
|
3187
|
-
return
|
|
3190
|
+
return escapeString(value);
|
|
3188
3191
|
else if (type === "boolean")
|
|
3189
3192
|
return value ? "true" : "false";
|
|
3190
3193
|
else if (value instanceof Date)
|
|
3191
3194
|
return `'${value.toISOString()}'`;
|
|
3192
3195
|
else if (Array.isArray(value))
|
|
3193
|
-
return
|
|
3196
|
+
return migration && nested && !value.length ? "" : (migration ? "{" : nested ? "[" : "ARRAY[") + value.map((el) => escape(el, migration, true)).join(",") + (migration ? "}" : "]");
|
|
3194
3197
|
else if (value === null || value === void 0)
|
|
3195
3198
|
return "NULL";
|
|
3196
3199
|
else
|
|
3197
|
-
return
|
|
3200
|
+
return escapeString(JSON.stringify(value));
|
|
3198
3201
|
};
|
|
3199
|
-
const
|
|
3200
|
-
const
|
|
3202
|
+
const escapeForLog = (value) => escape(value);
|
|
3203
|
+
const escapeForMigration = (value) => escape(value, true);
|
|
3204
|
+
const escapeString = (value) => `'${value.replaceAll("'", "''")}'`;
|
|
3201
3205
|
|
|
3202
3206
|
const makeMessage = (colors, timeColor, time, sqlColor, sql, valuesColor, values) => {
|
|
3203
3207
|
const elapsed = process.hrtime(time);
|
|
@@ -3206,7 +3210,7 @@ const makeMessage = (colors, timeColor, time, sqlColor, sql, valuesColor, values
|
|
|
3206
3210
|
if (!(values == null ? void 0 : values.length)) {
|
|
3207
3211
|
return result;
|
|
3208
3212
|
}
|
|
3209
|
-
const formattedValues = `[${values.map(
|
|
3213
|
+
const formattedValues = `[${values.map(escapeForLog).join(", ")}]`;
|
|
3210
3214
|
return `${result} ${colors ? valuesColor(formattedValues) : formattedValues}`;
|
|
3211
3215
|
};
|
|
3212
3216
|
const logParamToLogObject = (logger, log) => {
|
|
@@ -4239,7 +4243,7 @@ const addParserForSelectItem = (q, as, key, arg) => {
|
|
|
4239
4243
|
let returnType = originalReturnType;
|
|
4240
4244
|
const { hookSelect } = query;
|
|
4241
4245
|
const batches = [];
|
|
4242
|
-
|
|
4246
|
+
const last = path.length;
|
|
4243
4247
|
if (returnType === "value" || returnType === "valueOrThrow") {
|
|
4244
4248
|
if (hookSelect) {
|
|
4245
4249
|
batches.push = (item) => {
|
|
@@ -4249,8 +4253,6 @@ const addParserForSelectItem = (q, as, key, arg) => {
|
|
|
4249
4253
|
batches.push = Array.prototype.push;
|
|
4250
4254
|
return batches.push(item);
|
|
4251
4255
|
};
|
|
4252
|
-
} else {
|
|
4253
|
-
last--;
|
|
4254
4256
|
}
|
|
4255
4257
|
}
|
|
4256
4258
|
collectNestedSelectBatches(batches, rows, path, last);
|
|
@@ -4311,19 +4313,19 @@ const addParserForSelectItem = (q, as, key, arg) => {
|
|
|
4311
4313
|
const parse = (_b2 = query.parsers) == null ? void 0 : _b2[orchidCore.getValueKey];
|
|
4312
4314
|
if (parse) {
|
|
4313
4315
|
if (returnType === "value") {
|
|
4314
|
-
for (const
|
|
4315
|
-
|
|
4316
|
+
for (const item of batches) {
|
|
4317
|
+
item.parent[item.key] = item.data = item.data === void 0 ? arg.q.notFoundDefault : parse(item.data);
|
|
4316
4318
|
}
|
|
4317
4319
|
} else {
|
|
4318
|
-
for (const
|
|
4319
|
-
if (data
|
|
4320
|
+
for (const item of batches) {
|
|
4321
|
+
if (item.data === void 0)
|
|
4320
4322
|
throw new NotFoundError(arg);
|
|
4321
|
-
|
|
4323
|
+
item.parent[item.key] = item.data = parse(item.data);
|
|
4322
4324
|
}
|
|
4323
4325
|
}
|
|
4324
4326
|
} else if (returnType !== "value") {
|
|
4325
4327
|
for (const { data } of batches) {
|
|
4326
|
-
if (data
|
|
4328
|
+
if (data === void 0)
|
|
4327
4329
|
throw new NotFoundError(arg);
|
|
4328
4330
|
}
|
|
4329
4331
|
}
|
|
@@ -4392,7 +4394,9 @@ const collectNestedSelectBatches = (batches, rows, path, last) => {
|
|
|
4392
4394
|
const stack = rows.map(
|
|
4393
4395
|
(row) => ({
|
|
4394
4396
|
data: row,
|
|
4395
|
-
|
|
4397
|
+
parent: row,
|
|
4398
|
+
i: 0,
|
|
4399
|
+
key: path[0]
|
|
4396
4400
|
})
|
|
4397
4401
|
);
|
|
4398
4402
|
while (stack.length > 0) {
|
|
@@ -5824,7 +5828,7 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
|
|
|
5824
5828
|
}).join(", ")})` : "";
|
|
5825
5829
|
const target = "from" in copy ? copy.from : copy.to;
|
|
5826
5830
|
sql.push(
|
|
5827
|
-
`COPY "${table.table}"${columns} ${"from" in copy ? "FROM" : "TO"} ${typeof target === "string" ?
|
|
5831
|
+
`COPY "${table.table}"${columns} ${"from" in copy ? "FROM" : "TO"} ${typeof target === "string" ? escapeString(target) : `PROGRAM ${escapeString(target.program)}`}`
|
|
5828
5832
|
);
|
|
5829
5833
|
if (Object.keys(copy).length > (copy.columns ? 2 : 1)) {
|
|
5830
5834
|
const options = [];
|
|
@@ -5833,15 +5837,15 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
|
|
|
5833
5837
|
if (copy.freeze)
|
|
5834
5838
|
options.push(`FREEZE ${copy.freeze}`);
|
|
5835
5839
|
if (copy.delimiter)
|
|
5836
|
-
options.push(`DELIMITER ${
|
|
5840
|
+
options.push(`DELIMITER ${escapeString(copy.delimiter)}`);
|
|
5837
5841
|
if (copy.null)
|
|
5838
|
-
options.push(`NULL ${
|
|
5842
|
+
options.push(`NULL ${escapeString(copy.null)}`);
|
|
5839
5843
|
if (copy.header)
|
|
5840
5844
|
options.push(`HEADER ${copy.header}`);
|
|
5841
5845
|
if (copy.quote)
|
|
5842
|
-
options.push(`QUOTE ${
|
|
5846
|
+
options.push(`QUOTE ${escapeString(copy.quote)}`);
|
|
5843
5847
|
if (copy.escape)
|
|
5844
|
-
options.push(`ESCAPE ${
|
|
5848
|
+
options.push(`ESCAPE ${escapeString(copy.escape)}`);
|
|
5845
5849
|
if (copy.forceQuote)
|
|
5846
5850
|
options.push(
|
|
5847
5851
|
`FORCE_QUOTE ${copy.forceQuote === "*" ? "*" : `(${copy.forceQuote.map((x) => `"${x}"`).join(", ")})`}`
|
|
@@ -5855,7 +5859,7 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
|
|
|
5855
5859
|
`FORCE_NULL (${copy.forceNull.map((x) => `"${x}"`).join(", ")})`
|
|
5856
5860
|
);
|
|
5857
5861
|
if (copy.encoding)
|
|
5858
|
-
options.push(`ENCODING ${
|
|
5862
|
+
options.push(`ENCODING ${escapeString(copy.encoding)}`);
|
|
5859
5863
|
sql.push(`WITH (${options.join(", ")})`);
|
|
5860
5864
|
}
|
|
5861
5865
|
pushWhereStatementSql(ctx, table, query, quotedAs);
|
|
@@ -13168,6 +13172,9 @@ exports.copyTableData = copyTableData;
|
|
|
13168
13172
|
exports.countSelect = countSelect;
|
|
13169
13173
|
exports.createDb = createDb;
|
|
13170
13174
|
exports.defaultSchemaConfig = defaultSchemaConfig;
|
|
13175
|
+
exports.escapeForLog = escapeForLog;
|
|
13176
|
+
exports.escapeForMigration = escapeForMigration;
|
|
13177
|
+
exports.escapeString = escapeString;
|
|
13171
13178
|
exports.extendQuery = extendQuery;
|
|
13172
13179
|
exports.filterResult = filterResult;
|
|
13173
13180
|
exports.foreignKeyArgumentToCode = foreignKeyArgumentToCode;
|
|
@@ -13213,8 +13220,6 @@ exports.queryJson = queryJson;
|
|
|
13213
13220
|
exports.queryMethodByReturnType = queryMethodByReturnType;
|
|
13214
13221
|
exports.queryTypeWithLimitOne = queryTypeWithLimitOne;
|
|
13215
13222
|
exports.queryWrap = queryWrap;
|
|
13216
|
-
exports.quote = quote;
|
|
13217
|
-
exports.quoteString = quoteString;
|
|
13218
13223
|
exports.raw = raw;
|
|
13219
13224
|
exports.referencesArgsToCode = referencesArgsToCode;
|
|
13220
13225
|
exports.resolveSubQueryCallback = resolveSubQueryCallback;
|