pqb 0.48.5 → 0.49.0
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 +17 -8
- package/dist/index.js +29 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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, IsQuery, PickQueryReturnType, RecordUnknown, Expression, MaybeArray, ColumnTypesBase, TemplateLiteralArgs, EmptyObject, QueryColumns, QueryColumn, MaybePromise, FnUnknownToUnknown, QueryMetaBase, QueryReturnType, RecordString, ColumnsShapeBase, ColumnsParsers, PickQueryTable, HookSelect, BatchParsers, QueryLogObject, QueryLogger, QueryDataTransform, ExpressionChain, PickQueryShape, ColumnSchemaConfig, RawSQLBase, RawSQLValues, ExpressionTypeMethod, DynamicSQLArg, ExpressionData, StaticSQLArgs, SQLQueryArgs, PickQueryTableMetaResult, EmptyTuple, PickQueryMeta, PickQueryMetaResultReturnType, QueryColumnToNullable, QueryThenByQuery, ColumnShapeInput, SelectableBase, PickQueryMetaShape, PickQueryTableMetaResultShape, PickQueryMetaResultWindows, PickOutputTypeAndOperators, PickQueryResult, ValExpression, PickOutputType, QueryThen, DateColumnData, ColumnToCodeCtx, Code, TimeInterval, ColumnTypeSchemaArg, ColumnDataBase, ArrayMethodsData, ForeignKeyTable, ColumnNameOfTable, BaseNumberData, PickColumnBaseData, ColumnWithDefault, StringTypeData, PrimaryKeyColumn, ColumnTypeBase, ParseColumn, ParseNullColumn, EncodeColumn, QueryColumnsInit, QueryLogOptions, DefaultSelectColumns, DefaultSelectOutput, QueryThenShallowSimplifyArr, QueryCatch, TransactionState, QueryColumnOfDataType, PickQueryUniqueProperties, PickQueryMetaResult, PickQueryTableMetaResultInputType, UnionToIntersection, getValueKey, QueryThenByReturnType, QueryMetaIsSubQuery, QueryThenShallowSimplifyOptional, QueryThenShallowSimplify, PickQueryResultReturnType, PickQueryResultReturnTypeUniqueColumns, QueryInternalBase, PickType, RecordKeyTrue, ColumnShapeOutput, OperatorsNullable, PickQueryMetaReturnType, UniqueColumn, TimestampHelpers, ShallowSimplify, Codes, ColumnDataCheckBase } from 'orchid-core';
|
|
3
|
+
import { QueryResultRow, AdapterConfigBase, AdapterBase, QueryInput, SingleSqlItem, Sql, IsQuery, PickQueryReturnType, RecordUnknown, Expression, MaybeArray, ColumnTypesBase, TemplateLiteralArgs, EmptyObject, QueryColumns, QueryColumn, MaybePromise, FnUnknownToUnknown, QueryMetaBase, QueryReturnType, RecordString, ColumnsShapeBase, ColumnsParsers, PickQueryTable, HookSelect, BatchParsers, QueryLogObject, QueryLogger, QueryDataTransform, ExpressionChain, PickQueryShape, ColumnSchemaConfig, RawSQLBase, RawSQLValues, ExpressionTypeMethod, DynamicSQLArg, ExpressionData, StaticSQLArgs, SQLQueryArgs, PickQueryTableMetaResult, EmptyTuple, PickQueryMeta, PickQueryMetaResultReturnType, QueryColumnToNullable, QueryThenByQuery, ColumnShapeInput, SelectableBase, PickQueryMetaShape, PickQueryTableMetaResultShape, PickQueryMetaResultWindows, PickOutputTypeAndOperators, PickQueryResult, ValExpression, PickOutputType, QueryThen, DateColumnData, ColumnToCodeCtx, Code, TimeInterval, ColumnTypeSchemaArg, ColumnDataBase, ArrayMethodsData, ForeignKeyTable, ColumnNameOfTable, BaseNumberData, PickColumnBaseData, ColumnWithDefault, StringTypeData, PrimaryKeyColumn, ColumnTypeBase, ParseColumn, ParseNullColumn, EncodeColumn, QueryColumnsInit, QueryLogOptions, DefaultSelectColumns, DefaultSelectOutput, QueryThenShallowSimplifyArr, QueryCatch, TransactionState, QueryColumnOfDataType, PickQueryUniqueProperties, PickQueryMetaResult, PickQueryTableMetaResultInputType, UnionToIntersection, getValueKey, QueryThenByReturnType, QueryMetaIsSubQuery, QueryReturnTypeAll, QueryReturnTypeOptional, QueryThenShallowSimplifyOptional, QueryThenShallowSimplify, PickQueryResultReturnType, PickQueryResultReturnTypeUniqueColumns, QueryInternalBase, PickType, RecordKeyTrue, ColumnShapeOutput, OperatorsNullable, PickQueryMetaReturnType, UniqueColumn, TimestampHelpers, ShallowSimplify, Codes, ColumnDataCheckBase } from 'orchid-core';
|
|
4
4
|
import { inspect } from 'node:util';
|
|
5
5
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
6
6
|
|
|
@@ -373,7 +373,7 @@ interface CommonQueryData {
|
|
|
373
373
|
aliases: string[];
|
|
374
374
|
};
|
|
375
375
|
selectAllColumns?: string[];
|
|
376
|
-
|
|
376
|
+
selectableShape: RecordUnknown;
|
|
377
377
|
/**
|
|
378
378
|
* column type for query with 'value' or 'valueOrThrow' return type
|
|
379
379
|
* Is needed in {@link getShapeFromSelect} to get shape of sub-select that returns a single value.
|
|
@@ -7105,22 +7105,31 @@ declare class QueryMap {
|
|
|
7105
7105
|
*
|
|
7106
7106
|
* @param fn - function to transform an individual record
|
|
7107
7107
|
*/
|
|
7108
|
-
map<T extends PickQueryReturnType, Result>(this: T, fn:
|
|
7108
|
+
map<T extends PickQueryReturnType, Result>(this: T, fn: T extends {
|
|
7109
|
+
returnType: 'valueOrThrow';
|
|
7110
|
+
then: QueryThen<infer Data | null>;
|
|
7111
|
+
} ? (input: Data) => Result : (input: T['returnType'] extends QueryReturnTypeAll | 'pluck' ? T extends {
|
|
7109
7112
|
then: QueryThen<(infer Data)[]>;
|
|
7110
7113
|
} ? Data : never : T extends {
|
|
7111
7114
|
then: QueryThen<infer Data | undefined>;
|
|
7112
7115
|
} ? Data : never) => Result): Result extends RecordUnknown ? {
|
|
7113
7116
|
[K in keyof T]: K extends 'result' ? {
|
|
7114
7117
|
[K in keyof Result]: QueryColumn<Result[K]>;
|
|
7115
|
-
} : K extends 'then' ? QueryThen<T['returnType'] extends
|
|
7118
|
+
} : K extends 'then' ? QueryThen<T['returnType'] extends QueryReturnTypeAll ? Result[] : T['returnType'] extends QueryReturnTypeOptional ? Result | undefined : Result> : T[K];
|
|
7116
7119
|
} : {
|
|
7117
|
-
[K in keyof T]: K extends 'returnType' ? T['returnType'] extends
|
|
7120
|
+
[K in keyof T]: K extends 'returnType' ? T['returnType'] extends QueryReturnTypeAll | 'pluck' ? 'pluck' : T['returnType'] extends 'one' ? 'value' : 'valueOrThrow' : K extends 'result' ? T['returnType'] extends QueryReturnTypeAll | 'pluck' ? {
|
|
7118
7121
|
pluck: QueryColumn<Result>;
|
|
7119
|
-
} : T['returnType'] extends
|
|
7122
|
+
} : T['returnType'] extends QueryReturnTypeOptional ? {
|
|
7120
7123
|
value: QueryColumn<Result | undefined>;
|
|
7121
7124
|
} : {
|
|
7122
|
-
value: QueryColumn<
|
|
7123
|
-
|
|
7125
|
+
value: QueryColumn<T extends {
|
|
7126
|
+
returnType: 'valueOrThrow';
|
|
7127
|
+
then: QueryThen<unknown | null>;
|
|
7128
|
+
} ? Result | null : Result>;
|
|
7129
|
+
} : K extends 'then' ? QueryThen<T['returnType'] extends QueryReturnTypeAll | 'pluck' ? Result[] : T['returnType'] extends QueryReturnTypeOptional ? Result | undefined : T extends {
|
|
7130
|
+
returnType: 'valueOrThrow';
|
|
7131
|
+
then: QueryThen<unknown | null>;
|
|
7132
|
+
} ? Result | null : Result> : T[K];
|
|
7124
7133
|
};
|
|
7125
7134
|
}
|
|
7126
7135
|
|
package/dist/index.js
CHANGED
|
@@ -3002,7 +3002,12 @@ const runAfterCommit = async (afterCommit, result) => {
|
|
|
3002
3002
|
const applyBatchTransforms = (q, batches) => {
|
|
3003
3003
|
if (q.transform) {
|
|
3004
3004
|
for (const item of batches) {
|
|
3005
|
-
item.parent[item.key] =
|
|
3005
|
+
item.parent[item.key] = orchidCore.applyTransforms(
|
|
3006
|
+
q,
|
|
3007
|
+
q.returnType,
|
|
3008
|
+
q.transform,
|
|
3009
|
+
item.data
|
|
3010
|
+
);
|
|
3006
3011
|
}
|
|
3007
3012
|
}
|
|
3008
3013
|
};
|
|
@@ -3784,8 +3789,9 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
|
|
|
3784
3789
|
const { parsers } = query;
|
|
3785
3790
|
if (parsers) {
|
|
3786
3791
|
if (returnType === "one") {
|
|
3787
|
-
for (const
|
|
3788
|
-
if (data) parseRecord(parsers, data);
|
|
3792
|
+
for (const batch of batches) {
|
|
3793
|
+
if (batch.data) parseRecord(parsers, batch.data);
|
|
3794
|
+
else batch.data = void 0;
|
|
3789
3795
|
}
|
|
3790
3796
|
} else {
|
|
3791
3797
|
for (const { data } of batches) {
|
|
@@ -3793,7 +3799,11 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
|
|
|
3793
3799
|
parseRecord(parsers, data);
|
|
3794
3800
|
}
|
|
3795
3801
|
}
|
|
3796
|
-
} else if (returnType
|
|
3802
|
+
} else if (returnType === "one") {
|
|
3803
|
+
for (const batch of batches) {
|
|
3804
|
+
if (!batch.data) batch.data = void 0;
|
|
3805
|
+
}
|
|
3806
|
+
} else {
|
|
3797
3807
|
for (const { data } of batches) {
|
|
3798
3808
|
if (!data) throw new NotFoundError(arg);
|
|
3799
3809
|
}
|
|
@@ -4337,14 +4347,14 @@ function queryFrom(self, arg) {
|
|
|
4337
4347
|
data.batchParsers = q.q.batchParsers;
|
|
4338
4348
|
}
|
|
4339
4349
|
data.from = arg;
|
|
4340
|
-
data.selectAllColumns = data.
|
|
4350
|
+
data.selectAllColumns = data.scopes = void 0;
|
|
4341
4351
|
return self;
|
|
4342
4352
|
}
|
|
4343
4353
|
function queryFromSql(self, args) {
|
|
4344
4354
|
const data = self.q;
|
|
4345
4355
|
data.as || (data.as = "t");
|
|
4346
4356
|
data.from = sqlQueryArgsToExpression(args);
|
|
4347
|
-
data.selectAllColumns =
|
|
4357
|
+
data.selectAllColumns = void 0;
|
|
4348
4358
|
return self;
|
|
4349
4359
|
}
|
|
4350
4360
|
class FromMethods {
|
|
@@ -4816,7 +4826,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
4816
4826
|
if (item === "*") {
|
|
4817
4827
|
if (hookSelect) {
|
|
4818
4828
|
selected ?? (selected = {});
|
|
4819
|
-
for (const key in query.
|
|
4829
|
+
for (const key in query.selectableShape) {
|
|
4820
4830
|
selected[key] = quotedAs;
|
|
4821
4831
|
}
|
|
4822
4832
|
}
|
|
@@ -4942,10 +4952,7 @@ function selectedObjectToSQL(ctx, quotedAs, item) {
|
|
|
4942
4952
|
}
|
|
4943
4953
|
const selectAllSql = (query, quotedAs, jsonList) => {
|
|
4944
4954
|
if (jsonList) {
|
|
4945
|
-
Object.assign(
|
|
4946
|
-
jsonList,
|
|
4947
|
-
query.selectAllKeys || query.shape
|
|
4948
|
-
);
|
|
4955
|
+
Object.assign(jsonList, query.selectableShape);
|
|
4949
4956
|
}
|
|
4950
4957
|
return query.join?.length ? query.selectAllColumns?.map((item) => `${quotedAs}.${item}`).join(", ") || `${quotedAs}.*` : query.selectAllColumns?.join(", ") || "*";
|
|
4951
4958
|
};
|
|
@@ -10249,7 +10256,7 @@ const mergableObjects = /* @__PURE__ */ new Set([
|
|
|
10249
10256
|
"joinedBatchParsers",
|
|
10250
10257
|
"selectedComputeds"
|
|
10251
10258
|
]);
|
|
10252
|
-
const dontMergeArrays = /* @__PURE__ */ new Set(["selectAllColumns"
|
|
10259
|
+
const dontMergeArrays = /* @__PURE__ */ new Set(["selectAllColumns"]);
|
|
10253
10260
|
class MergeQueryMethods {
|
|
10254
10261
|
merge(q) {
|
|
10255
10262
|
const query = _clone(this);
|
|
@@ -12751,20 +12758,26 @@ class Db extends QueryMethods {
|
|
|
12751
12758
|
);
|
|
12752
12759
|
this.columns = columns;
|
|
12753
12760
|
if (options.computed) applyComputedColumns(this, options.computed);
|
|
12761
|
+
const selectableShape = this.q.selectableShape = {};
|
|
12754
12762
|
if (prepareSelectAll) {
|
|
12755
12763
|
const list = [];
|
|
12756
|
-
const keys = {};
|
|
12757
12764
|
for (const key in shape) {
|
|
12758
12765
|
const column = shape[key];
|
|
12759
|
-
if (!column.data.explicitSelect) {
|
|
12766
|
+
if (!column.data.explicitSelect && !(column instanceof VirtualColumn)) {
|
|
12760
12767
|
list.push(
|
|
12761
12768
|
column.data.name ? `"${column.data.name}" "${key}"` : `"${key}"`
|
|
12762
12769
|
);
|
|
12763
|
-
|
|
12770
|
+
selectableShape[key] = column;
|
|
12764
12771
|
}
|
|
12765
12772
|
}
|
|
12766
12773
|
this.q.selectAllColumns = list;
|
|
12767
|
-
|
|
12774
|
+
} else {
|
|
12775
|
+
for (const key in shape) {
|
|
12776
|
+
const column = shape[key];
|
|
12777
|
+
if (column instanceof VirtualColumn) {
|
|
12778
|
+
selectableShape[key] = column;
|
|
12779
|
+
}
|
|
12780
|
+
}
|
|
12768
12781
|
}
|
|
12769
12782
|
if (modifyQuery) {
|
|
12770
12783
|
for (const cb of modifyQuery) {
|