Skip to main content

Crate day_sqlite_worker

Crate day_sqlite_worker 

Source
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 len bytes for the worker page to write a request into (consumed by day_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_memory works in any instance (no file I/O at all); open_opfs routes through the day-opfs VFS and is the worker’s shape. A statement-trace sink (Connection::trace_stmt).