diff --git a/src/database/stores/fs/mod.rs b/src/database/stores/fs/mod.rs index 047cf37..f885e99 100644 --- a/src/database/stores/fs/mod.rs +++ b/src/database/stores/fs/mod.rs @@ -61,6 +61,25 @@ impl Drop for PragmaSynchronousGuard<'_> { } } +#[derive(Debug)] +struct ConnectionOptions; + +impl ConnectionOptions { + pub fn apply(&self, conn: &SqliteConnection) -> diesel::QueryResult<()> { + debug!(r#"Setting "synchronous" to NORMAL"#); + conn.execute("PRAGMA synchronous = NORMAL;")?; + Ok(()) + } +} + +impl diesel::r2d2::CustomizeConnection + for ConnectionOptions +{ + fn on_acquire(&self, conn: &mut SqliteConnection) -> Result<(), diesel::r2d2::Error> { + self.apply(conn).map_err(diesel::r2d2::Error::QueryError) + } +} + pub struct FsStore { path: PathBuf, pool: r2d2::Pool>, @@ -76,7 +95,9 @@ impl FsStore { .to_str() .unwrap(), ); - let pool = r2d2::Pool::builder().build(manager)?; + let pool = r2d2::Pool::builder() + .connection_customizer(Box::new(ConnectionOptions {})) + .build(manager)?; let connection = pool.get()?; // while diesel doesn't support multiple embedded migrations...