Hello !
Nice project, I would like to use wasm-sqlite to mimic D1 on Deno Deploy or any other V8 "serverless" workers.
I tried to edit your project for a basic test using Deno and localStorage but got the following error:
error: Uncaught (in promise) Error: failed to get next row: database disk image is malformed
throw new Error(err);
^
at SqliteConnection.throwLastError (file:///Users/sqlite-deploy/vfs.ts:217:13)
at async SqliteConnection.queryRaw (file:///Users/sqlite-deploy/vfs.ts:267:7)
at async file:///Users/sqlite-deploy/index.ts:32:20
The code:
import { Sqlite } from "./vfs.ts";
const sqlite = await Sqlite.instantiate({
pageCount(): number {
return self.pageCount;
},
async getPage(ix: number): Promise<Uint8Array> {
const page =
new Uint8Array(JSON.parse(await localStorage.getItem(ix))) ??
new Uint8Array(4096);
return page;
},
async putPage(ix: number, page: Uint8Array): Promise<void> {
await localStorage.setItem(ix, JSON.stringify(Array.from(page)));
self.pageCount = Math.max(self.pageCount, ix + 1);
},
async delPage(ix: number): Promise<void> {
await localStorage.removeItem(ix);
if (ix + 1 >= self.pageCount) {
self.pageCount = ix;
}
},
});
localStorage.clear();
const conn = await sqlite.connect();
const create: T = await conn.queryRaw(`CREATE TABLE td(a INT) STRICT;`);
const insert: T = await conn.queryRaw(`INSERT INTO td VALUES('000123');`);
console.log(create, insert);
And the vfs.ts
diff:
1c1,2
< import * as Asyncify from "https://unpkg.com/asyncify-wasm?module";
---
> import * as Asyncify from "asyncify-wasm";
> import module from "./wasm_sqlite.wasm";
23,24c24
< const { instance } = await Asyncify.instantiateStreaming(
< fetch(new URL("./wasm_sqlite.wasm", import.meta.url)), {
---
> const instance = await Asyncify.instantiate(module, {
Do you have any clue why the database got corrupted ?
Best,