pqb 0.48.6 → 0.49.1
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 +16 -7
- package/dist/index.js +44 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -10
- 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
|
|
|
@@ -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
|
}
|
|
@@ -4066,7 +4076,16 @@ const handleComputed = (q, computeds, column) => {
|
|
|
4066
4076
|
};
|
|
4067
4077
|
const getShapeFromSelect = (q, isSubQuery) => {
|
|
4068
4078
|
const query = q.q;
|
|
4069
|
-
const {
|
|
4079
|
+
const { shape } = query;
|
|
4080
|
+
let select;
|
|
4081
|
+
if (query.selectedComputeds) {
|
|
4082
|
+
select = query.select ? [...query.select] : [];
|
|
4083
|
+
for (const key in query.selectedComputeds) {
|
|
4084
|
+
select.push(...query.selectedComputeds[key].deps);
|
|
4085
|
+
}
|
|
4086
|
+
} else {
|
|
4087
|
+
select = query.select;
|
|
4088
|
+
}
|
|
4070
4089
|
let result;
|
|
4071
4090
|
if (!select) {
|
|
4072
4091
|
if (isSubQuery) {
|
|
@@ -4125,18 +4144,33 @@ const addColumnToShapeFromSelect = (q, arg, shape, query, result, isSubQuery, ke
|
|
|
4125
4144
|
result[key || column] = shape[column];
|
|
4126
4145
|
} else {
|
|
4127
4146
|
const it = query.joinedShapes?.[table]?.[column];
|
|
4128
|
-
if (it)
|
|
4147
|
+
if (it)
|
|
4148
|
+
result[key || column] = mapSubSelectColumn(
|
|
4149
|
+
it,
|
|
4150
|
+
isSubQuery
|
|
4151
|
+
);
|
|
4129
4152
|
}
|
|
4130
4153
|
} else if (arg === "*") {
|
|
4131
4154
|
for (const key2 in shape) {
|
|
4132
|
-
result[key2] =
|
|
4155
|
+
result[key2] = mapSubSelectColumn(
|
|
4156
|
+
shape[key2],
|
|
4157
|
+
isSubQuery
|
|
4158
|
+
);
|
|
4133
4159
|
}
|
|
4134
4160
|
} else {
|
|
4135
|
-
result[key || arg] =
|
|
4161
|
+
result[key || arg] = mapSubSelectColumn(
|
|
4162
|
+
shape[arg],
|
|
4163
|
+
isSubQuery
|
|
4164
|
+
);
|
|
4136
4165
|
}
|
|
4137
4166
|
};
|
|
4138
|
-
const
|
|
4139
|
-
|
|
4167
|
+
const mapSubSelectColumn = (column, isSubQuery) => {
|
|
4168
|
+
if (!isSubQuery || !column || !column.data.name && !column.data.explicitSelect) {
|
|
4169
|
+
return column;
|
|
4170
|
+
}
|
|
4171
|
+
const cloned = Object.create(column);
|
|
4172
|
+
cloned.data = { ...column.data, name: void 0, explicitSelect: void 0 };
|
|
4173
|
+
return cloned;
|
|
4140
4174
|
};
|
|
4141
4175
|
function _querySelect(q, args) {
|
|
4142
4176
|
var _a;
|