diff --git a/package.json b/package.json index b73c0967..aaa59ef2 100644 --- a/package.json +++ b/package.json @@ -123,6 +123,7 @@ "vue-picture-cropper": "^0.7.0", "vue-qrcode-reader": "^5.5.3", "vue-router": "^4.5.0", + "wa-sqlite": "github:rhashimoto/wa-sqlite", "web-did-resolver": "^2.0.27", "zod": "^3.24.2" }, diff --git a/src/db-sql/index.ts b/src/db-sql/index.ts new file mode 100644 index 00000000..18bbea26 --- /dev/null +++ b/src/db-sql/index.ts @@ -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; +} diff --git a/src/views/AccountViewView.vue b/src/views/AccountViewView.vue index 4dc68149..d626ea1c 100644 --- a/src/views/AccountViewView.vue +++ b/src/views/AccountViewView.vue @@ -996,6 +996,7 @@ import { retrieveSettingsForActiveAccount, updateAccountSettings, } from "../db/index"; +import { sql } from "../db-sql/index"; import { Account } from "../db/tables/accounts"; import { Contact } from "../db/tables/contacts"; import { @@ -1202,6 +1203,8 @@ export default class AccountViewView extends Vue { ); } this.passkeyExpirationDescription = tokenExpiryTimeDescription(); + const db = await sql(); + console.log("----- db", db); } beforeUnmount() {