3 changed files with 32 additions and 0 deletions
@ -0,0 +1,28 @@ |
|||
// Started with https://rhashimoto.github.io/wa-sqlite/docs/interfaces/SQLiteAPI.html
|
|||
// and then https://github.com/rhashimoto/wa-sqlite/blob/master/demo/demo-worker.js
|
|||
|
|||
import SQLiteESMFactory from 'wa-sqlite/dist/wa-sqlite.mjs'; |
|||
|
|||
import * as SQLite from 'wa-sqlite'; |
|||
|
|||
const IDBBatchAtomicVFS = await import('wa-sqlite/src/examples/IDBBatchAtomicVFS.js'); |
|||
|
|||
let db: any; |
|||
|
|||
export async function sql() { |
|||
if (!db) { |
|||
const module = await SQLiteESMFactory(); |
|||
|
|||
// Use the module to build the API instance.
|
|||
const sqlite3 = SQLite.Factory(module); |
|||
|
|||
const vfs = new IDBBatchAtomicVFS.create("IDBBatchAtomicVFS", module, { lockPolicy: 'shared+hint' }); |
|||
sqlite3.vfs_register(vfs, true); |
|||
|
|||
// Use the API to open and access a database.
|
|||
const db = await sqlite3.open_v2("myDB"); |
|||
console.log("----- sqlite3 db", db); |
|||
sqlite3.close(db); |
|||
} |
|||
return db; |
|||
} |
Loading…
Reference in new issue