Skip to content

Commit e2939a7

Browse files
committed
feat(dialect-generic-sqlite): init mutex lazily
1 parent dec68fc commit e2939a7

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

  • packages/dialect-generic-sqlite/src

packages/dialect-generic-sqlite/src/base.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ async function runSavepoint(
8585
}
8686

8787
export 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

0 commit comments

Comments
 (0)