#[derive(Clone)]
pub(super) struct HasRelation {
pub(super) child_type: syn::Path,
pub(super) field: String,
pub(super) fk_field: String,
pub(super) is_many: bool,
pub(super) mode: HasRelationMode,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub(super) enum HasRelationMode {
#[default]
Insert,
Upsert,
}
#[derive(Clone)]
pub(super) struct BelongsTo {
pub(super) parent_type: syn::Path,
pub(super) field: String,
pub(super) set_fk_field: String,
pub(super) mode: BelongsToMode,
pub(super) required: bool,
}
#[derive(Clone)]
pub(super) struct InsertStep {
pub(super) step_type: syn::Path,
pub(super) field: String,
pub(super) mode: StepMode,
pub(super) is_before: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub(super) enum BelongsToMode {
#[default]
InsertReturning,
UpsertReturning,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub(super) enum StepMode {
#[default]
Insert,
Upsert,
}
#[derive(Clone, Default)]
pub(super) struct GraphDeclarations {
pub(super) graph_root_id_field: Option<String>,
pub(super) has_relations: Vec<HasRelation>,
pub(super) belongs_to: Vec<BelongsTo>,
pub(super) insert_steps: Vec<InsertStep>,
}
impl GraphDeclarations {
pub(super) fn has_any(&self) -> bool {
!self.has_relations.is_empty()
|| !self.belongs_to.is_empty()
|| !self.insert_steps.is_empty()
}
pub(super) fn graph_field_names(&self) -> Vec<String> {
let mut names = Vec::new();
for rel in &self.has_relations {
names.push(rel.field.clone());
}
for bt in &self.belongs_to {
names.push(bt.field.clone());
}
for step in &self.insert_steps {
names.push(step.field.clone());
}
names
}
}