Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gajus/slonik
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v33.2.0
Choose a base ref
...
head repository: gajus/slonik
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v33.3.0
Choose a head ref
  • 1 commit
  • 12 files changed
  • 1 contributor

Commits on Apr 14, 2023

  1. 4
    Copy the full SHA
    7582b5c View commit details
7 changes: 5 additions & 2 deletions src/connectionMethods/transaction.ts
Original file line number Diff line number Diff line change
@@ -40,15 +40,18 @@ const execTransaction: InternalTransactionFunction = async (

if (
poolClientState.mock === false &&
poolClientState.ignoreCommit === false
poolClientState.ignoreCommitAndRollback === false
) {
await connection.query('COMMIT');
}

return result;
} catch (error) {
if (!poolClientState.terminated) {
if (poolClientState.mock === false) {
if (
poolClientState.mock === false &&
poolClientState.ignoreCommitAndRollback === false
) {
await connection.query('ROLLBACK');
}

2 changes: 1 addition & 1 deletion src/factories/createClientConfiguration.ts
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ export const createClientConfiguration = (
connectionTimeout: 5_000,
idleInTransactionSessionTimeout: 60_000,
idleTimeout: 5_000,
ignoreCommit: false,
ignoreCommitAndRollback: false,
interceptors: [],
maximumPoolSize: 10,
queryRetryLimit: 5,
2 changes: 1 addition & 1 deletion src/factories/createConnection.ts
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ export const createConnection = async (

poolClientStateMap.set(connection, {
connectionId: createUid(),
ignoreCommit: poolState.ignoreCommit,
ignoreCommitAndRollback: poolState.ignoreCommitAndRollback,
mock: poolState.mock,
poolId: poolState.poolId,
terminated: null,
2 changes: 1 addition & 1 deletion src/factories/createMockPool.ts
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ export const createMockPool = (

poolStateMap.set(pool, {
ended: false,
ignoreCommit: true,
ignoreCommitAndRollback: true,
mock: true,
poolId,
typeOverrides: null,
2 changes: 1 addition & 1 deletion src/factories/createPool.ts
Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@ export const createPool = async (

poolStateMap.set(pool, {
ended: false,
ignoreCommit: clientConfiguration.ignoreCommit,
ignoreCommitAndRollback: clientConfiguration.ignoreCommitAndRollback,
mock: false,
poolId,
typeOverrides: null,
4 changes: 2 additions & 2 deletions src/state.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import { type Pool as PgPool, type PoolClient as PgClientPool } from 'pg';

type PoolState = {
ended: boolean;
ignoreCommit: boolean;
ignoreCommitAndRollback: boolean;
mock: boolean;
poolId: string;
typeOverrides: Promise<TypeOverrides> | null;
@@ -14,7 +14,7 @@ type PoolState = {
type PoolClientState = {
activeQuery?: DeferredPromise<unknown>;
connectionId: string;
ignoreCommit: boolean;
ignoreCommitAndRollback: boolean;
mock: boolean;
poolId: string;
terminated: Error | null;
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ export type ClientConfiguration = {
/**
* Do not send COMMIT after successful transaction. (Default: false)
*/
readonly ignoreCommit: boolean;
readonly ignoreCommitAndRollback: boolean;
/**
* An array of [Slonik interceptors](https://github.com/gajus/slonik#slonik-interceptors).
*/
2 changes: 1 addition & 1 deletion test/helpers/createClientConfiguration.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ export const createClientConfiguration = (): ClientConfiguration => {
connectionTimeout: 5_000,
idleInTransactionSessionTimeout: 60_000,
idleTimeout: 5_000,
ignoreCommit: false,
ignoreCommitAndRollback: false,
interceptors: [],
maximumPoolSize: 10,
queryRetryLimit: 5,
4 changes: 2 additions & 2 deletions test/helpers/createPool.ts
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ export const createPool = async (

poolStateMap.set(internalPool, {
ended: false,
ignoreCommit: false,
ignoreCommitAndRollback: false,
mock: false,
poolId: '1',
typeOverrides: null,
@@ -62,7 +62,7 @@ export const createPool = async (
connectionTimeout: 5_000,
idleInTransactionSessionTimeout: 5_000,
idleTimeout: 5_000,
ignoreCommit: false,
ignoreCommitAndRollback: false,
interceptors: [],
maximumPoolSize: 1,
queryRetryLimit: 1,
2 changes: 1 addition & 1 deletion test/slonik/factories/createClientConfiguration.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ const defaultConfiguration = {
connectionTimeout: 5_000,
idleInTransactionSessionTimeout: 60_000,
idleTimeout: 5_000,
ignoreCommit: false,
ignoreCommitAndRollback: false,
interceptors: [],
maximumPoolSize: 10,
queryRetryLimit: 5,
2 changes: 1 addition & 1 deletion test/slonik/integration/pg.ts
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ createIntegrationTests(test, PgPool);

test('does not break out of a transaction', async (t) => {
const pool = await createPool(t.context.dsn, {
ignoreCommit: true,
ignoreCommitAndRollback: true,
PgPool,
});

4 changes: 2 additions & 2 deletions test/slonik/routines/executeQuery.ts
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ beforeEach((t) => {

poolClientStateMap.set(t.context.connection, {
connectionId: '1',
ignoreCommit: false,
ignoreCommitAndRollback: false,
mock: true,
poolId: '1',
terminated: null,
@@ -163,7 +163,7 @@ test('transaction errors are not handled if the function was called by a transac

poolClientStateMap.set(connection, {
connectionId: '1',
ignoreCommit: false,
ignoreCommitAndRollback: false,
mock: true,
poolId: '1',
terminated: null,