pub struct RelationshipValidator;Expand description
Relationship validator
Implementations§
Source§impl RelationshipValidator
impl RelationshipValidator
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new relationship validator
§Example
use data_modelling_core::validation::relationships::RelationshipValidator;
let validator = RelationshipValidator::new();Sourcepub fn check_circular_dependency(
&self,
relationships: &[Relationship],
source_table_id: Uuid,
target_table_id: Uuid,
) -> Result<(bool, Option<Vec<Uuid>>), RelationshipValidationError>
pub fn check_circular_dependency( &self, relationships: &[Relationship], source_table_id: Uuid, target_table_id: Uuid, ) -> Result<(bool, Option<Vec<Uuid>>), RelationshipValidationError>
Check for circular dependencies using graph cycle detection
Uses petgraph to detect cycles in the relationship graph. If adding the new relationship would create a cycle, returns the cycle path.
§Arguments
relationships- Existing relationships in the modelsource_table_id- Source table ID of the new relationshiptarget_table_id- Target table ID of the new relationship
§Returns
A tuple of (has_cycle: bool, cycle_path: Option<Vec
§Example
use data_modelling_core::validation::relationships::RelationshipValidator;
use data_modelling_core::models::Relationship;
let validator = RelationshipValidator::new();
let table_a = uuid::Uuid::new_v4();
let table_b = uuid::Uuid::new_v4();
let table_c = uuid::Uuid::new_v4();
// Create a cycle: A -> B -> C -> A
let rels = vec![
Relationship::new(table_a, table_b),
Relationship::new(table_b, table_c),
];
let (has_cycle, _) = validator.check_circular_dependency(&rels, table_c, table_a).unwrap();
assert!(has_cycle);Sourcepub fn validate_no_self_reference(
&self,
source_table_id: Uuid,
target_table_id: Uuid,
) -> Result<(), SelfReference>
pub fn validate_no_self_reference( &self, source_table_id: Uuid, target_table_id: Uuid, ) -> Result<(), SelfReference>
Validate that source and target tables are different
Trait Implementations§
Source§impl Default for RelationshipValidator
impl Default for RelationshipValidator
Source§fn default() -> RelationshipValidator
fn default() -> RelationshipValidator
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for RelationshipValidator
impl RefUnwindSafe for RelationshipValidator
impl Send for RelationshipValidator
impl Sync for RelationshipValidator
impl Unpin for RelationshipValidator
impl UnwindSafe for RelationshipValidator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more