INNER CODE UNIT · Rust

open_connection

aannoo/hcom · src/db/mod.rs:126

    fn open_connection(db_path: &std::path::Path) -> Result<Connection> {
        crate::paths::ensure_private_db(db_path)
            .with_context(|| format!("Failed to secure database: {}", db_path.display()))?;

        let conn = Connection::open(db_path)
            .with_context(|| format!("Failed to open database: {}", db_path.display()))?;
        // busy_timeout first: converting a fresh db to WAL takes a brief
        // exclusive lock, so with a 0 timeout a concurrent first-open (or heavy
        // load) fails instantly with SQLITE_BUSY. Setting the timeout up front
        // makes the WAL conversion retry instead.
        conn.execute_batch(
            "PRAGMA busy_timeout=5000; PRAGMA foreign_keys=ON; PRAGMA journal_mode=WAL;",
        )?;

        Ok(conn)
    }

    /// Access the underlying SQLite connection (for direct queries).

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…