pqb 0.52.1 → 0.52.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 +13 -6
- package/dist/index.js +45 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -28
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -925,20 +925,33 @@ const getSqlText = (sql) => {
|
|
|
925
925
|
};
|
|
926
926
|
|
|
927
927
|
class CustomTypeColumn extends ColumnType {
|
|
928
|
-
constructor(schema,
|
|
928
|
+
constructor(schema, typeName, typeSchema, extension) {
|
|
929
929
|
super(
|
|
930
930
|
schema,
|
|
931
931
|
schema.unknown(),
|
|
932
932
|
schema.unknown(),
|
|
933
933
|
schema.unknown()
|
|
934
934
|
);
|
|
935
|
-
this.
|
|
935
|
+
this.typeName = typeName;
|
|
936
|
+
this.typeSchema = typeSchema;
|
|
936
937
|
this.operators = Operators.any;
|
|
938
|
+
this.dataType = typeSchema ? typeSchema + "." + typeName : typeName;
|
|
937
939
|
this.data.isOfCustomType = true;
|
|
938
940
|
this.data.extension = extension;
|
|
939
941
|
}
|
|
940
942
|
toCode(ctx, key) {
|
|
941
|
-
|
|
943
|
+
const {
|
|
944
|
+
dataType,
|
|
945
|
+
data: { typmod }
|
|
946
|
+
} = this;
|
|
947
|
+
return columnCode(
|
|
948
|
+
this,
|
|
949
|
+
ctx,
|
|
950
|
+
key,
|
|
951
|
+
`type(${singleQuote(
|
|
952
|
+
(dataType.startsWith(ctx.currentSchema) ? dataType.slice(ctx.currentSchema.length + 1) : dataType) + (typmod !== void 0 && typmod !== -1 && !dataType.includes("(") ? `(${typmod})` : "")
|
|
953
|
+
)})`
|
|
954
|
+
);
|
|
942
955
|
}
|
|
943
956
|
as(column) {
|
|
944
957
|
const c = setColumnData(
|
|
@@ -2762,7 +2775,7 @@ const _joinLateralProcessArg = (q, arg, cb) => {
|
|
|
2762
2775
|
}
|
|
2763
2776
|
return result;
|
|
2764
2777
|
};
|
|
2765
|
-
const _joinLateral = (self, type, arg, as) => {
|
|
2778
|
+
const _joinLateral = (self, type, arg, as, innerJoinLateral) => {
|
|
2766
2779
|
const q = self;
|
|
2767
2780
|
arg.q.joinTo = q;
|
|
2768
2781
|
const joinedAs = getQueryAs(q);
|
|
@@ -2783,7 +2796,10 @@ const _joinLateral = (self, type, arg, as) => {
|
|
|
2783
2796
|
}
|
|
2784
2797
|
as || (as = getQueryAs(arg));
|
|
2785
2798
|
setObjectValueImmutable(q.q, "joinedComputeds", as, arg.q.computeds);
|
|
2786
|
-
pushQueryValueImmutable(q, "join",
|
|
2799
|
+
pushQueryValueImmutable(q, "join", {
|
|
2800
|
+
type: `${type} LATERAL`,
|
|
2801
|
+
args: { l: arg, a: as, i: innerJoinLateral }
|
|
2802
|
+
});
|
|
2787
2803
|
return q;
|
|
2788
2804
|
};
|
|
2789
2805
|
|
|
@@ -4235,10 +4251,12 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
4235
4251
|
joinQuery = true;
|
|
4236
4252
|
value = value.joinQuery(value, q);
|
|
4237
4253
|
let query;
|
|
4238
|
-
const returnType = value.q
|
|
4254
|
+
const { returnType, innerJoinLateral } = value.q;
|
|
4239
4255
|
if (!returnType || returnType === "all") {
|
|
4240
4256
|
query = value.json(false);
|
|
4241
|
-
|
|
4257
|
+
if (!innerJoinLateral) {
|
|
4258
|
+
value.q.coalesceValue = emptyArrSQL;
|
|
4259
|
+
}
|
|
4242
4260
|
} else if (returnType === "pluck") {
|
|
4243
4261
|
query = value.q.select ? value.wrap(cloneQueryBaseUnscoped(value)).jsonAgg(value.q.select[0]) : value.json(false);
|
|
4244
4262
|
value.q.coalesceValue = emptyArrSQL;
|
|
@@ -4265,9 +4283,12 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
4265
4283
|
}
|
|
4266
4284
|
_joinLateral(
|
|
4267
4285
|
q,
|
|
4268
|
-
|
|
4286
|
+
innerJoinLateral ? "JOIN" : "LEFT JOIN",
|
|
4269
4287
|
query,
|
|
4270
|
-
key
|
|
4288
|
+
key,
|
|
4289
|
+
// no need for `ON p.r IS NOT NULL` check when joining a single record,
|
|
4290
|
+
// `JOIN` will handle it on itself.
|
|
4291
|
+
innerJoinLateral && returnType !== "one" && returnType !== "oneOrThrow"
|
|
4271
4292
|
);
|
|
4272
4293
|
}
|
|
4273
4294
|
}
|
|
@@ -6034,7 +6055,13 @@ const pushIn = (ctx, query, ands, quotedAs, arg) => {
|
|
|
6034
6055
|
const processJoinItem = (ctx, table, query, args, quotedAs) => {
|
|
6035
6056
|
let target;
|
|
6036
6057
|
let on;
|
|
6037
|
-
if ("
|
|
6058
|
+
if ("l" in args) {
|
|
6059
|
+
const { aliasValue } = ctx;
|
|
6060
|
+
ctx.aliasValue = true;
|
|
6061
|
+
target = `(${getSqlText(args.l.toSQL(ctx))}) "${query.aliases?.[args.a] || args.a}"`;
|
|
6062
|
+
on = `${args.i ? `"${args.a}".r IS NOT NULL` : "true"}`;
|
|
6063
|
+
ctx.aliasValue = aliasValue;
|
|
6064
|
+
} else if ("j" in args) {
|
|
6038
6065
|
const { j, s, r } = args;
|
|
6039
6066
|
const tableName = typeof j.q.from === "string" ? j.q.from : j.table;
|
|
6040
6067
|
const quotedTable = quoteSchemaAndTable(j.q.schema, tableName);
|
|
@@ -6204,24 +6231,14 @@ const getObjectOrRawConditions = (ctx, query, data, quotedAs, joinAs, joinShape)
|
|
|
6204
6231
|
const pushJoinSql = (ctx, table, query, quotedAs) => {
|
|
6205
6232
|
const joinSet = query.join.length > 1 ? /* @__PURE__ */ new Set() : null;
|
|
6206
6233
|
for (const item of query.join) {
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
} else {
|
|
6216
|
-
const { target, on = "true" } = processJoinItem(
|
|
6217
|
-
ctx,
|
|
6218
|
-
table,
|
|
6219
|
-
query,
|
|
6220
|
-
item.args,
|
|
6221
|
-
quotedAs
|
|
6222
|
-
);
|
|
6223
|
-
sql = `${item.type} ${target} ON ${on}`;
|
|
6224
|
-
}
|
|
6234
|
+
const { target, on = "true" } = processJoinItem(
|
|
6235
|
+
ctx,
|
|
6236
|
+
table,
|
|
6237
|
+
query,
|
|
6238
|
+
item.args,
|
|
6239
|
+
quotedAs
|
|
6240
|
+
);
|
|
6241
|
+
const sql = `${item.type} ${target} ON ${on}`;
|
|
6225
6242
|
if (joinSet) {
|
|
6226
6243
|
if (joinSet.has(sql)) continue;
|
|
6227
6244
|
joinSet.add(sql);
|