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.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PoolConfig, Pool, PoolClient } from 'pg';
|
|
2
2
|
import * as orchid_core from 'orchid-core';
|
|
3
|
-
import { QueryResultRow, AdapterConfigBase, AdapterBase, QueryInput, SingleSqlItem, Sql, RecordUnknown, RecordKeyTrue, EmptyObject, QueryBaseCommon, QueryColumns, QueryMetaBase, QueryReturnType, QueryThen, Expression, MaybeArray, TemplateLiteralArgs, QueryColumn, MaybePromise, FnUnknownToUnknown, RecordString, ColumnsShapeBase, ColumnsParsers, PickQueryTable, BatchParsers, HookSelect, QueryLogObject, QueryLogger, QueryDataTransform, ExpressionChain,
|
|
3
|
+
import { QueryResultRow, AdapterConfigBase, AdapterBase, QueryInput, SingleSqlItem, Sql, RecordUnknown, RecordKeyTrue, EmptyObject, QueryBaseCommon, QueryColumns, QueryMetaBase, QueryReturnType, QueryThen, Expression, MaybeArray, TemplateLiteralArgs, QueryColumn, MaybePromise, FnUnknownToUnknown, RecordString, ColumnsShapeBase, ColumnsParsers, PickQueryTable, BatchParsers, HookSelect, QueryLogObject, QueryLogger, QueryDataTransform, ExpressionChain, PickQueryShape, PickQueryTableMetaResult, EmptyTuple, PickQueryMeta, PickQueryMetaResultReturnType, QueryColumnToNullable, SelectableBase, PickQueryMetaShape, PickQueryTableMetaResultShape, PickQueryMetaResultWindows, PickOutputTypeAndOperators, PickQueryResult, ExpressionData, ValExpression, PickOutputType, SQLQueryArgs, ColumnSchemaConfig, DateColumnData, ColumnToCodeCtx, Code, TimeInterval, ColumnTypeSchemaArg, ColumnDataBase, ArrayMethodsData, RawSQLBase, RawSQLValues, ExpressionTypeMethod, DynamicSQLArg, StaticSQLArgs, ForeignKeyTable, ColumnNameOfTable, BaseNumberData, PickColumnBaseData, ColumnWithDefault, StringTypeData, PrimaryKeyColumn, ParseColumn, EncodeColumn, QueryColumnsInit, QueryLogOptions, DefaultSelectColumns, DbBase, QueryCatch, TransactionState, ColumnTypeBase, PickQueryUniqueProperties, PickQueryMetaResult, IsQuery, PickQueryTableMetaResultInputType, getValueKey, PickQueryResultUniqueColumns, QueryInternalBase, PickQueryReturnType, PickType, ColumnShapeOutput, OperatorsNullable, PickQueryMetaReturnType, UniqueColumn, TimestampHelpers, Codes, ColumnDataCheckBase } from 'orchid-core';
|
|
4
4
|
import { inspect } from 'node:util';
|
|
5
5
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
6
6
|
|
|
@@ -384,6 +384,11 @@ interface CommonQueryData {
|
|
|
384
384
|
outerJoinOverrides?: JoinOverrides;
|
|
385
385
|
schema?: string;
|
|
386
386
|
select?: SelectItem[];
|
|
387
|
+
/**
|
|
388
|
+
* column type for query with 'value' or 'valueOrThrow' return type
|
|
389
|
+
* Is needed in {@link getShapeFromSelect} to get shape of sub-select that returns a single value.
|
|
390
|
+
*/
|
|
391
|
+
getColumn?: QueryColumn;
|
|
387
392
|
expr?: Expression;
|
|
388
393
|
as?: string;
|
|
389
394
|
from?: MaybeArray<QueryDataFromItem>;
|
|
@@ -454,7 +459,6 @@ interface SelectQueryData extends CommonQueryData {
|
|
|
454
459
|
tableNames?: string[] | Expression;
|
|
455
460
|
mode?: 'NO WAIT' | 'SKIP LOCKED';
|
|
456
461
|
};
|
|
457
|
-
[getValueKey]?: QueryColumn;
|
|
458
462
|
}
|
|
459
463
|
type CreateKind = 'object' | 'raw' | 'from';
|
|
460
464
|
interface InsertQueryData extends CommonQueryData {
|
package/dist/index.js
CHANGED
|
@@ -2146,7 +2146,7 @@ const andOrToSql = (ctx, table, query, quotedAs, parens) => {
|
|
|
2146
2146
|
} else {
|
|
2147
2147
|
return;
|
|
2148
2148
|
}
|
|
2149
|
-
return parens ? `(${sql})` : sql;
|
|
2149
|
+
return parens && sql ? `(${sql})` : sql;
|
|
2150
2150
|
};
|
|
2151
2151
|
const processAnds = (and, ctx, table, query, quotedAs, parens) => {
|
|
2152
2152
|
const ands = [];
|
|
@@ -4002,19 +4002,19 @@ const filterResult = (q, returnType, queryResult, result, tempColumns, hasAfterH
|
|
|
4002
4002
|
}
|
|
4003
4003
|
}
|
|
4004
4004
|
if (returnType === "value") {
|
|
4005
|
-
return (_a = result[0]) == null ? void 0 : _a[queryResult
|
|
4005
|
+
return (_a = result[0]) == null ? void 0 : _a[getFirstResultKey(q, queryResult)];
|
|
4006
4006
|
}
|
|
4007
4007
|
if (returnType === "valueOrThrow") {
|
|
4008
4008
|
const row = result[0];
|
|
4009
4009
|
if (!row)
|
|
4010
4010
|
throw new NotFoundError(q);
|
|
4011
|
-
return row[queryResult
|
|
4011
|
+
return row[getFirstResultKey(q, queryResult)];
|
|
4012
4012
|
}
|
|
4013
4013
|
if (returnType === "rowCount") {
|
|
4014
4014
|
return queryResult.rowCount;
|
|
4015
4015
|
}
|
|
4016
4016
|
if (returnType === "pluck") {
|
|
4017
|
-
const key = queryResult
|
|
4017
|
+
const key = getFirstResultKey(q, queryResult);
|
|
4018
4018
|
return result.map((row) => row[key]);
|
|
4019
4019
|
}
|
|
4020
4020
|
if (returnType === "rows") {
|
|
@@ -4023,6 +4023,16 @@ const filterResult = (q, returnType, queryResult, result, tempColumns, hasAfterH
|
|
|
4023
4023
|
}
|
|
4024
4024
|
return;
|
|
4025
4025
|
};
|
|
4026
|
+
const getFirstResultKey = (q, queryResult) => {
|
|
4027
|
+
if (q.q.select) {
|
|
4028
|
+
return queryResult.fields[0].name;
|
|
4029
|
+
} else {
|
|
4030
|
+
for (const key in q.q.selectedComputeds) {
|
|
4031
|
+
return key;
|
|
4032
|
+
}
|
|
4033
|
+
}
|
|
4034
|
+
return;
|
|
4035
|
+
};
|
|
4026
4036
|
const filterAllResult = (result, tempColumns, hasAfterHook) => {
|
|
4027
4037
|
if (tempColumns == null ? void 0 : tempColumns.size) {
|
|
4028
4038
|
if (hasAfterHook) {
|
|
@@ -4457,7 +4467,7 @@ const getShapeFromSelect = (q, isSubQuery) => {
|
|
|
4457
4467
|
} else if (it) {
|
|
4458
4468
|
const { returnType } = it.q;
|
|
4459
4469
|
if (returnType === "value" || returnType === "valueOrThrow") {
|
|
4460
|
-
const type = it.q
|
|
4470
|
+
const type = it.q.getColumn;
|
|
4461
4471
|
if (type)
|
|
4462
4472
|
result[key] = type;
|
|
4463
4473
|
} else {
|
|
@@ -4573,7 +4583,7 @@ const _get = (query, returnType, arg) => {
|
|
|
4573
4583
|
}
|
|
4574
4584
|
}
|
|
4575
4585
|
}
|
|
4576
|
-
q
|
|
4586
|
+
q.getColumn = type;
|
|
4577
4587
|
const selected = setParserForSelectedString(
|
|
4578
4588
|
query,
|
|
4579
4589
|
arg,
|
|
@@ -4589,7 +4599,7 @@ const _get = (query, returnType, arg) => {
|
|
|
4589
4599
|
] : void 0;
|
|
4590
4600
|
} else {
|
|
4591
4601
|
type = arg.result.value;
|
|
4592
|
-
q
|
|
4602
|
+
q.getColumn = type;
|
|
4593
4603
|
addParserForRawExpression(query, orchidCore.getValueKey, arg);
|
|
4594
4604
|
q.select = [q.expr = arg];
|
|
4595
4605
|
}
|
|
@@ -6434,7 +6444,7 @@ class FnExpression extends orchidCore.Expression {
|
|
|
6434
6444
|
Object.assign(query, value.operators);
|
|
6435
6445
|
query.q.returnType = "valueOrThrow";
|
|
6436
6446
|
query.q.returnsOne = true;
|
|
6437
|
-
query.q
|
|
6447
|
+
query.q.getColumn = value;
|
|
6438
6448
|
query.q.select = [this];
|
|
6439
6449
|
const { parseFn } = value;
|
|
6440
6450
|
if (parseFn) {
|
|
@@ -9153,7 +9163,6 @@ class MergeQueryMethods {
|
|
|
9153
9163
|
break;
|
|
9154
9164
|
}
|
|
9155
9165
|
}
|
|
9156
|
-
a[orchidCore.getValueKey] = b[orchidCore.getValueKey];
|
|
9157
9166
|
if (b.returnType)
|
|
9158
9167
|
a.returnType = b.returnType;
|
|
9159
9168
|
return query;
|