File tree Expand file tree Collapse file tree
packages/dialect-generic-sqlite/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ async function runSavepoint(
8585}
8686
8787export abstract class BaseSqliteDriver implements Driver {
88- private mutex = new ConnectionMutex ( )
88+ private mutex ?: ConnectionMutex
8989 public conn ?: DatabaseConnection
9090 savepoint : ( ( connection : DatabaseConnection , savepointName : string , compileQuery : QueryCompiler [ 'compileQuery' ] ) => Promise < void > ) | undefined
9191 releaseSavepoint : ( ( connection : DatabaseConnection , savepointName : string , compileQuery : QueryCompiler [ 'compileQuery' ] ) => Promise < void > ) | undefined
@@ -111,10 +111,17 @@ export abstract class BaseSqliteDriver implements Driver {
111111 async acquireConnection ( ) : Promise < DatabaseConnection > {
112112 // SQLite only has one single connection. We use a mutex here to wait
113113 // until the single connection has been released.
114+ if ( ! this . mutex ) {
115+ this . mutex = new ConnectionMutex ( )
116+ }
114117 await this . mutex . lock ( )
115118 return this . conn !
116119 }
117120
121+ async releaseConnection ( ) : Promise < void > {
122+ this . mutex ?. unlock ( )
123+ }
124+
118125 async beginTransaction ( connection : DatabaseConnection ) : Promise < void > {
119126 await connection . executeQuery ( CompiledQuery . raw ( 'begin' ) )
120127 }
@@ -127,10 +134,6 @@ export abstract class BaseSqliteDriver implements Driver {
127134 await connection . executeQuery ( CompiledQuery . raw ( 'rollback' ) )
128135 }
129136
130- async releaseConnection ( ) : Promise < void > {
131- this . mutex . unlock ( )
132- }
133-
134137 abstract destroy ( ) : Promise < void >
135138}
136139
You can’t perform that action at this time.
0 commit comments