Skip to content

Commit 87caa9f

Browse files
committed
v0breaking: renamed deleteDb to removeDb and added composable for it
1 parent 2c60f49 commit 87caa9f

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useGlobalClientDatabaseManager } from "./useGlobalClientDatabaseManager"
2+
3+
import type { ClientDatabaseManager } from "../utils/clientDatabaseManager"
4+
5+
/**
6+
* Closes and removes the database from the list of known databases.
7+
*
8+
* This does NOT delete the database, see `deleteIndexedDbDb` for that.
9+
*/
10+
11+
export async function useRemoveClientDb(...args: Parameters<ClientDatabaseManager["removeDb"]>): Promise<void> {
12+
return useGlobalClientDatabaseManager().removeDb(...args)
13+
}

src/runtime/utils/clientDatabaseManager.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,12 @@ export class ClientDatabaseManager {
164164
return entry
165165
}
166166

167-
async deleteEntry(name: string, { errorIfNotFound = true } = {}): Promise<void> {
167+
/**
168+
* Closes and removes the database from the list of known databases.
169+
*
170+
* This does NOT delete the database, deletion should be done before calling this through other methods (which, depends on the backend, e.g. fs.rm for a file, `deleteIndexedDbDb` for indexedDB, none for memory, etc.).
171+
*/
172+
async removeDb(name: string, { errorIfNotFound = true } = {}): Promise<void> {
168173
const entry = this.databases.get(name)
169174
await entry?.client?.close()
170175
if (errorIfNotFound && !entry) {
@@ -192,7 +197,7 @@ export class ClientDatabaseManager {
192197
): Promise<void> {
193198
const entry = this.getEntry(name, { errorIfNotFound: true })!
194199

195-
await this.deleteEntry(name, { errorIfNotFound: false })
200+
await this.removeDb(name, { errorIfNotFound: false })
196201
await this.useClientDb(name, entry.options, entry.initOptions)
197202
}
198203

@@ -251,7 +256,7 @@ export class ClientDatabaseManager {
251256
}
252257

253258
/**
254-
* Deletes indexedDB databases and any stored migration state. Note that this won't take proper effect until the user navigates away from the page if the request gets blocked.
259+
* Deletes indexedDB databases (this only works if the db is actually using indexedDB, other deletions are not implemented) and any stored migration state. Note that this won't take proper effect until the user navigates away from the page if the request gets blocked.
255260
*
256261
* PGlite does not have a close method yet, see [pglite#142](https://github.com/electric-sql/pglite/issues/142).
257262
*

0 commit comments

Comments
 (0)