coven_database/
object_removals.rs1use crate::{sqlite::DatabaseConnection, DbError};
7
8#[derive(Clone, Debug, PartialEq, Eq)]
10pub struct ObjectRemoval {
11 pub path: String,
13 pub after: u64,
15}
16
17pub(crate) fn record(db: &DatabaseConnection, removal: &ObjectRemoval) -> Result<(), DbError> {
18 let after = i64::try_from(removal.after)
19 .map_err(|_overflow| DbError::Invariant { what: "an object's removal time fits i64" })?;
20 db.internal_execute(
21 "INSERT INTO _coven_object_removals(path,after) VALUES(?1,?2)
22 ON CONFLICT(path) DO UPDATE SET after=max(after,excluded.after)",
23 (&removal.path, after),
24 )?;
25 Ok(())
26}
27
28pub(crate) fn removed(db: &DatabaseConnection, path: &str) -> Result<(), DbError> {
30 db.internal_execute("DELETE FROM _coven_object_removals WHERE path=?1", [path])?;
31 Ok(())
32}
33
34#[cfg(test)]
35#[path = "object_removals_tests.rs"]
36pub(crate) mod tests;