pqb 0.3.8 → 0.4.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 +52 -16
- package/dist/index.esm.js +63 -10
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +62 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/pnpm-lock.yaml +2821 -0
- package/src/db.ts +9 -1
- package/src/errors.test.ts +79 -0
- package/src/errors.ts +82 -0
- package/src/query.ts +6 -0
- package/src/queryMethods/then.test.ts +3 -1
- package/src/queryMethods/then.ts +49 -15
- package/src/test-utils.ts +8 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PoolConfig, Pool, PoolClient } from 'pg';
|
|
1
|
+
import { PoolConfig, Pool, PoolClient, DatabaseError } from 'pg';
|
|
2
2
|
|
|
3
3
|
declare type AliasOrTable<T extends Pick<Query, 'tableAlias' | 'table'>> = T['tableAlias'] extends string ? T['tableAlias'] : T['table'] extends string ? T['table'] : never;
|
|
4
4
|
declare type StringKey<K extends PropertyKey> = Exclude<K, symbol | number>;
|
|
@@ -549,11 +549,14 @@ declare const pushOrNewArray: <Arr extends unknown[]>(arr: Arr | undefined, valu
|
|
|
549
549
|
|
|
550
550
|
declare type ThenResult<Res> = (resolve?: (value: Res) => any, reject?: (error: any) => any) => Promise<Res | never>;
|
|
551
551
|
declare const queryMethodByReturnType: Record<QueryReturnType, 'query' | 'arrays'>;
|
|
552
|
+
declare type Resolve = (result: any) => any;
|
|
553
|
+
declare type Reject = (error: any) => any;
|
|
552
554
|
declare class Then {
|
|
553
|
-
then(
|
|
555
|
+
get then(): typeof maybeWrappedThen;
|
|
554
556
|
catch<T extends Query, Result>(this: T, fn: (reason: any) => Result | PromiseLike<Result>): Promise<ReturnType<T['then']> | Result>;
|
|
555
557
|
}
|
|
556
558
|
declare const handleResult: CommonQueryData['handleResult'];
|
|
559
|
+
declare function maybeWrappedThen(this: Query, resolve?: Resolve, reject?: Reject): Promise<any>;
|
|
557
560
|
declare const parseResult: (q: Query, returnType: QueryReturnType | undefined, result: QueryResult) => unknown;
|
|
558
561
|
declare const parseRecord: (parsers: ColumnsParsers, row: any) => any;
|
|
559
562
|
|
|
@@ -815,6 +818,50 @@ declare class OnQueryBuilder<S extends QueryBase = QueryBase, J extends QueryBas
|
|
|
815
818
|
_onJsonPathEquals<T extends this>(this: T, ...args: OnJsonPathEqualsArgs<T>): T;
|
|
816
819
|
}
|
|
817
820
|
|
|
821
|
+
declare class PormError extends Error {
|
|
822
|
+
}
|
|
823
|
+
declare type QueryErrorName = 'parseComplete' | 'bindComplete' | 'closeComplete' | 'noData' | 'portalSuspended' | 'replicationStart' | 'emptyQuery' | 'copyDone' | 'copyData' | 'rowDescription' | 'parameterDescription' | 'parameterStatus' | 'backendKeyData' | 'notification' | 'readyForQuery' | 'commandComplete' | 'dataRow' | 'copyInResponse' | 'copyOutResponse' | 'authenticationOk' | 'authenticationMD5Password' | 'authenticationCleartextPassword' | 'authenticationSASL' | 'authenticationSASLContinue' | 'authenticationSASLFinal' | 'error' | 'notice';
|
|
824
|
+
declare class QueryError<T extends {
|
|
825
|
+
shape: ColumnsShape;
|
|
826
|
+
} = {
|
|
827
|
+
shape: ColumnsShape;
|
|
828
|
+
}> extends DatabaseError {
|
|
829
|
+
message: string;
|
|
830
|
+
name: QueryErrorName;
|
|
831
|
+
stack: string | undefined;
|
|
832
|
+
code: string | undefined;
|
|
833
|
+
detail: string | undefined;
|
|
834
|
+
severity: string | undefined;
|
|
835
|
+
hint: string | undefined;
|
|
836
|
+
position: string | undefined;
|
|
837
|
+
internalPosition: string | undefined;
|
|
838
|
+
internalQuery: string | undefined;
|
|
839
|
+
where: string | undefined;
|
|
840
|
+
schema: string | undefined;
|
|
841
|
+
table: string | undefined;
|
|
842
|
+
column: string | undefined;
|
|
843
|
+
dataType: string | undefined;
|
|
844
|
+
constraint: string | undefined;
|
|
845
|
+
file: string | undefined;
|
|
846
|
+
line: string | undefined;
|
|
847
|
+
routine: string | undefined;
|
|
848
|
+
get isUnique(): boolean;
|
|
849
|
+
columnsCache?: {
|
|
850
|
+
[K in keyof T['shape']]?: true;
|
|
851
|
+
};
|
|
852
|
+
get columns(): T["shape"] extends infer T_1 ? { [K in keyof T_1]?: true | undefined; } : never;
|
|
853
|
+
}
|
|
854
|
+
declare class NotFoundError extends PormError {
|
|
855
|
+
constructor(message?: string);
|
|
856
|
+
}
|
|
857
|
+
declare class MoreThanOneRowError extends PormError {
|
|
858
|
+
}
|
|
859
|
+
declare class PormInternalError extends Error {
|
|
860
|
+
}
|
|
861
|
+
declare class UnhandledTypeError extends PormInternalError {
|
|
862
|
+
constructor(value: never);
|
|
863
|
+
}
|
|
864
|
+
|
|
818
865
|
declare type DbTableOptions = {
|
|
819
866
|
schema?: string;
|
|
820
867
|
} & QueryLogOptions;
|
|
@@ -855,6 +902,7 @@ interface Db<Table extends string | undefined = undefined, Shape extends Columns
|
|
|
855
902
|
columnsParsers?: ColumnsParsers;
|
|
856
903
|
relations: Relations;
|
|
857
904
|
withData: Query['withData'];
|
|
905
|
+
error: new (message: string, length: number, name: QueryErrorName) => QueryError<this>;
|
|
858
906
|
[defaultsKey]: Record<{
|
|
859
907
|
[K in keyof Shape]: Shape[K]['hasDefault'] extends true ? K : never;
|
|
860
908
|
}[keyof Shape], true>;
|
|
@@ -1493,6 +1541,7 @@ declare type Query = QueryMethods & {
|
|
|
1493
1541
|
columnsParsers?: ColumnsParsers;
|
|
1494
1542
|
relations: RelationsBase;
|
|
1495
1543
|
withData: WithDataBase;
|
|
1544
|
+
error: new (message: string, length: number, name: QueryErrorName) => QueryError;
|
|
1496
1545
|
[defaultsKey]: {};
|
|
1497
1546
|
};
|
|
1498
1547
|
declare type Selectable<T extends QueryBase> = StringKey<keyof T['selectable']>;
|
|
@@ -4256,17 +4305,4 @@ declare const setQueryObjectValue: <T extends {
|
|
|
4256
4305
|
query: QueryData;
|
|
4257
4306
|
}>(q: T, object: string, key: string, value: unknown) => T;
|
|
4258
4307
|
|
|
4259
|
-
|
|
4260
|
-
}
|
|
4261
|
-
declare class NotFoundError extends PormError {
|
|
4262
|
-
constructor(message?: string);
|
|
4263
|
-
}
|
|
4264
|
-
declare class MoreThanOneRowError extends PormError {
|
|
4265
|
-
}
|
|
4266
|
-
declare class PormInternalError extends Error {
|
|
4267
|
-
}
|
|
4268
|
-
declare class UnhandledTypeError extends PormInternalError {
|
|
4269
|
-
constructor(value: never);
|
|
4270
|
-
}
|
|
4271
|
-
|
|
4272
|
-
export { Adapter, AdapterOptions, AddQueryJoinedTable, AddQuerySelect, AddQueryWith, AfterCallback, Aggregate, Aggregate1ArgumentTypes, AggregateArg, AggregateItem, AggregateItemArg, AggregateItemOptions, AggregateOptions, AliasOrTable, AnyColumnType, AnyColumnTypeCreator, ArrayCardinality, ArrayColumn, ArrayData, ArrayOfColumnsObjects, AssertArray, BaseNumberData, BaseRelation, BaseStringData, BeforeCallback, BelongsToNestedInsert, BelongsToNestedUpdate, BelongsToRelation, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanExpression, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, Clear, ClearStatement, CoalesceString, ColumnData, ColumnInfo, ColumnInfoMethods, ColumnInfoQueryData, ColumnInput, ColumnNameOfModel, ColumnOperators, ColumnOutput, ColumnParser, ColumnShapeInput, ColumnShapeOutput, ColumnType, ColumnTypes, ColumnTypesBase, ColumnsObject, ColumnsParsers, ColumnsShape, CommonQueryData, DateBaseColumn, DateColumn, DateColumnData, DateTimeBaseClass, DateTimeColumnData, DateTimeWithTimeZoneBaseClass, Db, DbOptions, DbTableOptions, DecimalBaseColumn, DecimalColumn, DecimalColumnData, DeepPartial, DefaultSelectColumns, Delete, DeleteQueryData, DoublePrecisionColumn, DropMode, EMPTY_OBJECT, EmptyObject, EnumColumn, EnumLike, Except, Expression, ExpressionOfType, ExpressionOutput, FilterTuple, For, ForeignKey, ForeignKeyModel, ForeignKeyModelWithColumns, ForeignKeyOptions, From, GetArg, HasAndBelongsToManyRelation, HasManyNestedInsert, HasManyNestedUpdate, HasManyRelation, HasOneNestedInsert, HasOneNestedUpdate, HasOneRelation, Having, HavingArg, HavingItem, IndexColumnOptions, IndexOptions, InetColumn, Insert, InsertData, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsEqual, JSONAny, JSONArray, JSONBigInt, JSONBoolean, JSONColumn, JSONDate, JSONDiscriminatedObject, JSONDiscriminatedUnion, JSONEnum, JSONInstanceOf, JSONIntersection, JSONLazy, JSONLiteral, JSONMap, JSONNaN, JSONNativeEnum, JSONNever, JSONNotNullable, JSONNotNullish, JSONNull, JSONNullable, JSONNullish, JSONNumber, JSONObject, JSONObjectShape, JSONOptional, JSONRecord, JSONRecordKeyType, JSONRequired, JSONSet, JSONString, JSONTextColumn, JSONTuple, JSONTupleItems, JSONType, JSONTypeAny, JSONTypeData, JSONTypes, JSONUndefined, JSONUnion, JSONUnknown, JSONVoid, Join, JoinArgs, JoinCallback, JoinCallbackArg, JoinItem, JoinedTablesBase, Json, JsonItem, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MaybeArray, Merge, MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NestedInsertItem, NestedInsertManyItems, NestedInsertOneItem, NestedUpdateItem, NestedUpdateManyItems, NestedUpdateOneItem, NotFoundError, NullableColumn, NumberAsStringBaseColumn, NumberBaseColumn, NumberColumn, NumberColumnData, NumberExpression, OnConflictItem, OnConflictMergeUpdate, OnConflictQueryBuilder, OnQueryBuilder, Operator, Operators, OrderArg, OrderItem, OutputTypeOfTuple, OutputTypeOfTupleWithRest, OwnTypeProps, PathColumn, PluckResultColumnType, PointColumn, PolygonColumn, PormError, PormInternalError, Primitive, Query, QueryArraysResult, QueryBase, QueryCallbacks, QueryData, QueryGet, QueryInput, QueryLog, QueryLogObject, QueryLogOptions, QueryLogger, QueryMethods, QueryResult, QueryResultRow, QueryReturnType, QueryReturnsAll, QuerySelectAll, QueryThen, QueryUpsert, QueryWithTable, RawExpression, RealColumn, Relation, RelationQuery, RelationQueryBase, RelationsBase, Select, SelectAgg, SelectArg, SelectFunctionItem, SelectItem, SelectQueryData, Selectable, SelectableBase, SerialColumn, SetOptional, SetQueryJoinedTables, SetQueryReturns, SetQueryReturnsAll, SetQueryReturnsColumnInfo, SetQueryReturnsOne, SetQueryReturnsOneOptional, SetQueryReturnsPluck, SetQueryReturnsRowCount, SetQueryReturnsRows, SetQueryReturnsValue, SetQueryReturnsValueOptional, SetQueryReturnsVoid, SetQueryTableAlias, SetQueryWindows, SetQueryWith, SimpleSpread, SingleColumnIndexOptions, SinglePrimaryKey, SmallIntColumn, SmallSerialColumn, SomeIsTrue, SortDir, Spread, Sql, StringColumn, StringExpression, StringKey, TableData, TextBaseColumn, TextColumn, TextColumnData, Then, ThenResult, TimeColumn, TimeInterval, TimeWithTimeZoneColumn, TimestampColumn, TimestampWithTimeZoneColumn, ToSqlCtx, ToSqlOptions, Transaction, TransactionAdapter, TruncateQueryData, TsQueryColumn, TsVectorColumn, TypeParsers, UUIDColumn, UnhandledTypeError, Union, UnionArg, UnionItem, UnknownKeysParam, Update, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdatedAtDataInjector, UpsertData, UpsertResult, UpsertThis, ValidationContext, VarCharColumn, Where, WhereArg, WhereInArg, WhereInColumn, WhereInItem, WhereInValues, WhereItem, WhereJsonPathEqualsItem, WhereOnItem, WhereOnJoinItem, WhereQueryBuilder, WhereResult, WindowArg, WindowArgDeclaration, WindowDeclaration, WindowFunctionOptions, WindowItem, With, WithDataBase, WithDataItem, WithItem, WithOptions, XMLColumn, addOr, addOrNot, addParserForRawExpression, addParserForSelectItem, addParserToQuery, addQueryOn, addQueryOrOn, addQuestionMarks, addWhere, addWhereIn, addWhereNot, aggregate1FunctionNames, applyMixins, array, arrayToEnum, baseObjectOutputType, checkIfASimpleQuery, columnTypes, utils as columnUtils, constructType, createDb, createOperator, defaultsKey, discriminatedUnion, emptyObject, enumType, flatten, getClonedQueryData, getColumnTypes, getQueryAs, getQueryParsers, getRaw, getRawSql, getTableData, getValidEnumValues, getValueKey, handleResult, identity, instanceOf, intersection, isRaw, isRequiredRelationKey, joinTruthy, jsonTypes, lazy, literal, logColors, logParamToLogObject, makeRegexToFindInSql, map, nativeEnum, newTableData, noop, notNullable, notNullish, nullable, nullish, object, optional, parseRecord, parseResult, processSelectArg, pushOrNewArray, pushOrNewArrayToObject, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryMethodByReturnType, queryTypeWithLimitOne, quote, raw, record, relationQueryKey, required, resetTableData, scalarTypes, set, setQueryObjectValue, toArray, toSql, toSqlCacheKey, tuple, union };
|
|
4308
|
+
export { Adapter, AdapterOptions, AddQueryJoinedTable, AddQuerySelect, AddQueryWith, AfterCallback, Aggregate, Aggregate1ArgumentTypes, AggregateArg, AggregateItem, AggregateItemArg, AggregateItemOptions, AggregateOptions, AliasOrTable, AnyColumnType, AnyColumnTypeCreator, ArrayCardinality, ArrayColumn, ArrayData, ArrayOfColumnsObjects, AssertArray, BaseNumberData, BaseRelation, BaseStringData, BeforeCallback, BelongsToNestedInsert, BelongsToNestedUpdate, BelongsToRelation, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanExpression, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, Clear, ClearStatement, CoalesceString, ColumnData, ColumnInfo, ColumnInfoMethods, ColumnInfoQueryData, ColumnInput, ColumnNameOfModel, ColumnOperators, ColumnOutput, ColumnParser, ColumnShapeInput, ColumnShapeOutput, ColumnType, ColumnTypes, ColumnTypesBase, ColumnsObject, ColumnsParsers, ColumnsShape, CommonQueryData, DateBaseColumn, DateColumn, DateColumnData, DateTimeBaseClass, DateTimeColumnData, DateTimeWithTimeZoneBaseClass, Db, DbOptions, DbTableOptions, DecimalBaseColumn, DecimalColumn, DecimalColumnData, DeepPartial, DefaultSelectColumns, Delete, DeleteQueryData, DoublePrecisionColumn, DropMode, EMPTY_OBJECT, EmptyObject, EnumColumn, EnumLike, Except, Expression, ExpressionOfType, ExpressionOutput, FilterTuple, For, ForeignKey, ForeignKeyModel, ForeignKeyModelWithColumns, ForeignKeyOptions, From, GetArg, HasAndBelongsToManyRelation, HasManyNestedInsert, HasManyNestedUpdate, HasManyRelation, HasOneNestedInsert, HasOneNestedUpdate, HasOneRelation, Having, HavingArg, HavingItem, IndexColumnOptions, IndexOptions, InetColumn, Insert, InsertData, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsEqual, JSONAny, JSONArray, JSONBigInt, JSONBoolean, JSONColumn, JSONDate, JSONDiscriminatedObject, JSONDiscriminatedUnion, JSONEnum, JSONInstanceOf, JSONIntersection, JSONLazy, JSONLiteral, JSONMap, JSONNaN, JSONNativeEnum, JSONNever, JSONNotNullable, JSONNotNullish, JSONNull, JSONNullable, JSONNullish, JSONNumber, JSONObject, JSONObjectShape, JSONOptional, JSONRecord, JSONRecordKeyType, JSONRequired, JSONSet, JSONString, JSONTextColumn, JSONTuple, JSONTupleItems, JSONType, JSONTypeAny, JSONTypeData, JSONTypes, JSONUndefined, JSONUnion, JSONUnknown, JSONVoid, Join, JoinArgs, JoinCallback, JoinCallbackArg, JoinItem, JoinedTablesBase, Json, JsonItem, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MaybeArray, Merge, MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NestedInsertItem, NestedInsertManyItems, NestedInsertOneItem, NestedUpdateItem, NestedUpdateManyItems, NestedUpdateOneItem, NotFoundError, NullableColumn, NumberAsStringBaseColumn, NumberBaseColumn, NumberColumn, NumberColumnData, NumberExpression, OnConflictItem, OnConflictMergeUpdate, OnConflictQueryBuilder, OnQueryBuilder, Operator, Operators, OrderArg, OrderItem, OutputTypeOfTuple, OutputTypeOfTupleWithRest, OwnTypeProps, PathColumn, PluckResultColumnType, PointColumn, PolygonColumn, PormError, PormInternalError, Primitive, Query, QueryArraysResult, QueryBase, QueryCallbacks, QueryData, QueryError, QueryErrorName, QueryGet, QueryInput, QueryLog, QueryLogObject, QueryLogOptions, QueryLogger, QueryMethods, QueryResult, QueryResultRow, QueryReturnType, QueryReturnsAll, QuerySelectAll, QueryThen, QueryUpsert, QueryWithTable, RawExpression, RealColumn, Relation, RelationQuery, RelationQueryBase, RelationsBase, Select, SelectAgg, SelectArg, SelectFunctionItem, SelectItem, SelectQueryData, Selectable, SelectableBase, SerialColumn, SetOptional, SetQueryJoinedTables, SetQueryReturns, SetQueryReturnsAll, SetQueryReturnsColumnInfo, SetQueryReturnsOne, SetQueryReturnsOneOptional, SetQueryReturnsPluck, SetQueryReturnsRowCount, SetQueryReturnsRows, SetQueryReturnsValue, SetQueryReturnsValueOptional, SetQueryReturnsVoid, SetQueryTableAlias, SetQueryWindows, SetQueryWith, SimpleSpread, SingleColumnIndexOptions, SinglePrimaryKey, SmallIntColumn, SmallSerialColumn, SomeIsTrue, SortDir, Spread, Sql, StringColumn, StringExpression, StringKey, TableData, TextBaseColumn, TextColumn, TextColumnData, Then, ThenResult, TimeColumn, TimeInterval, TimeWithTimeZoneColumn, TimestampColumn, TimestampWithTimeZoneColumn, ToSqlCtx, ToSqlOptions, Transaction, TransactionAdapter, TruncateQueryData, TsQueryColumn, TsVectorColumn, TypeParsers, UUIDColumn, UnhandledTypeError, Union, UnionArg, UnionItem, UnknownKeysParam, Update, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdatedAtDataInjector, UpsertData, UpsertResult, UpsertThis, ValidationContext, VarCharColumn, Where, WhereArg, WhereInArg, WhereInColumn, WhereInItem, WhereInValues, WhereItem, WhereJsonPathEqualsItem, WhereOnItem, WhereOnJoinItem, WhereQueryBuilder, WhereResult, WindowArg, WindowArgDeclaration, WindowDeclaration, WindowFunctionOptions, WindowItem, With, WithDataBase, WithDataItem, WithItem, WithOptions, XMLColumn, addOr, addOrNot, addParserForRawExpression, addParserForSelectItem, addParserToQuery, addQueryOn, addQueryOrOn, addQuestionMarks, addWhere, addWhereIn, addWhereNot, aggregate1FunctionNames, applyMixins, array, arrayToEnum, baseObjectOutputType, checkIfASimpleQuery, columnTypes, utils as columnUtils, constructType, createDb, createOperator, defaultsKey, discriminatedUnion, emptyObject, enumType, flatten, getClonedQueryData, getColumnTypes, getQueryAs, getQueryParsers, getRaw, getRawSql, getTableData, getValidEnumValues, getValueKey, handleResult, identity, instanceOf, intersection, isRaw, isRequiredRelationKey, joinTruthy, jsonTypes, lazy, literal, logColors, logParamToLogObject, makeRegexToFindInSql, map, nativeEnum, newTableData, noop, notNullable, notNullish, nullable, nullish, object, optional, parseRecord, parseResult, processSelectArg, pushOrNewArray, pushOrNewArrayToObject, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryMethodByReturnType, queryTypeWithLimitOne, quote, raw, record, relationQueryKey, required, resetTableData, scalarTypes, set, setQueryObjectValue, toArray, toSql, toSqlCacheKey, tuple, union };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { types, Pool } from 'pg';
|
|
1
|
+
import { DatabaseError, types, Pool } from 'pg';
|
|
2
2
|
|
|
3
3
|
var __defProp$q = Object.defineProperty;
|
|
4
4
|
var __defProps$l = Object.defineProperties;
|
|
@@ -779,6 +779,27 @@ const aggregateToSql = (ctx, model, item, quotedAs) => {
|
|
|
779
779
|
|
|
780
780
|
class PormError extends Error {
|
|
781
781
|
}
|
|
782
|
+
class QueryError extends DatabaseError {
|
|
783
|
+
get isUnique() {
|
|
784
|
+
return this.code === "23505";
|
|
785
|
+
}
|
|
786
|
+
get columns() {
|
|
787
|
+
var _a;
|
|
788
|
+
if (this.columnsCache)
|
|
789
|
+
return this.columnsCache;
|
|
790
|
+
const columns = {};
|
|
791
|
+
if (this.detail) {
|
|
792
|
+
const list = (_a = this.detail.match(/\((.*)\)=/)) == null ? void 0 : _a[1];
|
|
793
|
+
if (list) {
|
|
794
|
+
list.split(", ").forEach((item) => {
|
|
795
|
+
const column = item.startsWith('"') ? item.slice(1, -1) : item;
|
|
796
|
+
columns[column] = true;
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
return this.columnsCache = columns;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
782
803
|
class NotFoundError extends PormError {
|
|
783
804
|
constructor(message = "Record is not found") {
|
|
784
805
|
super(message);
|
|
@@ -3191,13 +3212,11 @@ const queryMethodByReturnType = {
|
|
|
3191
3212
|
rowCount: "arrays",
|
|
3192
3213
|
void: "arrays"
|
|
3193
3214
|
};
|
|
3215
|
+
let queryError = void 0;
|
|
3194
3216
|
class Then {
|
|
3195
|
-
then(
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
} else {
|
|
3199
|
-
return then(this, resolve, reject);
|
|
3200
|
-
}
|
|
3217
|
+
get then() {
|
|
3218
|
+
queryError = new Error();
|
|
3219
|
+
return maybeWrappedThen;
|
|
3201
3220
|
}
|
|
3202
3221
|
async catch(fn) {
|
|
3203
3222
|
return this.then(void 0, fn);
|
|
@@ -3206,6 +3225,13 @@ class Then {
|
|
|
3206
3225
|
const handleResult = async (q, result) => {
|
|
3207
3226
|
return parseResult(q, q.query.returnType || "all", result);
|
|
3208
3227
|
};
|
|
3228
|
+
function maybeWrappedThen(resolve, reject) {
|
|
3229
|
+
if (this.query.wrapInTransaction && !this.query.inTransaction) {
|
|
3230
|
+
return this.transaction((q) => then(q, resolve, reject));
|
|
3231
|
+
} else {
|
|
3232
|
+
return then(this, resolve, reject);
|
|
3233
|
+
}
|
|
3234
|
+
}
|
|
3209
3235
|
const then = async (q, resolve, reject) => {
|
|
3210
3236
|
let sql;
|
|
3211
3237
|
let logData;
|
|
@@ -3245,13 +3271,38 @@ const then = async (q, resolve, reject) => {
|
|
|
3245
3271
|
);
|
|
3246
3272
|
}
|
|
3247
3273
|
resolve == null ? void 0 : resolve(result);
|
|
3248
|
-
} catch (
|
|
3274
|
+
} catch (err) {
|
|
3275
|
+
const error = err instanceof DatabaseError ? assignError(q, err) : err;
|
|
3249
3276
|
if (q.query.log && sql && logData) {
|
|
3250
3277
|
q.query.log.onError(error, sql, logData);
|
|
3251
3278
|
}
|
|
3252
3279
|
reject == null ? void 0 : reject(error);
|
|
3253
3280
|
}
|
|
3254
3281
|
};
|
|
3282
|
+
const assignError = (q, from) => {
|
|
3283
|
+
const to = new q.error();
|
|
3284
|
+
to.stack = queryError.stack;
|
|
3285
|
+
to.message = from.message;
|
|
3286
|
+
to.length = from.length;
|
|
3287
|
+
to.name = from.name;
|
|
3288
|
+
to.severity = from.severity;
|
|
3289
|
+
to.code = from.code;
|
|
3290
|
+
to.detail = from.detail;
|
|
3291
|
+
to.hint = from.hint;
|
|
3292
|
+
to.position = from.position;
|
|
3293
|
+
to.internalPosition = from.internalPosition;
|
|
3294
|
+
to.internalQuery = from.internalQuery;
|
|
3295
|
+
to.where = from.where;
|
|
3296
|
+
to.schema = from.schema;
|
|
3297
|
+
to.table = from.table;
|
|
3298
|
+
to.column = from.column;
|
|
3299
|
+
to.dataType = from.dataType;
|
|
3300
|
+
to.constraint = from.constraint;
|
|
3301
|
+
to.file = from.file;
|
|
3302
|
+
to.line = from.line;
|
|
3303
|
+
to.routine = from.routine;
|
|
3304
|
+
return to;
|
|
3305
|
+
};
|
|
3255
3306
|
const parseResult = (q, returnType = "all", result) => {
|
|
3256
3307
|
var _a, _b;
|
|
3257
3308
|
switch (returnType) {
|
|
@@ -5540,7 +5591,7 @@ class Db {
|
|
|
5540
5591
|
const defaultSelect = this.defaultSelectColumns.length === columns.length ? void 0 : this.defaultSelectColumns;
|
|
5541
5592
|
const columnsParsers = {};
|
|
5542
5593
|
let hasParsers = false;
|
|
5543
|
-
let modifyQuery;
|
|
5594
|
+
let modifyQuery = void 0;
|
|
5544
5595
|
for (const key in shape) {
|
|
5545
5596
|
const column = shape[key];
|
|
5546
5597
|
if (column.parseFn) {
|
|
@@ -5561,6 +5612,8 @@ class Db {
|
|
|
5561
5612
|
} : toSql;
|
|
5562
5613
|
this.relations = {};
|
|
5563
5614
|
modifyQuery == null ? void 0 : modifyQuery.forEach((cb) => cb(this));
|
|
5615
|
+
this.error = class extends QueryError {
|
|
5616
|
+
};
|
|
5564
5617
|
}
|
|
5565
5618
|
}
|
|
5566
5619
|
applyMixins(Db, [QueryMethods]);
|
|
@@ -5607,5 +5660,5 @@ const createDb = (_a) => {
|
|
|
5607
5660
|
const relationQueryKey = Symbol("relationQuery");
|
|
5608
5661
|
const isRequiredRelationKey = Symbol("isRequiredRelation");
|
|
5609
5662
|
|
|
5610
|
-
export { Adapter, Aggregate, ArrayColumn, ArrayOfColumnsObjects, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, Clear, ColumnInfoMethods, ColumnType, ColumnsObject, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeWithTimeZoneBaseClass, Db, DecimalBaseColumn, DecimalColumn, Delete, DoublePrecisionColumn, EMPTY_OBJECT, EnumColumn, For, From, Having, InetColumn, Insert, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, Json, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnQueryBuilder, Operators, PathColumn, PluckResultColumnType, PointColumn, PolygonColumn, PormError, PormInternalError, QueryCallbacks, QueryGet, QueryLog, QueryMethods, QueryUpsert, RealColumn, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimeWithTimeZoneColumn, TimestampColumn, TimestampWithTimeZoneColumn, Transaction, TransactionAdapter, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, Update, VarCharColumn, Where, WhereQueryBuilder, With, XMLColumn, addOr, addOrNot, addParserForRawExpression, addParserForSelectItem, addParserToQuery, addQueryOn, addQueryOrOn, addWhere, addWhereIn, addWhereNot, aggregate1FunctionNames, applyMixins, array, arrayToEnum, checkIfASimpleQuery, columnTypes, utils as columnUtils, constructType, createDb, createOperator, defaultsKey, discriminatedUnion, emptyObject, enumType, getClonedQueryData, getColumnTypes, getQueryAs, getQueryParsers, getRaw, getRawSql, getTableData, getValidEnumValues, getValueKey, handleResult, instanceOf, intersection, isRaw, isRequiredRelationKey, joinTruthy, jsonTypes, lazy, literal, logColors, logParamToLogObject, makeRegexToFindInSql, map, nativeEnum, newTableData, noop, notNullable, notNullish, nullable, nullish, object, optional, parseRecord, parseResult, processSelectArg, pushOrNewArray, pushOrNewArrayToObject, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryMethodByReturnType, queryTypeWithLimitOne, quote, raw, record, relationQueryKey, required, resetTableData, scalarTypes, set, setQueryObjectValue, toArray, toSql, toSqlCacheKey, tuple, union };
|
|
5663
|
+
export { Adapter, Aggregate, ArrayColumn, ArrayOfColumnsObjects, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, Clear, ColumnInfoMethods, ColumnType, ColumnsObject, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeWithTimeZoneBaseClass, Db, DecimalBaseColumn, DecimalColumn, Delete, DoublePrecisionColumn, EMPTY_OBJECT, EnumColumn, For, From, Having, InetColumn, Insert, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, Json, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnQueryBuilder, Operators, PathColumn, PluckResultColumnType, PointColumn, PolygonColumn, PormError, PormInternalError, QueryCallbacks, QueryError, QueryGet, QueryLog, QueryMethods, QueryUpsert, RealColumn, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimeWithTimeZoneColumn, TimestampColumn, TimestampWithTimeZoneColumn, Transaction, TransactionAdapter, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, Update, VarCharColumn, Where, WhereQueryBuilder, With, XMLColumn, addOr, addOrNot, addParserForRawExpression, addParserForSelectItem, addParserToQuery, addQueryOn, addQueryOrOn, addWhere, addWhereIn, addWhereNot, aggregate1FunctionNames, applyMixins, array, arrayToEnum, checkIfASimpleQuery, columnTypes, utils as columnUtils, constructType, createDb, createOperator, defaultsKey, discriminatedUnion, emptyObject, enumType, getClonedQueryData, getColumnTypes, getQueryAs, getQueryParsers, getRaw, getRawSql, getTableData, getValidEnumValues, getValueKey, handleResult, instanceOf, intersection, isRaw, isRequiredRelationKey, joinTruthy, jsonTypes, lazy, literal, logColors, logParamToLogObject, makeRegexToFindInSql, map, nativeEnum, newTableData, noop, notNullable, notNullish, nullable, nullish, object, optional, parseRecord, parseResult, processSelectArg, pushOrNewArray, pushOrNewArrayToObject, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryMethodByReturnType, queryTypeWithLimitOne, quote, raw, record, relationQueryKey, required, resetTableData, scalarTypes, set, setQueryObjectValue, toArray, toSql, toSqlCacheKey, tuple, union };
|
|
5611
5664
|
//# sourceMappingURL=index.esm.js.map
|