pqb 0.51.5 → 0.52.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 +42 -9
- package/dist/index.js +127 -66
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +126 -66
- 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, PickQueryMetaReturnType, RecordUnknown, Expression, MaybeArray, ColumnTypesBase, TemplateLiteralArgs, QueryColumn, EmptyObject, QueryColumns, 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, PickQueryReturnType, QueryReturnTypeAll, QueryReturnTypeOptional, QueryThenShallowSimplifyOptional, QueryThenShallowSimplify, PickQueryResultReturnType, PickQueryResultReturnTypeUniqueColumns, PickQueryTableMetaShape, QueryInternalBase, PickType, RecordKeyTrue, ColumnShapeOutput, OperatorsNullable, UniqueColumn, TimestampHelpers, ShallowSimplify, Codes, ColumnDataCheckBase } from 'orchid-core';
|
|
3
|
+
import { QueryResultRow, AdapterConfigBase, AdapterBase, QueryInput, SingleSqlItem, Sql, IsQuery, PickQueryMetaReturnType, RecordUnknown, Expression, MaybeArray, ColumnTypesBase, TemplateLiteralArgs, QueryColumn, EmptyObject, QueryColumns, 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, AfterCommitStandaloneHook, getValueKey, QueryThenByReturnType, QueryMetaIsSubQuery, PickQueryReturnType, QueryReturnTypeAll, QueryReturnTypeOptional, QueryThenShallowSimplifyOptional, QueryThenShallowSimplify, PickQueryResultReturnType, PickQueryResultReturnTypeUniqueColumns, PickQueryTableMetaShape, QueryInternalBase, PickType, RecordKeyTrue, ColumnShapeOutput, OperatorsNullable, 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
|
|
|
@@ -423,7 +423,7 @@ interface CommonQueryData {
|
|
|
423
423
|
afterDelete?: QueryAfterHook[];
|
|
424
424
|
afterDeleteCommit?: QueryAfterHook[];
|
|
425
425
|
afterDeleteSelect?: Set<string>;
|
|
426
|
-
|
|
426
|
+
catchAfterCommitErrors?: AfterCommitErrorHandler[];
|
|
427
427
|
log?: QueryLogObject;
|
|
428
428
|
logger: QueryLogger;
|
|
429
429
|
autoPreparedStatements?: boolean;
|
|
@@ -2730,7 +2730,7 @@ declare class IntervalColumn<Schema extends ColumnSchemaConfig> extends ColumnTy
|
|
|
2730
2730
|
toSQL(): string;
|
|
2731
2731
|
}
|
|
2732
2732
|
|
|
2733
|
-
declare class EnumColumn<Schema extends ColumnTypeSchemaArg, SchemaType extends Schema['type'], T extends readonly string[]> extends ColumnType<Schema, T[number], SchemaType, OperatorsAny> {
|
|
2733
|
+
declare class EnumColumn<Schema extends ColumnTypeSchemaArg, SchemaType extends Schema['type'], const T extends readonly string[]> extends ColumnType<Schema, T[number], SchemaType, OperatorsAny> {
|
|
2734
2734
|
enumName: string;
|
|
2735
2735
|
options: T;
|
|
2736
2736
|
operators: OperatorsAny;
|
|
@@ -3348,7 +3348,7 @@ declare class CitextColumn<Schema extends ColumnSchemaConfig> extends TextBaseCo
|
|
|
3348
3348
|
|
|
3349
3349
|
interface DefaultSchemaConfig extends ColumnSchemaConfig<ColumnType> {
|
|
3350
3350
|
parse<T extends ColumnTypeBase, Output>(this: T, fn: (input: T['type']) => Output): ParseColumn<T, unknown, Output>;
|
|
3351
|
-
parseNull<T extends ColumnTypeBase, Output>(this: T, fn: (
|
|
3351
|
+
parseNull<T extends ColumnTypeBase, Output>(this: T, fn: () => Output): ParseNullColumn<T, unknown, Output>;
|
|
3352
3352
|
encode<T extends {
|
|
3353
3353
|
type: unknown;
|
|
3354
3354
|
}, Input>(this: T, fn: (input: Input) => unknown): EncodeColumn<T, unknown, Input>;
|
|
@@ -3367,7 +3367,7 @@ interface DefaultSchemaConfig extends ColumnSchemaConfig<ColumnType> {
|
|
|
3367
3367
|
};
|
|
3368
3368
|
dateAsNumber<T extends ColumnType>(this: T): ParseColumn<T, unknown, number>;
|
|
3369
3369
|
dateAsDate<T extends ColumnType>(this: T): ParseColumn<T, unknown, Date>;
|
|
3370
|
-
enum<T extends readonly string[]>(dataType: string, type: T): EnumColumn<DefaultSchemaConfig, unknown, T>;
|
|
3370
|
+
enum<const T extends readonly [string, ...string[]]>(dataType: string, type: T): EnumColumn<DefaultSchemaConfig, unknown, T>;
|
|
3371
3371
|
array<Item extends ArrayColumnValue>(item: Item): ArrayColumn<DefaultSchemaConfig, Item, unknown, unknown, unknown>;
|
|
3372
3372
|
json<T>(): JSONColumn<unknown extends T ? MaybeArray<string | number | boolean | object> : T, DefaultSchemaConfig>;
|
|
3373
3373
|
inputSchema(): undefined;
|
|
@@ -5199,7 +5199,12 @@ declare class AfterCommitError extends OrchidOrmError {
|
|
|
5199
5199
|
hookResults: AfterCommitErrorResult[];
|
|
5200
5200
|
constructor(result: unknown, hookResults: AfterCommitErrorResult[]);
|
|
5201
5201
|
}
|
|
5202
|
-
|
|
5202
|
+
type AfterCommitErrorHandler = (error: AfterCommitError) => void | Promise<void>;
|
|
5203
|
+
declare const _runAfterCommitHooks: (result: unknown, promises: unknown[], getHookNames: () => string[], catchAfterCommitErrors: AfterCommitErrorHandler[] | undefined) => Promise<void>;
|
|
5204
|
+
/**
|
|
5205
|
+
* Check if inside transaction started by user (not test transaction).
|
|
5206
|
+
*/
|
|
5207
|
+
declare const isInUserTransaction: (trx: TransactionState | undefined) => trx is TransactionState;
|
|
5203
5208
|
declare class Transaction {
|
|
5204
5209
|
/**
|
|
5205
5210
|
* In Orchid ORM the method is `$transaction`, when using `pqb` on its own it is `transaction`.
|
|
@@ -5325,6 +5330,32 @@ declare class Transaction {
|
|
|
5325
5330
|
*/
|
|
5326
5331
|
ensureTransaction<Result>(this: PickQueryQAndInternal, cb: () => Promise<Result>): Promise<Result>;
|
|
5327
5332
|
isInTransaction(): boolean;
|
|
5333
|
+
/**
|
|
5334
|
+
* Schedules a hook to run after the outermost transaction commits:
|
|
5335
|
+
*
|
|
5336
|
+
* ```ts
|
|
5337
|
+
* await db.$transaction(async () => {
|
|
5338
|
+
* await db.table.create(data)
|
|
5339
|
+
* await db.table.where({ ...conditions }).update({ key: 'value' })
|
|
5340
|
+
*
|
|
5341
|
+
* db.$afterCommit(() => { // can be sync or async
|
|
5342
|
+
* console.log('after commit')
|
|
5343
|
+
* })
|
|
5344
|
+
* })
|
|
5345
|
+
* ```
|
|
5346
|
+
*
|
|
5347
|
+
* If used outside the transaction, the hook will be executed almost immediately, on the next microtask:
|
|
5348
|
+
*
|
|
5349
|
+
* ```ts
|
|
5350
|
+
* db.$afterCommit(async () => { // can be sync or async
|
|
5351
|
+
* console.log('after commit')
|
|
5352
|
+
* })
|
|
5353
|
+
* ```
|
|
5354
|
+
*
|
|
5355
|
+
* If the callback has no `try/catch` and throws an error,
|
|
5356
|
+
* this will cause `uncaughtException` if the callback is sync and `unhandledRejection` if it is async.
|
|
5357
|
+
*/
|
|
5358
|
+
afterCommit(this: Query, hook: AfterCommitStandaloneHook): void;
|
|
5328
5359
|
}
|
|
5329
5360
|
|
|
5330
5361
|
type AfterHook<Select extends PropertyKey[], Shape extends QueryColumns> = QueryAfterHook<{
|
|
@@ -5478,13 +5509,15 @@ declare abstract class QueryHooks {
|
|
|
5478
5509
|
* })
|
|
5479
5510
|
* .catchAfterCommitError((err) => {
|
|
5480
5511
|
* // err is instance of AfterCommitError (see below)
|
|
5481
|
-
* })
|
|
5512
|
+
* })
|
|
5513
|
+
* // can be added multiple times, all catchers will be executed
|
|
5514
|
+
* .catchAfterCommitError((err) => {});
|
|
5482
5515
|
*
|
|
5483
5516
|
* // result is available even if an after commit hook has failed
|
|
5484
5517
|
* result.id;
|
|
5485
5518
|
* ```
|
|
5486
5519
|
*/
|
|
5487
|
-
catchAfterCommitError<T>(this: T, fn:
|
|
5520
|
+
catchAfterCommitError<T>(this: T, fn: AfterCommitErrorHandler): T;
|
|
5488
5521
|
}
|
|
5489
5522
|
|
|
5490
5523
|
declare abstract class JsonMethods {
|
|
@@ -8912,4 +8945,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
|
|
|
8912
8945
|
*/
|
|
8913
8946
|
declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
|
|
8914
8947
|
|
|
8915
|
-
export { Adapter, type AdapterConfig, type AdapterOptions, type AddQueryDefaults, AfterCommitError, type AfterCommitErrorFulfilledResult, type AfterCommitErrorRejectedResult, type AfterCommitErrorResult, type AfterHook, type AggregateArgTypes, AggregateMethods, type AggregateOptions, type AliasOrTable, ArrayColumn, type ArrayColumnValue, type ArrayData, AsMethods, type AsQueryArg, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, type BooleanQueryColumn, BoxColumn, ByteaColumn, type ChangeCountArg, CidrColumn, CircleColumn, CitextColumn, Clear, type ClearStatement, type ColumnData, type ColumnDataGenerated, type ColumnFromDbParams, type ColumnInfoQueryData, ColumnRefExpression, ColumnType, type ColumnsByType, type ColumnsShape, type ColumnsShapeToNullableObject, type ColumnsShapeToObject, type ColumnsShapeToObjectArray, type ColumnsShapeToPluck, type CommonQueryData, ComputedColumn, type ComputedColumns, type ComputedColumnsFromOptions, type ComputedMethods, type ComputedOptionsConfig, type ComputedOptionsFactory, type CopyOptions, type CopyQueryData, Create, type CreateBelongsToData, type CreateColumn, type CreateCtx, type CreateData, type CreateKind, type CreateMethodsNames, type CreateRelationsData, type CreateRelationsDataOmittingFKeys, type CreateResult, type CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnInput, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbDomainArgRecord, type DbExtension, type DbOptions, type DbResult, type DbSharedOptions, type DbStructureDomainsMap, type DbTableConstructor, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultSchemaConfig, Delete, type DeleteArgs, type DeleteMethodsNames, type DeleteQueryData, type DeleteResult, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, type ExpressionOutput, FnExpression, type FnExpressionArgs, type FnExpressionArgsPairs, type FnExpressionArgsValue, For, type FromArg, FromMethods, type FromQuerySelf, type FromResult, type GeneratedColumn, type GeneratorIgnore, type GetArg, type GetColumnInfo, type GetResult, type GetResultOptional, type GetStringArg, type GroupArgs, type HandleResult, Having, type HavingItem, type HookAction, type HookSelectArg, type IdentityColumn, InetColumn, type InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsolationLevel, JSONColumn, JSONTextColumn, Join, type JoinArgToQuery, type JoinArgs, type JoinCallback, type JoinFirstArg, type JoinItem, type JoinItemArgs, type JoinLateralItem, type JoinLateralResult, type JoinQueryBuilder, type JoinQueryMethod, type JoinResult, type JoinResultRequireMain, type JoinedParsers, type JoinedShapes, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, type NumericColumns, type OnConflictMerge, OnConflictQueryBuilder, type OnConflictSet, type OnConflictTarget, OnMethods, type Operator, Operators, type OperatorsAny, type OperatorsArray, type OperatorsBoolean, type OperatorsDate, type OperatorsJson, type OperatorsNumber, type OperatorsText, type OperatorsTime, type OrCreateArg, OrExpression, OrchidOrmError, OrchidOrmInternalError, type OrderArg, type OrderArgSelf, type OrderArgs, type OrderItem, type OrderTsQueryConfig, type Over, PathColumn, type PickColumnData, type PickQueryBaseQuery, type PickQueryColumnTypes, type PickQueryDataShapeAndJoinedShapes, type PickQueryInternal, type PickQueryMetaColumnTypes, type PickQueryMetaRelations, type PickQueryMetaRelationsResult, type PickQueryMetaRelationsResultReturnType, type PickQueryMetaRelationsReturnType, type PickQueryMetaResultRelations, type PickQueryMetaResultRelationsWindows, type PickQueryMetaResultRelationsWindowsColumnTypes, type PickQueryMetaResultRelationsWithDataReturnType, type PickQueryMetaResultRelationsWithDataReturnTypeShape, type PickQueryMetaResultReturnTypeWithDataWindows, type PickQueryMetaResultReturnTypeWithDataWindowsThen, type PickQueryMetaShapeRelationsReturnType, type PickQueryMetaShapeRelationsWithData, type PickQueryMetaTable, type PickQueryMetaTableShape, type PickQueryMetaTableShapeReturnTypeWithData, type PickQueryMetaWithData, type PickQueryMetaWithDataColumnTypes, type PickQueryQ, type PickQueryQAndBaseQuery, type PickQueryQAndInternal, type PickQueryRelations, type PickQueryRelationsWithData, type PickQueryResultColumnTypes, type PickQueryShapeResultReturnTypeSinglePrimaryKey, type PickQueryShapeResultSinglePrimaryKey, type PickQueryShapeSinglePrimaryKey, type PickQuerySinglePrimaryKey, type PickQueryTableMetaResultReturnTypeWithDataWindowsThen, type PickQueryWindows, type PickQueryWithData, type PickQueryWithDataColumnTypes, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type PostgisPoint, type Query, type QueryAfterHook, type QueryArraysResult, type QueryBatchResult, type QueryBeforeHook, type QueryComputedArg, type QueryData, type QueryDataFromItem, type QueryDataJoinTo, type QueryDefaultReturnData, QueryError, type QueryErrorName, QueryGet, type QueryGetSelf, type QueryHelperResult, QueryHooks, type QueryIfResultThen, type QueryInternal, QueryLog, type QueryMetaHasSelect, type QueryMetaHasWhere, QueryMethods, type QueryOrExpression, type QueryOrExpressionBooleanOrNullResult, type QueryResult, type QueryScopeData, type QueryScopes, type QuerySourceItem, type QueryTake, type QueryTakeOptional, QueryUpsertOrCreate, RawSQL, RealColumn, type RecordOfColumnsShapeBase, RefExpression, type RelationConfigBase, type RelationConfigDataForCreate, type RelationJoinQuery, type RelationQueryBase, type RelationsBase, type ReturnsQueryOrExpression, type RuntimeComputedQueryColumn, type SearchArg, SearchMethods, type SearchWeight, type SearchWeightRecord, Select, type SelectArg, type SelectArgs, type SelectAs, type SelectAsValue, type SelectItem, type SelectQueryData, type SelectSubQueryResult, type SelectableFromShape, type SelectableOfType, type SelectableOrExpression, type SelectableOrExpressionOfType, type SelectableOrExpressions, SerialColumn, type SerialColumnData, type SetQueryKind, type SetQueryKindResult, type SetQueryReturnsAll, type SetQueryReturnsAllKind, type SetQueryReturnsAllKindResult, type SetQueryReturnsColumnInfo, type SetQueryReturnsColumnKind, type SetQueryReturnsColumnKindResult, type SetQueryReturnsColumnOptional, type SetQueryReturnsColumnOrThrow, type SetQueryReturnsOneKind, type SetQueryReturnsOneKindResult, type SetQueryReturnsPluck, type SetQueryReturnsPluckColumn, type SetQueryReturnsPluckColumnKind, type SetQueryReturnsPluckColumnKindResult, type SetQueryReturnsRowCount, type SetQueryReturnsRowCountMany, type SetQueryReturnsRows, type SetQueryReturnsValueOptional, type SetQueryReturnsValueOrThrow, type SetQueryReturnsVoid, type SetQueryReturnsVoidKind, type SetQueryTableAlias, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SimpleJoinItem, type SimpleJoinItemNonSubQueryArgs, SmallIntColumn, SmallSerialColumn, type SortDir, type SqlFn, SqlMethod, StringColumn$1 as StringColumn, TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, TextBaseColumn, TextColumn, type TextColumnData, Then, TimeColumn, TimestampColumn, TimestampTZColumn, type ToSQLCtx, type ToSQLOptions, type ToSQLQuery, Transaction, TransactionAdapter, type TransactionOptions, TransformMethods, type TruncateQueryData, TsQueryColumn, TsVectorColumn, type TypeParsers, UUIDColumn, UnhandledTypeError, Union, type UnionArgs, type UnionItem, type UnionKind, type UnionSet, type UniqueConstraints, type UniqueQueryTypeOrExpression, type UniqueTableDataItem, UnknownColumn, Update, type UpdateArg, type UpdateCtx, type UpdateCtxCollect, type UpdateData, type UpdateQueryData, type UpdateQueryDataItem, type UpdateQueryDataObject, type UpdateSelf, type UpdatedAtDataInjector, type UpsertResult, type UpsertThis, VarCharColumn, VirtualColumn, Where, type WhereArg, type WhereArgs, type WhereInArg, type WhereInColumn, type WhereInItem, type WhereInValues, type WhereItem, type WhereJsonPathEqualsItem, type WhereNotArgs, type WhereOnItem, type WhereOnJoinItem, type WhereQueryBuilder, type WhereResult, type WhereSearchItem, type WhereSearchResult, type WindowArg, type WindowArgDeclaration, type WindowDeclaration, type WindowItem, type WithArgsOptions, type WithConfigs, type WithDataItem, type WithDataItems, type WithItem, WithMethods, type WithOptions, type WithQueryBuilder, type WithRecursiveOptions, type WithResult, type WithSqlResult, type WrapQueryArg, XMLColumn, _afterCommitError, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryResolveAlias, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, addColumnParserToQuery, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, assignDbDataToColumn, checkIfASimpleQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnExcludesToCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, escapeForLog, escapeForMigration, escapeString, excludeInnerToCode, excludeToCode, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFullColumnTable, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, parseRecord, parseTableData, parseTableDataInput, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArrayImmutable, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValueImmutable, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallbackV2, rollbackSql, saveSearchAlias, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValueImmutable, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL };
|
|
8948
|
+
export { Adapter, type AdapterConfig, type AdapterOptions, type AddQueryDefaults, AfterCommitError, type AfterCommitErrorFulfilledResult, type AfterCommitErrorHandler, type AfterCommitErrorRejectedResult, type AfterCommitErrorResult, type AfterHook, type AggregateArgTypes, AggregateMethods, type AggregateOptions, type AliasOrTable, ArrayColumn, type ArrayColumnValue, type ArrayData, AsMethods, type AsQueryArg, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, type BooleanQueryColumn, BoxColumn, ByteaColumn, type ChangeCountArg, CidrColumn, CircleColumn, CitextColumn, Clear, type ClearStatement, type ColumnData, type ColumnDataGenerated, type ColumnFromDbParams, type ColumnInfoQueryData, ColumnRefExpression, ColumnType, type ColumnsByType, type ColumnsShape, type ColumnsShapeToNullableObject, type ColumnsShapeToObject, type ColumnsShapeToObjectArray, type ColumnsShapeToPluck, type CommonQueryData, ComputedColumn, type ComputedColumns, type ComputedColumnsFromOptions, type ComputedMethods, type ComputedOptionsConfig, type ComputedOptionsFactory, type CopyOptions, type CopyQueryData, Create, type CreateBelongsToData, type CreateColumn, type CreateCtx, type CreateData, type CreateKind, type CreateMethodsNames, type CreateRelationsData, type CreateRelationsDataOmittingFKeys, type CreateResult, type CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnInput, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbDomainArgRecord, type DbExtension, type DbOptions, type DbResult, type DbSharedOptions, type DbStructureDomainsMap, type DbTableConstructor, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultSchemaConfig, Delete, type DeleteArgs, type DeleteMethodsNames, type DeleteQueryData, type DeleteResult, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, type ExpressionOutput, FnExpression, type FnExpressionArgs, type FnExpressionArgsPairs, type FnExpressionArgsValue, For, type FromArg, FromMethods, type FromQuerySelf, type FromResult, type GeneratedColumn, type GeneratorIgnore, type GetArg, type GetColumnInfo, type GetResult, type GetResultOptional, type GetStringArg, type GroupArgs, type HandleResult, Having, type HavingItem, type HookAction, type HookSelectArg, type IdentityColumn, InetColumn, type InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsolationLevel, JSONColumn, JSONTextColumn, Join, type JoinArgToQuery, type JoinArgs, type JoinCallback, type JoinFirstArg, type JoinItem, type JoinItemArgs, type JoinLateralItem, type JoinLateralResult, type JoinQueryBuilder, type JoinQueryMethod, type JoinResult, type JoinResultRequireMain, type JoinedParsers, type JoinedShapes, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, type NumericColumns, type OnConflictMerge, OnConflictQueryBuilder, type OnConflictSet, type OnConflictTarget, OnMethods, type Operator, Operators, type OperatorsAny, type OperatorsArray, type OperatorsBoolean, type OperatorsDate, type OperatorsJson, type OperatorsNumber, type OperatorsText, type OperatorsTime, type OrCreateArg, OrExpression, OrchidOrmError, OrchidOrmInternalError, type OrderArg, type OrderArgSelf, type OrderArgs, type OrderItem, type OrderTsQueryConfig, type Over, PathColumn, type PickColumnData, type PickQueryBaseQuery, type PickQueryColumnTypes, type PickQueryDataShapeAndJoinedShapes, type PickQueryInternal, type PickQueryMetaColumnTypes, type PickQueryMetaRelations, type PickQueryMetaRelationsResult, type PickQueryMetaRelationsResultReturnType, type PickQueryMetaRelationsReturnType, type PickQueryMetaResultRelations, type PickQueryMetaResultRelationsWindows, type PickQueryMetaResultRelationsWindowsColumnTypes, type PickQueryMetaResultRelationsWithDataReturnType, type PickQueryMetaResultRelationsWithDataReturnTypeShape, type PickQueryMetaResultReturnTypeWithDataWindows, type PickQueryMetaResultReturnTypeWithDataWindowsThen, type PickQueryMetaShapeRelationsReturnType, type PickQueryMetaShapeRelationsWithData, type PickQueryMetaTable, type PickQueryMetaTableShape, type PickQueryMetaTableShapeReturnTypeWithData, type PickQueryMetaWithData, type PickQueryMetaWithDataColumnTypes, type PickQueryQ, type PickQueryQAndBaseQuery, type PickQueryQAndInternal, type PickQueryRelations, type PickQueryRelationsWithData, type PickQueryResultColumnTypes, type PickQueryShapeResultReturnTypeSinglePrimaryKey, type PickQueryShapeResultSinglePrimaryKey, type PickQueryShapeSinglePrimaryKey, type PickQuerySinglePrimaryKey, type PickQueryTableMetaResultReturnTypeWithDataWindowsThen, type PickQueryWindows, type PickQueryWithData, type PickQueryWithDataColumnTypes, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type PostgisPoint, type Query, type QueryAfterHook, type QueryArraysResult, type QueryBatchResult, type QueryBeforeHook, type QueryComputedArg, type QueryData, type QueryDataFromItem, type QueryDataJoinTo, type QueryDefaultReturnData, QueryError, type QueryErrorName, QueryGet, type QueryGetSelf, type QueryHelperResult, QueryHooks, type QueryIfResultThen, type QueryInternal, QueryLog, type QueryMetaHasSelect, type QueryMetaHasWhere, QueryMethods, type QueryOrExpression, type QueryOrExpressionBooleanOrNullResult, type QueryResult, type QueryScopeData, type QueryScopes, type QuerySourceItem, type QueryTake, type QueryTakeOptional, QueryUpsertOrCreate, RawSQL, RealColumn, type RecordOfColumnsShapeBase, RefExpression, type RelationConfigBase, type RelationConfigDataForCreate, type RelationJoinQuery, type RelationQueryBase, type RelationsBase, type ReturnsQueryOrExpression, type RuntimeComputedQueryColumn, type SearchArg, SearchMethods, type SearchWeight, type SearchWeightRecord, Select, type SelectArg, type SelectArgs, type SelectAs, type SelectAsValue, type SelectItem, type SelectQueryData, type SelectSubQueryResult, type SelectableFromShape, type SelectableOfType, type SelectableOrExpression, type SelectableOrExpressionOfType, type SelectableOrExpressions, SerialColumn, type SerialColumnData, type SetQueryKind, type SetQueryKindResult, type SetQueryReturnsAll, type SetQueryReturnsAllKind, type SetQueryReturnsAllKindResult, type SetQueryReturnsColumnInfo, type SetQueryReturnsColumnKind, type SetQueryReturnsColumnKindResult, type SetQueryReturnsColumnOptional, type SetQueryReturnsColumnOrThrow, type SetQueryReturnsOneKind, type SetQueryReturnsOneKindResult, type SetQueryReturnsPluck, type SetQueryReturnsPluckColumn, type SetQueryReturnsPluckColumnKind, type SetQueryReturnsPluckColumnKindResult, type SetQueryReturnsRowCount, type SetQueryReturnsRowCountMany, type SetQueryReturnsRows, type SetQueryReturnsValueOptional, type SetQueryReturnsValueOrThrow, type SetQueryReturnsVoid, type SetQueryReturnsVoidKind, type SetQueryTableAlias, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SimpleJoinItem, type SimpleJoinItemNonSubQueryArgs, SmallIntColumn, SmallSerialColumn, type SortDir, type SqlFn, SqlMethod, StringColumn$1 as StringColumn, TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, TextBaseColumn, TextColumn, type TextColumnData, Then, TimeColumn, TimestampColumn, TimestampTZColumn, type ToSQLCtx, type ToSQLOptions, type ToSQLQuery, Transaction, TransactionAdapter, type TransactionOptions, TransformMethods, type TruncateQueryData, TsQueryColumn, TsVectorColumn, type TypeParsers, UUIDColumn, UnhandledTypeError, Union, type UnionArgs, type UnionItem, type UnionKind, type UnionSet, type UniqueConstraints, type UniqueQueryTypeOrExpression, type UniqueTableDataItem, UnknownColumn, Update, type UpdateArg, type UpdateCtx, type UpdateCtxCollect, type UpdateData, type UpdateQueryData, type UpdateQueryDataItem, type UpdateQueryDataObject, type UpdateSelf, type UpdatedAtDataInjector, type UpsertResult, type UpsertThis, VarCharColumn, VirtualColumn, Where, type WhereArg, type WhereArgs, type WhereInArg, type WhereInColumn, type WhereInItem, type WhereInValues, type WhereItem, type WhereJsonPathEqualsItem, type WhereNotArgs, type WhereOnItem, type WhereOnJoinItem, type WhereQueryBuilder, type WhereResult, type WhereSearchItem, type WhereSearchResult, type WindowArg, type WindowArgDeclaration, type WindowDeclaration, type WindowItem, type WithArgsOptions, type WithConfigs, type WithDataItem, type WithDataItems, type WithItem, WithMethods, type WithOptions, type WithQueryBuilder, type WithRecursiveOptions, type WithResult, type WithSqlResult, type WrapQueryArg, XMLColumn, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryResolveAlias, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, _runAfterCommitHooks, addColumnParserToQuery, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, assignDbDataToColumn, checkIfASimpleQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnExcludesToCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, escapeForLog, escapeForMigration, escapeString, excludeInnerToCode, excludeToCode, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFullColumnTable, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, isDefaultTimeStamp, isInUserTransaction, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, parseRecord, parseTableData, parseTableDataInput, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArrayImmutable, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValueImmutable, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallbackV2, rollbackSql, saveSearchAlias, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValueImmutable, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL };
|
package/dist/index.js
CHANGED
|
@@ -2864,14 +2864,25 @@ class AfterCommitError extends OrchidOrmError {
|
|
|
2864
2864
|
this.hookResults = hookResults;
|
|
2865
2865
|
}
|
|
2866
2866
|
}
|
|
2867
|
-
const
|
|
2868
|
-
const
|
|
2869
|
-
if (
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2867
|
+
const _runAfterCommitHooks = async (result, promises, getHookNames, catchAfterCommitErrors) => {
|
|
2868
|
+
const hookResults = await Promise.allSettled(promises);
|
|
2869
|
+
if (hookResults.some((result2) => result2.status === "rejected")) {
|
|
2870
|
+
const hookNames = getHookNames();
|
|
2871
|
+
for (const [i, r] of hookResults.entries()) {
|
|
2872
|
+
r.name = hookNames[i];
|
|
2873
|
+
}
|
|
2874
|
+
const err = new AfterCommitError(result, hookResults);
|
|
2875
|
+
if (!catchAfterCommitErrors) throw err;
|
|
2876
|
+
for (const fn of catchAfterCommitErrors) {
|
|
2877
|
+
try {
|
|
2878
|
+
fn(err);
|
|
2879
|
+
} catch {
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2873
2882
|
}
|
|
2874
2883
|
};
|
|
2884
|
+
const isInUserTransaction = (trx) => !!(trx && // when inside test transactions, compare transaction counts to ensure there is a user transaction.
|
|
2885
|
+
(!trx.testTransactionCount || trx.transactionId >= trx.testTransactionCount));
|
|
2875
2886
|
class Transaction {
|
|
2876
2887
|
async transaction(cbOrOptions, cb) {
|
|
2877
2888
|
let options;
|
|
@@ -2914,10 +2925,7 @@ class Transaction {
|
|
|
2914
2925
|
throw err;
|
|
2915
2926
|
});
|
|
2916
2927
|
if (log) log.afterQuery(commitSql$1, logData);
|
|
2917
|
-
|
|
2918
|
-
trx.afterCommit,
|
|
2919
|
-
result
|
|
2920
|
-
);
|
|
2928
|
+
runAfterCommit(trx.afterCommit, result);
|
|
2921
2929
|
return result;
|
|
2922
2930
|
} else {
|
|
2923
2931
|
try {
|
|
@@ -2942,7 +2950,7 @@ class Transaction {
|
|
|
2942
2950
|
if (transactionId === trx.testTransactionCount) {
|
|
2943
2951
|
const { afterCommit } = trx;
|
|
2944
2952
|
trx.afterCommit = void 0;
|
|
2945
|
-
|
|
2953
|
+
runAfterCommit(afterCommit, result);
|
|
2946
2954
|
}
|
|
2947
2955
|
return result;
|
|
2948
2956
|
} finally {
|
|
@@ -2977,42 +2985,95 @@ class Transaction {
|
|
|
2977
2985
|
}
|
|
2978
2986
|
isInTransaction() {
|
|
2979
2987
|
const trx = this.internal.transactionStorage.getStore();
|
|
2980
|
-
return
|
|
2988
|
+
return isInUserTransaction(trx);
|
|
2981
2989
|
}
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2990
|
+
/**
|
|
2991
|
+
* Schedules a hook to run after the outermost transaction commits:
|
|
2992
|
+
*
|
|
2993
|
+
* ```ts
|
|
2994
|
+
* await db.$transaction(async () => {
|
|
2995
|
+
* await db.table.create(data)
|
|
2996
|
+
* await db.table.where({ ...conditions }).update({ key: 'value' })
|
|
2997
|
+
*
|
|
2998
|
+
* db.$afterCommit(() => { // can be sync or async
|
|
2999
|
+
* console.log('after commit')
|
|
3000
|
+
* })
|
|
3001
|
+
* })
|
|
3002
|
+
* ```
|
|
3003
|
+
*
|
|
3004
|
+
* If used outside the transaction, the hook will be executed almost immediately, on the next microtask:
|
|
3005
|
+
*
|
|
3006
|
+
* ```ts
|
|
3007
|
+
* db.$afterCommit(async () => { // can be sync or async
|
|
3008
|
+
* console.log('after commit')
|
|
3009
|
+
* })
|
|
3010
|
+
* ```
|
|
3011
|
+
*
|
|
3012
|
+
* If the callback has no `try/catch` and throws an error,
|
|
3013
|
+
* this will cause `uncaughtException` if the callback is sync and `unhandledRejection` if it is async.
|
|
3014
|
+
*/
|
|
3015
|
+
afterCommit(hook) {
|
|
3016
|
+
const trx = this.internal.transactionStorage.getStore();
|
|
3017
|
+
if (isInUserTransaction(trx)) {
|
|
3018
|
+
(trx.afterCommit ?? (trx.afterCommit = [])).push(hook);
|
|
3019
|
+
} else {
|
|
3020
|
+
queueMicrotask(hook);
|
|
3021
|
+
}
|
|
3022
|
+
}
|
|
3023
|
+
}
|
|
3024
|
+
const runAfterCommit = (afterCommit, result) => {
|
|
3025
|
+
queueMicrotask(async () => {
|
|
3026
|
+
if (afterCommit) {
|
|
3027
|
+
const promises = [];
|
|
3028
|
+
let catchAfterCommitErrors;
|
|
3029
|
+
for (let i = 0, len = afterCommit.length; i < len; ) {
|
|
3030
|
+
const first = afterCommit[i];
|
|
3031
|
+
if (typeof first === "function") {
|
|
3032
|
+
try {
|
|
3033
|
+
promises.push(first());
|
|
3034
|
+
} catch (err) {
|
|
3035
|
+
promises.push(Promise.reject(err));
|
|
3036
|
+
}
|
|
3037
|
+
i++;
|
|
3038
|
+
} else {
|
|
3039
|
+
const q = afterCommit[i + 1];
|
|
3040
|
+
if (q.q.catchAfterCommitErrors) {
|
|
3041
|
+
(catchAfterCommitErrors ?? (catchAfterCommitErrors = [])).push(...q.q.catchAfterCommitErrors);
|
|
3042
|
+
}
|
|
3043
|
+
for (const fn of afterCommit[i + 2]) {
|
|
3044
|
+
try {
|
|
3045
|
+
promises.push(fn(first, q));
|
|
3046
|
+
} catch (err) {
|
|
3047
|
+
promises.push(Promise.reject(err));
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
i += 3;
|
|
2998
3051
|
}
|
|
2999
3052
|
}
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3053
|
+
const getHookNames = () => {
|
|
3054
|
+
const hookNames = [];
|
|
3055
|
+
for (let i = 0, len = afterCommit.length; i < len; ) {
|
|
3056
|
+
const first = afterCommit[i];
|
|
3057
|
+
if (typeof first === "function") {
|
|
3058
|
+
hookNames.push(first.name);
|
|
3059
|
+
i++;
|
|
3060
|
+
} else {
|
|
3061
|
+
for (const fn of afterCommit[i + 2]) {
|
|
3062
|
+
hookNames.push(fn.name);
|
|
3063
|
+
}
|
|
3064
|
+
i += 3;
|
|
3065
|
+
}
|
|
3011
3066
|
}
|
|
3012
|
-
|
|
3013
|
-
|
|
3067
|
+
return hookNames;
|
|
3068
|
+
};
|
|
3069
|
+
await _runAfterCommitHooks(
|
|
3070
|
+
result,
|
|
3071
|
+
promises,
|
|
3072
|
+
getHookNames,
|
|
3073
|
+
catchAfterCommitErrors
|
|
3074
|
+
);
|
|
3014
3075
|
}
|
|
3015
|
-
}
|
|
3076
|
+
});
|
|
3016
3077
|
};
|
|
3017
3078
|
|
|
3018
3079
|
const applyBatchTransforms = (q, batches) => {
|
|
@@ -3430,35 +3491,32 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
|
|
|
3430
3491
|
);
|
|
3431
3492
|
}
|
|
3432
3493
|
if (afterCommitHooks) {
|
|
3433
|
-
if (trx
|
|
3434
|
-
(!trx.testTransactionCount || trx.transactionId + 1 > trx.testTransactionCount)) {
|
|
3494
|
+
if (isInUserTransaction(trx)) {
|
|
3435
3495
|
(trx.afterCommit ?? (trx.afterCommit = [])).push(
|
|
3436
3496
|
result,
|
|
3437
3497
|
q,
|
|
3438
3498
|
afterCommitHooks
|
|
3439
3499
|
);
|
|
3440
3500
|
} else {
|
|
3441
|
-
const
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3501
|
+
const localResult = result;
|
|
3502
|
+
queueMicrotask(async () => {
|
|
3503
|
+
const promises = [];
|
|
3504
|
+
for (const fn of afterCommitHooks) {
|
|
3505
|
+
try {
|
|
3506
|
+
promises.push(
|
|
3507
|
+
fn(localResult, q)
|
|
3508
|
+
);
|
|
3509
|
+
} catch (err) {
|
|
3510
|
+
promises.push(Promise.reject(err));
|
|
3511
|
+
}
|
|
3449
3512
|
}
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
hookResults.map((result2, i) => ({
|
|
3456
|
-
...result2,
|
|
3457
|
-
name: afterCommitHooks[i].name
|
|
3458
|
-
})),
|
|
3459
|
-
q.q.catchAfterCommitError
|
|
3513
|
+
await _runAfterCommitHooks(
|
|
3514
|
+
localResult,
|
|
3515
|
+
promises,
|
|
3516
|
+
() => afterCommitHooks.map((h) => h.name),
|
|
3517
|
+
q.q.catchAfterCommitErrors
|
|
3460
3518
|
);
|
|
3461
|
-
}
|
|
3519
|
+
});
|
|
3462
3520
|
}
|
|
3463
3521
|
}
|
|
3464
3522
|
} else if (query.after) {
|
|
@@ -9506,7 +9564,9 @@ class QueryHooks {
|
|
|
9506
9564
|
* })
|
|
9507
9565
|
* .catchAfterCommitError((err) => {
|
|
9508
9566
|
* // err is instance of AfterCommitError (see below)
|
|
9509
|
-
* })
|
|
9567
|
+
* })
|
|
9568
|
+
* // can be added multiple times, all catchers will be executed
|
|
9569
|
+
* .catchAfterCommitError((err) => {});
|
|
9510
9570
|
*
|
|
9511
9571
|
* // result is available even if an after commit hook has failed
|
|
9512
9572
|
* result.id;
|
|
@@ -9514,7 +9574,7 @@ class QueryHooks {
|
|
|
9514
9574
|
*/
|
|
9515
9575
|
catchAfterCommitError(fn) {
|
|
9516
9576
|
const q = _clone(this);
|
|
9517
|
-
q
|
|
9577
|
+
pushQueryValueImmutable(q, "catchAfterCommitErrors", fn);
|
|
9518
9578
|
return q;
|
|
9519
9579
|
}
|
|
9520
9580
|
}
|
|
@@ -13296,7 +13356,6 @@ exports.VirtualColumn = VirtualColumn;
|
|
|
13296
13356
|
exports.Where = Where;
|
|
13297
13357
|
exports.WithMethods = WithMethods;
|
|
13298
13358
|
exports.XMLColumn = XMLColumn;
|
|
13299
|
-
exports._afterCommitError = _afterCommitError;
|
|
13300
13359
|
exports._clone = _clone;
|
|
13301
13360
|
exports._getSelectableColumn = _getSelectableColumn;
|
|
13302
13361
|
exports._initQueryBuilder = _initQueryBuilder;
|
|
@@ -13358,6 +13417,7 @@ exports._queryWhereNotOneOf = _queryWhereNotOneOf;
|
|
|
13358
13417
|
exports._queryWhereNotSql = _queryWhereNotSql;
|
|
13359
13418
|
exports._queryWhereOneOf = _queryWhereOneOf;
|
|
13360
13419
|
exports._queryWhereSql = _queryWhereSql;
|
|
13420
|
+
exports._runAfterCommitHooks = _runAfterCommitHooks;
|
|
13361
13421
|
exports.addColumnParserToQuery = addColumnParserToQuery;
|
|
13362
13422
|
exports.addParserForRawExpression = addParserForRawExpression;
|
|
13363
13423
|
exports.addParserForSelectItem = addParserForSelectItem;
|
|
@@ -13402,6 +13462,7 @@ exports.identityToCode = identityToCode;
|
|
|
13402
13462
|
exports.indexInnerToCode = indexInnerToCode;
|
|
13403
13463
|
exports.indexToCode = indexToCode;
|
|
13404
13464
|
exports.isDefaultTimeStamp = isDefaultTimeStamp;
|
|
13465
|
+
exports.isInUserTransaction = isInUserTransaction;
|
|
13405
13466
|
exports.isQueryReturnsAll = isQueryReturnsAll;
|
|
13406
13467
|
exports.isSelectingCount = isSelectingCount;
|
|
13407
13468
|
exports.joinSubQuery = joinSubQuery;
|