#[derive(Clone, Copy, PartialEq, Eq, Default)]
pub(super) enum UpdateStrategy {
#[default]
Replace,
Append,
Upsert,
Diff,
}
#[derive(Clone)]
pub(super) struct HasManyUpdate {
pub(super) child_type: syn::Path,
pub(super) field: String,
pub(super) fk_column: String,
pub(super) fk_field: String,
pub(super) strategy: UpdateStrategy,
pub(super) key_columns: Option<Vec<String>>,
}
#[derive(Clone)]
pub(super) struct HasOneUpdate {
pub(super) child_type: syn::Path,
pub(super) field: String,
pub(super) fk_column: String,
pub(super) fk_field: String,
pub(super) strategy: UpdateStrategy,
}
#[derive(Clone, Default)]
pub(super) struct UpdateGraphDeclarations {
pub(super) has_many: Vec<HasManyUpdate>,
pub(super) has_one: Vec<HasOneUpdate>,
}
impl UpdateGraphDeclarations {
pub(super) fn has_any(&self) -> bool {
!self.has_many.is_empty() || !self.has_one.is_empty()
}
pub(super) fn graph_field_names(&self) -> Vec<String> {
let mut names = Vec::new();
for rel in &self.has_many {
names.push(rel.field.clone());
}
for rel in &self.has_one {
names.push(rel.field.clone());
}
names
}
}