radicle/node/db: Model SQLite `synchronous` pragma

The newly introduced enum models the SQLite pragma of the same name.
This commit is contained in:
Yorgos Saslis 2026-02-20 18:08:59 +02:00 committed by Fintan Halpenny
parent d36bf41f25
commit 6cc3da95e6
2 changed files with 31 additions and 0 deletions

View File

@ -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,

View File

@ -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",
})
}
}