Refactor of the virtual wal API. Drop global wals in favor of passing
the wal implementation as an argument to libsql_open.
The WAL interface is split in two sets of virtual methods:
- `create_wal` is passed when opening a sqlite connection. It's role is
to instantiate a wal.
- `libql_wal` is the wal itself, created by the `create_wal`.
The sqlite3_wal and `sqlite3_create_wal` implementation are completely
decoupled from the wal implementation. They are the default
implementation when using the traditional open methods, and
sqlite3_create_wal is exposed as a global variable, and can be composed
with other wal implementations.
On top of a special VFS, `make wasi` now also compiles-in
a specialized virtual WAL methods module. It doesn't do anything
right now (just falls back to the regular implementation),
but can be used to call back to the host, inject hooks, etc.
It's far from working, but it already properly calls back
from a WebAssembly instance to the host for VFS operations.
We also want the same for virtual WAL and we'll have a solid foundation
for running libSQL in a Wasm runtime.
It is not directly tested or usable yet, and depends on having
wasi-libc library available at /usr/share/wasi-sysroot.
Still, it compiled, so it's a nice start.
`make wasi` produces `libsql.wasm` module.
Future work includes using this module to run a WebAssembly app
in a runtime that supports WASI, using `libsql.wasm` as the database
implementation.
The patch is based on splitting SQLITE_OMIT_WAL into SQLITE_OMIT_SHARED_MEM,
so that we can still compile WAL mode, just without shared memory,
so still usable with exclusive mode or via libSQL's virtual WAL.
The libSQL extensions are moved to the libsql_module struct
with its accompanying libsql_create_module interface.
It's a breaking change, because we were lazy before and just appended
xPreparedSql call right at the end of the sqlite3_module struct
and it diverged upstream :(