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.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExpressionTypeMethod, Expression, RawSQLBase, emptyObject, isTemplateLiteralArgs, ColumnTypeBase, setColumnData, pushColumnData, quoteObjectKey, toArray, singleQuote, addCode, singleQuoteArray, objectHasValues, toSnakeCase, columnDefaultArgumentToCode, columnErrorMessagesToCode, getValueKey, emptyArray, addValue, isExpression, joinTruthy,
|
|
1
|
+
import { ExpressionTypeMethod, Expression, RawSQLBase, emptyObject, isTemplateLiteralArgs, ColumnTypeBase, setColumnData, pushColumnData, quoteObjectKey, toArray, singleQuote, addCode, singleQuoteArray, objectHasValues, toSnakeCase, columnDefaultArgumentToCode, columnErrorMessagesToCode, getValueKey, emptyArray, addValue, isExpression, joinTruthy, stringDataToCode, getDefaultLanguage, dateDataToCode, pushOrNewArrayToObject, returnArg as returnArg$1, noop, arrayDataToCode, numberDataToCode, logColors, 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';
|
|
@@ -919,7 +919,7 @@ const makeVarArg = (_op) => {
|
|
|
919
919
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
920
920
|
);
|
|
921
921
|
};
|
|
922
|
-
const quoteValue
|
|
922
|
+
const quoteValue = (arg, ctx, quotedAs, jsonArray) => {
|
|
923
923
|
if (arg && typeof arg === "object") {
|
|
924
924
|
if (!jsonArray && Array.isArray(arg)) {
|
|
925
925
|
return `(${arg.map((value) => addValue(ctx.values, value)).join(", ")})`;
|
|
@@ -951,16 +951,16 @@ const quoteLikeValue = (arg, ctx, quotedAs, jsonArray) => {
|
|
|
951
951
|
};
|
|
952
952
|
const base = {
|
|
953
953
|
equals: make(
|
|
954
|
-
(key, value, ctx, quotedAs) => value === null ? `${key} IS NULL` : `${key} = ${quoteValue
|
|
954
|
+
(key, value, ctx, quotedAs) => value === null ? `${key} IS NULL` : `${key} = ${quoteValue(value, ctx, quotedAs)}`
|
|
955
955
|
),
|
|
956
956
|
not: make(
|
|
957
|
-
(key, value, ctx, quotedAs) => value === null ? `${key} IS NOT NULL` : `${key} <> ${quoteValue
|
|
957
|
+
(key, value, ctx, quotedAs) => value === null ? `${key} IS NOT NULL` : `${key} <> ${quoteValue(value, ctx, quotedAs)}`
|
|
958
958
|
),
|
|
959
959
|
in: make(
|
|
960
|
-
(key, value, ctx, quotedAs) => `${key} IN ${quoteValue
|
|
960
|
+
(key, value, ctx, quotedAs) => `${key} IN ${quoteValue(value, ctx, quotedAs)}`
|
|
961
961
|
),
|
|
962
962
|
notIn: make(
|
|
963
|
-
(key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteValue
|
|
963
|
+
(key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteValue(value, ctx, quotedAs)}`
|
|
964
964
|
)
|
|
965
965
|
};
|
|
966
966
|
const boolean = __spreadProps$b(__spreadValues$k({}, base), {
|
|
@@ -973,19 +973,19 @@ const boolean = __spreadProps$b(__spreadValues$k({}, base), {
|
|
|
973
973
|
});
|
|
974
974
|
const numeric = __spreadProps$b(__spreadValues$k({}, base), {
|
|
975
975
|
lt: make(
|
|
976
|
-
(key, value, ctx, quotedAs) => `${key} < ${quoteValue
|
|
976
|
+
(key, value, ctx, quotedAs) => `${key} < ${quoteValue(value, ctx, quotedAs)}`
|
|
977
977
|
),
|
|
978
978
|
lte: make(
|
|
979
|
-
(key, value, ctx, quotedAs) => `${key} <= ${quoteValue
|
|
979
|
+
(key, value, ctx, quotedAs) => `${key} <= ${quoteValue(value, ctx, quotedAs)}`
|
|
980
980
|
),
|
|
981
981
|
gt: make(
|
|
982
|
-
(key, value, ctx, quotedAs) => `${key} > ${quoteValue
|
|
982
|
+
(key, value, ctx, quotedAs) => `${key} > ${quoteValue(value, ctx, quotedAs)}`
|
|
983
983
|
),
|
|
984
984
|
gte: make(
|
|
985
|
-
(key, value, ctx, quotedAs) => `${key} >= ${quoteValue
|
|
985
|
+
(key, value, ctx, quotedAs) => `${key} >= ${quoteValue(value, ctx, quotedAs)}`
|
|
986
986
|
),
|
|
987
987
|
between: make(
|
|
988
|
-
(key, [from, to], ctx, quotedAs) => `${key} BETWEEN ${quoteValue
|
|
988
|
+
(key, [from, to], ctx, quotedAs) => `${key} BETWEEN ${quoteValue(from, ctx, quotedAs)} AND ${quoteValue(
|
|
989
989
|
to,
|
|
990
990
|
ctx,
|
|
991
991
|
quotedAs
|
|
@@ -1039,10 +1039,10 @@ const json = __spreadProps$b(__spreadValues$k({}, base), {
|
|
|
1039
1039
|
{ _op: jsonPathQueryOp }
|
|
1040
1040
|
),
|
|
1041
1041
|
jsonSupersetOf: make(
|
|
1042
|
-
(key, value, ctx, quotedAs) => `${key} @> ${quoteValue
|
|
1042
|
+
(key, value, ctx, quotedAs) => `${key} @> ${quoteValue(value, ctx, quotedAs, true)}`
|
|
1043
1043
|
),
|
|
1044
1044
|
jsonSubsetOf: make(
|
|
1045
|
-
(key, value, ctx, quotedAs) => `${key} <@ ${quoteValue
|
|
1045
|
+
(key, value, ctx, quotedAs) => `${key} <@ ${quoteValue(value, ctx, quotedAs, true)}`
|
|
1046
1046
|
),
|
|
1047
1047
|
jsonSet: makeVarArg(
|
|
1048
1048
|
(key, [path, value], ctx) => `jsonb_set(${key}, ${encodeJsonPath(ctx, path)}, ${addValue(
|
|
@@ -1077,193 +1077,6 @@ const Operators = {
|
|
|
1077
1077
|
array: base
|
|
1078
1078
|
};
|
|
1079
1079
|
|
|
1080
|
-
class NumberBaseColumn extends ColumnType {
|
|
1081
|
-
constructor() {
|
|
1082
|
-
super(...arguments);
|
|
1083
|
-
this.operators = Operators.number;
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
class IntegerBaseColumn extends NumberBaseColumn {
|
|
1087
|
-
constructor(schema) {
|
|
1088
|
-
super(schema, schema.int());
|
|
1089
|
-
this.data.int = true;
|
|
1090
|
-
}
|
|
1091
|
-
}
|
|
1092
|
-
class NumberAsStringBaseColumn extends ColumnType {
|
|
1093
|
-
constructor(schema) {
|
|
1094
|
-
super(schema, schema.stringSchema());
|
|
1095
|
-
this.operators = Operators.number;
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
class DecimalColumn extends NumberAsStringBaseColumn {
|
|
1099
|
-
constructor(schema, numericPrecision, numericScale) {
|
|
1100
|
-
super(schema);
|
|
1101
|
-
this.operators = Operators.number;
|
|
1102
|
-
this.dataType = "numeric";
|
|
1103
|
-
this.data.numericPrecision = numericPrecision;
|
|
1104
|
-
this.data.numericScale = numericScale;
|
|
1105
|
-
this.data.alias = "decimal";
|
|
1106
|
-
}
|
|
1107
|
-
toCode(ctx, key) {
|
|
1108
|
-
const { numericPrecision, numericScale } = this.data;
|
|
1109
|
-
return columnCode(
|
|
1110
|
-
this,
|
|
1111
|
-
ctx,
|
|
1112
|
-
key,
|
|
1113
|
-
`decimal(${numericPrecision || ""}${numericScale ? `, ${numericScale}` : ""})`
|
|
1114
|
-
);
|
|
1115
|
-
}
|
|
1116
|
-
toSQL() {
|
|
1117
|
-
const { numericPrecision, numericScale } = this.data;
|
|
1118
|
-
return joinTruthy(
|
|
1119
|
-
this.dataType,
|
|
1120
|
-
numericPrecision ? numericScale ? `(${numericPrecision}, ${numericScale})` : `(${numericPrecision})` : void 0
|
|
1121
|
-
);
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
const skipNumberMethods = { int: true };
|
|
1125
|
-
const intToCode = (column, ctx, key, alias) => {
|
|
1126
|
-
let code;
|
|
1127
|
-
if (column.data.identity) {
|
|
1128
|
-
code = identityToCode(column.data.identity, alias);
|
|
1129
|
-
} else {
|
|
1130
|
-
code = [`${alias}()`];
|
|
1131
|
-
}
|
|
1132
|
-
addCode(
|
|
1133
|
-
code,
|
|
1134
|
-
numberDataToCode(column.data, ctx.migration, skipNumberMethods)
|
|
1135
|
-
);
|
|
1136
|
-
return columnCode(column, ctx, key, code);
|
|
1137
|
-
};
|
|
1138
|
-
class SmallIntColumn extends IntegerBaseColumn {
|
|
1139
|
-
constructor(schema) {
|
|
1140
|
-
super(schema);
|
|
1141
|
-
this.dataType = "int2";
|
|
1142
|
-
this.parseItem = parseInt;
|
|
1143
|
-
this.data.alias = "smallint";
|
|
1144
|
-
}
|
|
1145
|
-
toCode(ctx, key) {
|
|
1146
|
-
return intToCode(this, ctx, key, "smallint");
|
|
1147
|
-
}
|
|
1148
|
-
identity(options = {}) {
|
|
1149
|
-
return setColumnData(this, "identity", options);
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
class IntegerColumn extends IntegerBaseColumn {
|
|
1153
|
-
constructor(schema) {
|
|
1154
|
-
super(schema);
|
|
1155
|
-
this.dataType = "int4";
|
|
1156
|
-
this.parseItem = parseInt;
|
|
1157
|
-
this.data.alias = "integer";
|
|
1158
|
-
}
|
|
1159
|
-
toCode(ctx, key) {
|
|
1160
|
-
return intToCode(this, ctx, key, "integer");
|
|
1161
|
-
}
|
|
1162
|
-
identity(options = {}) {
|
|
1163
|
-
return setColumnData(this, "identity", options);
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
class BigIntColumn extends NumberAsStringBaseColumn {
|
|
1167
|
-
constructor(schema) {
|
|
1168
|
-
super(schema);
|
|
1169
|
-
this.dataType = "int8";
|
|
1170
|
-
this.data.alias = "bigint";
|
|
1171
|
-
}
|
|
1172
|
-
toCode(ctx, key) {
|
|
1173
|
-
return intToCode(this, ctx, key, "bigint");
|
|
1174
|
-
}
|
|
1175
|
-
identity(options = {}) {
|
|
1176
|
-
return setColumnData(this, "identity", options);
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
class RealColumn extends NumberBaseColumn {
|
|
1180
|
-
constructor(schema) {
|
|
1181
|
-
super(schema, schema.number());
|
|
1182
|
-
this.dataType = "float4";
|
|
1183
|
-
this.parseItem = parseFloat;
|
|
1184
|
-
this.data.alias = "real";
|
|
1185
|
-
}
|
|
1186
|
-
toCode(ctx, key) {
|
|
1187
|
-
return columnCode(
|
|
1188
|
-
this,
|
|
1189
|
-
ctx,
|
|
1190
|
-
key,
|
|
1191
|
-
`real()${numberDataToCode(this.data, ctx.migration)}`
|
|
1192
|
-
);
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
class DoublePrecisionColumn extends NumberAsStringBaseColumn {
|
|
1196
|
-
constructor(schema) {
|
|
1197
|
-
super(schema);
|
|
1198
|
-
this.dataType = "float8";
|
|
1199
|
-
this.data.alias = "doublePrecision";
|
|
1200
|
-
}
|
|
1201
|
-
toCode(ctx, key) {
|
|
1202
|
-
return columnCode(this, ctx, key, `doublePrecision()`);
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
class SmallSerialColumn extends IntegerBaseColumn {
|
|
1206
|
-
constructor(schema) {
|
|
1207
|
-
super(schema);
|
|
1208
|
-
this.dataType = "int2";
|
|
1209
|
-
this.parseItem = parseInt;
|
|
1210
|
-
this.data.int = true;
|
|
1211
|
-
this.data.alias = "smallSerial";
|
|
1212
|
-
}
|
|
1213
|
-
toSQL() {
|
|
1214
|
-
return "smallserial";
|
|
1215
|
-
}
|
|
1216
|
-
toCode(ctx, key) {
|
|
1217
|
-
return columnCode(
|
|
1218
|
-
this,
|
|
1219
|
-
ctx,
|
|
1220
|
-
key,
|
|
1221
|
-
`smallSerial()${numberDataToCode(
|
|
1222
|
-
this.data,
|
|
1223
|
-
ctx.migration,
|
|
1224
|
-
skipNumberMethods
|
|
1225
|
-
)}`
|
|
1226
|
-
);
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
class SerialColumn extends IntegerBaseColumn {
|
|
1230
|
-
constructor(schema) {
|
|
1231
|
-
super(schema);
|
|
1232
|
-
this.dataType = "int4";
|
|
1233
|
-
this.parseItem = parseInt;
|
|
1234
|
-
this.data.int = true;
|
|
1235
|
-
this.data.alias = "serial";
|
|
1236
|
-
}
|
|
1237
|
-
toSQL() {
|
|
1238
|
-
return "serial";
|
|
1239
|
-
}
|
|
1240
|
-
toCode(ctx, key) {
|
|
1241
|
-
return columnCode(
|
|
1242
|
-
this,
|
|
1243
|
-
ctx,
|
|
1244
|
-
key,
|
|
1245
|
-
`serial()${numberDataToCode(
|
|
1246
|
-
this.data,
|
|
1247
|
-
ctx.migration,
|
|
1248
|
-
skipNumberMethods
|
|
1249
|
-
)}`
|
|
1250
|
-
);
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
class BigSerialColumn extends NumberAsStringBaseColumn {
|
|
1254
|
-
constructor(schema) {
|
|
1255
|
-
super(schema);
|
|
1256
|
-
this.dataType = "int8";
|
|
1257
|
-
this.data.alias = "bigint";
|
|
1258
|
-
}
|
|
1259
|
-
toSQL() {
|
|
1260
|
-
return "bigserial";
|
|
1261
|
-
}
|
|
1262
|
-
toCode(ctx, key) {
|
|
1263
|
-
return columnCode(this, ctx, key, `bigSerial()`);
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
1080
|
var __defProp$j = Object.defineProperty;
|
|
1268
1081
|
var __defProps$a = Object.defineProperties;
|
|
1269
1082
|
var __getOwnPropDescs$a = Object.getOwnPropertyDescriptors;
|
|
@@ -1447,13 +1260,14 @@ class CircleColumn extends ColumnType {
|
|
|
1447
1260
|
return columnCode(this, ctx, key, `circle()`);
|
|
1448
1261
|
}
|
|
1449
1262
|
}
|
|
1450
|
-
class MoneyColumn extends
|
|
1263
|
+
class MoneyColumn extends ColumnType {
|
|
1451
1264
|
constructor(schema) {
|
|
1452
1265
|
super(schema, schema.stringSchema());
|
|
1453
1266
|
this.dataType = "money";
|
|
1267
|
+
this.operators = Operators.number;
|
|
1454
1268
|
this.parseFn = Object.assign(
|
|
1455
1269
|
function(input) {
|
|
1456
|
-
return parseFloat(input.replace(/,/g, "").replace(/\$/g, ""));
|
|
1270
|
+
return input === null ? input : parseFloat(input.replace(/,/g, "").replace(/\$/g, ""));
|
|
1457
1271
|
},
|
|
1458
1272
|
{
|
|
1459
1273
|
hideFromCode: true
|
|
@@ -3019,6 +2833,8 @@ class ArrayColumn extends ColumnType {
|
|
|
3019
2833
|
this.operators = Operators.array;
|
|
3020
2834
|
this.parseFn = Object.assign(
|
|
3021
2835
|
(source) => {
|
|
2836
|
+
if (!source)
|
|
2837
|
+
return source;
|
|
3022
2838
|
const entries = [];
|
|
3023
2839
|
parsePostgresArray(source, entries, this.data.item.parseItem);
|
|
3024
2840
|
return entries;
|
|
@@ -3107,6 +2923,193 @@ const parsePostgresArray = (source, entries, transform) => {
|
|
|
3107
2923
|
return pos;
|
|
3108
2924
|
};
|
|
3109
2925
|
|
|
2926
|
+
class NumberBaseColumn extends ColumnType {
|
|
2927
|
+
constructor() {
|
|
2928
|
+
super(...arguments);
|
|
2929
|
+
this.operators = Operators.number;
|
|
2930
|
+
}
|
|
2931
|
+
}
|
|
2932
|
+
class IntegerBaseColumn extends NumberBaseColumn {
|
|
2933
|
+
constructor(schema) {
|
|
2934
|
+
super(schema, schema.int());
|
|
2935
|
+
this.data.int = true;
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
class NumberAsStringBaseColumn extends ColumnType {
|
|
2939
|
+
constructor(schema) {
|
|
2940
|
+
super(schema, schema.stringSchema());
|
|
2941
|
+
this.operators = Operators.number;
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
class DecimalColumn extends NumberAsStringBaseColumn {
|
|
2945
|
+
constructor(schema, numericPrecision, numericScale) {
|
|
2946
|
+
super(schema);
|
|
2947
|
+
this.operators = Operators.number;
|
|
2948
|
+
this.dataType = "numeric";
|
|
2949
|
+
this.data.numericPrecision = numericPrecision;
|
|
2950
|
+
this.data.numericScale = numericScale;
|
|
2951
|
+
this.data.alias = "decimal";
|
|
2952
|
+
}
|
|
2953
|
+
toCode(ctx, key) {
|
|
2954
|
+
const { numericPrecision, numericScale } = this.data;
|
|
2955
|
+
return columnCode(
|
|
2956
|
+
this,
|
|
2957
|
+
ctx,
|
|
2958
|
+
key,
|
|
2959
|
+
`decimal(${numericPrecision || ""}${numericScale ? `, ${numericScale}` : ""})`
|
|
2960
|
+
);
|
|
2961
|
+
}
|
|
2962
|
+
toSQL() {
|
|
2963
|
+
const { numericPrecision, numericScale } = this.data;
|
|
2964
|
+
return joinTruthy(
|
|
2965
|
+
this.dataType,
|
|
2966
|
+
numericPrecision ? numericScale ? `(${numericPrecision}, ${numericScale})` : `(${numericPrecision})` : void 0
|
|
2967
|
+
);
|
|
2968
|
+
}
|
|
2969
|
+
}
|
|
2970
|
+
const skipNumberMethods = { int: true };
|
|
2971
|
+
const intToCode = (column, ctx, key, alias) => {
|
|
2972
|
+
let code;
|
|
2973
|
+
if (column.data.identity) {
|
|
2974
|
+
code = identityToCode(column.data.identity, alias);
|
|
2975
|
+
} else {
|
|
2976
|
+
code = [`${alias}()`];
|
|
2977
|
+
}
|
|
2978
|
+
addCode(
|
|
2979
|
+
code,
|
|
2980
|
+
numberDataToCode(column.data, ctx.migration, skipNumberMethods)
|
|
2981
|
+
);
|
|
2982
|
+
return columnCode(column, ctx, key, code);
|
|
2983
|
+
};
|
|
2984
|
+
class SmallIntColumn extends IntegerBaseColumn {
|
|
2985
|
+
constructor(schema) {
|
|
2986
|
+
super(schema);
|
|
2987
|
+
this.dataType = "int2";
|
|
2988
|
+
this.parseItem = parseInt;
|
|
2989
|
+
this.data.alias = "smallint";
|
|
2990
|
+
}
|
|
2991
|
+
toCode(ctx, key) {
|
|
2992
|
+
return intToCode(this, ctx, key, "smallint");
|
|
2993
|
+
}
|
|
2994
|
+
identity(options = {}) {
|
|
2995
|
+
return setColumnData(this, "identity", options);
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
class IntegerColumn extends IntegerBaseColumn {
|
|
2999
|
+
constructor(schema) {
|
|
3000
|
+
super(schema);
|
|
3001
|
+
this.dataType = "int4";
|
|
3002
|
+
this.parseItem = parseInt;
|
|
3003
|
+
this.data.alias = "integer";
|
|
3004
|
+
}
|
|
3005
|
+
toCode(ctx, key) {
|
|
3006
|
+
return intToCode(this, ctx, key, "integer");
|
|
3007
|
+
}
|
|
3008
|
+
identity(options = {}) {
|
|
3009
|
+
return setColumnData(this, "identity", options);
|
|
3010
|
+
}
|
|
3011
|
+
}
|
|
3012
|
+
class BigIntColumn extends NumberAsStringBaseColumn {
|
|
3013
|
+
constructor(schema) {
|
|
3014
|
+
super(schema);
|
|
3015
|
+
this.dataType = "int8";
|
|
3016
|
+
this.data.alias = "bigint";
|
|
3017
|
+
}
|
|
3018
|
+
toCode(ctx, key) {
|
|
3019
|
+
return intToCode(this, ctx, key, "bigint");
|
|
3020
|
+
}
|
|
3021
|
+
identity(options = {}) {
|
|
3022
|
+
return setColumnData(this, "identity", options);
|
|
3023
|
+
}
|
|
3024
|
+
}
|
|
3025
|
+
class RealColumn extends NumberBaseColumn {
|
|
3026
|
+
constructor(schema) {
|
|
3027
|
+
super(schema, schema.number());
|
|
3028
|
+
this.dataType = "float4";
|
|
3029
|
+
this.parseItem = parseFloat;
|
|
3030
|
+
this.data.alias = "real";
|
|
3031
|
+
}
|
|
3032
|
+
toCode(ctx, key) {
|
|
3033
|
+
return columnCode(
|
|
3034
|
+
this,
|
|
3035
|
+
ctx,
|
|
3036
|
+
key,
|
|
3037
|
+
`real()${numberDataToCode(this.data, ctx.migration)}`
|
|
3038
|
+
);
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
3041
|
+
class DoublePrecisionColumn extends NumberAsStringBaseColumn {
|
|
3042
|
+
constructor(schema) {
|
|
3043
|
+
super(schema);
|
|
3044
|
+
this.dataType = "float8";
|
|
3045
|
+
this.data.alias = "doublePrecision";
|
|
3046
|
+
}
|
|
3047
|
+
toCode(ctx, key) {
|
|
3048
|
+
return columnCode(this, ctx, key, `doublePrecision()`);
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
class SmallSerialColumn extends IntegerBaseColumn {
|
|
3052
|
+
constructor(schema) {
|
|
3053
|
+
super(schema);
|
|
3054
|
+
this.dataType = "int2";
|
|
3055
|
+
this.parseItem = parseInt;
|
|
3056
|
+
this.data.int = true;
|
|
3057
|
+
this.data.alias = "smallSerial";
|
|
3058
|
+
}
|
|
3059
|
+
toSQL() {
|
|
3060
|
+
return "smallserial";
|
|
3061
|
+
}
|
|
3062
|
+
toCode(ctx, key) {
|
|
3063
|
+
return columnCode(
|
|
3064
|
+
this,
|
|
3065
|
+
ctx,
|
|
3066
|
+
key,
|
|
3067
|
+
`smallSerial()${numberDataToCode(
|
|
3068
|
+
this.data,
|
|
3069
|
+
ctx.migration,
|
|
3070
|
+
skipNumberMethods
|
|
3071
|
+
)}`
|
|
3072
|
+
);
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
class SerialColumn extends IntegerBaseColumn {
|
|
3076
|
+
constructor(schema) {
|
|
3077
|
+
super(schema);
|
|
3078
|
+
this.dataType = "int4";
|
|
3079
|
+
this.parseItem = parseInt;
|
|
3080
|
+
this.data.int = true;
|
|
3081
|
+
this.data.alias = "serial";
|
|
3082
|
+
}
|
|
3083
|
+
toSQL() {
|
|
3084
|
+
return "serial";
|
|
3085
|
+
}
|
|
3086
|
+
toCode(ctx, key) {
|
|
3087
|
+
return columnCode(
|
|
3088
|
+
this,
|
|
3089
|
+
ctx,
|
|
3090
|
+
key,
|
|
3091
|
+
`serial()${numberDataToCode(
|
|
3092
|
+
this.data,
|
|
3093
|
+
ctx.migration,
|
|
3094
|
+
skipNumberMethods
|
|
3095
|
+
)}`
|
|
3096
|
+
);
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
class BigSerialColumn extends NumberAsStringBaseColumn {
|
|
3100
|
+
constructor(schema) {
|
|
3101
|
+
super(schema);
|
|
3102
|
+
this.dataType = "int8";
|
|
3103
|
+
this.data.alias = "bigint";
|
|
3104
|
+
}
|
|
3105
|
+
toSQL() {
|
|
3106
|
+
return "bigserial";
|
|
3107
|
+
}
|
|
3108
|
+
toCode(ctx, key) {
|
|
3109
|
+
return columnCode(this, ctx, key, `bigSerial()`);
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
|
|
3110
3113
|
const parseDateToNumber = (value) => value ? Date.parse(value) : value;
|
|
3111
3114
|
const parseDateToDate = (value) => value ? new Date(value) : value;
|
|
3112
3115
|
parseDateToNumber.hideFromCode = parseDateToDate.hideFromCode = true;
|
|
@@ -3177,25 +3180,26 @@ const defaultSchemaConfig = {
|
|
|
3177
3180
|
timestamp: (precision) => new TimestampTZColumn(defaultSchemaConfig, precision)
|
|
3178
3181
|
};
|
|
3179
3182
|
|
|
3180
|
-
const
|
|
3183
|
+
const escape = (value, migration, nested) => {
|
|
3181
3184
|
const type = typeof value;
|
|
3182
3185
|
if (type === "number" || type === "bigint")
|
|
3183
3186
|
return String(value);
|
|
3184
3187
|
else if (type === "string")
|
|
3185
|
-
return
|
|
3188
|
+
return escapeString(value);
|
|
3186
3189
|
else if (type === "boolean")
|
|
3187
3190
|
return value ? "true" : "false";
|
|
3188
3191
|
else if (value instanceof Date)
|
|
3189
3192
|
return `'${value.toISOString()}'`;
|
|
3190
3193
|
else if (Array.isArray(value))
|
|
3191
|
-
return
|
|
3194
|
+
return migration && nested && !value.length ? "" : (migration ? "{" : nested ? "[" : "ARRAY[") + value.map((el) => escape(el, migration, true)).join(",") + (migration ? "}" : "]");
|
|
3192
3195
|
else if (value === null || value === void 0)
|
|
3193
3196
|
return "NULL";
|
|
3194
3197
|
else
|
|
3195
|
-
return
|
|
3198
|
+
return escapeString(JSON.stringify(value));
|
|
3196
3199
|
};
|
|
3197
|
-
const
|
|
3198
|
-
const
|
|
3200
|
+
const escapeForLog = (value) => escape(value);
|
|
3201
|
+
const escapeForMigration = (value) => escape(value, true);
|
|
3202
|
+
const escapeString = (value) => `'${value.replaceAll("'", "''")}'`;
|
|
3199
3203
|
|
|
3200
3204
|
const makeMessage = (colors, timeColor, time, sqlColor, sql, valuesColor, values) => {
|
|
3201
3205
|
const elapsed = process.hrtime(time);
|
|
@@ -3204,7 +3208,7 @@ const makeMessage = (colors, timeColor, time, sqlColor, sql, valuesColor, values
|
|
|
3204
3208
|
if (!(values == null ? void 0 : values.length)) {
|
|
3205
3209
|
return result;
|
|
3206
3210
|
}
|
|
3207
|
-
const formattedValues = `[${values.map(
|
|
3211
|
+
const formattedValues = `[${values.map(escapeForLog).join(", ")}]`;
|
|
3208
3212
|
return `${result} ${colors ? valuesColor(formattedValues) : formattedValues}`;
|
|
3209
3213
|
};
|
|
3210
3214
|
const logParamToLogObject = (logger, log) => {
|
|
@@ -4237,7 +4241,7 @@ const addParserForSelectItem = (q, as, key, arg) => {
|
|
|
4237
4241
|
let returnType = originalReturnType;
|
|
4238
4242
|
const { hookSelect } = query;
|
|
4239
4243
|
const batches = [];
|
|
4240
|
-
|
|
4244
|
+
const last = path.length;
|
|
4241
4245
|
if (returnType === "value" || returnType === "valueOrThrow") {
|
|
4242
4246
|
if (hookSelect) {
|
|
4243
4247
|
batches.push = (item) => {
|
|
@@ -4247,8 +4251,6 @@ const addParserForSelectItem = (q, as, key, arg) => {
|
|
|
4247
4251
|
batches.push = Array.prototype.push;
|
|
4248
4252
|
return batches.push(item);
|
|
4249
4253
|
};
|
|
4250
|
-
} else {
|
|
4251
|
-
last--;
|
|
4252
4254
|
}
|
|
4253
4255
|
}
|
|
4254
4256
|
collectNestedSelectBatches(batches, rows, path, last);
|
|
@@ -4309,19 +4311,19 @@ const addParserForSelectItem = (q, as, key, arg) => {
|
|
|
4309
4311
|
const parse = (_b2 = query.parsers) == null ? void 0 : _b2[getValueKey];
|
|
4310
4312
|
if (parse) {
|
|
4311
4313
|
if (returnType === "value") {
|
|
4312
|
-
for (const
|
|
4313
|
-
|
|
4314
|
+
for (const item of batches) {
|
|
4315
|
+
item.parent[item.key] = item.data = item.data === void 0 ? arg.q.notFoundDefault : parse(item.data);
|
|
4314
4316
|
}
|
|
4315
4317
|
} else {
|
|
4316
|
-
for (const
|
|
4317
|
-
if (data
|
|
4318
|
+
for (const item of batches) {
|
|
4319
|
+
if (item.data === void 0)
|
|
4318
4320
|
throw new NotFoundError(arg);
|
|
4319
|
-
|
|
4321
|
+
item.parent[item.key] = item.data = parse(item.data);
|
|
4320
4322
|
}
|
|
4321
4323
|
}
|
|
4322
4324
|
} else if (returnType !== "value") {
|
|
4323
4325
|
for (const { data } of batches) {
|
|
4324
|
-
if (data
|
|
4326
|
+
if (data === void 0)
|
|
4325
4327
|
throw new NotFoundError(arg);
|
|
4326
4328
|
}
|
|
4327
4329
|
}
|
|
@@ -4390,7 +4392,9 @@ const collectNestedSelectBatches = (batches, rows, path, last) => {
|
|
|
4390
4392
|
const stack = rows.map(
|
|
4391
4393
|
(row) => ({
|
|
4392
4394
|
data: row,
|
|
4393
|
-
|
|
4395
|
+
parent: row,
|
|
4396
|
+
i: 0,
|
|
4397
|
+
key: path[0]
|
|
4394
4398
|
})
|
|
4395
4399
|
);
|
|
4396
4400
|
while (stack.length > 0) {
|
|
@@ -5822,7 +5826,7 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
|
|
|
5822
5826
|
}).join(", ")})` : "";
|
|
5823
5827
|
const target = "from" in copy ? copy.from : copy.to;
|
|
5824
5828
|
sql.push(
|
|
5825
|
-
`COPY "${table.table}"${columns} ${"from" in copy ? "FROM" : "TO"} ${typeof target === "string" ?
|
|
5829
|
+
`COPY "${table.table}"${columns} ${"from" in copy ? "FROM" : "TO"} ${typeof target === "string" ? escapeString(target) : `PROGRAM ${escapeString(target.program)}`}`
|
|
5826
5830
|
);
|
|
5827
5831
|
if (Object.keys(copy).length > (copy.columns ? 2 : 1)) {
|
|
5828
5832
|
const options = [];
|
|
@@ -5831,15 +5835,15 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
|
|
|
5831
5835
|
if (copy.freeze)
|
|
5832
5836
|
options.push(`FREEZE ${copy.freeze}`);
|
|
5833
5837
|
if (copy.delimiter)
|
|
5834
|
-
options.push(`DELIMITER ${
|
|
5838
|
+
options.push(`DELIMITER ${escapeString(copy.delimiter)}`);
|
|
5835
5839
|
if (copy.null)
|
|
5836
|
-
options.push(`NULL ${
|
|
5840
|
+
options.push(`NULL ${escapeString(copy.null)}`);
|
|
5837
5841
|
if (copy.header)
|
|
5838
5842
|
options.push(`HEADER ${copy.header}`);
|
|
5839
5843
|
if (copy.quote)
|
|
5840
|
-
options.push(`QUOTE ${
|
|
5844
|
+
options.push(`QUOTE ${escapeString(copy.quote)}`);
|
|
5841
5845
|
if (copy.escape)
|
|
5842
|
-
options.push(`ESCAPE ${
|
|
5846
|
+
options.push(`ESCAPE ${escapeString(copy.escape)}`);
|
|
5843
5847
|
if (copy.forceQuote)
|
|
5844
5848
|
options.push(
|
|
5845
5849
|
`FORCE_QUOTE ${copy.forceQuote === "*" ? "*" : `(${copy.forceQuote.map((x) => `"${x}"`).join(", ")})`}`
|
|
@@ -5853,7 +5857,7 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
|
|
|
5853
5857
|
`FORCE_NULL (${copy.forceNull.map((x) => `"${x}"`).join(", ")})`
|
|
5854
5858
|
);
|
|
5855
5859
|
if (copy.encoding)
|
|
5856
|
-
options.push(`ENCODING ${
|
|
5860
|
+
options.push(`ENCODING ${escapeString(copy.encoding)}`);
|
|
5857
5861
|
sql.push(`WITH (${options.join(", ")})`);
|
|
5858
5862
|
}
|
|
5859
5863
|
pushWhereStatementSql(ctx, table, query, quotedAs);
|
|
@@ -12983,5 +12987,5 @@ function copyTableData(query, arg) {
|
|
|
12983
12987
|
return q;
|
|
12984
12988
|
}
|
|
12985
12989
|
|
|
12986
|
-
export { Adapter, AfterCommitError, AggregateMethods, ArrayColumn, AsMethods, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, ComputedColumn, Create, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, Delete, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, FnExpression, For, FromMethods, Having, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnMethods, Operators, OrExpression, OrchidOrmError, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, QueryBase, QueryError, QueryGet, QueryHooks, QueryLog, QueryMethods, QueryUpsertOrCreate, RawSQL, RealColumn, RefExpression, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, SqlMethod, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransactionAdapter, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, WithMethods, XMLColumn, _afterCommitError, _getSelectableColumn, _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, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql$1 as commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseTableData, parseTableDataInput, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap,
|
|
12990
|
+
export { Adapter, AfterCommitError, AggregateMethods, ArrayColumn, AsMethods, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, ComputedColumn, Create, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, Delete, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, FnExpression, For, FromMethods, Having, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnMethods, Operators, OrExpression, OrchidOrmError, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, QueryBase, QueryError, QueryGet, QueryHooks, QueryLog, QueryMethods, QueryUpsertOrCreate, RawSQL, RealColumn, RefExpression, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, SqlMethod, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransactionAdapter, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, WithMethods, XMLColumn, _afterCommitError, _getSelectableColumn, _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, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql$1 as commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, escapeForLog, escapeForMigration, escapeString, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseTableData, parseTableDataInput, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql$1 as rollbackSql, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
|
|
12987
12991
|
//# sourceMappingURL=index.mjs.map
|