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';
|
import { DB_FILENAME } from './opfs';
|
||||||
|
|
||||||
let db: OpfsDatabase | null = null;
|
let db: any | null = null;
|
||||||
|
|
||||||
self.onmessage = async (e) => {
|
self.onmessage = async (e) => {
|
||||||
try {
|
try {
|
||||||
|
console.log(e.data.type)
|
||||||
switch (e.data.type) {
|
switch (e.data.type) {
|
||||||
case 'start': {
|
case 'start': {
|
||||||
try {
|
try {
|
||||||
@@ -13,7 +14,6 @@ self.onmessage = async (e) => {
|
|||||||
printErr: console.error, // Сюда будут падать детали ошибок VFS
|
printErr: console.error, // Сюда будут падать детали ошибок VFS
|
||||||
});
|
});
|
||||||
const filename = '/' + DB_FILENAME;
|
const filename = '/' + DB_FILENAME;
|
||||||
console.log(filename)
|
|
||||||
db = new sqlite3.oo1.OpfsDb(filename, 'rwt');
|
db = new sqlite3.oo1.OpfsDb(filename, 'rwt');
|
||||||
|
|
||||||
db.exec('PRAGMA foreign_keys = ON;');
|
db.exec('PRAGMA foreign_keys = ON;');
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ export function renderHomePage(root: HTMLElement, nav: HomeNav): void {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
worker.postMessage({ type: 'start' });
|
|
||||||
const raw = await readDatabaseFile();
|
const raw = await readDatabaseFile();
|
||||||
const ok = looksLikeSQLite(raw);
|
const ok = looksLikeSQLite(raw);
|
||||||
statusEl.textContent = ok
|
statusEl.textContent = ok
|
||||||
|
|||||||
@@ -6,6 +6,13 @@ export const worker = new Worker(new URL('./db-worker.ts', import.meta.url), {
|
|||||||
type: 'module',
|
type: 'module',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
worker.onerror = (ee) => {
|
||||||
|
console.log(ee)
|
||||||
|
};
|
||||||
|
|
||||||
|
worker.onmessageerror = (ee) => {
|
||||||
|
console.log(ee)
|
||||||
|
};
|
||||||
worker.onmessage = (e) => {
|
worker.onmessage = (e) => {
|
||||||
if (e.data.type === 'success') {
|
if (e.data.type === 'success') {
|
||||||
const app = document.getElementById('app');
|
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> {
|
export async function hasDatabaseFile(): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
const root = await opfsRoot();
|
const root = await opfsRoot();
|
||||||
console.log("in root dir " + root.entries.length + " files");
|
|
||||||
const handle = await root.getFileHandle(DB_FILENAME);
|
const handle = await root.getFileHandle(DB_FILENAME);
|
||||||
const file = await handle.getFile();
|
const file = await handle.getFile();
|
||||||
console.log(file.size);
|
|
||||||
console.log(file.name);
|
|
||||||
console.log(handle);
|
|
||||||
return file.size > 0;
|
return file.size > 0;
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in new issue
Block a user