Expand description
std.sql — SQLite (rusqlite WAL) bridge for Lua scripts.
Provides:
std.sql.query(sql, params?) -> rowsrows = array of { col_name = value, … }std.sql.exec(sql, params?) -> { affected = N, last_id = M }std.sql.null— sentinel for SQL NULL on the Lua side
rusqlite calls are executed inside tokio::task::spawn_blocking to avoid
blocking the async runtime. Lock acquisition is also inside spawn_blocking
to prevent holding a Mutex guard across .await (await-holding-lock).
§Wiring contract
The host owns the rusqlite::Connection (file path / busy_timeout /
journal_mode are host-side concerns, not this crate’s) and its
rusqlite::InterruptHandle. Pass them to register /
register_with wrapped in Arc<Mutex<_>> / Arc<_>. This crate
does not open the database, does not read environment variables, and
does not attempt to recover from a corrupt connection.
Which rusqlite those types come from is decided by this crate’s
dependency — see crate::rusqlite to name it without a second
dependency that could drift onto another libsqlite3-sys cluster.
§Cancellation integration
Every query/exec races against the enclosing task.scope /
task.with_timeout’s
CancelToken via
mlua_batteries::task::effective_token. When the token fires we call
sqlite3_interrupt so the blocking thread returns quickly and the
Mutex guard is released.
Structs§
- SqlConfig
- Runtime configuration for the SQL/KV bridges.
Functions§
- register
- Register
std.sqlwith defaultSqlConfig. - register_
with - Register
std.sqlwith caller-providedSqlConfig.