diff --git a/src/database/mod.rs b/src/database/mod.rs index 193c86c..9084527 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -205,6 +205,7 @@ pub fn insert_entry>( #[derive(Debug)] pub struct ConnectionOptions { pub enable_foreign_keys: bool, + pub enable_wal_mode: bool, pub busy_timeout: Option, } @@ -213,6 +214,13 @@ impl ConnectionOptions { if self.enable_foreign_keys { conn.execute("PRAGMA foreign_keys = ON;")?; } + + conn.execute(if self.enable_wal_mode { + "PRAGMA journal_mode = WAL;" + } else { + "PRAGMA journal_mode = TRUNCATE;" + })?; + if let Some(duration) = self.busy_timeout { conn.execute(&format!("PRAGMA busy_timeout = {};", duration.as_millis()))?; } @@ -255,6 +263,7 @@ pub fn open_upend>( let pool = r2d2::Pool::builder() .connection_customizer(Box::new(ConnectionOptions { enable_foreign_keys: true, + enable_wal_mode: true, busy_timeout: Some(Duration::from_secs(30)), })) .build(manager)?;