agent_orchestrator/persistence/
sqlite.rs1use anyhow::{Context, Result};
2use rusqlite::Connection;
3use std::path::Path;
4use std::time::Duration;
5
6pub const SQLITE_BUSY_TIMEOUT_MS: u64 = 5000;
8
9pub fn open_conn(db_path: &Path) -> Result<Connection> {
11 let conn = Connection::open(db_path).context("failed to open sqlite db")?;
12 configure_conn(&conn)?;
13 Ok(conn)
14}
15
16pub fn configure_conn(conn: &Connection) -> Result<()> {
18 conn.busy_timeout(Duration::from_millis(SQLITE_BUSY_TIMEOUT_MS))
19 .context("failed to set sqlite busy timeout")?;
20 conn.execute_batch(
21 r#"
22 PRAGMA foreign_keys = ON;
23 "#,
24 )
25 .context("failed to configure sqlite pragmas")?;
26 Ok(())
27}