Skip to content

Commit 2f1754b

Browse files
davecosecoskardudycz
authored andcommitted
Added test to fail if nested transaction is attempted but is not enabled
1 parent ab56176 commit 2f1754b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/packages/dumbo/src/storage/sqlite/core/transactions/transactions.int.spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,49 @@ void describe('SQLite Transactions', () => {
7878
await pool.close();
7979
}
8080
});
81+
void it('should fail with an error if transaction nested is false', async () => {
82+
const pool = sqlitePool({
83+
connector: 'SQLite:sqlite3',
84+
fileName,
85+
allowNestedTransactions: false,
86+
});
87+
const connection = await pool.connection();
88+
89+
try {
90+
await connection.execute.query(
91+
rawSql('CREATE TABLE test_table (id INTEGER, value TEXT)'),
92+
);
93+
94+
await connection.withTransaction<number>(async () => {
95+
await connection.execute.query(
96+
rawSql(
97+
'INSERT INTO test_table (id, value) VALUES (2, "test") RETURNING id',
98+
),
99+
);
100+
101+
const result = await connection.withTransaction<number>(
102+
async () => {
103+
const result = await connection.execute.query(
104+
rawSql(
105+
'INSERT INTO test_table (id, value) VALUES (1, "test") RETURNING id',
106+
),
107+
);
108+
return (result.rows[0]?.id as number) ?? null;
109+
},
110+
);
111+
112+
return result;
113+
});
114+
} catch (error) {
115+
assert.strictEqual(
116+
(error as Error).message,
117+
'SQLITE_ERROR: cannot start a transaction within a transaction',
118+
);
119+
} finally {
120+
await connection.close();
121+
await pool.close();
122+
}
123+
});
81124

82125
void it('should try catch and roll back everything when the inner transaction errors for a pooled connection', async () => {
83126
const pool = sqlitePool({

0 commit comments

Comments
 (0)