pqb 0.56.11 → 0.56.12
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 +6 -2
- package/dist/index.js +54 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -20
- package/dist/index.mjs.map +1 -1
- package/dist/postgres-js.js +3 -0
- package/dist/postgres-js.js.map +1 -1
- package/dist/postgres-js.mjs +3 -0
- package/dist/postgres-js.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1078,6 +1078,9 @@ const quoteValue = (arg, ctx, quotedAs, IN) => {
|
|
|
1078
1078
|
if ("toSQL" in arg) {
|
|
1079
1079
|
return `(${getSqlText(arg.toSQL(ctx))})`;
|
|
1080
1080
|
}
|
|
1081
|
+
if (!(arg instanceof Date) && !Array.isArray(arg)) {
|
|
1082
|
+
arg = JSON.stringify(arg);
|
|
1083
|
+
}
|
|
1081
1084
|
}
|
|
1082
1085
|
return addValue(ctx.values, arg);
|
|
1083
1086
|
};
|
|
@@ -2592,7 +2595,7 @@ const columnToSql = (ctx, data, shape, column, quotedAs, select) => {
|
|
|
2592
2595
|
);
|
|
2593
2596
|
}
|
|
2594
2597
|
if (!select && data.joinedShapes?.[column]) {
|
|
2595
|
-
return `"${column}".
|
|
2598
|
+
return `"${column}"."${column}"`;
|
|
2596
2599
|
}
|
|
2597
2600
|
return simpleColumnToSQL(ctx, column, shape[column], quotedAs);
|
|
2598
2601
|
};
|
|
@@ -2602,7 +2605,7 @@ const maybeSelectedColumnToSql = (ctx, data, column, quotedAs) => {
|
|
|
2602
2605
|
return columnWithDotToSql(ctx, data, data.shape, column, index, quotedAs);
|
|
2603
2606
|
} else {
|
|
2604
2607
|
if (data.joinedShapes?.[column]) {
|
|
2605
|
-
return `"${column}".
|
|
2608
|
+
return `"${column}"."${column}"`;
|
|
2606
2609
|
}
|
|
2607
2610
|
if (data.select) {
|
|
2608
2611
|
for (const s of data.select) {
|
|
@@ -2907,7 +2910,7 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
|
|
|
2907
2910
|
quotedColumn = simpleColumnToSQL(ctx, name, column, quoted);
|
|
2908
2911
|
} else {
|
|
2909
2912
|
column = query.joinedShapes?.[key]?.value;
|
|
2910
|
-
quotedColumn = `"${key}".
|
|
2913
|
+
quotedColumn = `"${key}"."${key}"`;
|
|
2911
2914
|
}
|
|
2912
2915
|
if (!column || !quotedColumn) {
|
|
2913
2916
|
throw new Error(`Unknown column ${key} provided to condition`);
|
|
@@ -2980,7 +2983,7 @@ const processJoinItem = (ctx, table, query, args, quotedAs) => {
|
|
|
2980
2983
|
query,
|
|
2981
2984
|
args.a
|
|
2982
2985
|
)}"`;
|
|
2983
|
-
on = `${args.i ? `"${args.a}".
|
|
2986
|
+
on = `${args.i ? `"${args.a}"."${args.a}" IS NOT NULL` : "true"}`;
|
|
2984
2987
|
ctx.aliasValue = aliasValue;
|
|
2985
2988
|
} else if ("j" in args) {
|
|
2986
2989
|
const { j, s, r } = args;
|
|
@@ -4562,11 +4565,38 @@ const _joinLateral = (self, type, arg, as, innerJoinLateral) => {
|
|
|
4562
4565
|
}
|
|
4563
4566
|
as || (as = getQueryAs(arg));
|
|
4564
4567
|
setObjectValueImmutable(q.q, "joinedComputeds", as, arg.q.runtimeComputeds);
|
|
4568
|
+
const joinArgs = {
|
|
4569
|
+
l: arg,
|
|
4570
|
+
a: as,
|
|
4571
|
+
i: innerJoinLateral
|
|
4572
|
+
};
|
|
4573
|
+
if (arg.q.returnType === "value" || arg.q.returnType === "valueOrThrow") {
|
|
4574
|
+
const map = q.q.joinValueDedup ? new Map(q.q.joinValueDedup) : /* @__PURE__ */ new Map();
|
|
4575
|
+
q.q.joinValueDedup = map;
|
|
4576
|
+
const select = arg.q.select[0];
|
|
4577
|
+
arg.q.select = [];
|
|
4578
|
+
const dedupKey = getSqlText(arg.toSQL());
|
|
4579
|
+
const existing = map.get(dedupKey);
|
|
4580
|
+
if (existing) {
|
|
4581
|
+
existing.q.q.select = [
|
|
4582
|
+
{
|
|
4583
|
+
selectAs: {
|
|
4584
|
+
...existing.q.q.select[0].selectAs,
|
|
4585
|
+
[joinKey]: select
|
|
4586
|
+
}
|
|
4587
|
+
}
|
|
4588
|
+
];
|
|
4589
|
+
return existing.a;
|
|
4590
|
+
} else {
|
|
4591
|
+
arg.q.select = [{ selectAs: { [joinKey]: select } }];
|
|
4592
|
+
map.set(dedupKey, { q: arg, a: as });
|
|
4593
|
+
}
|
|
4594
|
+
}
|
|
4565
4595
|
pushQueryValueImmutable(q, "join", {
|
|
4566
4596
|
type: `${type} LATERAL`,
|
|
4567
|
-
args:
|
|
4597
|
+
args: joinArgs
|
|
4568
4598
|
});
|
|
4569
|
-
return
|
|
4599
|
+
return joinKey;
|
|
4570
4600
|
};
|
|
4571
4601
|
|
|
4572
4602
|
const escape = (value, migration, nested) => {
|
|
@@ -6024,12 +6054,7 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
6024
6054
|
subQuery = value;
|
|
6025
6055
|
}
|
|
6026
6056
|
}
|
|
6027
|
-
|
|
6028
|
-
value,
|
|
6029
|
-
q,
|
|
6030
|
-
key
|
|
6031
|
-
);
|
|
6032
|
-
_joinLateral(
|
|
6057
|
+
const as2 = _joinLateral(
|
|
6033
6058
|
q,
|
|
6034
6059
|
innerJoinLateral ? "JOIN" : "LEFT JOIN",
|
|
6035
6060
|
subQuery,
|
|
@@ -6038,6 +6063,13 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
6038
6063
|
// `JOIN` will handle it on itself.
|
|
6039
6064
|
innerJoinLateral && returnType !== "one" && returnType !== "oneOrThrow"
|
|
6040
6065
|
);
|
|
6066
|
+
if (as2) {
|
|
6067
|
+
value.q.joinedForSelect = _copyQueryAliasToQuery(
|
|
6068
|
+
value,
|
|
6069
|
+
q,
|
|
6070
|
+
as2
|
|
6071
|
+
);
|
|
6072
|
+
}
|
|
6041
6073
|
}
|
|
6042
6074
|
}
|
|
6043
6075
|
selectAs[key] = addParserForSelectItem(
|
|
@@ -6162,7 +6194,7 @@ const getShapeFromSelect = (q, isSubQuery) => {
|
|
|
6162
6194
|
const { returnType } = it.q;
|
|
6163
6195
|
if (returnType === "value" || returnType === "valueOrThrow") {
|
|
6164
6196
|
const type = it.q.getColumn;
|
|
6165
|
-
result[key] = type
|
|
6197
|
+
result[key] = type ? mapSubSelectColumn(type, isSubQuery) : UnknownColumn.instance;
|
|
6166
6198
|
} else {
|
|
6167
6199
|
result[key] = new JSONTextColumn(defaultSchemaConfig);
|
|
6168
6200
|
}
|
|
@@ -7119,7 +7151,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
7119
7151
|
};
|
|
7120
7152
|
function selectedObjectToSQL(ctx, quotedAs, item) {
|
|
7121
7153
|
const sql = item.toSQL(ctx, quotedAs);
|
|
7122
|
-
return ctx.aliasValue ? `${sql}
|
|
7154
|
+
return ctx.aliasValue ? `${sql} "${quotedAs}"` : sql;
|
|
7123
7155
|
}
|
|
7124
7156
|
const selectAllSql = (query, quotedAs, jsonList) => {
|
|
7125
7157
|
if (jsonList) {
|
|
@@ -7167,14 +7199,14 @@ const pushSubQuerySql = (ctx, mainQuery, query, as, list, quotedAs, aliases) =>
|
|
|
7167
7199
|
break;
|
|
7168
7200
|
}
|
|
7169
7201
|
case "all":
|
|
7170
|
-
case "pluck":
|
|
7171
7202
|
case "value":
|
|
7203
|
+
case "pluck":
|
|
7172
7204
|
case "rows":
|
|
7173
|
-
sql = `"${query.q.joinedForSelect}".
|
|
7205
|
+
sql = `"${query.q.joinedForSelect}"."${as}"`;
|
|
7174
7206
|
break;
|
|
7175
7207
|
case "valueOrThrow":
|
|
7176
7208
|
if (query.q.returning) return;
|
|
7177
|
-
sql = `"${query.q.joinedForSelect}".
|
|
7209
|
+
sql = `"${query.q.joinedForSelect}"."${as}"`;
|
|
7178
7210
|
break;
|
|
7179
7211
|
case "void":
|
|
7180
7212
|
return;
|
|
@@ -10760,11 +10792,12 @@ class Join {
|
|
|
10760
10792
|
*/
|
|
10761
10793
|
joinLateral(arg, cb) {
|
|
10762
10794
|
const q = _clone(this);
|
|
10763
|
-
|
|
10795
|
+
_joinLateral(
|
|
10764
10796
|
q,
|
|
10765
10797
|
"JOIN",
|
|
10766
10798
|
_joinLateralProcessArg(q, arg, cb)
|
|
10767
10799
|
);
|
|
10800
|
+
return q;
|
|
10768
10801
|
}
|
|
10769
10802
|
/**
|
|
10770
10803
|
* The same as {@link joinLateral}, but when no records found for the join it will result in `null`:
|
|
@@ -10783,11 +10816,12 @@ class Join {
|
|
|
10783
10816
|
*/
|
|
10784
10817
|
leftJoinLateral(arg, cb) {
|
|
10785
10818
|
const q = _clone(this);
|
|
10786
|
-
|
|
10787
|
-
|
|
10819
|
+
_joinLateral(
|
|
10820
|
+
q,
|
|
10788
10821
|
"LEFT JOIN",
|
|
10789
10822
|
_joinLateralProcessArg(q, arg, cb)
|
|
10790
10823
|
);
|
|
10824
|
+
return q;
|
|
10791
10825
|
}
|
|
10792
10826
|
/**
|
|
10793
10827
|
* This method may be useful
|