-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.worker.js
More file actions
49 lines (36 loc) · 1.11 KB
/
Copy pathindex.worker.js
File metadata and controls
49 lines (36 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import initSqlJs from '@jlongster/sql.js';
import { SQLiteFS } from 'absurd-sql';
import IndexedDBBackend from 'absurd-sql/dist/indexeddb-backend';
async function init() {
console.log("initializing database...");
let SQL = await initSqlJs({ locateFile: file => file });
let sqlFS = new SQLiteFS(SQL.FS, new IndexedDBBackend());
SQL.register_for_idb(sqlFS);
SQL.FS.mkdir('/sql');
SQL.FS.mount(sqlFS, {}, '/sql');
const path = '/sql/db.sqlite';
if (typeof SharedArrayBuffer === 'undefined') {
let stream = SQL.FS.open(path, 'a+');
await stream.node.contents.readIfFallback();
SQL.FS.close(stream);
}
let db = new SQL.Database(path, { filename: true });
// You might want to try `PRAGMA page_size=8192;` too!
db.exec(`
PRAGMA journal_mode=MEMORY;
`);
// Your code
//console.log("Database initialized. Ready for Queries");
postMessage("Ready for Queries.");
return db;
}
function run() {
console.log("started worker.");
let db = init();
console.log("called init.");
}
onmessage = function(e) {
console.log("got a message: " + e.data);
postMessage("this is a reply.");
}
run();