Standardized the upsert and delete pattern across the repo.
This commit is contained in:
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user