pub struct ForeignKeyConstraint { /* private fields */ }Expand description
Foreign key constraint for validating referential integrity between tables.
This constraint ensures that all non-null values in a child table’s foreign key column exist as values in the parent table’s referenced column. It’s essential for maintaining data consistency and preventing orphaned records.
The constraint supports:
- Inner and left joins for different validation strategies
- Null value handling (allow/disallow nulls in foreign key)
- Custom error messages and violation reporting
- Performance optimization through predicate pushdown
Implementations§
Source§impl ForeignKeyConstraint
impl ForeignKeyConstraint
Sourcepub fn new(
child_column: impl Into<String>,
parent_column: impl Into<String>,
) -> Self
pub fn new( child_column: impl Into<String>, parent_column: impl Into<String>, ) -> Self
Create a new foreign key constraint.
§Arguments
child_column- Column in child table containing foreign key valuesparent_column- Column in parent table containing referenced values
§Examples
use term_guard::constraints::ForeignKeyConstraint;
let fk = ForeignKeyConstraint::new("orders.customer_id", "customers.id");Sourcepub fn allow_nulls(self, allow: bool) -> Self
pub fn allow_nulls(self, allow: bool) -> Self
Set whether to allow NULL values in the foreign key column.
When true, NULL values in the child column are considered valid.
When false, NULL values are treated as constraint violations.
Sourcepub fn use_left_join(self, use_left_join: bool) -> Self
pub fn use_left_join(self, use_left_join: bool) -> Self
Set the join strategy for validation.
true(default): Use LEFT JOIN strategy, better for tables with few violationsfalse: Use NOT EXISTS strategy, better for tables with many violations
Sourcepub fn max_violations_reported(self, max_violations: usize) -> Self
pub fn max_violations_reported(self, max_violations: usize) -> Self
Set the maximum number of violation examples to report.
Defaults to 100. Set to 0 to disable violation example collection.
Sourcepub fn child_column(&self) -> &str
pub fn child_column(&self) -> &str
Get the child column name
Sourcepub fn parent_column(&self) -> &str
pub fn parent_column(&self) -> &str
Get the parent column name
Trait Implementations§
Source§impl Clone for ForeignKeyConstraint
impl Clone for ForeignKeyConstraint
Source§fn clone(&self) -> ForeignKeyConstraint
fn clone(&self) -> ForeignKeyConstraint
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Constraint for ForeignKeyConstraint
impl Constraint for ForeignKeyConstraint
Source§fn evaluate<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SessionContext,
) -> Pin<Box<dyn Future<Output = Result<ConstraintResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn evaluate<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 SessionContext,
) -> Pin<Box<dyn Future<Output = Result<ConstraintResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn column(&self) -> Option<&str>
fn column(&self) -> Option<&str>
Source§fn description(&self) -> Option<&str>
fn description(&self) -> Option<&str>
Source§fn metadata(&self) -> ConstraintMetadata
fn metadata(&self) -> ConstraintMetadata
Source§impl Debug for ForeignKeyConstraint
impl Debug for ForeignKeyConstraint
Source§impl<'de> Deserialize<'de> for ForeignKeyConstraint
impl<'de> Deserialize<'de> for ForeignKeyConstraint
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ForeignKeyConstraint
impl RefUnwindSafe for ForeignKeyConstraint
impl Send for ForeignKeyConstraint
impl Sync for ForeignKeyConstraint
impl Unpin for ForeignKeyConstraint
impl UnwindSafe for ForeignKeyConstraint
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more