Standardized the upsert and delete pattern across the repo.

This commit is contained in:
2026-10-09 15:09:04 +02:00
parent 4a84c8330a
commit 66984567f8
30 changed files with 776 additions and 386 deletions
+4 -23
View File
@@ -1,25 +1,11 @@
pub enum Upsert<T> {
Created(T),
Updated(T),
}
impl<T> Upsert<T> {
pub fn try_map<U, E>(self, f: impl FnOnce(T) -> Result<U, E>) -> Result<Upsert<U>, E> {
Ok(match self {
Self::Created(value) => Upsert::Created(f(value)?),
Self::Updated(value) => Upsert::Updated(f(value)?),
})
}
}
pub struct Upserted<T> {
pub struct Upsert<T> {
pub current: T,
pub previous: Option<T>,
}
impl<T> Upserted<T> {
pub fn try_map<U, E>(self, mut f: impl FnMut(T) -> Result<U, E>) -> Result<Upserted<U>, E> {
Ok(Upserted {
impl<T> Upsert<T> {
pub fn try_map<U, E>(self, mut f: impl FnMut(T) -> Result<U, E>) -> Result<Upsert<U>, E> {
Ok(Upsert {
current: f(self.current)?,
previous: match self.previous {
Some(value) => Some(f(value)?),
@@ -28,8 +14,3 @@ impl<T> Upserted<T> {
})
}
}
pub enum Delete {
Deleted,
NotFound,
}