diff --git a/crates/radicle/src/node/db.rs b/crates/radicle/src/node/db.rs index 084e4c83..8b2a2c02 100644 --- a/crates/radicle/src/node/db.rs +++ b/crates/radicle/src/node/db.rs @@ -110,6 +110,13 @@ impl Database { Ok(self) } + /// Set the `synchronous` pragma. + pub fn synchronous(self, synchronous: sqlite_ext::Synchronous) -> Result { + self.db + .execute(format!("PRAGMA synchronous = {synchronous};"))?; + Ok(self) + } + /// Initialize by adding our local node to the database. pub fn init<'a>( mut self, diff --git a/crates/radicle/src/node/db/sqlite_ext.rs b/crates/radicle/src/node/db/sqlite_ext.rs index e8b955f4..e0f4f457 100644 --- a/crates/radicle/src/node/db/sqlite_ext.rs +++ b/crates/radicle/src/node/db/sqlite_ext.rs @@ -30,3 +30,27 @@ impl std::fmt::Display for JournalMode { }) } } + +/// Value for a `synchronous` pragma statement. +/// For a description of all variants please refer to +/// . +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +pub enum Synchronous { + EXTRA = 3, + #[default] + FULL = 2, + NORMAL = 1, + OFF = 0, +} + +impl std::fmt::Display for Synchronous { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(match self { + Self::EXTRA => "EXTRA", + Self::FULL => "FULL", + Self::NORMAL => "NORMAL", + Self::OFF => "OFF", + }) + } +}