sqlite_graphrag/
pragmas.rs1use crate::errors::AppError;
4use rusqlite::Connection;
5
6pub fn apply_init_pragmas(conn: &Connection) -> Result<(), AppError> {
14 conn.execute_batch("PRAGMA auto_vacuum = INCREMENTAL;")?;
15 apply_connection_pragmas(conn)?;
16 conn.execute_batch(&format!(
17 "PRAGMA wal_autocheckpoint = {};",
18 crate::constants::WAL_AUTOCHECKPOINT_PAGES
19 ))?;
20 Ok(())
21}
22
23pub fn ensure_wal_mode(conn: &Connection) -> Result<(), AppError> {
28 let mode: String = conn.query_row("PRAGMA journal_mode = WAL;", [], |r| r.get(0))?;
29 if mode != "wal" {
30 tracing::warn!(mode = %mode, "journal_mode did not switch to WAL after re-assertion");
31 }
32 Ok(())
33}
34
35pub fn apply_connection_pragmas(conn: &Connection) -> Result<(), AppError> {
42 conn.execute_batch(&format!(
43 "PRAGMA synchronous = NORMAL;
44 PRAGMA foreign_keys = ON;
45 PRAGMA busy_timeout = {busy};
46 PRAGMA cache_size = {cache};
47 PRAGMA temp_store = MEMORY;
48 PRAGMA mmap_size = {mmap};",
49 busy = crate::constants::BUSY_TIMEOUT_MILLIS,
50 cache = crate::constants::CACHE_SIZE_KB,
51 mmap = crate::constants::MMAP_SIZE_BYTES,
52 ))?;
53 let mode: String = conn.query_row("PRAGMA journal_mode = WAL;", [], |r| r.get(0))?;
54 if mode != "wal" {
55 tracing::warn!(mode = %mode, "journal_mode did not switch to WAL");
56 }
57 Ok(())
58}