pqb 0.38.2 → 0.38.4
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 +18 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2144,7 +2144,7 @@ const andOrToSql = (ctx, table, query, quotedAs, parens) => {
|
|
|
2144
2144
|
} else {
|
|
2145
2145
|
return;
|
|
2146
2146
|
}
|
|
2147
|
-
return parens ? `(${sql})` : sql;
|
|
2147
|
+
return parens && sql ? `(${sql})` : sql;
|
|
2148
2148
|
};
|
|
2149
2149
|
const processAnds = (and, ctx, table, query, quotedAs, parens) => {
|
|
2150
2150
|
const ands = [];
|
|
@@ -4000,19 +4000,19 @@ const filterResult = (q, returnType, queryResult, result, tempColumns, hasAfterH
|
|
|
4000
4000
|
}
|
|
4001
4001
|
}
|
|
4002
4002
|
if (returnType === "value") {
|
|
4003
|
-
return (_a = result[0]) == null ? void 0 : _a[queryResult
|
|
4003
|
+
return (_a = result[0]) == null ? void 0 : _a[getFirstResultKey(q, queryResult)];
|
|
4004
4004
|
}
|
|
4005
4005
|
if (returnType === "valueOrThrow") {
|
|
4006
4006
|
const row = result[0];
|
|
4007
4007
|
if (!row)
|
|
4008
4008
|
throw new NotFoundError(q);
|
|
4009
|
-
return row[queryResult
|
|
4009
|
+
return row[getFirstResultKey(q, queryResult)];
|
|
4010
4010
|
}
|
|
4011
4011
|
if (returnType === "rowCount") {
|
|
4012
4012
|
return queryResult.rowCount;
|
|
4013
4013
|
}
|
|
4014
4014
|
if (returnType === "pluck") {
|
|
4015
|
-
const key = queryResult
|
|
4015
|
+
const key = getFirstResultKey(q, queryResult);
|
|
4016
4016
|
return result.map((row) => row[key]);
|
|
4017
4017
|
}
|
|
4018
4018
|
if (returnType === "rows") {
|
|
@@ -4021,6 +4021,16 @@ const filterResult = (q, returnType, queryResult, result, tempColumns, hasAfterH
|
|
|
4021
4021
|
}
|
|
4022
4022
|
return;
|
|
4023
4023
|
};
|
|
4024
|
+
const getFirstResultKey = (q, queryResult) => {
|
|
4025
|
+
if (q.q.select) {
|
|
4026
|
+
return queryResult.fields[0].name;
|
|
4027
|
+
} else {
|
|
4028
|
+
for (const key in q.q.selectedComputeds) {
|
|
4029
|
+
return key;
|
|
4030
|
+
}
|
|
4031
|
+
}
|
|
4032
|
+
return;
|
|
4033
|
+
};
|
|
4024
4034
|
const filterAllResult = (result, tempColumns, hasAfterHook) => {
|
|
4025
4035
|
if (tempColumns == null ? void 0 : tempColumns.size) {
|
|
4026
4036
|
if (hasAfterHook) {
|
|
@@ -4455,7 +4465,7 @@ const getShapeFromSelect = (q, isSubQuery) => {
|
|
|
4455
4465
|
} else if (it) {
|
|
4456
4466
|
const { returnType } = it.q;
|
|
4457
4467
|
if (returnType === "value" || returnType === "valueOrThrow") {
|
|
4458
|
-
const type = it.q
|
|
4468
|
+
const type = it.q.getColumn;
|
|
4459
4469
|
if (type)
|
|
4460
4470
|
result[key] = type;
|
|
4461
4471
|
} else {
|
|
@@ -4571,7 +4581,7 @@ const _get = (query, returnType, arg) => {
|
|
|
4571
4581
|
}
|
|
4572
4582
|
}
|
|
4573
4583
|
}
|
|
4574
|
-
q
|
|
4584
|
+
q.getColumn = type;
|
|
4575
4585
|
const selected = setParserForSelectedString(
|
|
4576
4586
|
query,
|
|
4577
4587
|
arg,
|
|
@@ -4587,7 +4597,7 @@ const _get = (query, returnType, arg) => {
|
|
|
4587
4597
|
] : void 0;
|
|
4588
4598
|
} else {
|
|
4589
4599
|
type = arg.result.value;
|
|
4590
|
-
q
|
|
4600
|
+
q.getColumn = type;
|
|
4591
4601
|
addParserForRawExpression(query, getValueKey, arg);
|
|
4592
4602
|
q.select = [q.expr = arg];
|
|
4593
4603
|
}
|
|
@@ -6432,7 +6442,7 @@ class FnExpression extends Expression {
|
|
|
6432
6442
|
Object.assign(query, value.operators);
|
|
6433
6443
|
query.q.returnType = "valueOrThrow";
|
|
6434
6444
|
query.q.returnsOne = true;
|
|
6435
|
-
query.q
|
|
6445
|
+
query.q.getColumn = value;
|
|
6436
6446
|
query.q.select = [this];
|
|
6437
6447
|
const { parseFn } = value;
|
|
6438
6448
|
if (parseFn) {
|
|
@@ -9151,7 +9161,6 @@ class MergeQueryMethods {
|
|
|
9151
9161
|
break;
|
|
9152
9162
|
}
|
|
9153
9163
|
}
|
|
9154
|
-
a[getValueKey] = b[getValueKey];
|
|
9155
9164
|
if (b.returnType)
|
|
9156
9165
|
a.returnType = b.returnType;
|
|
9157
9166
|
return query;
|