pub struct ForeignKey {
pub table: Cow<'static, str>,
pub name: Cow<'static, str>,
pub columns: Cow<'static, [Cow<'static, str>]>,
pub table_to: Cow<'static, str>,
pub columns_to: Cow<'static, [Cow<'static, str>]>,
pub on_delete: Option<Cow<'static, str>>,
pub on_update: Option<Cow<'static, str>>,
pub name_explicit: bool,
}Expand description
Runtime foreign key constraint entity
Uses Cow<'static, str> for all string fields, which works with both:
- Borrowed data from const definitions (
Cow::Borrowed) - Owned data from deserialization/introspection (
Cow::Owned)
Fields§
§table: Cow<'static, str>Parent table name
name: Cow<'static, str>Constraint name
columns: Cow<'static, [Cow<'static, str>]>Source columns
table_to: Cow<'static, str>Referenced table name
columns_to: Cow<'static, [Cow<'static, str>]>Referenced columns
on_delete: Option<Cow<'static, str>>ON DELETE action (as SQL string)
on_update: Option<Cow<'static, str>>ON UPDATE action (as SQL string)
name_explicit: boolWhether the constraint name was explicitly specified
Implementations§
Source§impl ForeignKey
impl ForeignKey
Sourcepub fn new(
table: impl Into<Cow<'static, str>>,
name: impl Into<Cow<'static, str>>,
columns: impl Into<Cow<'static, [Cow<'static, str>]>>,
table_to: impl Into<Cow<'static, str>>,
columns_to: impl Into<Cow<'static, [Cow<'static, str>]>>,
) -> Self
pub fn new( table: impl Into<Cow<'static, str>>, name: impl Into<Cow<'static, str>>, columns: impl Into<Cow<'static, [Cow<'static, str>]>>, table_to: impl Into<Cow<'static, str>>, columns_to: impl Into<Cow<'static, [Cow<'static, str>]>>, ) -> Self
Create a new foreign key
Sourcepub fn from_strings(
table: String,
name: String,
columns: Vec<String>,
table_to: String,
columns_to: Vec<String>,
) -> ForeignKey
pub fn from_strings( table: String, name: String, columns: Vec<String>, table_to: String, columns_to: Vec<String>, ) -> ForeignKey
Create a new foreign key from owned strings (convenience for runtime construction)
Source§impl ForeignKey
impl ForeignKey
Sourcepub fn to_constraint_sql(&self) -> String
pub fn to_constraint_sql(&self) -> String
Generate the CONSTRAINT … FOREIGN KEY clause SQL
Sourcepub fn add_fk_sql(&self) -> String
pub fn add_fk_sql(&self) -> String
Generate ADD FOREIGN KEY SQL (via new table constraint)
Sourcepub fn drop_fk_sql(&self) -> String
pub fn drop_fk_sql(&self) -> String
Generate DROP FOREIGN KEY SQL (comment since SQLite doesn’t support it)
Trait Implementations§
Source§impl Clone for ForeignKey
impl Clone for ForeignKey
Source§fn clone(&self) -> ForeignKey
fn clone(&self) -> ForeignKey
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ForeignKey
impl Debug for ForeignKey
Source§impl Default for ForeignKey
impl Default for ForeignKey
Source§impl From<ForeignKeyDef> for ForeignKey
impl From<ForeignKeyDef> for ForeignKey
Source§fn from(def: ForeignKeyDef) -> Self
fn from(def: ForeignKeyDef) -> Self
Converts to this type from the input type.
Source§impl PartialEq for ForeignKey
impl PartialEq for ForeignKey
impl Eq for ForeignKey
impl StructuralPartialEq for ForeignKey
Auto Trait Implementations§
impl Freeze for ForeignKey
impl RefUnwindSafe for ForeignKey
impl Send for ForeignKey
impl Sync for ForeignKey
impl Unpin for ForeignKey
impl UnwindSafe for ForeignKey
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