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
A foreign key that can be built in a const.
§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 user gave the constraint name (rather than it being generated)
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
Creates a foreign key with no columns; set them with
columns and references.
Sourcepub const fn columns(self, cols: &'static [Cow<'static, str>]) -> Self
pub const fn columns(self, cols: &'static [Cow<'static, str>]) -> Self
Sets the referencing columns.
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
Sets the referenced table and columns.
Sourcepub const fn on_delete(self, action: ReferentialAction) -> Self
pub const fn on_delete(self, action: ReferentialAction) -> Self
Sets the ON DELETE action.
Sourcepub const fn on_update(self, action: ReferentialAction) -> Self
pub const fn on_update(self, action: ReferentialAction) -> Self
Sets the ON UPDATE action.
Sourcepub const fn explicit_name(self) -> Self
pub const fn explicit_name(self) -> Self
Marks the name as given by the user.
Sourcepub const fn into_foreign_key(self) -> ForeignKey
pub const fn into_foreign_key(self) -> ForeignKey
Converts to the runtime ForeignKey.
Trait Implementations§
Source§impl Clone for ForeignKeyDef
impl Clone for ForeignKeyDef
impl Copy for ForeignKeyDef
Source§impl Debug for ForeignKeyDef
impl Debug for ForeignKeyDef
Source§impl Default for ForeignKeyDef
impl Default for ForeignKeyDef
impl Eq 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 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 UnsafeUnpin 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