Skip to content

Commit 5356b1a

Browse files
committed
v0fix: clientDabataseManager's deleteEntry now closes the database if it can
1 parent ead3b87 commit 5356b1a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/runtime/utils/clientDatabaseManager.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ export class ClientDatabaseManager {
9696
initOptions: InitOptions = {}
9797
): ClientDatabaseEntry | undefined {
9898
const exists = this.databases.has(name)
99-
if (!exists) {
99+
if (exists) {
100+
if (opts) {
101+
throw new Error("Cannot re-initialize a client database with different options unless it's entry is removed first.")
102+
}
103+
return this.databases.get(name)
104+
}
100105
if (!opts) {
101106
throw new Error("No config or client passed to useClientDb. Config/client must be passed at least once for each database name.")
102107
}
@@ -144,8 +149,6 @@ export class ClientDatabaseManager {
144149
}
145150
this.databases.set(name, entry)
146151
return entry
147-
}
148-
return this.databases.get(name)
149152
}
150153

151154
switchDatabase(name: string) {
@@ -161,8 +164,9 @@ export class ClientDatabaseManager {
161164
return entry
162165
}
163166

164-
deleteEntry(name: string, { errorIfNotFound = true } = {}): void {
167+
async deleteEntry(name: string, { errorIfNotFound = true } = {}): void {
165168
const entry = this.databases.get(name)
169+
await entry?.client?.close()
166170
if (errorIfNotFound && !entry) {
167171
throw new Error(`No database found by the name of ${name}.`)
168172
}
@@ -188,7 +192,7 @@ export class ClientDatabaseManager {
188192
): Promise<void> {
189193
const entry = this.getEntry(name, { errorIfNotFound: true })!
190194

191-
this.deleteEntry(name, { errorIfNotFound: false })
195+
await this.deleteEntry(name, { errorIfNotFound: false })
192196
await this.useClientDb(name, entry.options, entry.initOptions)
193197
}
194198

0 commit comments

Comments
 (0)