Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle/node/db: Model SQLite `synchronous` pragma
Yorgos Saslis committed 2 months ago
commit c0f0f15b73f08cdc33fd00166ac0acd9c686a158
parent 3cbd1fc216f3748f528c9e949a41d552141e2bd8
1 file changed +21 -0
modified crates/radicle/src/node/db.rs
@@ -67,6 +67,19 @@ pub enum JournalMode {
    OFF,
}

+
/// 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,
+
}
+

/// A file-backed database storing information about the network.
#[derive(Clone)]
pub struct Database {
@@ -127,6 +140,14 @@ impl Database {
        Ok(self)
    }

+
    /// Set the `synchronous` pragma.
+
    /// See <https://sqlite.org/pragma.html#pragma_synchronous>.
+
    pub fn synchronous(self, synchronous: 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,