Skip to main content

agent_block_core/bridge/
sql.rs

1//! `std.sql` thin adapter.
2//!
3//! Bridge implementation moved to the `mlua-batteries` crate
4//! (`mlua_batteries::sql`).  This module only resolves the host's
5//! environment-driven SQL configuration into a
6//! [`mlua_batteries::sql::SqlConfig`] before delegating to
7//! [`mlua_batteries::sql::register_with`], then layers the agent-block
8//! Lua tool helpers (`sql_tools.lua`) on top.
9//!
10//! See `bridge/config.rs` for the ENV → config mapping.
11
12use std::sync::Arc;
13
14use mlua::prelude::*;
15use mlua_batteries::sql::SqlConfig;
16
17use crate::host::HostContext;
18
19pub fn register(lua: &Lua, ctx: &HostContext) -> LuaResult<()> {
20    let cfg = SqlConfig {
21        query_timeout: super::config::sql_query_timeout(),
22    };
23    mlua_batteries::sql::register_with(
24        lua,
25        Arc::clone(&ctx.sql_conn),
26        Arc::clone(&ctx.sql_interrupt),
27        cfg,
28    )?;
29
30    // Load std.sql.register_tools (LLM-facing helper; requires `tool` global).
31    lua.load(include_str!("sql_tools.lua"))
32        .set_name("std.sql.register_tools")
33        .exec()?;
34
35    Ok(())
36}