Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
radicle/node/db: Model SQLite `synchronous` pragma
Yorgos Saslis committed 1 month ago
commit 6cc3da95e6bee6bae062da2af8ebdffd71aa183b
parent d36bf41
2 files changed +31 -0
modified 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, Error> {
+
        self.db
+
            .execute(format!("PRAGMA synchronous = {synchronous};"))?;
+
        Ok(self)
+
    }
+

    /// Initialize by adding our local node to the database.
    pub fn init<'a>(
        mut self,
modified 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
+
/// <https://sqlite.org/pragma.html#pragma_synchronous>.
+
#[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",
+
        })
+
    }
+
}