Compare commits
2 Commits
master
...
sql-wa-sql
Author | SHA1 | Date |
---|---|---|
|
1d7bc5f728 | 3 months ago |
|
753d178fc3 | 3 months ago |
4 changed files with 37 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; |
|||
} |
@ -0,0 +1,5 @@ |
|||
declare module "wa-sqlite/src/examples/IDBBatchAtomicVFS.js" { |
|||
export const create: { |
|||
new (name: string, module: any, options?: { lockPolicy?: string }): any; |
|||
}; |
|||
} |
Loading…
Reference in new issue