Skip to content

Commit

Permalink
fix: add support for transaction isolation level commands, closes #55
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmosh committed Oct 7, 2024
1 parent b0a9f95 commit 74123a2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type ResponseTypes = {
simulateErrorOnce: (error: Handler['error']) => Tracker;
};

type QueryMethodType = typeof queryMethods[number];
type QueryMethodType = (typeof queryMethods)[number];

type History = Record<QueryMethodType, RawQuery[]> & {
transactions: TransactionState[];
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ export const transactionCommands = [
'ROLLBACK',
'SAVEPOINT',
'RELEASE SAVEPOINT',
'SET TRANSACTION ISOLATION LEVEL',
'BEGIN TRANSACTION ISOLATION LEVEL',
] as const;
13 changes: 13 additions & 0 deletions tests/dialects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ describe('specific dialect', () => {
expect(tracker.history.insert[0].sql).toContain('returning');
expect(tracker.history.delete).toHaveLength(1);
});

it('should support transactions with an explicit isolation level', async () => {
tracker.on.insert('table_name').responseOnce(1);
tracker.on.delete('table_name').responseOnce(1);
tracker.on.select('foo').responseOnce([]);

const trx = await db.transaction({ isolationLevel: 'read uncommitted' });

await db('table_name').transacting(trx).insert({ name: 'Steve' }).transacting(trx);
await db('table_name').transacting(trx).delete().where({ name: 'Steve' }).transacting(trx);

await trx.commit();
});
});

describe('mysql', () => {
Expand Down
13 changes: 13 additions & 0 deletions tests/transaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,17 @@ describe('transaction', () => {
},
]);
});

it('should support transactions with an explicit isolation level', async () => {
tracker.on.insert('table_name').responseOnce(1);
tracker.on.delete('table_name').responseOnce(1);
tracker.on.select('foo').responseOnce([]);

const trx = await db.transaction({ isolationLevel: 'serializable' });

await db('table_name').transacting(trx).insert({ name: 'Steve' }).transacting(trx);
await db('table_name').transacting(trx).delete().where({ name: 'Steve' }).transacting(trx);

await trx.commit();
});
});

0 comments on commit 74123a2

Please sign in to comment.