fix db worker
This commit is contained in:
1 parent
fc8455e353
commit
154c55a7bb
4 files changed
+11
-8
No files matched your search
+3
-3
@@ -1,10 +1,11 @@
|
||||
import sqlite3InitModule, { OpfsDatabase } from '@sqlite.org/sqlite-wasm';
|
||||
import sqlite3InitModule from '@sqlite.org/sqlite-wasm';
|
||||
import { DB_FILENAME } from './opfs';
|
||||
|
||||
let db: OpfsDatabase | null = null;
|
||||
let db: any | null = null;
|
||||
|
||||
self.onmessage = async (e) => {
|
||||
try {
|
||||
console.log(e.data.type)
|
||||
switch (e.data.type) {
|
||||
case 'start': {
|
||||
try {
|
||||
@@ -13,7 +14,6 @@ self.onmessage = async (e) => {
|
||||
printErr: console.error, // Сюда будут падать детали ошибок VFS
|
||||
});
|
||||
const filename = '/' + DB_FILENAME;
|
||||
console.log(filename)
|
||||
db = new sqlite3.oo1.OpfsDb(filename, 'rwt');
|
||||
|
||||
db.exec('PRAGMA foreign_keys = ON;');
|
||||
|
||||
@@ -42,7 +42,6 @@ export function renderHomePage(root: HTMLElement, nav: HomeNav): void {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
worker.postMessage({ type: 'start' });
|
||||
const raw = await readDatabaseFile();
|
||||
const ok = looksLikeSQLite(raw);
|
||||
statusEl.textContent = ok
|
||||
|
||||
@@ -6,6 +6,13 @@ export const worker = new Worker(new URL('./db-worker.ts', import.meta.url), {
|
||||
type: 'module',
|
||||
});
|
||||
|
||||
worker.onerror = (ee) => {
|
||||
console.log(ee)
|
||||
};
|
||||
|
||||
worker.onmessageerror = (ee) => {
|
||||
console.log(ee)
|
||||
};
|
||||
worker.onmessage = (e) => {
|
||||
if (e.data.type === 'success') {
|
||||
const app = document.getElementById('app');
|
||||
@@ -17,6 +24,7 @@ worker.onmessage = (e) => {
|
||||
}
|
||||
};
|
||||
|
||||
worker.postMessage({ type: 'start' });
|
||||
|
||||
// Каркас приложения: топ-бар + бургер-меню + две страницы (Главная / Синхронизация).
|
||||
|
||||
|
||||
@@ -70,12 +70,8 @@ export async function readDatabaseFile(): Promise<Uint8Array> {
|
||||
export async function hasDatabaseFile(): Promise<boolean> {
|
||||
try {
|
||||
const root = await opfsRoot();
|
||||
console.log("in root dir " + root.entries.length + " files");
|
||||
const handle = await root.getFileHandle(DB_FILENAME);
|
||||
const file = await handle.getFile();
|
||||
console.log(file.size);
|
||||
console.log(file.name);
|
||||
console.log(handle);
|
||||
return file.size > 0;
|
||||
} catch {
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user