Expand description
The SQLite engine behind day-persistence on web-dom (docs/persistence.md).
The vendored amalgamation compiles with no libc and no wasm-bindgen: vendor/shim renames
every libc symbol it needs onto the freestanding C subset compiled beside it, and the
handful of Rust-side shims in this file (allocator, UTC localtime, entropy, abort). The
only imports the wasm module gains are day_sql_*: time, entropy and a log line, the
three channel calls, and, for the worker instance, the ten day_sql_fs_* OPFS primitives.
The browser half ships with the crate, so nothing in the Day host page knows about SQL.
[package.metadata.day.web] (docs/web.md) declares web/day-sql.js, a web module the
page imports before it instantiates the app: it supplies those imports and boots
web/day-sql-worker.js beside it. The module instantiates in Day’s raw-wasm pipeline.
One wasm, two instantiations. The app instance may use Connection::open_memory
in-process (:memory: engines never touch a file) and reaches file databases through
channel. The worker instance services the SharedArrayBuffer channel: the worker
page copies each request into wasm memory and calls day_sql_exec, which runs it
against real OPFS files through the day-opfs VFS and returns the reply bytes. The
protocol module is the wire format both sides share.
Everything (VFS, connection layer, worker loop) compiles and unit-tests on native hosts against an in-memory OPFS fake; only the browser glue is wasm-specific.
The C tree under vendor/ and the shim recipe come from sqlite-wasm-rs (MIT, see
vendor/LICENSE); SQLite itself is public domain.
Modules§
- protocol
- The statement protocol the main thread speaks to the SQL worker (docs/persistence.md). Both sides link this module (the day-persistence proxy driver encodes requests and decodes replies; the worker loop does the reverse), so the wire format cannot drift. Everything is little-endian, length-prefixed, and version-tagged; the JS shuttle between them moves opaque bytes and never parses them (oversized replies are chunked JS-side, invisible here).
Structs§
- Connection
- SqlError
- An engine failure: SQLite’s result code and its message.
- Tm
- musl’s
struct tm(what<time.h>in the vendored headers declares).
Functions§
- day_
sql_ alloc - Allocate
lenbytes for the worker page to write a request into (consumed byday_sql_exec). - day_
sql_ ⚠exec - Safety
- handle_
request - Service one request: the worker loop’s whole body, and the entry point the native tests drive.
- rust_
sqlite_ ⚠wasm_ abort - Safety
- rust_
sqlite_ ⚠wasm_ assert_ fail - Safety
- rust_
sqlite_ ⚠wasm_ calloc - Safety
- rust_
sqlite_ ⚠wasm_ free - Safety
- rust_
sqlite_ ⚠wasm_ getentropy - Safety
- rust_
sqlite_ ⚠wasm_ localtime - Safety
- rust_
sqlite_ ⚠wasm_ malloc - Safety
- rust_
sqlite_ ⚠wasm_ realloc - Safety
- sqlite3_
os_ ⚠end - Safety
- sqlite3_
os_ ⚠init - Safety
Type Aliases§
- TraceFn
- One open database.
open_memoryworks in any instance (no file I/O at all);open_opfsroutes through the day-opfs VFS and is the worker’s shape. A statement-trace sink (Connection::trace_stmt).