pqb 0.66.3 → 0.66.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +33 -13
- package/dist/index.js +65 -52
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -52
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +2 -2
- package/dist/node-postgres.js +59 -14
- package/dist/node-postgres.js.map +1 -1
- package/dist/node-postgres.mjs +59 -14
- package/dist/node-postgres.mjs.map +1 -1
- package/dist/postgres-js.js +52 -18
- package/dist/postgres-js.js.map +1 -1
- package/dist/postgres-js.mjs +53 -19
- package/dist/postgres-js.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -329,7 +329,7 @@ declare class QueryWithSchema {
|
|
|
329
329
|
withSchema<T>(this: T, schema: QuerySchema | undefined): T;
|
|
330
330
|
}
|
|
331
331
|
interface AsyncState extends SqlSessionState {
|
|
332
|
-
transactionAdapter?:
|
|
332
|
+
transactionAdapter?: TransactionAdapter;
|
|
333
333
|
transactionId?: number;
|
|
334
334
|
afterCommit?: TransactionAfterCommitHook[];
|
|
335
335
|
log?: QueryLogObject;
|
|
@@ -457,10 +457,10 @@ interface Adapter {
|
|
|
457
457
|
errorClass: new (...args: any[]) => Error;
|
|
458
458
|
searchPath?: string;
|
|
459
459
|
driverAdapter: DriverAdapter;
|
|
460
|
-
isInTransaction():
|
|
460
|
+
isInTransaction(this: Adapter): this is TransactionAdapter;
|
|
461
461
|
assignError(to: QueryError, from: Error): void;
|
|
462
|
-
query<T extends QueryResultRow = QueryResultRow>(text: string, values?: unknown[],
|
|
463
|
-
arrays<R extends any[] = any[]>(text: string, values?: unknown[],
|
|
462
|
+
query<T extends QueryResultRow = QueryResultRow>(text: string, values?: unknown[], sqlSessionState?: SqlSessionState): Promise<QueryResult<T>>;
|
|
463
|
+
arrays<R extends any[] = any[]>(text: string, values?: unknown[], sqlSessionState?: SqlSessionState): Promise<QueryArraysResult<R>>;
|
|
464
464
|
/**
|
|
465
465
|
* Run a transaction
|
|
466
466
|
*
|
|
@@ -479,7 +479,15 @@ interface Adapter {
|
|
|
479
479
|
* Adapter interface for transaction contexts.
|
|
480
480
|
*/
|
|
481
481
|
interface TransactionAdapter extends Adapter {
|
|
482
|
-
isInTransaction():
|
|
482
|
+
isInTransaction(this: Adapter): this is TransactionAdapter;
|
|
483
|
+
savepoint<T>(name: string, cb: () => Promise<T>): Promise<T>;
|
|
484
|
+
/**
|
|
485
|
+
* This is a workaround for postgres-js savepoint limitations.
|
|
486
|
+
* Postgres-js dictates this:
|
|
487
|
+
* - must use its `savepoint` method over manual `SAVEPOINT` because when doing it manually there is no way to prevent transaction from being rolled back when a query in a savepoint fails.
|
|
488
|
+
* - must use its `sql` client from inside the `savepoint` method for the lifetime of the savepoint because of the reason above.
|
|
489
|
+
*/
|
|
490
|
+
hackySavepoint<T extends QueryResultRow = QueryResultRow>(state: HackySavepointState, text: string, values?: unknown[], arraysMode?: boolean): Promise<QueryResult<T>>;
|
|
483
491
|
}
|
|
484
492
|
type Pool = any;
|
|
485
493
|
type Client = any;
|
|
@@ -493,8 +501,10 @@ interface DriverAdapter {
|
|
|
493
501
|
manualPool: boolean;
|
|
494
502
|
borrow(pool: Pool): Client;
|
|
495
503
|
release(client: Client): void;
|
|
496
|
-
queryClient<T extends QueryResultRow = QueryResultRow>(client: Client, text: string, values?: unknown[],
|
|
504
|
+
queryClient<T extends QueryResultRow = QueryResultRow>(client: Client, text: string, values?: unknown[], arraysMode?: boolean): Promise<QueryResult<T>>;
|
|
497
505
|
begin<DriverClient, Result>(pool: Pool, cb: (client: DriverClient) => Promise<Result>, options?: string): Promise<Result>;
|
|
506
|
+
savepoint<T>(client: Client, setClient: (client: Client) => void, name: string, cb: () => Promise<T>): Promise<T>;
|
|
507
|
+
hackySavepoint<T extends QueryResultRow>(client: Client, setClient: (client: Client) => void, state: HackySavepointState, text: string, values?: unknown[], arraysMode?: boolean): Promise<QueryResult<T>>;
|
|
498
508
|
close(pool: Pool): Promise<void>;
|
|
499
509
|
}
|
|
500
510
|
/**
|
|
@@ -521,10 +531,10 @@ declare class AdapterClass implements Adapter {
|
|
|
521
531
|
private readonly config;
|
|
522
532
|
private readonly connectionState;
|
|
523
533
|
constructor(params: AdapterParams);
|
|
524
|
-
query<T extends QueryResultRow = QueryResultRow>(text: string, values?: unknown[],
|
|
525
|
-
arrays<R extends any[] = any[]>(text: string, values?: unknown[],
|
|
534
|
+
query<T extends QueryResultRow = QueryResultRow>(text: string, values?: unknown[], sqlSessionState?: SqlSessionState): Promise<QueryResult<T>>;
|
|
535
|
+
arrays<R extends any[] = any[]>(text: string, values?: unknown[], sqlSessionState?: SqlSessionState): Promise<QueryArraysResult<R>>;
|
|
526
536
|
clone(params?: AdapterConfigBase): Adapter;
|
|
527
|
-
isInTransaction():
|
|
537
|
+
isInTransaction(this: Adapter): this is TransactionAdapter;
|
|
528
538
|
getDatabase(): string;
|
|
529
539
|
getUser(): string;
|
|
530
540
|
getSearchPath(): string | undefined;
|
|
@@ -534,6 +544,14 @@ declare class AdapterClass implements Adapter {
|
|
|
534
544
|
close: () => Promise<void>;
|
|
535
545
|
assignError(to: QueryError, from: Error): void;
|
|
536
546
|
}
|
|
547
|
+
interface HackySavepointStateActiveSavepoint {
|
|
548
|
+
release(): Promise<void>;
|
|
549
|
+
rollback(err: unknown): Promise<void>;
|
|
550
|
+
}
|
|
551
|
+
interface HackySavepointState {
|
|
552
|
+
name: string;
|
|
553
|
+
activeSavepoint?: HackySavepointStateActiveSavepoint;
|
|
554
|
+
}
|
|
537
555
|
/**
|
|
538
556
|
* Shared runtime transaction adapter orchestrator over a driver-specific transaction adapter.
|
|
539
557
|
*/
|
|
@@ -543,16 +561,18 @@ declare class TransactionAdapterClass implements TransactionAdapter {
|
|
|
543
561
|
errorClass: new (...args: any[]) => Error;
|
|
544
562
|
driverAdapter: DriverAdapter;
|
|
545
563
|
constructor(adapter: Adapter, client: Client);
|
|
546
|
-
query<T extends QueryResultRow = QueryResultRow>(text: string, values?: unknown[],
|
|
547
|
-
arrays<R extends any[] = any[]>(text: string, values?: unknown[],
|
|
564
|
+
query<T extends QueryResultRow = QueryResultRow>(text: string, values?: unknown[], sqlSessionState?: SqlSessionState): Promise<QueryResult<T>>;
|
|
565
|
+
arrays<R extends any[] = any[]>(text: string, values?: unknown[], sqlSessionState?: SqlSessionState): Promise<QueryArraysResult<R>>;
|
|
548
566
|
clone(params?: AdapterConfigBase): Adapter;
|
|
549
|
-
isInTransaction():
|
|
567
|
+
isInTransaction(this: Adapter): this is TransactionAdapter;
|
|
550
568
|
getDatabase(): string;
|
|
551
569
|
getUser(): string;
|
|
552
570
|
getSearchPath(): string | undefined;
|
|
553
571
|
getHost(): string;
|
|
554
572
|
getSchema(): QuerySchema | undefined;
|
|
555
573
|
transaction<T>(asyncStorage: AsyncLocalStorage<AsyncState> | undefined, options: AdapterTransactionOptions | undefined, cb: (adapter: TransactionAdapter) => Promise<T>): Promise<T>;
|
|
574
|
+
savepoint<T>(name: string, cb: () => Promise<T>): Promise<T>;
|
|
575
|
+
hackySavepoint<T extends QueryResultRow = QueryResultRow>(state: HackySavepointState, text: string, values?: unknown[], arraysMode?: boolean): Promise<QueryResult<T>>;
|
|
556
576
|
close(): Promise<void>;
|
|
557
577
|
assignError(to: QueryError, from: Error): void;
|
|
558
578
|
}
|
|
@@ -10462,4 +10482,4 @@ declare const testTransaction: {
|
|
|
10462
10482
|
*/
|
|
10463
10483
|
close(arg: Arg$1): Promise<void>;
|
|
10464
10484
|
};
|
|
10465
|
-
export { type Adapter, AdapterClass, type AdapterConfigBase, type AdapterParams, type AfterCommitStandaloneHook, type AfterHook, ArrayColumn, type ArrayColumnValue, type ArrayData, type AsyncState, type BaseNumberData, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, type Code, type Codes, Column, type ColumnFromDbParams, type ColumnSchemaConfig, type ColumnSchemaGetterColumns, type ColumnSchemaGetterTableClass, type ColumnToCodeCtx, type ColumnTypeSchemaArg, type ColumnsByType, type ColumnsShape, type ComputedColumnsFromOptions, type ComputedOptionsConfig, type ComputedOptionsFactory, type CreateCtx, type CreateData, type CreateManyMethodsNames, type CreateMethodsNames, type CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnData, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbExtension, type DbOptions, type DbResult, type DbRlsOptions, type DbSharedOptions, type DbSqlMethod, type DbStructureDomainsMap, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultPrivileges, type DefaultSchemaConfig, type DeleteMethodsNames, DomainColumn, DoublePrecisionColumn, type DriverAdapter, DynamicRawSQL, type EmptyObject, type EmptyTuple, EnumColumn, Expression, type FromArg, type FromResult, type GeneratorIgnore, type HookSelectValue, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsQuery, type IsolationLevel, JSONColumn, JSONTextColumn, type JoinQueryMethod, type JoinedShapes, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MaybeArray, type MaybePromise, type MergeQuery, MoneyColumn, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, Operators, type OperatorsArray, type OperatorsJson, type OperatorsOrdinalText, OrchidOrmInternalError, type Ord, PathColumn, type PickQueryInputType, type PickQueryInternal, type PickQueryQ, type PickQueryRelations, type PickQuerySelectableRelations, type PickQueryShape, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type Query, type QueryAfterHook, type QueryArraysResult, type QueryBeforeActionHook, type QueryBeforeHook, type QueryData, QueryError, type QueryHasWhere, type QueryHelperResult, QueryHookUtils, QueryHooks, type QueryInternal, type QueryLogObject, type QueryLogOptions, type QueryLogger, type QueryManyTake, type QueryManyTakeOptional, type QueryOrExpression, type QueryResult, type QueryResultRow, type QueryReturnType, type QuerySchema, type QueryScopes, RawSql, type RawSqlBase, RealColumn, type RecordKeyTrue, type RecordOptionalString, type RecordString, type RecordStringOrNumber, type RecordUnknown, type RelationConfigBase, type RelationJoinQuery, type RelationsBase, type SearchWeight, type SelectableFromShape, SerialColumn, type SerialColumnData, type ShallowSimplify, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SingleSql, type SingleSqlItem, SmallIntColumn, SmallSerialColumn, type Sql, type SqlFn, type SqlSessionState, type StorageOptions, StringColumn, type StringData, type TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, type TableRlsConfig, type TemplateLiteralArgs, TextBaseColumn, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, type Timestamps, TransactionAdapterClass, type TransactionOptions, TsQueryColumn, TsVectorColumn, UUIDColumn, type UniqueConstraints, type UniqueTableDataItem, UnknownColumn, type UpdateData, type UpsertData, type UpsertThis, VarCharColumn, VirtualColumn, type WhereArg, XMLColumn, _appendQuery, _clone, _createDbSqlMethod, _hookSelectColumns, _initQueryBuilder, _orCreate, _prependWith, _queryCreate, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryFindBy, _queryFindByOptional, _queryHookAfterCreate, _queryHookAfterUpdate, _queryInsert, _queryInsertMany, _queryJoinOn, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpsert, _queryWhere, _queryWhereExists, _queryWhereIn, addCode, addTopCte, addTopCteSql, applyMixins, assignDbDataToColumn, backtickQuote, cloneQueryBaseUnscoped, codeToString, colors, columnsShapeToCode, constraintInnerToCode, consumeColumnName, copyTableData, createDbWithAdapter, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeConnectRetryConfig, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, referencesArgsToCode, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, tableDataMethods, testTransaction, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
|
|
10485
|
+
export { type Adapter, AdapterClass, type AdapterConfigBase, type AdapterParams, type AfterCommitStandaloneHook, type AfterHook, ArrayColumn, type ArrayColumnValue, type ArrayData, type AsyncState, type BaseNumberData, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, type Code, type Codes, Column, type ColumnFromDbParams, type ColumnSchemaConfig, type ColumnSchemaGetterColumns, type ColumnSchemaGetterTableClass, type ColumnToCodeCtx, type ColumnTypeSchemaArg, type ColumnsByType, type ColumnsShape, type ComputedColumnsFromOptions, type ComputedOptionsConfig, type ComputedOptionsFactory, type CreateCtx, type CreateData, type CreateManyMethodsNames, type CreateMethodsNames, type CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnData, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbExtension, type DbOptions, type DbResult, type DbRlsOptions, type DbSharedOptions, type DbSqlMethod, type DbStructureDomainsMap, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultPrivileges, type DefaultSchemaConfig, type DeleteMethodsNames, DomainColumn, DoublePrecisionColumn, type DriverAdapter, DynamicRawSQL, type EmptyObject, type EmptyTuple, EnumColumn, Expression, type FromArg, type FromResult, type GeneratorIgnore, type HookSelectValue, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsQuery, type IsolationLevel, JSONColumn, JSONTextColumn, type JoinQueryMethod, type JoinedShapes, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MaybeArray, type MaybePromise, type MergeQuery, MoneyColumn, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, Operators, type OperatorsArray, type OperatorsJson, type OperatorsOrdinalText, OrchidOrmInternalError, type Ord, PathColumn, type PickQueryInputType, type PickQueryInternal, type PickQueryQ, type PickQueryRelations, type PickQuerySelectableRelations, type PickQueryShape, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type Query, type QueryAfterHook, type QueryArraysResult, type QueryBeforeActionHook, type QueryBeforeHook, type QueryData, QueryError, type QueryHasWhere, type QueryHelperResult, QueryHookUtils, QueryHooks, type QueryInternal, type QueryLogObject, type QueryLogOptions, type QueryLogger, type QueryManyTake, type QueryManyTakeOptional, type QueryOrExpression, type QueryResult, type QueryResultRow, type QueryReturnType, type QuerySchema, type QueryScopes, RawSql, type RawSqlBase, RealColumn, type RecordKeyTrue, type RecordOptionalString, type RecordString, type RecordStringOrNumber, type RecordUnknown, type RelationConfigBase, type RelationJoinQuery, type RelationsBase, type SearchWeight, type SelectableFromShape, SerialColumn, type SerialColumnData, type ShallowSimplify, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SingleSql, type SingleSqlItem, SmallIntColumn, SmallSerialColumn, type Sql, type SqlFn, type SqlSessionState, type StorageOptions, StringColumn, type StringData, type TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, type TableRlsConfig, type TemplateLiteralArgs, TextBaseColumn, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, type Timestamps, type TransactionAdapter, TransactionAdapterClass, type TransactionOptions, TsQueryColumn, TsVectorColumn, UUIDColumn, type UniqueConstraints, type UniqueTableDataItem, UnknownColumn, type UpdateData, type UpsertData, type UpsertThis, VarCharColumn, VirtualColumn, type WhereArg, XMLColumn, _appendQuery, _clone, _createDbSqlMethod, _hookSelectColumns, _initQueryBuilder, _orCreate, _prependWith, _queryCreate, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryFindBy, _queryFindByOptional, _queryHookAfterCreate, _queryHookAfterUpdate, _queryInsert, _queryInsertMany, _queryJoinOn, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpsert, _queryWhere, _queryWhereExists, _queryWhereIn, addCode, addTopCte, addTopCteSql, applyMixins, assignDbDataToColumn, backtickQuote, cloneQueryBaseUnscoped, codeToString, colors, columnsShapeToCode, constraintInnerToCode, consumeColumnName, copyTableData, createDbWithAdapter, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeConnectRetryConfig, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, referencesArgsToCode, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, tableDataMethods, testTransaction, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
|
package/dist/index.js
CHANGED
|
@@ -4116,8 +4116,8 @@ const checkIfNeedResultAllForMutativeQueriesSelectRelations = (sql) => {
|
|
|
4116
4116
|
const checkIfShouldReleaseSavepointForMutativeQueriesSelectRelations = (sql) => {
|
|
4117
4117
|
return sql.mutativeQueriesSelectRelationsState?.value;
|
|
4118
4118
|
};
|
|
4119
|
-
const loadMutativeQueriesSelectRelations = (sql, result,
|
|
4120
|
-
const loadRelations = async (state, result,
|
|
4119
|
+
const loadMutativeQueriesSelectRelations = (sql, result, savepointState, renames) => sql.mutativeQueriesSelectRelationsState?.value ? loadRelations(sql.mutativeQueriesSelectRelationsState, result, savepointState, renames) : void 0;
|
|
4120
|
+
const loadRelations = async (state, result, savepointState, renames) => {
|
|
4121
4121
|
const q = state.query;
|
|
4122
4122
|
const primaryKeys = requirePrimaryKeys(q, "Cannot select a relation of a table that has no primary keys");
|
|
4123
4123
|
const selectQuery = _unscope(q, "nonDeleted");
|
|
@@ -4140,9 +4140,9 @@ const loadRelations = async (state, result, adapter, startingSavepoint, renames)
|
|
|
4140
4140
|
});
|
|
4141
4141
|
selectQuery.q.select = select;
|
|
4142
4142
|
const relationsResult = await maybeWrappedThen.call(selectQuery, void 0, async (err) => {
|
|
4143
|
-
await
|
|
4143
|
+
await savepointState?.activeSavepoint?.rollback(err);
|
|
4144
4144
|
throw err;
|
|
4145
|
-
},
|
|
4145
|
+
}, savepointState);
|
|
4146
4146
|
for (const row of result) {
|
|
4147
4147
|
const relationRow = relationsResult.find((relationRow) => {
|
|
4148
4148
|
return !primaryKeys.some((key, i) => relationRow[relationKeyAliases[i]] !== row[key]);
|
|
@@ -4267,7 +4267,7 @@ const then = async (q, adapter, state, beforeHooks, afterHooks, afterSaveHooks,
|
|
|
4267
4267
|
let queryResult;
|
|
4268
4268
|
let cteData;
|
|
4269
4269
|
const startingSavepoint = setCatchingSavepoint(!parentSavepoint && shouldCatch && state);
|
|
4270
|
-
const releasingSavepoint = checkIfShouldReleaseSavepointForMutativeQueriesSelectRelations(sql) || parentSavepoint ? void 0 : startingSavepoint;
|
|
4270
|
+
const releasingSavepoint = checkIfShouldReleaseSavepointForMutativeQueriesSelectRelations(sql) || parentSavepoint ? void 0 : parentSavepoint || startingSavepoint;
|
|
4271
4271
|
if ("text" in sql) {
|
|
4272
4272
|
if (query.autoPreparedStatements) sql.name = queriesNames[sql.text] || (queriesNames[sql.text] = (nameI++).toString(36));
|
|
4273
4273
|
if (log) logData = log.beforeQuery(sql);
|
|
@@ -4442,7 +4442,7 @@ const then = async (q, adapter, state, beforeHooks, afterHooks, afterSaveHooks,
|
|
|
4442
4442
|
}
|
|
4443
4443
|
}
|
|
4444
4444
|
}
|
|
4445
|
-
const promise = loadMutativeQueriesSelectRelations(localSql, result,
|
|
4445
|
+
const promise = loadMutativeQueriesSelectRelations(localSql, result, startingSavepoint, renames) || parseBatch(q, queryResult);
|
|
4446
4446
|
if (promise) await promise;
|
|
4447
4447
|
if (tableHook?.select || tempReturnType !== returnType) {
|
|
4448
4448
|
if (renames) {
|
|
@@ -4488,7 +4488,10 @@ const then = async (q, adapter, state, beforeHooks, afterHooks, afterSaveHooks,
|
|
|
4488
4488
|
}
|
|
4489
4489
|
};
|
|
4490
4490
|
const setCatchingSavepoint = (catchTrx) => {
|
|
4491
|
-
return catchTrx
|
|
4491
|
+
return catchTrx && catchTrx.transactionAdapter ? {
|
|
4492
|
+
transactionAdapter: catchTrx.transactionAdapter,
|
|
4493
|
+
name: `s${catchTrx.catchI = (catchTrx.catchI || 0) + 1}`
|
|
4494
|
+
} : void 0;
|
|
4492
4495
|
};
|
|
4493
4496
|
/**
|
|
4494
4497
|
* Executes a query and in the case there are rows, but nothing was selected,
|
|
@@ -4496,7 +4499,17 @@ const setCatchingSavepoint = (catchTrx) => {
|
|
|
4496
4499
|
* because user might expect empty objects to be returned for an empty select.
|
|
4497
4500
|
*/
|
|
4498
4501
|
const execQuery = (adapter, method, sql, startingSavepoint, releasingSavepoint, sqlSessionState) => {
|
|
4499
|
-
|
|
4502
|
+
let promise;
|
|
4503
|
+
if (startingSavepoint) if (releasingSavepoint) promise = startingSavepoint.transactionAdapter.savepoint(startingSavepoint.name, () => {
|
|
4504
|
+
return promise = adapter[method](sql.text, sql.values, sqlSessionState);
|
|
4505
|
+
});
|
|
4506
|
+
else promise = startingSavepoint.transactionAdapter.hackySavepoint(startingSavepoint, sql.text, sql.values, method === "arrays");
|
|
4507
|
+
else promise = adapter[method](sql.text, sql.values, sqlSessionState);
|
|
4508
|
+
if (!startingSavepoint && releasingSavepoint) promise = promise.then(async (res) => {
|
|
4509
|
+
await releasingSavepoint.activeSavepoint?.release();
|
|
4510
|
+
return res;
|
|
4511
|
+
});
|
|
4512
|
+
return promise.then((result) => {
|
|
4500
4513
|
if (result.rowCount && !result.rows.length) {
|
|
4501
4514
|
result.rows.length = result.rowCount;
|
|
4502
4515
|
result.rows.fill({});
|
|
@@ -13240,7 +13253,7 @@ const performQuery = async (q, args, method) => {
|
|
|
13240
13253
|
let logData;
|
|
13241
13254
|
if (log) logData = log.beforeQuery(sql);
|
|
13242
13255
|
try {
|
|
13243
|
-
const result = await (trx?.transactionAdapter || q.adapterNotInTransaction)[method](sql.text, sql.values,
|
|
13256
|
+
const result = await (trx?.transactionAdapter || q.adapterNotInTransaction)[method](sql.text, sql.values, sqlSessionContextGetStateFromAsyncState(trx));
|
|
13244
13257
|
if (log) log.afterQuery(sql, logData);
|
|
13245
13258
|
return result;
|
|
13246
13259
|
} catch (err) {
|
|
@@ -13690,11 +13703,11 @@ var AdapterClass = class AdapterClass {
|
|
|
13690
13703
|
this.pool = this.driverAdapter.configure(this.config);
|
|
13691
13704
|
this.errorClass = this.driverAdapter.errorClass;
|
|
13692
13705
|
}
|
|
13693
|
-
query(text, values,
|
|
13694
|
-
return runQueryHandlePool(this.pool, this.driverAdapter, text, values,
|
|
13706
|
+
query(text, values, sqlSessionState) {
|
|
13707
|
+
return runQueryHandlePool(this.pool, this.driverAdapter, text, values, sqlSessionState);
|
|
13695
13708
|
}
|
|
13696
|
-
arrays(text, values,
|
|
13697
|
-
return runQueryHandlePool(this.pool, this.driverAdapter, text, values,
|
|
13709
|
+
arrays(text, values, sqlSessionState) {
|
|
13710
|
+
return runQueryHandlePool(this.pool, this.driverAdapter, text, values, sqlSessionState, true);
|
|
13698
13711
|
}
|
|
13699
13712
|
clone(params) {
|
|
13700
13713
|
return new AdapterClass({
|
|
@@ -13738,13 +13751,13 @@ var TransactionAdapterClass = class {
|
|
|
13738
13751
|
this.driverAdapter = adapter.driverAdapter;
|
|
13739
13752
|
this.errorClass = this.adapter.errorClass;
|
|
13740
13753
|
}
|
|
13741
|
-
query(text, values,
|
|
13754
|
+
query(text, values, sqlSessionState) {
|
|
13742
13755
|
const setup = sqlSessionContextComputeSetup(sqlSessionState);
|
|
13743
|
-
return runQueryHandleSetupAndCleanup(this.driverAdapter, this.client, text, values,
|
|
13756
|
+
return runQueryHandleSetupAndCleanup(this.driverAdapter, this.client, text, values, setup);
|
|
13744
13757
|
}
|
|
13745
|
-
arrays(text, values,
|
|
13758
|
+
arrays(text, values, sqlSessionState) {
|
|
13746
13759
|
const setup = sqlSessionContextComputeSetup(sqlSessionState);
|
|
13747
|
-
return runQueryHandleSetupAndCleanup(this.driverAdapter, this.client, text, values,
|
|
13760
|
+
return runQueryHandleSetupAndCleanup(this.driverAdapter, this.client, text, values, setup, true);
|
|
13748
13761
|
}
|
|
13749
13762
|
clone(params) {
|
|
13750
13763
|
return this.adapter.clone(params);
|
|
@@ -13770,6 +13783,16 @@ var TransactionAdapterClass = class {
|
|
|
13770
13783
|
async transaction(asyncStorage, options, cb) {
|
|
13771
13784
|
return transaction(asyncStorage, this.adapter, this.driverAdapter, this.client, options, cb, this);
|
|
13772
13785
|
}
|
|
13786
|
+
savepoint(name, cb) {
|
|
13787
|
+
return this.driverAdapter.savepoint(this.client, (client) => {
|
|
13788
|
+
this.client = client;
|
|
13789
|
+
}, name, cb);
|
|
13790
|
+
}
|
|
13791
|
+
hackySavepoint(state, text, values, arraysMode) {
|
|
13792
|
+
return this.driverAdapter.hackySavepoint(this.client, (client) => {
|
|
13793
|
+
this.client = client;
|
|
13794
|
+
}, state, text, values, arraysMode);
|
|
13795
|
+
}
|
|
13773
13796
|
close() {
|
|
13774
13797
|
return this.adapter.close();
|
|
13775
13798
|
}
|
|
@@ -13787,7 +13810,7 @@ const transaction = (asyncStorage, adapter, driverAdapter, poolOrClient, options
|
|
|
13787
13810
|
};
|
|
13788
13811
|
const transactionId = state?.transactionId !== void 0 ? state.transactionId + 1 : 0;
|
|
13789
13812
|
const fn = (transactionAdapter) => {
|
|
13790
|
-
if (log) log.afterQuery(sql, ctx.logData);
|
|
13813
|
+
if (log && sql.text) log.afterQuery(sql, ctx.logData);
|
|
13791
13814
|
if (log) ctx.logData = log.beforeQuery(commitSql);
|
|
13792
13815
|
if (state || !asyncStorage) {
|
|
13793
13816
|
const parentTransactionRole = state?.transactionRole;
|
|
@@ -13822,7 +13845,7 @@ const transaction = (asyncStorage, adapter, driverAdapter, poolOrClient, options
|
|
|
13822
13845
|
return asyncStorage.run(ctx.state, () => cb(transactionAdapter));
|
|
13823
13846
|
};
|
|
13824
13847
|
transactionAdapter ??= state?.transactionAdapter;
|
|
13825
|
-
if (transactionAdapter) return nestedTransaction(adapter, driverAdapter, transactionAdapter, poolOrClient, options, fn, ctx, transactionId
|
|
13848
|
+
if (transactionAdapter) return nestedTransaction(adapter, driverAdapter, transactionAdapter, poolOrClient, options, fn, ctx, transactionId);
|
|
13826
13849
|
else return realTransaction(adapter, driverAdapter, poolOrClient, options, fn, ctx, sql, log);
|
|
13827
13850
|
};
|
|
13828
13851
|
const realTransaction = async (adapter, driverAdapter, pool, options, cb, ctx, sql, log) => {
|
|
@@ -13856,36 +13879,26 @@ const realTransaction = async (adapter, driverAdapter, pool, options, cb, ctx, s
|
|
|
13856
13879
|
if (ctx.state) runAfterCommit(ctx.state.afterCommit, result);
|
|
13857
13880
|
return result;
|
|
13858
13881
|
};
|
|
13859
|
-
const nestedTransaction = async (adapter, driverAdapter, transactionAdapter, client, options, cb, ctx, transactionId
|
|
13882
|
+
const nestedTransaction = async (adapter, driverAdapter, transactionAdapter, client, options, cb, ctx, transactionId) => {
|
|
13860
13883
|
const state = ctx.state;
|
|
13861
13884
|
const parentRole = state?.transactionRole;
|
|
13862
13885
|
const parentSetConfig = state?.transactionSetConfig;
|
|
13863
|
-
|
|
13864
|
-
|
|
13865
|
-
|
|
13866
|
-
|
|
13867
|
-
|
|
13868
|
-
|
|
13869
|
-
|
|
13870
|
-
|
|
13871
|
-
|
|
13872
|
-
|
|
13873
|
-
|
|
13874
|
-
|
|
13875
|
-
|
|
13876
|
-
|
|
13877
|
-
|
|
13878
|
-
|
|
13879
|
-
} finally {
|
|
13880
|
-
const resetRoleSql = getResetRoleSql(parentRole, options);
|
|
13881
|
-
if (resetRoleSql) await driverAdapter.queryClient(client, resetRoleSql);
|
|
13882
|
-
}
|
|
13883
|
-
const resetSetConfigSql = getResetSetConfigSql(parentSetConfig, options);
|
|
13884
|
-
if (resetSetConfigSql) driverAdapter.queryClient(client, resetSetConfigSql);
|
|
13885
|
-
sql.text = `RELEASE SAVEPOINT "t${transactionId}"`;
|
|
13886
|
-
if (log) ctx.logData = log.beforeQuery(sql);
|
|
13887
|
-
await transactionAdapter.arrays(sql.text, sql.values);
|
|
13888
|
-
if (log) log.afterQuery(sql, ctx.logData);
|
|
13886
|
+
const result = await transactionAdapter.savepoint(`t${transactionId}`, async () => {
|
|
13887
|
+
const setRoleSql = getSetRoleSql(parentRole, options);
|
|
13888
|
+
if (setRoleSql) driverAdapter.queryClient(client, setRoleSql);
|
|
13889
|
+
const setConfigSql = getSetConfigSql(parentSetConfig, options);
|
|
13890
|
+
if (setConfigSql) driverAdapter.queryClient(client, setConfigSql);
|
|
13891
|
+
let result;
|
|
13892
|
+
try {
|
|
13893
|
+
result = await cb(new TransactionAdapterClass(adapter, client));
|
|
13894
|
+
} finally {
|
|
13895
|
+
const resetRoleSql = getResetRoleSql(parentRole, options);
|
|
13896
|
+
if (resetRoleSql) await driverAdapter.queryClient(client, resetRoleSql);
|
|
13897
|
+
}
|
|
13898
|
+
const resetSetConfigSql = getResetSetConfigSql(parentSetConfig, options);
|
|
13899
|
+
if (resetSetConfigSql) driverAdapter.queryClient(client, resetSetConfigSql);
|
|
13900
|
+
return result;
|
|
13901
|
+
});
|
|
13889
13902
|
if (ctx.state && transactionId === ctx.state.testTransactionCount) {
|
|
13890
13903
|
const { afterCommit } = ctx.state;
|
|
13891
13904
|
ctx.state.afterCommit = void 0;
|
|
@@ -13936,19 +13949,19 @@ const runAfterCommit = (afterCommit, result) => {
|
|
|
13936
13949
|
}
|
|
13937
13950
|
});
|
|
13938
13951
|
};
|
|
13939
|
-
const runQueryHandlePool = async (pool, driverAdapter, text, values,
|
|
13952
|
+
const runQueryHandlePool = async (pool, driverAdapter, text, values, sqlSessionState, arraysMode, client) => {
|
|
13940
13953
|
const setup = sqlSessionContextComputeSetup(sqlSessionState);
|
|
13941
|
-
if (client || !driverAdapter.manualPool && !setup) return runQueryHandleSetupAndCleanup(driverAdapter, client || pool, text, values,
|
|
13954
|
+
if (client || !driverAdapter.manualPool && !setup) return runQueryHandleSetupAndCleanup(driverAdapter, client || pool, text, values, setup, arraysMode);
|
|
13942
13955
|
client = await driverAdapter.borrow(pool);
|
|
13943
13956
|
try {
|
|
13944
|
-
return await runQueryHandleSetupAndCleanup(driverAdapter, client, text, values,
|
|
13957
|
+
return await runQueryHandleSetupAndCleanup(driverAdapter, client, text, values, setup, arraysMode);
|
|
13945
13958
|
} finally {
|
|
13946
13959
|
driverAdapter.release(client);
|
|
13947
13960
|
}
|
|
13948
13961
|
};
|
|
13949
|
-
const runQueryHandleSetupAndCleanup = (driverAdapter, client, text, values,
|
|
13950
|
-
if (setup) return sqlSessionContextExecute((text, values) => driverAdapter.queryClient(client, text, values,
|
|
13951
|
-
return driverAdapter.queryClient(client, text, values,
|
|
13962
|
+
const runQueryHandleSetupAndCleanup = (driverAdapter, client, text, values, setup, arraysMode) => {
|
|
13963
|
+
if (setup) return sqlSessionContextExecute((text, values) => driverAdapter.queryClient(client, text, values, true), setup, () => driverAdapter.queryClient(client, text, values, arraysMode));
|
|
13964
|
+
return driverAdapter.queryClient(client, text, values, arraysMode);
|
|
13952
13965
|
};
|
|
13953
13966
|
const createAdapterConnectionState = (config) => {
|
|
13954
13967
|
const state = { originalConfig: { ...config } };
|