[Pas2js] pas2js WebAssembly SQLite demos

Pierce Ng pierce at samadhiweb.com
Fri Feb 20 01:43:37 CET 2026


Hi all,

I've put up two demos of using WebAssembly SQLite from pas2js.

- https://samadhiweb.com/demo/demo1.html
- https://samadhiweb.com/demo/demo2.html

Demo 1 loads and runs WebAssembly SQLite in the browser's main UI thread
and stores data in the browser local storage. Demo 2 runs in a worker
thread and stores data in the browser's OPFS.

One quirk I encountered in demo 2 is that I've had to initialize SQLite
like this:

  asm
    importScripts('/dist/sqlite3.js');
  end;
  await(sqlite3InitModule._then(function(sqlite3: JSValue): JSValue
    begin
      asm
        self.sqlite3 = sqlite3
      end;
    end, Nil));

I tried the below initially, but I got self.sqlite3 not defined later in
the code, so looks like self in the _then function is different from the
self outside of it. I also tried globalThis instead of self, same
unsuccessful outcome.

  asm
    importScripts('/dist/sqlite3.js');
    globalThis.sqlite3InitModule().then(function(sqlite3){
      self.sqlite3 = sqlite3
    });
  end;

I noticed that there is an importScripts procedure declared in Pascal,
but didn't figure out how to use it.

I'll publish my demos as a code repo somewhere somewhen. Meanwhile,
thanks to Javascript source maps, all Pascal code is accessible in the
browser debugger.

Next demo, unlikely any time soon, will probably be importing an
existing SQLite database into the browser.

Pierce


More information about the Pas2js mailing list