pub struct ForeignKeyDef {
pub table: &'static str,
pub name: &'static str,
pub columns: &'static [Cow<'static, str>],
pub table_to: &'static str,
pub columns_to: &'static [Cow<'static, str>],
pub on_delete: Option<ReferentialAction>,
pub on_update: Option<ReferentialAction>,
pub name_explicit: bool,
}Expand description
Const-friendly foreign key definition
§Examples
use drizzle_types::sqlite::ddl::{ForeignKeyDef, ReferentialAction};
use std::borrow::Cow;
const COLS: &[Cow<'static, str>] = &[Cow::Borrowed("user_id")];
const REFS: &[Cow<'static, str>] = &[Cow::Borrowed("id")];
const FK: ForeignKeyDef = ForeignKeyDef::new("posts", "fk_posts_user")
.columns(COLS)
.references("users", REFS)
.on_delete(ReferentialAction::Cascade);Fields§
§table: &'static strParent table name
name: &'static strConstraint name
columns: &'static [Cow<'static, str>]Source columns
table_to: &'static strReferenced table name
columns_to: &'static [Cow<'static, str>]Referenced columns
on_delete: Option<ReferentialAction>ON DELETE action
on_update: Option<ReferentialAction>ON UPDATE action
name_explicit: boolWhether the constraint name was explicitly specified
Implementations§
Source§impl ForeignKeyDef
impl ForeignKeyDef
Sourcepub const fn new(table: &'static str, name: &'static str) -> Self
pub const fn new(table: &'static str, name: &'static str) -> Self
Create a new foreign key definition
Sourcepub const fn references(
self,
table: &'static str,
columns: &'static [Cow<'static, str>],
) -> Self
pub const fn references( self, table: &'static str, columns: &'static [Cow<'static, str>], ) -> Self
Set reference table and columns
Sourcepub const fn on_delete(self, action: ReferentialAction) -> Self
pub const fn on_delete(self, action: ReferentialAction) -> Self
Set ON DELETE action
Sourcepub const fn on_update(self, action: ReferentialAction) -> Self
pub const fn on_update(self, action: ReferentialAction) -> Self
Set ON UPDATE action
Sourcepub const fn explicit_name(self) -> Self
pub const fn explicit_name(self) -> Self
Mark the name as explicitly specified
Sourcepub const fn into_foreign_key(self) -> ForeignKey
pub const fn into_foreign_key(self) -> ForeignKey
Convert to runtime ForeignKey type
Trait Implementations§
Source§impl Clone for ForeignKeyDef
impl Clone for ForeignKeyDef
Source§fn clone(&self) -> ForeignKeyDef
fn clone(&self) -> ForeignKeyDef
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 ForeignKeyDef
impl Debug for ForeignKeyDef
Source§impl Default for ForeignKeyDef
impl Default for ForeignKeyDef
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 Hash for ForeignKeyDef
impl Hash for ForeignKeyDef
Source§impl PartialEq for ForeignKeyDef
impl PartialEq for ForeignKeyDef
impl Copy for ForeignKeyDef
impl Eq for ForeignKeyDef
impl StructuralPartialEq for ForeignKeyDef
Auto Trait Implementations§
impl Freeze for ForeignKeyDef
impl RefUnwindSafe for ForeignKeyDef
impl Send for ForeignKeyDef
impl Sync for ForeignKeyDef
impl Unpin for ForeignKeyDef
impl UnwindSafe for ForeignKeyDef
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