@@ -78,6 +78,49 @@ void describe('SQLite Transactions', () => {
78
78
await pool . close ( ) ;
79
79
}
80
80
} ) ;
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
+ } ) ;
81
124
82
125
void it ( 'should try catch and roll back everything when the inner transaction errors for a pooled connection' , async ( ) => {
83
126
const pool = sqlitePool ( {
0 commit comments