web: allow multi tab access when using idb vfs

This commit is contained in:
Abdullah Atta
2024-07-10 09:01:42 +05:00
committed by Abdullah Atta
parent 8302f8ba4c
commit 727ac6d907
5 changed files with 36 additions and 17 deletions

View File

@@ -27,7 +27,6 @@ import {
WaSqliteWorkerMultipleTabDriver,
WaSqliteWorkerSingleTabDriver
} from "./wa-sqlite-kysely-driver";
import { isFeatureSupported } from "../../utils/feature-check";
declare module "kysely" {
interface Driver {
@@ -35,22 +34,26 @@ declare module "kysely" {
}
}
export const createDialect = (
name: string,
encrypted: boolean,
init?: () => Promise<void>
): Dialect => {
export type DialectOptions = {
name: string;
encrypted: boolean;
async: boolean;
multiTab: boolean;
init?: () => Promise<void>;
};
export const createDialect = (options: DialectOptions): Dialect => {
const { async, encrypted, multiTab, name, init } = options;
return {
createDriver: () =>
globalThis.SharedWorker
multiTab
? new WaSqliteWorkerMultipleTabDriver({
async: !isFeatureSupported("opfs"),
async,
dbName: name,
encrypted,
init
})
: new WaSqliteWorkerSingleTabDriver({
async: !isFeatureSupported("opfs"),
async,
dbName: name,
encrypted
}),