use alloc::vec::Vec;
use crate::encoding::Value;
pub type ChangesetUpdatePair<S, B> = (Option<Value<S, B>>, Option<Value<S, B>>);
pub type PatchsetUpdateEntry<S, B> = ((), Option<Value<S, B>>);
#[derive(Debug)]
pub enum ChangesetOp<'a, T, S, B> {
Insert {
table: &'a T,
values: &'a [Value<S, B>],
indirect: bool,
},
Update {
table: &'a T,
values: &'a [ChangesetUpdatePair<S, B>],
indirect: bool,
},
Delete {
table: &'a T,
old_values: &'a [Value<S, B>],
indirect: bool,
},
}
impl<'a, T, S, B> ChangesetOp<'a, T, S, B> {
#[must_use]
pub fn table(&self) -> &'a T {
match self {
Self::Insert { table, .. }
| Self::Update { table, .. }
| Self::Delete { table, .. } => table,
}
}
#[must_use]
pub fn indirect(&self) -> bool {
match self {
Self::Insert { indirect, .. }
| Self::Update { indirect, .. }
| Self::Delete { indirect, .. } => *indirect,
}
}
}
#[derive(Debug)]
pub enum PatchsetOp<'a, T, S, B> {
Insert {
table: &'a T,
values: &'a [Value<S, B>],
indirect: bool,
},
Update {
table: &'a T,
pk: &'a [Value<S, B>],
entries: &'a [PatchsetUpdateEntry<S, B>],
indirect: bool,
},
Delete {
table: &'a T,
pk: &'a [Value<S, B>],
indirect: bool,
},
}
impl<'a, T, S, B> PatchsetOp<'a, T, S, B> {
#[must_use]
pub fn table(&self) -> &'a T {
match self {
Self::Insert { table, .. }
| Self::Update { table, .. }
| Self::Delete { table, .. } => table,
}
}
#[must_use]
pub fn indirect(&self) -> bool {
match self {
Self::Insert { indirect, .. }
| Self::Update { indirect, .. }
| Self::Delete { indirect, .. } => *indirect,
}
}
#[must_use]
pub fn update_new_values(&self) -> Option<Vec<&'a Option<Value<S, B>>>> {
match self {
Self::Update { entries, .. } => Some(entries.iter().map(|((), v)| v).collect()),
_ => None,
}
}
}