Skip to content

Commit 33afa28

Browse files
committed
v0feat: added option to switch to db that does not exist
1 parent 34d2555 commit 33afa28

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/runtime/composables/useSwitchDefaultDatabase.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import type { ClientDatabaseManager } from "../utils/clientDatabaseManager"
55
/**
66
* Switches the default database to the name passed.
77
*
8-
* The database must already exist.
8+
* The database must already exist unless you pass { errorIfNotFound: false }.
9+
*
10+
* See {@link ClientDatabaseManager.switchDefaultDatabase} for more info.
911
*/
1012
export async function useSwitchDefaultDatabase(...args: Parameters<ClientDatabaseManager["switchDatabase"]>): Promise<void> {
1113
return useGlobalClientDatabaseManager().switchDatabase(...args)

src/runtime/utils/clientDatabaseManager.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,13 @@ export class ClientDatabaseManager {
151151
return entry
152152
}
153153

154-
switchDatabase(name: string) {
155-
this.getEntry(name, { errorIfNotFound: true })
154+
switchDatabase(name: string, { errorIfNotFound = true }: { errorIfNotFound?: boolean } = {}) {
155+
/**
156+
* This only changes the default database used by useClientDb, it does not init/re-init anything.
157+
*
158+
* You can pass { errorIfNotFound: false } to allow setting to an undefined database (to, for example, allow deletion of the database on logout).
159+
*/
160+
this.getEntry(name, { errorIfNotFound })
156161
this.defaultDatabaseName = name
157162
}
158163

0 commit comments

Comments
 (0)