feat: Refactor database initialization code

This commit is contained in:
doprz
2023-12-23 09:26:49 -06:00
parent 9f1dcc667d
commit 5e98f45210

View File

@@ -25,13 +25,14 @@ export async function initializeDB(): Promise<Database> {
return db; return db;
} }
const databasePromise = await initSqlJs({ const [{ Database }, dbBuffer] = await Promise.all([
initSqlJs({
locateFile: () => WASM_FILE_URL, locateFile: () => WASM_FILE_URL,
}); }),
const dbBufferPromise = await fetch(DB_FILE_URL).then(res => res.arrayBuffer()); fetch(DB_FILE_URL).then(res => res.arrayBuffer()),
const [database, dbBuffer] = await Promise.all([databasePromise, dbBufferPromise]); ]);
db = new database.Database(new Uint8Array(dbBuffer)); db = new Database(new Uint8Array(dbBuffer));
return db; return db;
} }