pqb 0.40.11 → 0.41.0
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 +20 -31
- package/dist/index.js +418 -366
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +413 -367
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -119,25 +119,25 @@ const sqlFn = (...args) => {
|
|
|
119
119
|
return (...args2) => new RawSQL(args2, arg);
|
|
120
120
|
};
|
|
121
121
|
|
|
122
|
-
var __defProp$
|
|
123
|
-
var __defProps$
|
|
124
|
-
var __getOwnPropDescs$
|
|
125
|
-
var __getOwnPropSymbols$
|
|
126
|
-
var __hasOwnProp$
|
|
127
|
-
var __propIsEnum$
|
|
128
|
-
var __defNormalProp$
|
|
129
|
-
var __spreadValues$
|
|
122
|
+
var __defProp$o = Object.defineProperty;
|
|
123
|
+
var __defProps$e = Object.defineProperties;
|
|
124
|
+
var __getOwnPropDescs$e = Object.getOwnPropertyDescriptors;
|
|
125
|
+
var __getOwnPropSymbols$p = Object.getOwnPropertySymbols;
|
|
126
|
+
var __hasOwnProp$p = Object.prototype.hasOwnProperty;
|
|
127
|
+
var __propIsEnum$p = Object.prototype.propertyIsEnumerable;
|
|
128
|
+
var __defNormalProp$o = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
129
|
+
var __spreadValues$o = (a, b) => {
|
|
130
130
|
for (var prop in b || (b = {}))
|
|
131
|
-
if (__hasOwnProp$
|
|
132
|
-
__defNormalProp$
|
|
133
|
-
if (__getOwnPropSymbols$
|
|
134
|
-
for (var prop of __getOwnPropSymbols$
|
|
135
|
-
if (__propIsEnum$
|
|
136
|
-
__defNormalProp$
|
|
131
|
+
if (__hasOwnProp$p.call(b, prop))
|
|
132
|
+
__defNormalProp$o(a, prop, b[prop]);
|
|
133
|
+
if (__getOwnPropSymbols$p)
|
|
134
|
+
for (var prop of __getOwnPropSymbols$p(b)) {
|
|
135
|
+
if (__propIsEnum$p.call(b, prop))
|
|
136
|
+
__defNormalProp$o(a, prop, b[prop]);
|
|
137
137
|
}
|
|
138
138
|
return a;
|
|
139
139
|
};
|
|
140
|
-
var __spreadProps$
|
|
140
|
+
var __spreadProps$e = (a, b) => __defProps$e(a, __getOwnPropDescs$e(b));
|
|
141
141
|
class ColumnType extends orchidCore.ColumnTypeBase {
|
|
142
142
|
/**
|
|
143
143
|
* Mark the column as a primary key.
|
|
@@ -336,13 +336,13 @@ class ColumnType extends orchidCore.ColumnTypeBase {
|
|
|
336
336
|
*/
|
|
337
337
|
searchIndex(...args) {
|
|
338
338
|
return orchidCore.pushColumnData(this, "indexes", {
|
|
339
|
-
options: __spreadValues$
|
|
339
|
+
options: __spreadValues$o(__spreadValues$o({}, typeof args[0] === "string" ? args[1] : args[0]), this.dataType === "tsvector" ? { using: "GIN" } : { tsVector: true }),
|
|
340
340
|
name: typeof args[0] === "string" ? args[0] : void 0
|
|
341
341
|
});
|
|
342
342
|
}
|
|
343
343
|
unique(...args) {
|
|
344
344
|
return orchidCore.pushColumnData(this, "indexes", {
|
|
345
|
-
options: __spreadProps$
|
|
345
|
+
options: __spreadProps$e(__spreadValues$o({}, typeof args[0] === "string" ? args[1] : args[0]), {
|
|
346
346
|
unique: true
|
|
347
347
|
}),
|
|
348
348
|
name: typeof args[0] === "string" ? args[0] : void 0
|
|
@@ -385,25 +385,25 @@ class ColumnType extends orchidCore.ColumnTypeBase {
|
|
|
385
385
|
}
|
|
386
386
|
}
|
|
387
387
|
|
|
388
|
-
var __defProp$
|
|
389
|
-
var __defProps$
|
|
390
|
-
var __getOwnPropDescs$
|
|
391
|
-
var __getOwnPropSymbols$
|
|
392
|
-
var __hasOwnProp$
|
|
393
|
-
var __propIsEnum$
|
|
394
|
-
var __defNormalProp$
|
|
395
|
-
var __spreadValues$
|
|
388
|
+
var __defProp$n = Object.defineProperty;
|
|
389
|
+
var __defProps$d = Object.defineProperties;
|
|
390
|
+
var __getOwnPropDescs$d = Object.getOwnPropertyDescriptors;
|
|
391
|
+
var __getOwnPropSymbols$o = Object.getOwnPropertySymbols;
|
|
392
|
+
var __hasOwnProp$o = Object.prototype.hasOwnProperty;
|
|
393
|
+
var __propIsEnum$o = Object.prototype.propertyIsEnumerable;
|
|
394
|
+
var __defNormalProp$n = (obj, key, value) => key in obj ? __defProp$n(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
395
|
+
var __spreadValues$n = (a, b) => {
|
|
396
396
|
for (var prop in b || (b = {}))
|
|
397
|
-
if (__hasOwnProp$
|
|
398
|
-
__defNormalProp$
|
|
399
|
-
if (__getOwnPropSymbols$
|
|
400
|
-
for (var prop of __getOwnPropSymbols$
|
|
401
|
-
if (__propIsEnum$
|
|
402
|
-
__defNormalProp$
|
|
397
|
+
if (__hasOwnProp$o.call(b, prop))
|
|
398
|
+
__defNormalProp$n(a, prop, b[prop]);
|
|
399
|
+
if (__getOwnPropSymbols$o)
|
|
400
|
+
for (var prop of __getOwnPropSymbols$o(b)) {
|
|
401
|
+
if (__propIsEnum$o.call(b, prop))
|
|
402
|
+
__defNormalProp$n(a, prop, b[prop]);
|
|
403
403
|
}
|
|
404
404
|
return a;
|
|
405
405
|
};
|
|
406
|
-
var __spreadProps$
|
|
406
|
+
var __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b));
|
|
407
407
|
const knownDefaults = {
|
|
408
408
|
current_timestamp: "now()",
|
|
409
409
|
"transaction_timestamp()": "now()"
|
|
@@ -419,7 +419,7 @@ const simplifyColumnDefault = (value) => {
|
|
|
419
419
|
const instantiateColumn = (typeFn, params) => {
|
|
420
420
|
const column = typeFn();
|
|
421
421
|
const { dateTimePrecision } = params;
|
|
422
|
-
Object.assign(column.data, __spreadProps$
|
|
422
|
+
Object.assign(column.data, __spreadProps$d(__spreadValues$n({}, params), {
|
|
423
423
|
dateTimePrecision: (
|
|
424
424
|
// 0 is default for date, 6 is default for timestamp
|
|
425
425
|
dateTimePrecision && dateTimePrecision !== 6 ? dateTimePrecision : void 0
|
|
@@ -777,8 +777,9 @@ const identityToCode = (identity, dataType) => {
|
|
|
777
777
|
orchidCore.addCode(code, ")");
|
|
778
778
|
return code;
|
|
779
779
|
};
|
|
780
|
-
const columnCode = (type, ctx, key, code
|
|
780
|
+
const columnCode = (type, ctx, key, code) => {
|
|
781
781
|
var _a;
|
|
782
|
+
const { data } = type;
|
|
782
783
|
code = orchidCore.toArray(code);
|
|
783
784
|
let prepend = `${ctx.t}.`;
|
|
784
785
|
const keyName = ctx.snakeCase ? orchidCore.toSnakeCase(key) : key;
|
|
@@ -809,13 +810,15 @@ const columnCode = (type, ctx, key, code, data = type.data, skip) => {
|
|
|
809
810
|
orchidCore.addCode(code, ".select(false)");
|
|
810
811
|
if (data.isNullable)
|
|
811
812
|
orchidCore.addCode(code, ".nullable()");
|
|
812
|
-
if (
|
|
813
|
-
orchidCore.addCode(code, `.encode(${
|
|
814
|
-
if (
|
|
815
|
-
orchidCore.addCode(code, `.parse(${
|
|
813
|
+
if (data.encode && data.encode !== data.defaultEncode)
|
|
814
|
+
orchidCore.addCode(code, `.encode(${data.encode.toString()})`);
|
|
815
|
+
if (data.parse && data.parse !== data.defaultParse)
|
|
816
|
+
orchidCore.addCode(code, `.parse(${data.parse.toString()})`);
|
|
817
|
+
if (type.data.parseNull)
|
|
818
|
+
orchidCore.addCode(code, `.parseNull(${type.data.parseNull.toString()})`);
|
|
816
819
|
if (data.as)
|
|
817
820
|
orchidCore.addCode(code, `.as(${data.as.toCode(ctx, key)})`);
|
|
818
|
-
if (data.default !== void 0 && (!ctx.migration || typeof data.default !== "function")) {
|
|
821
|
+
if (data.default !== void 0 && data.default !== data.defaultDefault && (!ctx.migration || typeof data.default !== "function")) {
|
|
819
822
|
orchidCore.addCode(
|
|
820
823
|
code,
|
|
821
824
|
`.default(${orchidCore.columnDefaultArgumentToCode(ctx.t, data.default)})`
|
|
@@ -858,21 +861,73 @@ const getSqlText = (sql) => {
|
|
|
858
861
|
throw new Error(`Batch SQL is not supported in this query`);
|
|
859
862
|
};
|
|
860
863
|
|
|
861
|
-
var __defProp$
|
|
864
|
+
var __defProp$m = Object.defineProperty;
|
|
865
|
+
var __defProps$c = Object.defineProperties;
|
|
866
|
+
var __getOwnPropDescs$c = Object.getOwnPropertyDescriptors;
|
|
867
|
+
var __getOwnPropSymbols$n = Object.getOwnPropertySymbols;
|
|
868
|
+
var __hasOwnProp$n = Object.prototype.hasOwnProperty;
|
|
869
|
+
var __propIsEnum$n = Object.prototype.propertyIsEnumerable;
|
|
870
|
+
var __defNormalProp$m = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
871
|
+
var __spreadValues$m = (a, b) => {
|
|
872
|
+
for (var prop in b || (b = {}))
|
|
873
|
+
if (__hasOwnProp$n.call(b, prop))
|
|
874
|
+
__defNormalProp$m(a, prop, b[prop]);
|
|
875
|
+
if (__getOwnPropSymbols$n)
|
|
876
|
+
for (var prop of __getOwnPropSymbols$n(b)) {
|
|
877
|
+
if (__propIsEnum$n.call(b, prop))
|
|
878
|
+
__defNormalProp$m(a, prop, b[prop]);
|
|
879
|
+
}
|
|
880
|
+
return a;
|
|
881
|
+
};
|
|
882
|
+
var __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
|
|
883
|
+
const addColumnParserToQuery = (q, key, column) => {
|
|
884
|
+
var _a;
|
|
885
|
+
if (column._parse) {
|
|
886
|
+
((_a = q.parsers) != null ? _a : q.parsers = {})[key] = column._parse;
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
const setColumnDefaultParse = (column, parse) => {
|
|
890
|
+
column.data.parse = column.data.defaultParse = parse;
|
|
891
|
+
column._parse = (input) => input === null ? null : parse(input);
|
|
892
|
+
};
|
|
893
|
+
const setColumnParse = (column, fn, outputSchema) => {
|
|
894
|
+
const c = Object.create(column);
|
|
895
|
+
c.outputSchema = outputSchema;
|
|
896
|
+
c.data = __spreadProps$c(__spreadValues$m({}, column.data), { parse: fn });
|
|
897
|
+
const { parseNull } = column.data;
|
|
898
|
+
c._parse = parseNull ? (input) => input === null ? parseNull() : fn(input) : (input) => input === null ? null : fn(input);
|
|
899
|
+
return c;
|
|
900
|
+
};
|
|
901
|
+
const setColumnParseNull = (column, fn, nullSchema) => {
|
|
902
|
+
const c = Object.create(column);
|
|
903
|
+
c.nullSchema = nullSchema;
|
|
904
|
+
c.data = __spreadProps$c(__spreadValues$m({}, column.data), { parseNull: fn });
|
|
905
|
+
const { parse } = column.data;
|
|
906
|
+
c._parse = parse ? (input) => input === null ? fn() : parse(input) : (input) => input === null ? fn() : input;
|
|
907
|
+
return c;
|
|
908
|
+
};
|
|
909
|
+
const setColumnEncode = (column, fn, inputSchema) => {
|
|
910
|
+
const c = Object.create(column);
|
|
911
|
+
c.inputSchema = inputSchema;
|
|
912
|
+
c.data = __spreadProps$c(__spreadValues$m({}, column.data), { encode: fn });
|
|
913
|
+
return c;
|
|
914
|
+
};
|
|
915
|
+
|
|
916
|
+
var __defProp$l = Object.defineProperty;
|
|
862
917
|
var __defProps$b = Object.defineProperties;
|
|
863
918
|
var __getOwnPropDescs$b = Object.getOwnPropertyDescriptors;
|
|
864
|
-
var __getOwnPropSymbols$
|
|
865
|
-
var __hasOwnProp$
|
|
866
|
-
var __propIsEnum$
|
|
867
|
-
var __defNormalProp$
|
|
868
|
-
var __spreadValues$
|
|
919
|
+
var __getOwnPropSymbols$m = Object.getOwnPropertySymbols;
|
|
920
|
+
var __hasOwnProp$m = Object.prototype.hasOwnProperty;
|
|
921
|
+
var __propIsEnum$m = Object.prototype.propertyIsEnumerable;
|
|
922
|
+
var __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
923
|
+
var __spreadValues$l = (a, b) => {
|
|
869
924
|
for (var prop in b || (b = {}))
|
|
870
|
-
if (__hasOwnProp$
|
|
871
|
-
__defNormalProp$
|
|
872
|
-
if (__getOwnPropSymbols$
|
|
873
|
-
for (var prop of __getOwnPropSymbols$
|
|
874
|
-
if (__propIsEnum$
|
|
875
|
-
__defNormalProp$
|
|
925
|
+
if (__hasOwnProp$m.call(b, prop))
|
|
926
|
+
__defNormalProp$l(a, prop, b[prop]);
|
|
927
|
+
if (__getOwnPropSymbols$m)
|
|
928
|
+
for (var prop of __getOwnPropSymbols$m(b)) {
|
|
929
|
+
if (__propIsEnum$m.call(b, prop))
|
|
930
|
+
__defNormalProp$l(a, prop, b[prop]);
|
|
876
931
|
}
|
|
877
932
|
return a;
|
|
878
933
|
};
|
|
@@ -965,7 +1020,7 @@ const base = {
|
|
|
965
1020
|
(key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteValue(value, ctx, quotedAs)}`
|
|
966
1021
|
)
|
|
967
1022
|
};
|
|
968
|
-
const boolean = __spreadProps$b(__spreadValues$
|
|
1023
|
+
const boolean = __spreadProps$b(__spreadValues$l({}, base), {
|
|
969
1024
|
and: make(
|
|
970
1025
|
(key, value, ctx, quotedAs) => `${key} AND ${value.q.expr.toSQL(ctx, quotedAs)}`
|
|
971
1026
|
),
|
|
@@ -973,7 +1028,7 @@ const boolean = __spreadProps$b(__spreadValues$k({}, base), {
|
|
|
973
1028
|
(key, value, ctx, quotedAs) => `(${key}) OR (${value.q.expr.toSQL(ctx, quotedAs)})`
|
|
974
1029
|
)
|
|
975
1030
|
});
|
|
976
|
-
const numeric = __spreadProps$b(__spreadValues$
|
|
1031
|
+
const numeric = __spreadProps$b(__spreadValues$l({}, base), {
|
|
977
1032
|
lt: make(
|
|
978
1033
|
(key, value, ctx, quotedAs) => `${key} < ${quoteValue(value, ctx, quotedAs)}`
|
|
979
1034
|
),
|
|
@@ -994,7 +1049,7 @@ const numeric = __spreadProps$b(__spreadValues$k({}, base), {
|
|
|
994
1049
|
)}`
|
|
995
1050
|
)
|
|
996
1051
|
});
|
|
997
|
-
const text = __spreadProps$b(__spreadValues$
|
|
1052
|
+
const text = __spreadProps$b(__spreadValues$l({}, base), {
|
|
998
1053
|
contains: make(
|
|
999
1054
|
(key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)} || '%'`
|
|
1000
1055
|
),
|
|
@@ -1016,10 +1071,10 @@ const text = __spreadProps$b(__spreadValues$k({}, base), {
|
|
|
1016
1071
|
});
|
|
1017
1072
|
const encodeJsonPath = (ctx, path) => orchidCore.addValue(ctx.values, `{${Array.isArray(path) ? path.join(", ") : path}}`);
|
|
1018
1073
|
const jsonPathQueryOp = (key, [path, options], ctx) => `jsonb_path_query_first(${key}, ${orchidCore.addValue(ctx.values, path)}${(options == null ? void 0 : options.vars) ? `, ${orchidCore.addValue(ctx.values, JSON.stringify(options.vars))}${options.silent ? ", true" : ""}` : (options == null ? void 0 : options.silent) ? ", NULL, true" : ""})`;
|
|
1019
|
-
const json = __spreadProps$b(__spreadValues$
|
|
1074
|
+
const json = __spreadProps$b(__spreadValues$l({}, base), {
|
|
1020
1075
|
jsonPathQueryFirst: Object.assign(
|
|
1021
1076
|
function(path, options) {
|
|
1022
|
-
var _a, _b, _c
|
|
1077
|
+
var _a, _b, _c;
|
|
1023
1078
|
const chain = (_b = (_a = this.q).chain) != null ? _b : _a.chain = [];
|
|
1024
1079
|
chain.push(jsonPathQueryOp, [path, options]);
|
|
1025
1080
|
if ((_c = this.q.parsers) == null ? void 0 : _c[orchidCore.getValueKey]) {
|
|
@@ -1027,8 +1082,7 @@ const json = __spreadProps$b(__spreadValues$k({}, base), {
|
|
|
1027
1082
|
}
|
|
1028
1083
|
if (options == null ? void 0 : options.type) {
|
|
1029
1084
|
const type = options.type(this.columnTypes);
|
|
1030
|
-
|
|
1031
|
-
((_e = (_d = this.q).parsers) != null ? _e : _d.parsers = {})[orchidCore.getValueKey] = type.parseFn;
|
|
1085
|
+
addColumnParserToQuery(this.q, orchidCore.getValueKey, type);
|
|
1032
1086
|
chain.push = (...args) => {
|
|
1033
1087
|
chain.push = Array.prototype.push;
|
|
1034
1088
|
chain.push((s) => `${s}::${type.dataType}`, orchidCore.emptyArray);
|
|
@@ -1079,25 +1133,22 @@ const Operators = {
|
|
|
1079
1133
|
array: base
|
|
1080
1134
|
};
|
|
1081
1135
|
|
|
1082
|
-
var __defProp$
|
|
1083
|
-
var
|
|
1084
|
-
var
|
|
1085
|
-
var
|
|
1086
|
-
var
|
|
1087
|
-
var
|
|
1088
|
-
var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1089
|
-
var __spreadValues$j = (a, b) => {
|
|
1136
|
+
var __defProp$k = Object.defineProperty;
|
|
1137
|
+
var __getOwnPropSymbols$l = Object.getOwnPropertySymbols;
|
|
1138
|
+
var __hasOwnProp$l = Object.prototype.hasOwnProperty;
|
|
1139
|
+
var __propIsEnum$l = Object.prototype.propertyIsEnumerable;
|
|
1140
|
+
var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1141
|
+
var __spreadValues$k = (a, b) => {
|
|
1090
1142
|
for (var prop in b || (b = {}))
|
|
1091
|
-
if (__hasOwnProp$
|
|
1092
|
-
__defNormalProp$
|
|
1093
|
-
if (__getOwnPropSymbols$
|
|
1094
|
-
for (var prop of __getOwnPropSymbols$
|
|
1095
|
-
if (__propIsEnum$
|
|
1096
|
-
__defNormalProp$
|
|
1143
|
+
if (__hasOwnProp$l.call(b, prop))
|
|
1144
|
+
__defNormalProp$k(a, prop, b[prop]);
|
|
1145
|
+
if (__getOwnPropSymbols$l)
|
|
1146
|
+
for (var prop of __getOwnPropSymbols$l(b)) {
|
|
1147
|
+
if (__propIsEnum$l.call(b, prop))
|
|
1148
|
+
__defNormalProp$k(a, prop, b[prop]);
|
|
1097
1149
|
}
|
|
1098
1150
|
return a;
|
|
1099
1151
|
};
|
|
1100
|
-
var __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
|
|
1101
1152
|
class TextBaseColumn extends ColumnType {
|
|
1102
1153
|
constructor(schema, schemaType = schema.stringSchema()) {
|
|
1103
1154
|
super(schema, schemaType);
|
|
@@ -1151,7 +1202,7 @@ class StringColumn extends VarCharColumn {
|
|
|
1151
1202
|
}
|
|
1152
1203
|
}
|
|
1153
1204
|
const textColumnToCode = (column, ctx, key) => {
|
|
1154
|
-
const data = __spreadValues$
|
|
1205
|
+
const data = __spreadValues$k({}, column.data);
|
|
1155
1206
|
let args = "";
|
|
1156
1207
|
const hasMax = data.maxArg !== void 0 && data.max === data.maxArg;
|
|
1157
1208
|
if (data.minArg !== void 0 && data.min === data.minArg || hasMax) {
|
|
@@ -1267,19 +1318,20 @@ class MoneyColumn extends ColumnType {
|
|
|
1267
1318
|
super(schema, schema.number());
|
|
1268
1319
|
this.dataType = "money";
|
|
1269
1320
|
this.operators = Operators.number;
|
|
1270
|
-
this
|
|
1271
|
-
function(input) {
|
|
1272
|
-
return input === null ? input : parseFloat(input.replace(/,/g, "").replace(/\$/g, ""));
|
|
1273
|
-
},
|
|
1274
|
-
{
|
|
1275
|
-
hideFromCode: true
|
|
1276
|
-
}
|
|
1277
|
-
);
|
|
1321
|
+
setColumnDefaultParse(this, moneyParse);
|
|
1278
1322
|
}
|
|
1279
1323
|
toCode(ctx, key) {
|
|
1280
1324
|
return columnCode(this, ctx, key, `money()`);
|
|
1281
1325
|
}
|
|
1282
1326
|
}
|
|
1327
|
+
const moneyParse = Object.assign(
|
|
1328
|
+
function(input) {
|
|
1329
|
+
return input === null ? input : parseFloat(input.replace(/,/g, "").replace(/\$/g, ""));
|
|
1330
|
+
},
|
|
1331
|
+
{
|
|
1332
|
+
hideFromCode: true
|
|
1333
|
+
}
|
|
1334
|
+
);
|
|
1283
1335
|
class CidrColumn extends ColumnType {
|
|
1284
1336
|
constructor(schema) {
|
|
1285
1337
|
super(schema, schema.stringSchema());
|
|
@@ -1438,6 +1490,7 @@ class UUIDColumn extends ColumnType {
|
|
|
1438
1490
|
super(schema, schema.uuid());
|
|
1439
1491
|
this.dataType = "uuid";
|
|
1440
1492
|
this.operators = Operators.text;
|
|
1493
|
+
this.data.defaultDefault = uuidDefault;
|
|
1441
1494
|
}
|
|
1442
1495
|
/**
|
|
1443
1496
|
* see {@link ColumnType.primaryKey}
|
|
@@ -1449,15 +1502,7 @@ class UUIDColumn extends ColumnType {
|
|
|
1449
1502
|
return column;
|
|
1450
1503
|
}
|
|
1451
1504
|
toCode(ctx, key) {
|
|
1452
|
-
|
|
1453
|
-
return columnCode(
|
|
1454
|
-
this,
|
|
1455
|
-
ctx,
|
|
1456
|
-
key,
|
|
1457
|
-
`uuid()`,
|
|
1458
|
-
// don't output the default default
|
|
1459
|
-
data.default instanceof orchidCore.RawSQLBase && data.default._sql === uuidDefaultSQL ? __spreadProps$a(__spreadValues$j({}, data), { default: void 0 }) : data
|
|
1460
|
-
);
|
|
1505
|
+
return columnCode(this, ctx, key, `uuid()`);
|
|
1461
1506
|
}
|
|
1462
1507
|
}
|
|
1463
1508
|
class XMLColumn extends ColumnType {
|
|
@@ -1484,7 +1529,6 @@ class CitextColumn extends TextBaseColumn {
|
|
|
1484
1529
|
const dateTimeEncode = (input) => {
|
|
1485
1530
|
return typeof input === "number" ? new Date(input) : input;
|
|
1486
1531
|
};
|
|
1487
|
-
const skipDateMethodsFromToCode = { encodeFn: dateTimeEncode };
|
|
1488
1532
|
class DateBaseColumn extends ColumnType {
|
|
1489
1533
|
constructor(schema) {
|
|
1490
1534
|
super(
|
|
@@ -1494,9 +1538,9 @@ class DateBaseColumn extends ColumnType {
|
|
|
1494
1538
|
schema.stringNumberDate()
|
|
1495
1539
|
);
|
|
1496
1540
|
this.operators = Operators.date;
|
|
1497
|
-
this.encodeFn = dateTimeEncode;
|
|
1498
1541
|
this.asNumber = schema.dateAsNumber;
|
|
1499
1542
|
this.asDate = schema.dateAsDate;
|
|
1543
|
+
this.data.encode = this.data.defaultEncode = dateTimeEncode;
|
|
1500
1544
|
}
|
|
1501
1545
|
}
|
|
1502
1546
|
class DateColumn extends DateBaseColumn {
|
|
@@ -1509,9 +1553,7 @@ class DateColumn extends DateBaseColumn {
|
|
|
1509
1553
|
this,
|
|
1510
1554
|
ctx,
|
|
1511
1555
|
key,
|
|
1512
|
-
`date()${orchidCore.dateDataToCode(this.data, ctx.migration)}
|
|
1513
|
-
this.data,
|
|
1514
|
-
skipDateMethodsFromToCode
|
|
1556
|
+
`date()${orchidCore.dateDataToCode(this.data, ctx.migration)}`
|
|
1515
1557
|
);
|
|
1516
1558
|
}
|
|
1517
1559
|
}
|
|
@@ -1549,9 +1591,7 @@ const timestampToCode = (self, ctx, key) => {
|
|
|
1549
1591
|
self,
|
|
1550
1592
|
ctx,
|
|
1551
1593
|
key,
|
|
1552
|
-
`timestamps${noTz}(${p && p !== 6 ? p : ""}).${defaultTimestamp}${orchidCore.dateDataToCode(self.data, ctx.migration)}
|
|
1553
|
-
self.data,
|
|
1554
|
-
skipDateMethodsFromToCode
|
|
1594
|
+
`timestamps${noTz}(${p && p !== 6 ? p : ""}).${defaultTimestamp}${orchidCore.dateDataToCode(self.data, ctx.migration)}`
|
|
1555
1595
|
);
|
|
1556
1596
|
self.data.default = def;
|
|
1557
1597
|
self.data.modifyQuery = modifyQuery;
|
|
@@ -1561,9 +1601,7 @@ const timestampToCode = (self, ctx, key) => {
|
|
|
1561
1601
|
self,
|
|
1562
1602
|
ctx,
|
|
1563
1603
|
key,
|
|
1564
|
-
`${self instanceof TimestampColumn ? "timestampNoTZ" : "timestamp"}(${p && p !== 6 ? p : ""})${orchidCore.dateDataToCode(self.data, ctx.migration)}
|
|
1565
|
-
self.data,
|
|
1566
|
-
skipDateMethodsFromToCode
|
|
1604
|
+
`${self instanceof TimestampColumn ? "timestampNoTZ" : "timestamp"}(${p && p !== 6 ? p : ""})${orchidCore.dateDataToCode(self.data, ctx.migration)}`
|
|
1567
1605
|
);
|
|
1568
1606
|
}
|
|
1569
1607
|
};
|
|
@@ -1602,9 +1640,7 @@ class TimeColumn extends ColumnType {
|
|
|
1602
1640
|
`time(${dateTimePrecision || ""})${orchidCore.dateDataToCode(
|
|
1603
1641
|
this.data,
|
|
1604
1642
|
ctx.migration
|
|
1605
|
-
)}
|
|
1606
|
-
this.data,
|
|
1607
|
-
skipDateMethodsFromToCode
|
|
1643
|
+
)}`
|
|
1608
1644
|
);
|
|
1609
1645
|
}
|
|
1610
1646
|
}
|
|
@@ -1622,9 +1658,7 @@ class IntervalColumn extends ColumnType {
|
|
|
1622
1658
|
this,
|
|
1623
1659
|
ctx,
|
|
1624
1660
|
key,
|
|
1625
|
-
`interval(${[fields && `'${fields}'`, precision && String(precision)].filter((part) => part).join(", ")})
|
|
1626
|
-
this.data,
|
|
1627
|
-
skipDateMethodsFromToCode
|
|
1661
|
+
`interval(${[fields && `'${fields}'`, precision && String(precision)].filter((part) => part).join(", ")})`
|
|
1628
1662
|
);
|
|
1629
1663
|
}
|
|
1630
1664
|
toSQL() {
|
|
@@ -1642,28 +1676,26 @@ class BooleanColumn extends ColumnType {
|
|
|
1642
1676
|
this.dataType = "bool";
|
|
1643
1677
|
this.operators = Operators.boolean;
|
|
1644
1678
|
this.data.alias = "boolean";
|
|
1679
|
+
this.data.parseItem = parseItem;
|
|
1645
1680
|
}
|
|
1646
1681
|
toCode(ctx, key) {
|
|
1647
1682
|
return columnCode(this, ctx, key, "boolean()");
|
|
1648
1683
|
}
|
|
1649
|
-
parseItem(input) {
|
|
1650
|
-
return input[0] === "t";
|
|
1651
|
-
}
|
|
1652
1684
|
}
|
|
1685
|
+
const parseItem = (input) => input[0] === "t";
|
|
1653
1686
|
|
|
1654
|
-
const
|
|
1655
|
-
const toCodeSkip = { encodeFn };
|
|
1687
|
+
const encode = (x) => x === null ? x : JSON.stringify(x);
|
|
1656
1688
|
class JSONColumn extends ColumnType {
|
|
1657
|
-
constructor() {
|
|
1658
|
-
super(
|
|
1689
|
+
constructor(schema, inputType) {
|
|
1690
|
+
super(schema, inputType);
|
|
1659
1691
|
this.dataType = "jsonb";
|
|
1660
1692
|
this.operators = Operators.json;
|
|
1693
|
+
this.data.encode = this.data.defaultEncode = encode;
|
|
1661
1694
|
}
|
|
1662
1695
|
toCode(ctx, key) {
|
|
1663
|
-
return columnCode(this, ctx, key, `json()
|
|
1696
|
+
return columnCode(this, ctx, key, `json()`);
|
|
1664
1697
|
}
|
|
1665
1698
|
}
|
|
1666
|
-
JSONColumn.prototype.encodeFn = encodeFn;
|
|
1667
1699
|
class JSONTextColumn extends ColumnType {
|
|
1668
1700
|
constructor(schema) {
|
|
1669
1701
|
super(schema, schema.stringSchema());
|
|
@@ -1671,7 +1703,7 @@ class JSONTextColumn extends ColumnType {
|
|
|
1671
1703
|
this.operators = Operators.text;
|
|
1672
1704
|
}
|
|
1673
1705
|
toCode(ctx, key) {
|
|
1674
|
-
return columnCode(this, ctx, key, `jsonText()
|
|
1706
|
+
return columnCode(this, ctx, key, `jsonText()`);
|
|
1675
1707
|
}
|
|
1676
1708
|
}
|
|
1677
1709
|
|
|
@@ -1684,10 +1716,7 @@ const queryTypeWithLimitOne = {
|
|
|
1684
1716
|
const isQueryReturnsAll = (q) => !q.q.returnType || q.q.returnType === "all";
|
|
1685
1717
|
|
|
1686
1718
|
const applySqlComputed = (ctx, q, computed, as, quotedAs) => {
|
|
1687
|
-
|
|
1688
|
-
const parser = computed.result.value.parseFn;
|
|
1689
|
-
if (parser)
|
|
1690
|
-
((_a = q.parsers) != null ? _a : q.parsers = {})[as] = parser;
|
|
1719
|
+
addColumnParserToQuery(q, as, computed.result.value);
|
|
1691
1720
|
return computed.toSQL(ctx, quotedAs);
|
|
1692
1721
|
};
|
|
1693
1722
|
function simpleColumnToSQL(ctx, q, key, column, quotedAs) {
|
|
@@ -1747,7 +1776,7 @@ const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) =
|
|
|
1747
1776
|
if (key === "*") {
|
|
1748
1777
|
return ((_a = data.joinedShapes) == null ? void 0 : _a[table]) ? select ? `row_to_json("${table}".*)` : `"${table}".*` : column;
|
|
1749
1778
|
}
|
|
1750
|
-
const tableName = ((_b = data.
|
|
1779
|
+
const tableName = ((_b = data.aliases) == null ? void 0 : _b[table]) || table;
|
|
1751
1780
|
const quoted = `"${table}"`;
|
|
1752
1781
|
const col = quoted === quotedAs ? shape[key] : (_d = (_c = data.joinedShapes) == null ? void 0 : _c[tableName]) == null ? void 0 : _d[key];
|
|
1753
1782
|
if (col) {
|
|
@@ -1798,7 +1827,7 @@ const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, sel
|
|
|
1798
1827
|
}
|
|
1799
1828
|
return column;
|
|
1800
1829
|
}
|
|
1801
|
-
const tableName = ((_b = data.
|
|
1830
|
+
const tableName = ((_b = data.aliases) == null ? void 0 : _b[table]) || table;
|
|
1802
1831
|
const quoted = `"${table}"`;
|
|
1803
1832
|
const col = quoted === quotedAs ? data.shape[key] : (_c = data.joinedShapes) == null ? void 0 : _c[tableName][key];
|
|
1804
1833
|
if (col) {
|
|
@@ -2139,9 +2168,9 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
|
|
|
2139
2168
|
const item = value;
|
|
2140
2169
|
const joinAs = `"${getJoinItemSource(item.joinFrom)}"`;
|
|
2141
2170
|
const { on } = item;
|
|
2142
|
-
const q = item.
|
|
2171
|
+
const q = item.useOuterAliases ? {
|
|
2143
2172
|
joinedShapes: query.joinedShapes,
|
|
2144
|
-
|
|
2173
|
+
aliases: query.outerAliases,
|
|
2145
2174
|
shape: query.shape
|
|
2146
2175
|
} : query;
|
|
2147
2176
|
ands.push(
|
|
@@ -2269,25 +2298,25 @@ const pushIn = (ctx, query, ands, quotedAs, arg) => {
|
|
|
2269
2298
|
ands.push(`${multiple ? `(${columnsSql})` : columnsSql} IN ${value}`);
|
|
2270
2299
|
};
|
|
2271
2300
|
|
|
2272
|
-
var __defProp$
|
|
2273
|
-
var __defProps$
|
|
2274
|
-
var __getOwnPropDescs$
|
|
2275
|
-
var __getOwnPropSymbols$
|
|
2276
|
-
var __hasOwnProp$
|
|
2277
|
-
var __propIsEnum$
|
|
2278
|
-
var __defNormalProp$
|
|
2279
|
-
var __spreadValues$
|
|
2301
|
+
var __defProp$j = Object.defineProperty;
|
|
2302
|
+
var __defProps$a = Object.defineProperties;
|
|
2303
|
+
var __getOwnPropDescs$a = Object.getOwnPropertyDescriptors;
|
|
2304
|
+
var __getOwnPropSymbols$k = Object.getOwnPropertySymbols;
|
|
2305
|
+
var __hasOwnProp$k = Object.prototype.hasOwnProperty;
|
|
2306
|
+
var __propIsEnum$k = Object.prototype.propertyIsEnumerable;
|
|
2307
|
+
var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2308
|
+
var __spreadValues$j = (a, b) => {
|
|
2280
2309
|
for (var prop in b || (b = {}))
|
|
2281
|
-
if (__hasOwnProp$
|
|
2282
|
-
__defNormalProp$
|
|
2283
|
-
if (__getOwnPropSymbols$
|
|
2284
|
-
for (var prop of __getOwnPropSymbols$
|
|
2285
|
-
if (__propIsEnum$
|
|
2286
|
-
__defNormalProp$
|
|
2310
|
+
if (__hasOwnProp$k.call(b, prop))
|
|
2311
|
+
__defNormalProp$j(a, prop, b[prop]);
|
|
2312
|
+
if (__getOwnPropSymbols$k)
|
|
2313
|
+
for (var prop of __getOwnPropSymbols$k(b)) {
|
|
2314
|
+
if (__propIsEnum$k.call(b, prop))
|
|
2315
|
+
__defNormalProp$j(a, prop, b[prop]);
|
|
2287
2316
|
}
|
|
2288
2317
|
return a;
|
|
2289
2318
|
};
|
|
2290
|
-
var __spreadProps$
|
|
2319
|
+
var __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
|
|
2291
2320
|
const processJoinItem = (ctx, table, query, args, quotedAs) => {
|
|
2292
2321
|
let target;
|
|
2293
2322
|
let on;
|
|
@@ -2349,8 +2378,8 @@ const processJoinItem = (ctx, table, query, args, quotedAs) => {
|
|
|
2349
2378
|
const whereSql = whereToSql(
|
|
2350
2379
|
ctx,
|
|
2351
2380
|
q,
|
|
2352
|
-
__spreadProps$
|
|
2353
|
-
joinedShapes: __spreadProps$
|
|
2381
|
+
__spreadProps$a(__spreadValues$j({}, q.q), {
|
|
2382
|
+
joinedShapes: __spreadProps$a(__spreadValues$j(__spreadValues$j({}, query.joinedShapes), q.q.joinedShapes), {
|
|
2354
2383
|
[table.q.as || table.table]: table.q.shape
|
|
2355
2384
|
})
|
|
2356
2385
|
}),
|
|
@@ -2453,7 +2482,7 @@ const pushJoinSql = (ctx, table, query, quotedAs) => {
|
|
|
2453
2482
|
const { aliasValue } = ctx;
|
|
2454
2483
|
ctx.aliasValue = true;
|
|
2455
2484
|
const as = item[2];
|
|
2456
|
-
sql = `${item[0]} LATERAL (${getSqlText(q.toSQL(ctx))}) "${((_a = query.
|
|
2485
|
+
sql = `${item[0]} LATERAL (${getSqlText(q.toSQL(ctx))}) "${((_a = query.aliases) == null ? void 0 : _a[as]) || as}" ON true`;
|
|
2457
2486
|
ctx.aliasValue = aliasValue;
|
|
2458
2487
|
} else {
|
|
2459
2488
|
const { target, on = "true" } = processJoinItem(
|
|
@@ -2482,7 +2511,8 @@ const skipQueryKeysForSubQuery = {
|
|
|
2482
2511
|
or: true,
|
|
2483
2512
|
returnType: true,
|
|
2484
2513
|
joinedShapes: true,
|
|
2485
|
-
returnsOne: true
|
|
2514
|
+
returnsOne: true,
|
|
2515
|
+
aliases: true
|
|
2486
2516
|
};
|
|
2487
2517
|
const getIsJoinSubQuery = (query) => {
|
|
2488
2518
|
const {
|
|
@@ -2497,25 +2527,25 @@ const getIsJoinSubQuery = (query) => {
|
|
|
2497
2527
|
return false;
|
|
2498
2528
|
};
|
|
2499
2529
|
|
|
2500
|
-
var __defProp$
|
|
2501
|
-
var __defProps$
|
|
2502
|
-
var __getOwnPropDescs$
|
|
2503
|
-
var __getOwnPropSymbols$
|
|
2504
|
-
var __hasOwnProp$
|
|
2505
|
-
var __propIsEnum$
|
|
2506
|
-
var __defNormalProp$
|
|
2507
|
-
var __spreadValues$
|
|
2530
|
+
var __defProp$i = Object.defineProperty;
|
|
2531
|
+
var __defProps$9 = Object.defineProperties;
|
|
2532
|
+
var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
|
|
2533
|
+
var __getOwnPropSymbols$j = Object.getOwnPropertySymbols;
|
|
2534
|
+
var __hasOwnProp$j = Object.prototype.hasOwnProperty;
|
|
2535
|
+
var __propIsEnum$j = Object.prototype.propertyIsEnumerable;
|
|
2536
|
+
var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2537
|
+
var __spreadValues$i = (a, b) => {
|
|
2508
2538
|
for (var prop in b || (b = {}))
|
|
2509
|
-
if (__hasOwnProp$
|
|
2510
|
-
__defNormalProp$
|
|
2511
|
-
if (__getOwnPropSymbols$
|
|
2512
|
-
for (var prop of __getOwnPropSymbols$
|
|
2513
|
-
if (__propIsEnum$
|
|
2514
|
-
__defNormalProp$
|
|
2539
|
+
if (__hasOwnProp$j.call(b, prop))
|
|
2540
|
+
__defNormalProp$i(a, prop, b[prop]);
|
|
2541
|
+
if (__getOwnPropSymbols$j)
|
|
2542
|
+
for (var prop of __getOwnPropSymbols$j(b)) {
|
|
2543
|
+
if (__propIsEnum$j.call(b, prop))
|
|
2544
|
+
__defNormalProp$i(a, prop, b[prop]);
|
|
2515
2545
|
}
|
|
2516
2546
|
return a;
|
|
2517
2547
|
};
|
|
2518
|
-
var __spreadProps$
|
|
2548
|
+
var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
|
|
2519
2549
|
const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
|
|
2520
2550
|
var _a;
|
|
2521
2551
|
if (typeof first === "string") {
|
|
@@ -2552,13 +2582,13 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
|
|
|
2552
2582
|
logger: joinToQ.logger
|
|
2553
2583
|
};
|
|
2554
2584
|
j.baseQuery = j;
|
|
2555
|
-
const joinedShapes = __spreadProps$
|
|
2585
|
+
const joinedShapes = __spreadProps$9(__spreadValues$i({}, joinToQ.joinedShapes), {
|
|
2556
2586
|
[joinToQ.as || joinTo.table]: joinTo.shape
|
|
2557
2587
|
});
|
|
2558
2588
|
const r = args[0](
|
|
2559
2589
|
makeJoinQueryBuilder(
|
|
2560
2590
|
j,
|
|
2561
|
-
j.q.joinedShapes ? __spreadValues$
|
|
2591
|
+
j.q.joinedShapes ? __spreadValues$i(__spreadValues$i({}, j.q.joinedShapes), joinedShapes) : joinedShapes,
|
|
2562
2592
|
joinTo
|
|
2563
2593
|
)
|
|
2564
2594
|
);
|
|
@@ -2585,16 +2615,16 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
|
|
|
2585
2615
|
pushQueryArray(q, "or", query.or);
|
|
2586
2616
|
}
|
|
2587
2617
|
if (query.scopes) {
|
|
2588
|
-
q.q.scopes = __spreadValues$
|
|
2618
|
+
q.q.scopes = __spreadValues$i(__spreadValues$i({}, q.q.scopes), query.scopes);
|
|
2589
2619
|
}
|
|
2590
2620
|
}
|
|
2591
|
-
const joinedShapes = __spreadProps$
|
|
2621
|
+
const joinedShapes = __spreadProps$9(__spreadValues$i({}, joinTo.q.joinedShapes), {
|
|
2592
2622
|
[joinTo.q.as || joinTo.table]: joinTo.shape
|
|
2593
2623
|
});
|
|
2594
2624
|
const r = args0(
|
|
2595
2625
|
makeJoinQueryBuilder(
|
|
2596
2626
|
q,
|
|
2597
|
-
q.q.joinedShapes ? __spreadValues$
|
|
2627
|
+
q.q.joinedShapes ? __spreadValues$i(__spreadValues$i({}, q.q.joinedShapes), joinedShapes) : joinedShapes,
|
|
2598
2628
|
joinTo
|
|
2599
2629
|
)
|
|
2600
2630
|
);
|
|
@@ -2649,25 +2679,25 @@ const _queryNone = (q) => {
|
|
|
2649
2679
|
};
|
|
2650
2680
|
const isQueryNone = (q) => q.then === noneMethods.then;
|
|
2651
2681
|
|
|
2652
|
-
var __defProp$
|
|
2653
|
-
var __defProps$
|
|
2654
|
-
var __getOwnPropDescs$
|
|
2655
|
-
var __getOwnPropSymbols$
|
|
2656
|
-
var __hasOwnProp$
|
|
2657
|
-
var __propIsEnum$
|
|
2658
|
-
var __defNormalProp$
|
|
2659
|
-
var __spreadValues$
|
|
2682
|
+
var __defProp$h = Object.defineProperty;
|
|
2683
|
+
var __defProps$8 = Object.defineProperties;
|
|
2684
|
+
var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
|
|
2685
|
+
var __getOwnPropSymbols$i = Object.getOwnPropertySymbols;
|
|
2686
|
+
var __hasOwnProp$i = Object.prototype.hasOwnProperty;
|
|
2687
|
+
var __propIsEnum$i = Object.prototype.propertyIsEnumerable;
|
|
2688
|
+
var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2689
|
+
var __spreadValues$h = (a, b) => {
|
|
2660
2690
|
for (var prop in b || (b = {}))
|
|
2661
|
-
if (__hasOwnProp$
|
|
2662
|
-
__defNormalProp$
|
|
2663
|
-
if (__getOwnPropSymbols$
|
|
2664
|
-
for (var prop of __getOwnPropSymbols$
|
|
2665
|
-
if (__propIsEnum$
|
|
2666
|
-
__defNormalProp$
|
|
2691
|
+
if (__hasOwnProp$i.call(b, prop))
|
|
2692
|
+
__defNormalProp$h(a, prop, b[prop]);
|
|
2693
|
+
if (__getOwnPropSymbols$i)
|
|
2694
|
+
for (var prop of __getOwnPropSymbols$i(b)) {
|
|
2695
|
+
if (__propIsEnum$i.call(b, prop))
|
|
2696
|
+
__defNormalProp$h(a, prop, b[prop]);
|
|
2667
2697
|
}
|
|
2668
2698
|
return a;
|
|
2669
2699
|
};
|
|
2670
|
-
var __spreadProps$
|
|
2700
|
+
var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
|
|
2671
2701
|
const _join = (query, require2, type, first, args) => {
|
|
2672
2702
|
var _a, _b, _c, _d;
|
|
2673
2703
|
let joinKey;
|
|
@@ -2709,13 +2739,10 @@ const _join = (query, require2, type, first, args) => {
|
|
|
2709
2739
|
computeds = w == null ? void 0 : w.computeds;
|
|
2710
2740
|
if (shape) {
|
|
2711
2741
|
if (!require2)
|
|
2712
|
-
shape = __spreadValues$
|
|
2713
|
-
|
|
2742
|
+
shape = __spreadValues$h({}, shape);
|
|
2743
|
+
const arg = { parsers: {} };
|
|
2714
2744
|
for (const key in shape) {
|
|
2715
|
-
|
|
2716
|
-
if (parser) {
|
|
2717
|
-
parsers[key] = parser;
|
|
2718
|
-
}
|
|
2745
|
+
addColumnParserToQuery(arg, key, shape[key]);
|
|
2719
2746
|
}
|
|
2720
2747
|
}
|
|
2721
2748
|
}
|
|
@@ -2813,7 +2840,7 @@ const _joinLateral = (self, type, arg, cb, as) => {
|
|
|
2813
2840
|
t.table = arg;
|
|
2814
2841
|
t.shape = w.shape;
|
|
2815
2842
|
t.computeds = w.computeds;
|
|
2816
|
-
t.q = __spreadProps$
|
|
2843
|
+
t.q = __spreadProps$8(__spreadValues$h({}, t.q), {
|
|
2817
2844
|
shape: w.shape
|
|
2818
2845
|
});
|
|
2819
2846
|
t.baseQuery = t;
|
|
@@ -2871,19 +2898,8 @@ class ArrayColumn extends ColumnType {
|
|
|
2871
2898
|
super(schema, inputType, outputType, queryType);
|
|
2872
2899
|
this.dataType = "array";
|
|
2873
2900
|
this.operators = Operators.array;
|
|
2874
|
-
this.parseFn = Object.assign(
|
|
2875
|
-
(source) => {
|
|
2876
|
-
if (!source)
|
|
2877
|
-
return source;
|
|
2878
|
-
const entries = [];
|
|
2879
|
-
parsePostgresArray(source, entries, this.data.item.parseItem);
|
|
2880
|
-
return entries;
|
|
2881
|
-
},
|
|
2882
|
-
{
|
|
2883
|
-
hideFromCode: true
|
|
2884
|
-
}
|
|
2885
|
-
);
|
|
2886
2901
|
item.data.isNullable = true;
|
|
2902
|
+
setColumnDefaultParse(this, (input) => parse.call(this, input));
|
|
2887
2903
|
this.data.item = item instanceof ArrayColumn ? item.data.item : item;
|
|
2888
2904
|
this.data.name = item.data.name;
|
|
2889
2905
|
this.data.arrayDims = item instanceof ArrayColumn ? item.data.arrayDims + 1 : 1;
|
|
@@ -2908,6 +2924,11 @@ class ArrayColumn extends ColumnType {
|
|
|
2908
2924
|
return columnCode(this, ctx, key, code);
|
|
2909
2925
|
}
|
|
2910
2926
|
}
|
|
2927
|
+
const parse = function(source) {
|
|
2928
|
+
const entries = [];
|
|
2929
|
+
parsePostgresArray(source, entries, this.data.item.data.parseItem);
|
|
2930
|
+
return entries;
|
|
2931
|
+
};
|
|
2911
2932
|
const parsePostgresArray = (source, entries, transform) => {
|
|
2912
2933
|
let pos = 0;
|
|
2913
2934
|
if (source[0] === "[") {
|
|
@@ -3025,8 +3046,8 @@ class SmallIntColumn extends IntegerBaseColumn {
|
|
|
3025
3046
|
constructor(schema) {
|
|
3026
3047
|
super(schema);
|
|
3027
3048
|
this.dataType = "int2";
|
|
3028
|
-
this.parseItem = parseInt;
|
|
3029
3049
|
this.data.alias = "smallint";
|
|
3050
|
+
this.data.parseItem = parseInt;
|
|
3030
3051
|
}
|
|
3031
3052
|
toCode(ctx, key) {
|
|
3032
3053
|
return intToCode(this, ctx, key, "smallint");
|
|
@@ -3039,8 +3060,8 @@ class IntegerColumn extends IntegerBaseColumn {
|
|
|
3039
3060
|
constructor(schema) {
|
|
3040
3061
|
super(schema);
|
|
3041
3062
|
this.dataType = "int4";
|
|
3042
|
-
this.parseItem = parseInt;
|
|
3043
3063
|
this.data.alias = "integer";
|
|
3064
|
+
this.data.parseItem = parseInt;
|
|
3044
3065
|
}
|
|
3045
3066
|
toCode(ctx, key) {
|
|
3046
3067
|
return intToCode(this, ctx, key, "integer");
|
|
@@ -3066,8 +3087,8 @@ class RealColumn extends NumberBaseColumn {
|
|
|
3066
3087
|
constructor(schema) {
|
|
3067
3088
|
super(schema, schema.number());
|
|
3068
3089
|
this.dataType = "float4";
|
|
3069
|
-
this.parseItem = parseFloat;
|
|
3070
3090
|
this.data.alias = "real";
|
|
3091
|
+
this.data.parseItem = parseFloat;
|
|
3071
3092
|
}
|
|
3072
3093
|
toCode(ctx, key) {
|
|
3073
3094
|
return columnCode(
|
|
@@ -3092,9 +3113,9 @@ class SmallSerialColumn extends IntegerBaseColumn {
|
|
|
3092
3113
|
constructor(schema) {
|
|
3093
3114
|
super(schema);
|
|
3094
3115
|
this.dataType = "int2";
|
|
3095
|
-
this.parseItem = parseInt;
|
|
3096
3116
|
this.data.int = true;
|
|
3097
3117
|
this.data.alias = "smallSerial";
|
|
3118
|
+
this.data.parseItem = parseInt;
|
|
3098
3119
|
}
|
|
3099
3120
|
toSQL() {
|
|
3100
3121
|
return "smallserial";
|
|
@@ -3116,9 +3137,9 @@ class SerialColumn extends IntegerBaseColumn {
|
|
|
3116
3137
|
constructor(schema) {
|
|
3117
3138
|
super(schema);
|
|
3118
3139
|
this.dataType = "int4";
|
|
3119
|
-
this.parseItem = parseInt;
|
|
3120
3140
|
this.data.int = true;
|
|
3121
3141
|
this.data.alias = "serial";
|
|
3142
|
+
this.data.parseItem = parseInt;
|
|
3122
3143
|
}
|
|
3123
3144
|
toSQL() {
|
|
3124
3145
|
return "serial";
|
|
@@ -3150,29 +3171,31 @@ class BigSerialColumn extends NumberAsStringBaseColumn {
|
|
|
3150
3171
|
}
|
|
3151
3172
|
}
|
|
3152
3173
|
|
|
3153
|
-
const
|
|
3154
|
-
const parseDateToDate = (value) => value ? new Date(value) : value;
|
|
3155
|
-
parseDateToNumber.hideFromCode = parseDateToDate.hideFromCode = true;
|
|
3174
|
+
const parseDateToDate = (value) => new Date(value);
|
|
3156
3175
|
const defaultSchemaConfig = {
|
|
3176
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3157
3177
|
parse(fn) {
|
|
3158
|
-
return
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3178
|
+
return setColumnParse(this, fn);
|
|
3179
|
+
},
|
|
3180
|
+
parseNull(fn) {
|
|
3181
|
+
return setColumnParseNull(this, fn);
|
|
3162
3182
|
},
|
|
3183
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3163
3184
|
encode(fn) {
|
|
3164
|
-
return
|
|
3165
|
-
encodeFn: fn
|
|
3166
|
-
});
|
|
3185
|
+
return orchidCore.setColumnData(this, "encode", fn);
|
|
3167
3186
|
},
|
|
3168
3187
|
asType() {
|
|
3169
3188
|
return this;
|
|
3170
3189
|
},
|
|
3171
3190
|
dateAsNumber() {
|
|
3172
|
-
|
|
3191
|
+
const c = this.parse(Date.parse);
|
|
3192
|
+
c.data.defaultParse = Date.parse;
|
|
3193
|
+
return c;
|
|
3173
3194
|
},
|
|
3174
3195
|
dateAsDate() {
|
|
3175
|
-
|
|
3196
|
+
const c = this.parse(parseDateToDate);
|
|
3197
|
+
c.data.defaultParse = parseDateToDate;
|
|
3198
|
+
return c;
|
|
3176
3199
|
},
|
|
3177
3200
|
enum(dataType, type) {
|
|
3178
3201
|
return new EnumColumn(defaultSchemaConfig, dataType, type, void 0);
|
|
@@ -3302,25 +3325,25 @@ class QueryLog {
|
|
|
3302
3325
|
}
|
|
3303
3326
|
}
|
|
3304
3327
|
|
|
3305
|
-
var __defProp$
|
|
3306
|
-
var __defProps$
|
|
3307
|
-
var __getOwnPropDescs$
|
|
3308
|
-
var __getOwnPropSymbols$
|
|
3309
|
-
var __hasOwnProp$
|
|
3310
|
-
var __propIsEnum$
|
|
3311
|
-
var __defNormalProp$
|
|
3312
|
-
var __spreadValues$
|
|
3328
|
+
var __defProp$g = Object.defineProperty;
|
|
3329
|
+
var __defProps$7 = Object.defineProperties;
|
|
3330
|
+
var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
|
|
3331
|
+
var __getOwnPropSymbols$h = Object.getOwnPropertySymbols;
|
|
3332
|
+
var __hasOwnProp$h = Object.prototype.hasOwnProperty;
|
|
3333
|
+
var __propIsEnum$h = Object.prototype.propertyIsEnumerable;
|
|
3334
|
+
var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3335
|
+
var __spreadValues$g = (a, b) => {
|
|
3313
3336
|
for (var prop in b || (b = {}))
|
|
3314
|
-
if (__hasOwnProp$
|
|
3315
|
-
__defNormalProp$
|
|
3316
|
-
if (__getOwnPropSymbols$
|
|
3317
|
-
for (var prop of __getOwnPropSymbols$
|
|
3318
|
-
if (__propIsEnum$
|
|
3319
|
-
__defNormalProp$
|
|
3337
|
+
if (__hasOwnProp$h.call(b, prop))
|
|
3338
|
+
__defNormalProp$g(a, prop, b[prop]);
|
|
3339
|
+
if (__getOwnPropSymbols$h)
|
|
3340
|
+
for (var prop of __getOwnPropSymbols$h(b)) {
|
|
3341
|
+
if (__propIsEnum$h.call(b, prop))
|
|
3342
|
+
__defNormalProp$g(a, prop, b[prop]);
|
|
3320
3343
|
}
|
|
3321
3344
|
return a;
|
|
3322
3345
|
};
|
|
3323
|
-
var __spreadProps$
|
|
3346
|
+
var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
|
|
3324
3347
|
const commitSql$1 = {
|
|
3325
3348
|
text: "COMMIT"
|
|
3326
3349
|
};
|
|
@@ -3485,7 +3508,7 @@ const runAfterCommit = async (afterCommit, result) => {
|
|
|
3485
3508
|
let r = 0;
|
|
3486
3509
|
for (let i = 0, len = afterCommit.length; i < len; i += 3) {
|
|
3487
3510
|
for (const fn of afterCommit[i + 2]) {
|
|
3488
|
-
resultsWithNames.push(__spreadProps$
|
|
3511
|
+
resultsWithNames.push(__spreadProps$7(__spreadValues$g({}, hookResults[r++]), {
|
|
3489
3512
|
name: fn.name
|
|
3490
3513
|
}));
|
|
3491
3514
|
}
|
|
@@ -3547,25 +3570,25 @@ const finalizeNestedHookSelect = (batches, returnType, tempColumns, renames, key
|
|
|
3547
3570
|
}
|
|
3548
3571
|
};
|
|
3549
3572
|
|
|
3550
|
-
var __defProp$
|
|
3551
|
-
var __defProps$
|
|
3552
|
-
var __getOwnPropDescs$
|
|
3553
|
-
var __getOwnPropSymbols$
|
|
3554
|
-
var __hasOwnProp$
|
|
3555
|
-
var __propIsEnum$
|
|
3556
|
-
var __defNormalProp$
|
|
3557
|
-
var __spreadValues$
|
|
3573
|
+
var __defProp$f = Object.defineProperty;
|
|
3574
|
+
var __defProps$6 = Object.defineProperties;
|
|
3575
|
+
var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
|
|
3576
|
+
var __getOwnPropSymbols$g = Object.getOwnPropertySymbols;
|
|
3577
|
+
var __hasOwnProp$g = Object.prototype.hasOwnProperty;
|
|
3578
|
+
var __propIsEnum$g = Object.prototype.propertyIsEnumerable;
|
|
3579
|
+
var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3580
|
+
var __spreadValues$f = (a, b) => {
|
|
3558
3581
|
for (var prop in b || (b = {}))
|
|
3559
|
-
if (__hasOwnProp$
|
|
3560
|
-
__defNormalProp$
|
|
3561
|
-
if (__getOwnPropSymbols$
|
|
3562
|
-
for (var prop of __getOwnPropSymbols$
|
|
3563
|
-
if (__propIsEnum$
|
|
3564
|
-
__defNormalProp$
|
|
3582
|
+
if (__hasOwnProp$g.call(b, prop))
|
|
3583
|
+
__defNormalProp$f(a, prop, b[prop]);
|
|
3584
|
+
if (__getOwnPropSymbols$g)
|
|
3585
|
+
for (var prop of __getOwnPropSymbols$g(b)) {
|
|
3586
|
+
if (__propIsEnum$g.call(b, prop))
|
|
3587
|
+
__defNormalProp$f(a, prop, b[prop]);
|
|
3565
3588
|
}
|
|
3566
3589
|
return a;
|
|
3567
3590
|
};
|
|
3568
|
-
var __spreadProps$
|
|
3591
|
+
var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
|
|
3569
3592
|
class ComputedColumn {
|
|
3570
3593
|
constructor(kind, deps, fn) {
|
|
3571
3594
|
this.kind = kind;
|
|
@@ -3582,7 +3605,7 @@ const applyComputedColumns = (q, fn) => {
|
|
|
3582
3605
|
for (const key in computed) {
|
|
3583
3606
|
const item = computed[key];
|
|
3584
3607
|
if (item instanceof ComputedColumn) {
|
|
3585
|
-
q.q.computeds = __spreadProps$
|
|
3608
|
+
q.q.computeds = __spreadProps$6(__spreadValues$f({}, q.q.computeds), { [key]: item });
|
|
3586
3609
|
} else {
|
|
3587
3610
|
const data = (q.shape[key] = item.result.value || UnknownColumn.instance).data;
|
|
3588
3611
|
data.computed = item;
|
|
@@ -3692,25 +3715,25 @@ const saveBatchComputed = (key, result, res, blanks) => {
|
|
|
3692
3715
|
}
|
|
3693
3716
|
};
|
|
3694
3717
|
|
|
3695
|
-
var __defProp$
|
|
3696
|
-
var __defProps$
|
|
3697
|
-
var __getOwnPropDescs$
|
|
3698
|
-
var __getOwnPropSymbols$
|
|
3699
|
-
var __hasOwnProp$
|
|
3700
|
-
var __propIsEnum$
|
|
3701
|
-
var __defNormalProp$
|
|
3702
|
-
var __spreadValues$
|
|
3718
|
+
var __defProp$e = Object.defineProperty;
|
|
3719
|
+
var __defProps$5 = Object.defineProperties;
|
|
3720
|
+
var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
|
|
3721
|
+
var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
|
|
3722
|
+
var __hasOwnProp$f = Object.prototype.hasOwnProperty;
|
|
3723
|
+
var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
|
|
3724
|
+
var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3725
|
+
var __spreadValues$e = (a, b) => {
|
|
3703
3726
|
for (var prop in b || (b = {}))
|
|
3704
|
-
if (__hasOwnProp$
|
|
3705
|
-
__defNormalProp$
|
|
3706
|
-
if (__getOwnPropSymbols$
|
|
3707
|
-
for (var prop of __getOwnPropSymbols$
|
|
3708
|
-
if (__propIsEnum$
|
|
3709
|
-
__defNormalProp$
|
|
3727
|
+
if (__hasOwnProp$f.call(b, prop))
|
|
3728
|
+
__defNormalProp$e(a, prop, b[prop]);
|
|
3729
|
+
if (__getOwnPropSymbols$f)
|
|
3730
|
+
for (var prop of __getOwnPropSymbols$f(b)) {
|
|
3731
|
+
if (__propIsEnum$f.call(b, prop))
|
|
3732
|
+
__defNormalProp$e(a, prop, b[prop]);
|
|
3710
3733
|
}
|
|
3711
3734
|
return a;
|
|
3712
3735
|
};
|
|
3713
|
-
var __spreadProps$
|
|
3736
|
+
var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
3714
3737
|
const queryMethodByReturnType = {
|
|
3715
3738
|
undefined: "query",
|
|
3716
3739
|
all: "query",
|
|
@@ -3954,7 +3977,7 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
|
|
|
3954
3977
|
if (hookResults.some((result2) => result2.status === "rejected")) {
|
|
3955
3978
|
_afterCommitError(
|
|
3956
3979
|
result,
|
|
3957
|
-
hookResults.map((result2, i) => __spreadProps$
|
|
3980
|
+
hookResults.map((result2, i) => __spreadProps$5(__spreadValues$e({}, result2), {
|
|
3958
3981
|
name: afterCommitHooks[i].name
|
|
3959
3982
|
})),
|
|
3960
3983
|
q.q.catchAfterCommitError
|
|
@@ -4196,7 +4219,7 @@ const filterResult = (q, returnType, queryResult, result, tempColumns, hasAfterH
|
|
|
4196
4219
|
return row;
|
|
4197
4220
|
} else {
|
|
4198
4221
|
if (hasAfterHook)
|
|
4199
|
-
row = __spreadValues$
|
|
4222
|
+
row = __spreadValues$e({}, row);
|
|
4200
4223
|
for (const column of tempColumns) {
|
|
4201
4224
|
delete row[column];
|
|
4202
4225
|
}
|
|
@@ -4239,7 +4262,7 @@ const filterAllResult = (result, tempColumns, hasAfterHook) => {
|
|
|
4239
4262
|
if (tempColumns == null ? void 0 : tempColumns.size) {
|
|
4240
4263
|
if (hasAfterHook) {
|
|
4241
4264
|
return result.map((data) => {
|
|
4242
|
-
const record = __spreadValues$
|
|
4265
|
+
const record = __spreadValues$e({}, data);
|
|
4243
4266
|
for (const key of tempColumns) {
|
|
4244
4267
|
delete record[key];
|
|
4245
4268
|
}
|
|
@@ -4256,29 +4279,28 @@ const filterAllResult = (result, tempColumns, hasAfterHook) => {
|
|
|
4256
4279
|
return result;
|
|
4257
4280
|
};
|
|
4258
4281
|
|
|
4259
|
-
var __defProp$
|
|
4260
|
-
var __defProps$
|
|
4261
|
-
var __getOwnPropDescs$
|
|
4262
|
-
var __getOwnPropSymbols$
|
|
4263
|
-
var __hasOwnProp$
|
|
4264
|
-
var __propIsEnum$
|
|
4265
|
-
var __defNormalProp$
|
|
4266
|
-
var __spreadValues$
|
|
4282
|
+
var __defProp$d = Object.defineProperty;
|
|
4283
|
+
var __defProps$4 = Object.defineProperties;
|
|
4284
|
+
var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
|
|
4285
|
+
var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
|
|
4286
|
+
var __hasOwnProp$e = Object.prototype.hasOwnProperty;
|
|
4287
|
+
var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
|
|
4288
|
+
var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4289
|
+
var __spreadValues$d = (a, b) => {
|
|
4267
4290
|
for (var prop in b || (b = {}))
|
|
4268
|
-
if (__hasOwnProp$
|
|
4269
|
-
__defNormalProp$
|
|
4270
|
-
if (__getOwnPropSymbols$
|
|
4271
|
-
for (var prop of __getOwnPropSymbols$
|
|
4272
|
-
if (__propIsEnum$
|
|
4273
|
-
__defNormalProp$
|
|
4291
|
+
if (__hasOwnProp$e.call(b, prop))
|
|
4292
|
+
__defNormalProp$d(a, prop, b[prop]);
|
|
4293
|
+
if (__getOwnPropSymbols$e)
|
|
4294
|
+
for (var prop of __getOwnPropSymbols$e(b)) {
|
|
4295
|
+
if (__propIsEnum$e.call(b, prop))
|
|
4296
|
+
__defNormalProp$d(a, prop, b[prop]);
|
|
4274
4297
|
}
|
|
4275
4298
|
return a;
|
|
4276
4299
|
};
|
|
4277
|
-
var __spreadProps$
|
|
4300
|
+
var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
|
|
4278
4301
|
const addParserForRawExpression = (q, key, raw) => {
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
orchidCore.setParserToQuery(q.q, key, type.parseFn);
|
|
4302
|
+
if (raw.result.value)
|
|
4303
|
+
addColumnParserToQuery(q.q, key, raw.result.value);
|
|
4282
4304
|
};
|
|
4283
4305
|
const addParsersForSelectJoined = (q, arg, as = arg) => {
|
|
4284
4306
|
var _a, _b, _c, _d;
|
|
@@ -4496,11 +4518,12 @@ const collectNestedSelectBatches = (batches, rows, path, last) => {
|
|
|
4496
4518
|
};
|
|
4497
4519
|
const emptyArrSQL = new RawSQL("'[]'");
|
|
4498
4520
|
const processSelectArg = (q, as, arg, columnAs) => {
|
|
4499
|
-
var _a, _b
|
|
4521
|
+
var _a, _b;
|
|
4500
4522
|
if (typeof arg === "string") {
|
|
4501
4523
|
return setParserForSelectedString(q, arg, as, columnAs);
|
|
4502
4524
|
}
|
|
4503
4525
|
const selectAs = {};
|
|
4526
|
+
let aliases;
|
|
4504
4527
|
for (const key in arg) {
|
|
4505
4528
|
let value = arg[key];
|
|
4506
4529
|
if (typeof value === "function") {
|
|
@@ -4535,17 +4558,11 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
4535
4558
|
query = value;
|
|
4536
4559
|
}
|
|
4537
4560
|
}
|
|
4538
|
-
|
|
4539
|
-
if ((_a = value.q.joinedShapes) == null ? void 0 : _a[key]) {
|
|
4540
|
-
let suffix = 2;
|
|
4541
|
-
const joinOverrides = (_c = (_b = q.q).joinOverrides) != null ? _c : _b.joinOverrides = {};
|
|
4542
|
-
while (joinOverrides[asOverride = `${key}${suffix}`]) {
|
|
4543
|
-
suffix++;
|
|
4544
|
-
}
|
|
4545
|
-
joinOverrides[asOverride] = asOverride;
|
|
4546
|
-
joinOverrides[key] = asOverride;
|
|
4547
|
-
}
|
|
4561
|
+
const asOverride = (_a = value.q.aliases[key]) != null ? _a : key;
|
|
4548
4562
|
value.q.joinedForSelect = asOverride;
|
|
4563
|
+
if (asOverride !== key) {
|
|
4564
|
+
aliases = __spreadProps$4(__spreadValues$d({}, q.q.aliases), { [key]: asOverride });
|
|
4565
|
+
}
|
|
4549
4566
|
_joinLateral(
|
|
4550
4567
|
q,
|
|
4551
4568
|
value.q.innerJoinLateral ? "JOIN" : "LEFT JOIN",
|
|
@@ -4553,10 +4570,12 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
4553
4570
|
(q2) => q2,
|
|
4554
4571
|
key
|
|
4555
4572
|
);
|
|
4556
|
-
} else if (((
|
|
4573
|
+
} else if (((_b = value.q) == null ? void 0 : _b.subQuery) && value.q.expr) {
|
|
4557
4574
|
value = value.q.expr;
|
|
4558
4575
|
}
|
|
4559
4576
|
}
|
|
4577
|
+
if (aliases)
|
|
4578
|
+
q.q.aliases = aliases;
|
|
4560
4579
|
selectAs[key] = addParserForSelectItem(
|
|
4561
4580
|
q,
|
|
4562
4581
|
as,
|
|
@@ -4601,7 +4620,7 @@ const setParserForSelectedString = (q, arg, as, columnAs) => {
|
|
|
4601
4620
|
for (const column2 of computed.deps) {
|
|
4602
4621
|
map.set(column2, { select: `${table}.${column2}` });
|
|
4603
4622
|
}
|
|
4604
|
-
q.q.selectedComputeds = __spreadProps$
|
|
4623
|
+
q.q.selectedComputeds = __spreadProps$4(__spreadValues$d({}, q.q.selectedComputeds), {
|
|
4605
4624
|
[column]: computed
|
|
4606
4625
|
});
|
|
4607
4626
|
return;
|
|
@@ -4625,7 +4644,7 @@ const handleComputed = (q, computeds, column) => {
|
|
|
4625
4644
|
for (const column2 of computed.deps) {
|
|
4626
4645
|
map.set(column2, { select: column2 });
|
|
4627
4646
|
}
|
|
4628
|
-
q.q.selectedComputeds = __spreadProps$
|
|
4647
|
+
q.q.selectedComputeds = __spreadProps$4(__spreadValues$d({}, q.q.selectedComputeds), { [column]: computed });
|
|
4629
4648
|
return;
|
|
4630
4649
|
}
|
|
4631
4650
|
return column;
|
|
@@ -4823,10 +4842,43 @@ function _queryGetOptional(self, arg) {
|
|
|
4823
4842
|
return _get(self, "value", arg);
|
|
4824
4843
|
}
|
|
4825
4844
|
|
|
4845
|
+
var __defProp$c = Object.defineProperty;
|
|
4846
|
+
var __defProps$3 = Object.defineProperties;
|
|
4847
|
+
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
|
|
4848
|
+
var __getOwnPropSymbols$d = Object.getOwnPropertySymbols;
|
|
4849
|
+
var __hasOwnProp$d = Object.prototype.hasOwnProperty;
|
|
4850
|
+
var __propIsEnum$d = Object.prototype.propertyIsEnumerable;
|
|
4851
|
+
var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4852
|
+
var __spreadValues$c = (a, b) => {
|
|
4853
|
+
for (var prop in b || (b = {}))
|
|
4854
|
+
if (__hasOwnProp$d.call(b, prop))
|
|
4855
|
+
__defNormalProp$c(a, prop, b[prop]);
|
|
4856
|
+
if (__getOwnPropSymbols$d)
|
|
4857
|
+
for (var prop of __getOwnPropSymbols$d(b)) {
|
|
4858
|
+
if (__propIsEnum$d.call(b, prop))
|
|
4859
|
+
__defNormalProp$c(a, prop, b[prop]);
|
|
4860
|
+
}
|
|
4861
|
+
return a;
|
|
4862
|
+
};
|
|
4863
|
+
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
|
|
4826
4864
|
const _queryAs = (self, as) => {
|
|
4827
|
-
|
|
4865
|
+
const { q } = self;
|
|
4866
|
+
q.as = as;
|
|
4867
|
+
q.aliases = __spreadProps$3(__spreadValues$c({}, q.aliases), {
|
|
4868
|
+
[as]: q.aliases ? _queryResolveAlias(q.aliases, as) : as
|
|
4869
|
+
});
|
|
4828
4870
|
return self;
|
|
4829
4871
|
};
|
|
4872
|
+
const _queryResolveAlias = (aliases, as) => {
|
|
4873
|
+
if (!aliases[as])
|
|
4874
|
+
return as;
|
|
4875
|
+
let suffix = 2;
|
|
4876
|
+
let privateAs;
|
|
4877
|
+
while (aliases[privateAs = as + suffix]) {
|
|
4878
|
+
suffix++;
|
|
4879
|
+
}
|
|
4880
|
+
return privateAs;
|
|
4881
|
+
};
|
|
4830
4882
|
class AsMethods {
|
|
4831
4883
|
/**
|
|
4832
4884
|
* Sets table alias:
|
|
@@ -4873,7 +4925,6 @@ function queryFrom(self, arg) {
|
|
|
4873
4925
|
data.as || (data.as = "t");
|
|
4874
4926
|
} else if (Array.isArray(arg)) {
|
|
4875
4927
|
const { shape } = data;
|
|
4876
|
-
const parsers = (_c = data.parsers) != null ? _c : data.parsers = {};
|
|
4877
4928
|
for (const item of arg) {
|
|
4878
4929
|
if (typeof item === "string") {
|
|
4879
4930
|
const w = data.withShapes[item];
|
|
@@ -4881,13 +4932,15 @@ function queryFrom(self, arg) {
|
|
|
4881
4932
|
if (w.computeds)
|
|
4882
4933
|
data.computeds = __spreadValues$b(__spreadValues$b({}, data.computeds), w.computeds);
|
|
4883
4934
|
for (const key in w.shape) {
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4935
|
+
addColumnParserToQuery(
|
|
4936
|
+
self,
|
|
4937
|
+
key,
|
|
4938
|
+
w.shape[key]
|
|
4939
|
+
);
|
|
4887
4940
|
}
|
|
4888
4941
|
} else if (!orchidCore.isExpression(item)) {
|
|
4889
4942
|
Object.assign(shape, getShapeFromSelect(item, true));
|
|
4890
|
-
Object.assign(parsers, item.q.parsers);
|
|
4943
|
+
Object.assign((_c = data.parsers) != null ? _c : data.parsers = {}, item.q.parsers);
|
|
4891
4944
|
}
|
|
4892
4945
|
}
|
|
4893
4946
|
} else {
|
|
@@ -6192,14 +6245,14 @@ const makeRegexToFindInSql = (value) => {
|
|
|
6192
6245
|
return new RegExp(`${value}(?=(?:[^']*'[^']*')*[^']*$)`, "g");
|
|
6193
6246
|
};
|
|
6194
6247
|
const resolveSubQueryCallback = (q, cb) => {
|
|
6195
|
-
const { subQuery, relChain,
|
|
6248
|
+
const { subQuery, relChain, outerAliases } = q.q;
|
|
6196
6249
|
q.q.subQuery = 1;
|
|
6197
6250
|
q.q.relChain = void 0;
|
|
6198
|
-
q.q.
|
|
6251
|
+
q.q.outerAliases = q.q.aliases;
|
|
6199
6252
|
const result = cb(q);
|
|
6200
6253
|
q.q.subQuery = subQuery;
|
|
6201
6254
|
q.q.relChain = relChain;
|
|
6202
|
-
q.q.
|
|
6255
|
+
q.q.outerAliases = outerAliases;
|
|
6203
6256
|
return result;
|
|
6204
6257
|
};
|
|
6205
6258
|
const joinSubQuery = (q, sub) => {
|
|
@@ -6251,45 +6304,46 @@ class PostgisGeographyPointColumn extends ColumnType {
|
|
|
6251
6304
|
super(schema, schema.geographyPointSchema());
|
|
6252
6305
|
this.dataType = "geography(Point)";
|
|
6253
6306
|
this.operators = Operators.any;
|
|
6307
|
+
setColumnDefaultParse(this, defaultParse);
|
|
6308
|
+
this.data.encode = this.data.defaultEncode = defaultEncode;
|
|
6254
6309
|
}
|
|
6255
6310
|
static isDefaultPoint(typmod) {
|
|
6256
6311
|
return typmodType(typmod) === "Point" && typmodSrid(typmod) === defaultSrid;
|
|
6257
6312
|
}
|
|
6258
|
-
parseFn(input) {
|
|
6259
|
-
if (!input)
|
|
6260
|
-
return null;
|
|
6261
|
-
const bytes = new Uint8Array(20);
|
|
6262
|
-
for (let i = 0; i < 40; i += 2) {
|
|
6263
|
-
bytes[i / 2] = parseInt(input.slice(10 + i, 12 + i), 16);
|
|
6264
|
-
}
|
|
6265
|
-
const view = new DataView(bytes.buffer);
|
|
6266
|
-
const srid = view.getUint32(0, true);
|
|
6267
|
-
const lon = view.getFloat64(4, true);
|
|
6268
|
-
const lat = view.getFloat64(12, true);
|
|
6269
|
-
return srid === defaultSrid ? { lon, lat } : {
|
|
6270
|
-
lon,
|
|
6271
|
-
lat,
|
|
6272
|
-
srid
|
|
6273
|
-
};
|
|
6274
|
-
}
|
|
6275
|
-
encodeFn({ srid = defaultSrid, lon, lat }) {
|
|
6276
|
-
const arr = new Uint8Array(25);
|
|
6277
|
-
const view = new DataView(arr.buffer);
|
|
6278
|
-
view.setInt8(0, 1);
|
|
6279
|
-
view.setInt8(1, 1);
|
|
6280
|
-
view.setInt8(4, 32);
|
|
6281
|
-
view.setUint32(5, srid, true);
|
|
6282
|
-
view.setFloat64(9, lon, true);
|
|
6283
|
-
view.setFloat64(17, lat, true);
|
|
6284
|
-
return uint8ArrToHex(arr);
|
|
6285
|
-
}
|
|
6286
6313
|
toCode(ctx, key) {
|
|
6287
|
-
return columnCode(this, ctx, key, `geography.point()
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
|
|
6314
|
+
return columnCode(this, ctx, key, `geography.point()`);
|
|
6315
|
+
}
|
|
6316
|
+
}
|
|
6317
|
+
const defaultParse = (input) => {
|
|
6318
|
+
const bytes = new Uint8Array(20);
|
|
6319
|
+
for (let i = 0; i < 40; i += 2) {
|
|
6320
|
+
bytes[i / 2] = parseInt(input.slice(10 + i, 12 + i), 16);
|
|
6321
|
+
}
|
|
6322
|
+
const view = new DataView(bytes.buffer);
|
|
6323
|
+
const srid = view.getUint32(0, true);
|
|
6324
|
+
const lon = view.getFloat64(4, true);
|
|
6325
|
+
const lat = view.getFloat64(12, true);
|
|
6326
|
+
return srid === defaultSrid ? { lon, lat } : {
|
|
6327
|
+
lon,
|
|
6328
|
+
lat,
|
|
6329
|
+
srid
|
|
6330
|
+
};
|
|
6331
|
+
};
|
|
6332
|
+
const defaultEncode = ({
|
|
6333
|
+
srid = defaultSrid,
|
|
6334
|
+
lon,
|
|
6335
|
+
lat
|
|
6336
|
+
}) => {
|
|
6337
|
+
const arr = new Uint8Array(25);
|
|
6338
|
+
const view = new DataView(arr.buffer);
|
|
6339
|
+
view.setInt8(0, 1);
|
|
6340
|
+
view.setInt8(1, 1);
|
|
6341
|
+
view.setInt8(4, 32);
|
|
6342
|
+
view.setUint32(5, srid, true);
|
|
6343
|
+
view.setFloat64(9, lon, true);
|
|
6344
|
+
view.setFloat64(17, lat, true);
|
|
6345
|
+
return uint8ArrToHex(arr);
|
|
6346
|
+
};
|
|
6293
6347
|
const typmodGetType = (typmod) => (typmod & 252) >> 2;
|
|
6294
6348
|
const lwtypeName = (type) => [
|
|
6295
6349
|
"Unknown",
|
|
@@ -6766,10 +6820,7 @@ class FnExpression extends orchidCore.Expression {
|
|
|
6766
6820
|
query.q.returnsOne = true;
|
|
6767
6821
|
query.q.getColumn = value;
|
|
6768
6822
|
query.q.select = [this];
|
|
6769
|
-
|
|
6770
|
-
if (parseFn) {
|
|
6771
|
-
orchidCore.setParserToQuery(query.q, orchidCore.getValueKey, parseFn);
|
|
6772
|
-
}
|
|
6823
|
+
addColumnParserToQuery(query.q, orchidCore.getValueKey, value);
|
|
6773
6824
|
}
|
|
6774
6825
|
// Builds function SQL.
|
|
6775
6826
|
makeSQL(ctx, quotedAs) {
|
|
@@ -6859,18 +6910,14 @@ const isSelectingCount = (q) => {
|
|
|
6859
6910
|
const { expr } = q.q;
|
|
6860
6911
|
return expr instanceof FnExpression && expr.fn === "count" && expr.args[0] === "*";
|
|
6861
6912
|
};
|
|
6862
|
-
const int = new IntegerColumn(defaultSchemaConfig);
|
|
6863
|
-
|
|
6864
|
-
const nullableInt = new IntegerColumn(defaultSchemaConfig);
|
|
6865
|
-
nullableInt.parseItem = nullableInt.parseFn = (input) => input === null ? null : parseInt(input);
|
|
6866
|
-
const nullableFloat = new RealColumn(defaultSchemaConfig);
|
|
6867
|
-
nullableFloat.parseItem = nullableFloat.parseFn = (input) => input === null ? null : parseFloat(input);
|
|
6913
|
+
const int = new IntegerColumn(defaultSchemaConfig).parse(parseInt);
|
|
6914
|
+
const float = new RealColumn(defaultSchemaConfig).parse(parseFloat);
|
|
6868
6915
|
const stringAsNumber = new NumberAsStringBaseColumn(
|
|
6869
6916
|
defaultSchemaConfig
|
|
6870
6917
|
);
|
|
6871
6918
|
const numericResultColumn = (q, arg) => {
|
|
6872
6919
|
const type = typeof arg === "string" ? _getSelectableColumn(q, arg) : arg.result.value;
|
|
6873
|
-
return type instanceof NumberBaseColumn ?
|
|
6920
|
+
return type instanceof NumberBaseColumn ? float : stringAsNumber;
|
|
6874
6921
|
};
|
|
6875
6922
|
class AggregateMethods {
|
|
6876
6923
|
/**
|
|
@@ -7332,7 +7379,7 @@ class AggregateMethods {
|
|
|
7332
7379
|
* @param over - OVER clause config
|
|
7333
7380
|
*/
|
|
7334
7381
|
rowNumber(over) {
|
|
7335
|
-
return makeFnExpression(this,
|
|
7382
|
+
return makeFnExpression(this, int, "row_number", orchidCore.emptyArray, {
|
|
7336
7383
|
over
|
|
7337
7384
|
});
|
|
7338
7385
|
}
|
|
@@ -7355,7 +7402,7 @@ class AggregateMethods {
|
|
|
7355
7402
|
* @param over - OVER clause config
|
|
7356
7403
|
*/
|
|
7357
7404
|
rank(over) {
|
|
7358
|
-
return makeFnExpression(this,
|
|
7405
|
+
return makeFnExpression(this, int, "rank", orchidCore.emptyArray, {
|
|
7359
7406
|
over
|
|
7360
7407
|
});
|
|
7361
7408
|
}
|
|
@@ -7378,7 +7425,7 @@ class AggregateMethods {
|
|
|
7378
7425
|
* @param over - OVER clause config
|
|
7379
7426
|
*/
|
|
7380
7427
|
denseRank(over) {
|
|
7381
|
-
return makeFnExpression(this,
|
|
7428
|
+
return makeFnExpression(this, int, "dense_rank", orchidCore.emptyArray, {
|
|
7382
7429
|
over
|
|
7383
7430
|
});
|
|
7384
7431
|
}
|
|
@@ -7401,7 +7448,7 @@ class AggregateMethods {
|
|
|
7401
7448
|
* @param over - OVER clause config
|
|
7402
7449
|
*/
|
|
7403
7450
|
percentRank(over) {
|
|
7404
|
-
return makeFnExpression(this,
|
|
7451
|
+
return makeFnExpression(this, int, "percent_rank", orchidCore.emptyArray, {
|
|
7405
7452
|
over
|
|
7406
7453
|
});
|
|
7407
7454
|
}
|
|
@@ -7424,7 +7471,7 @@ class AggregateMethods {
|
|
|
7424
7471
|
* @param over - OVER clause config
|
|
7425
7472
|
*/
|
|
7426
7473
|
cumeDist(over) {
|
|
7427
|
-
return makeFnExpression(this,
|
|
7474
|
+
return makeFnExpression(this, float, "cume_dist", orchidCore.emptyArray, {
|
|
7428
7475
|
over
|
|
7429
7476
|
});
|
|
7430
7477
|
}
|
|
@@ -7508,7 +7555,7 @@ const processCreateItem = (q, item, rowIndex, ctx, encoders) => {
|
|
|
7508
7555
|
}
|
|
7509
7556
|
if (!ctx.columns.has(key) && (shape[key] && !shape[key].data.computed || shape === anyShape) && item[key] !== void 0) {
|
|
7510
7557
|
ctx.columns.set(key, ctx.columns.size);
|
|
7511
|
-
encoders[key] = (_c = shape[key]) == null ? void 0 : _c.
|
|
7558
|
+
encoders[key] = (_c = shape[key]) == null ? void 0 : _c.data.encode;
|
|
7512
7559
|
}
|
|
7513
7560
|
}
|
|
7514
7561
|
}
|
|
@@ -9353,7 +9400,7 @@ const pushQueryOnForOuter = (q, joinFrom, joinTo, ...on) => {
|
|
|
9353
9400
|
ON: {
|
|
9354
9401
|
joinTo: joinFrom,
|
|
9355
9402
|
joinFrom: joinTo,
|
|
9356
|
-
|
|
9403
|
+
useOuterAliases: true,
|
|
9357
9404
|
on
|
|
9358
9405
|
}
|
|
9359
9406
|
});
|
|
@@ -9762,7 +9809,7 @@ const resolveCallbacksInArgs = (q, args) => {
|
|
|
9762
9809
|
qb.q = getClonedQueryData(q.q);
|
|
9763
9810
|
qb.q.and = qb.q.or = qb.q.scopes = void 0;
|
|
9764
9811
|
qb.q.subQuery = 1;
|
|
9765
|
-
qb.q.
|
|
9812
|
+
qb.q.outerAliases = qb.q.aliases;
|
|
9766
9813
|
args[i] = resolveSubQueryCallback(qb, arg);
|
|
9767
9814
|
}
|
|
9768
9815
|
}
|
|
@@ -10656,7 +10703,7 @@ const _queryUpdate = (query, arg) => {
|
|
|
10656
10703
|
set[key] = new RawSQL(`(SELECT * FROM "${as}")`);
|
|
10657
10704
|
}
|
|
10658
10705
|
} else {
|
|
10659
|
-
const encode = shape[key].
|
|
10706
|
+
const encode = shape[key].data.encode;
|
|
10660
10707
|
if (encode)
|
|
10661
10708
|
set[key] = encode(value);
|
|
10662
10709
|
}
|
|
@@ -12749,9 +12796,9 @@ class Db {
|
|
|
12749
12796
|
for (const key in shape) {
|
|
12750
12797
|
const column = shape[key];
|
|
12751
12798
|
column.data.key = key;
|
|
12752
|
-
if (column.
|
|
12799
|
+
if (column._parse) {
|
|
12753
12800
|
hasParsers = true;
|
|
12754
|
-
parsers[key] = column.
|
|
12801
|
+
parsers[key] = column._parse;
|
|
12755
12802
|
}
|
|
12756
12803
|
if (column.data.name) {
|
|
12757
12804
|
prepareSelectAll = true;
|
|
@@ -12777,10 +12824,9 @@ class Db {
|
|
|
12777
12824
|
arr.push(key);
|
|
12778
12825
|
if (!column.data.runtimeDefault) {
|
|
12779
12826
|
const {
|
|
12780
|
-
data: { default: def }
|
|
12781
|
-
encodeFn
|
|
12827
|
+
data: { default: def, encode }
|
|
12782
12828
|
} = column;
|
|
12783
|
-
column.data.runtimeDefault =
|
|
12829
|
+
column.data.runtimeDefault = encode ? () => encode(def()) : def;
|
|
12784
12830
|
}
|
|
12785
12831
|
}
|
|
12786
12832
|
}
|
|
@@ -13349,6 +13395,7 @@ exports._queryJoinOnJsonPathEquals = _queryJoinOnJsonPathEquals;
|
|
|
13349
13395
|
exports._queryJoinOrOn = _queryJoinOrOn;
|
|
13350
13396
|
exports._queryOr = _queryOr;
|
|
13351
13397
|
exports._queryOrNot = _queryOrNot;
|
|
13398
|
+
exports._queryResolveAlias = _queryResolveAlias;
|
|
13352
13399
|
exports._queryRows = _queryRows;
|
|
13353
13400
|
exports._querySelect = _querySelect;
|
|
13354
13401
|
exports._queryTake = _queryTake;
|
|
@@ -13365,6 +13412,7 @@ exports._queryWhereNotOneOf = _queryWhereNotOneOf;
|
|
|
13365
13412
|
exports._queryWhereNotSql = _queryWhereNotSql;
|
|
13366
13413
|
exports._queryWhereOneOf = _queryWhereOneOf;
|
|
13367
13414
|
exports._queryWhereSql = _queryWhereSql;
|
|
13415
|
+
exports.addColumnParserToQuery = addColumnParserToQuery;
|
|
13368
13416
|
exports.addParserForRawExpression = addParserForRawExpression;
|
|
13369
13417
|
exports.addParserForSelectItem = addParserForSelectItem;
|
|
13370
13418
|
exports.addQueryOn = addQueryOn;
|
|
@@ -13439,6 +13487,10 @@ exports.referencesArgsToCode = referencesArgsToCode;
|
|
|
13439
13487
|
exports.resolveSubQueryCallback = resolveSubQueryCallback;
|
|
13440
13488
|
exports.rollbackSql = rollbackSql$1;
|
|
13441
13489
|
exports.saveSearchAlias = saveSearchAlias;
|
|
13490
|
+
exports.setColumnDefaultParse = setColumnDefaultParse;
|
|
13491
|
+
exports.setColumnEncode = setColumnEncode;
|
|
13492
|
+
exports.setColumnParse = setColumnParse;
|
|
13493
|
+
exports.setColumnParseNull = setColumnParseNull;
|
|
13442
13494
|
exports.setParserForSelectedString = setParserForSelectedString;
|
|
13443
13495
|
exports.setQueryObjectValue = setQueryObjectValue;
|
|
13444
13496
|
exports.setQueryOperators = setQueryOperators;
|