pub async fn with_connection<T, F>(
db_path: Option<String>,
f: F,
) -> Result<T, ToolError>Expand description
Executes a closure with a database connection in a blocking task.
This helper abstracts the common pattern of:
- Spawning a blocking task for SQLite operations
- Acquiring a connection from the manager
- Locking the connection mutex
- Mapping errors to ToolError
§Example
ⓘ
let tables = with_connection(input.db_path, |conn| {
let mut stmt = conn.prepare("SELECT name FROM sqlite_master")?;
// ... use the connection
Ok(result)
}).await?;