pqb 0.56.11 → 0.56.13
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 +55 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -24
- 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
|
}
|
|
@@ -7059,7 +7091,8 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
7059
7091
|
}
|
|
7060
7092
|
}
|
|
7061
7093
|
} else {
|
|
7062
|
-
|
|
7094
|
+
const sql = item.toSQL(ctx, quotedAs);
|
|
7095
|
+
list.push(ctx.aliasValue ? `${sql} ${quotedAs}` : sql);
|
|
7063
7096
|
aliases?.push("");
|
|
7064
7097
|
}
|
|
7065
7098
|
}
|
|
@@ -7117,10 +7150,6 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
7117
7150
|
}
|
|
7118
7151
|
return list.length ? list.join(", ") : query.select ? "" : selectAllSql(query, quotedAs, jsonList);
|
|
7119
7152
|
};
|
|
7120
|
-
function selectedObjectToSQL(ctx, quotedAs, item) {
|
|
7121
|
-
const sql = item.toSQL(ctx, quotedAs);
|
|
7122
|
-
return ctx.aliasValue ? `${sql} r` : sql;
|
|
7123
|
-
}
|
|
7124
7153
|
const selectAllSql = (query, quotedAs, jsonList) => {
|
|
7125
7154
|
if (jsonList) {
|
|
7126
7155
|
Object.assign(jsonList, query.selectAllShape);
|
|
@@ -7167,14 +7196,14 @@ const pushSubQuerySql = (ctx, mainQuery, query, as, list, quotedAs, aliases) =>
|
|
|
7167
7196
|
break;
|
|
7168
7197
|
}
|
|
7169
7198
|
case "all":
|
|
7170
|
-
case "pluck":
|
|
7171
7199
|
case "value":
|
|
7200
|
+
case "pluck":
|
|
7172
7201
|
case "rows":
|
|
7173
|
-
sql = `"${query.q.joinedForSelect}".
|
|
7202
|
+
sql = `"${query.q.joinedForSelect}"."${as}"`;
|
|
7174
7203
|
break;
|
|
7175
7204
|
case "valueOrThrow":
|
|
7176
7205
|
if (query.q.returning) return;
|
|
7177
|
-
sql = `"${query.q.joinedForSelect}".
|
|
7206
|
+
sql = `"${query.q.joinedForSelect}"."${as}"`;
|
|
7178
7207
|
break;
|
|
7179
7208
|
case "void":
|
|
7180
7209
|
return;
|
|
@@ -10760,11 +10789,12 @@ class Join {
|
|
|
10760
10789
|
*/
|
|
10761
10790
|
joinLateral(arg, cb) {
|
|
10762
10791
|
const q = _clone(this);
|
|
10763
|
-
|
|
10792
|
+
_joinLateral(
|
|
10764
10793
|
q,
|
|
10765
10794
|
"JOIN",
|
|
10766
10795
|
_joinLateralProcessArg(q, arg, cb)
|
|
10767
10796
|
);
|
|
10797
|
+
return q;
|
|
10768
10798
|
}
|
|
10769
10799
|
/**
|
|
10770
10800
|
* The same as {@link joinLateral}, but when no records found for the join it will result in `null`:
|
|
@@ -10783,11 +10813,12 @@ class Join {
|
|
|
10783
10813
|
*/
|
|
10784
10814
|
leftJoinLateral(arg, cb) {
|
|
10785
10815
|
const q = _clone(this);
|
|
10786
|
-
|
|
10787
|
-
|
|
10816
|
+
_joinLateral(
|
|
10817
|
+
q,
|
|
10788
10818
|
"LEFT JOIN",
|
|
10789
10819
|
_joinLateralProcessArg(q, arg, cb)
|
|
10790
10820
|
);
|
|
10821
|
+
return q;
|
|
10791
10822
|
}
|
|
10792
10823
|
/**
|
|
10793
10824
|
* This method may be useful
|