Skip to content

Commit

Permalink
opening with OPFS works
Browse files Browse the repository at this point in the history
  • Loading branch information
insipx committed Jul 25, 2024
1 parent f374b7e commit 5c198d0
Show file tree
Hide file tree
Showing 4 changed files with 1,328 additions and 12 deletions.
10 changes: 7 additions & 3 deletions diesel-wasm-sqlite/package.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as WasmSQLiteLibrary from "@xmtp/wa-sqlite";
import { OPFSCoopSyncVFS } from "@xmtp/wa-sqlite/vfs/OPFSCoopSync";
import SQLiteESMFactory from "./node_modules/@xmtp/wa-sqlite/dist/wa-sqlite.mjs";
import base64Wasm from "./node_modules/@xmtp/wa-sqlite/dist/wa-sqlite.wasm";

Expand All @@ -21,7 +22,7 @@ export class SQLite {
if (typeof module === "undefined") {
throw new Error("Cannot be called directly");
}

this.module = module;
this.sqlite3 = WasmSQLiteLibrary.Factory(module);
}

Expand Down Expand Up @@ -65,10 +66,13 @@ export class SQLite {
async open_v2(database_url, iflags) {
try {
console.log("Opening database!", database_url);
const vfs = await OPFSCoopSyncVFS.create(database_url, this.module);
this.sqlite3.vfs_register(vfs, true);
let db = await this.sqlite3.open_v2(database_url, iflags);
return db;
} catch {
console.log("openv2 error");
} catch (error) {
console.log("openv2 error", error);
throw error;
}
}

Expand Down
5 changes: 3 additions & 2 deletions diesel-wasm-sqlite/src/connection/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// use super::{Sqlite, SqliteAggregateFunction};
// use crate::deserialize::FromSqlRow;
// use crate::result::Error::DatabaseError;
use crate::sqlite_types::SqliteOpenFlags;
use crate::{sqlite_types::SqliteOpenFlags, WasmSqliteError};
use diesel::result::*;
use diesel::serialize::ToSql;
use diesel::sql_types::HasSqlType;
Expand Down Expand Up @@ -54,7 +54,8 @@ impl RawConnection {
internal_connection: sqlite3
.open_v2(&database_url, Some(flags.bits() as i32))
.await
.unwrap(),
.map_err(WasmSqliteError::from)
.map_err(ConnectionError::from)?,
})
}

Expand Down
Loading

0 comments on commit 5c198d0

Please sign in to comment.