@rkusa/wasm-sqlite
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

wasm-sqlite

SQLite compiled to WASM with pluggable data storage. Useful to save SQLite in e.g. Cloudflare Durable Objects (example: https://github.com/rkusa/do-sqlite).

Status: This is very experimental. Don't use it for real applications yet! See the conclusion of my blog post for reasons for why not to use it.

npm install -S @rkusa/wasm-sqlite

Example

const sqlite = await Sqlite.instantiate({
  pageCount(): number {
    return self.pageCount;
  },

  async getPage(ix: number): Promise<Uint8Array> {
    return (await storage.get(ix)) ?? new Uint8Array(4096);
  },

  async putPage(ix: number, page: Uint8Array): Promise<void> {
    await storage.put(ix, page);
  },

  async delPage(ix: number): Promise<void> {
    await storage.delete(ix);
    if (ix + 1 >= self.pageCount) {
      self.pageCount = ix;
    }
  },
});

const conn = await this.sqlite.connect();
await conn.execute("...", []);
const query: T = await conn.query("...", []);

Build

Execute the following once:

brew install cmake ninja binaryen
./build-wasi-sdk.sh

After that, build it via:

npm run build

Readme

Keywords

Package Sidebar

Install

npm i @rkusa/wasm-sqlite

Weekly Downloads

0

Version

0.1.1

License

MIT OR Apache-2.0

Unpacked Size

4.01 MB

Total Files

7

Last publish

Collaborators

  • rkusa