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
A foreign key, as stored in migration snapshots.
Actions are stored as SQL keywords ("CASCADE", …); None means not
written.
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 user gave the constraint name (rather than it being generated)
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
Creates a foreign key with no actions.
Sourcepub fn from_strings(
table: String,
name: String,
columns: Vec<String>,
table_to: String,
columns_to: Vec<String>,
) -> Self
pub fn from_strings( table: String, name: String, columns: Vec<String>, table_to: String, columns_to: Vec<String>, ) -> Self
Creates a foreign key with no actions from owned strings.
Sourcepub fn on_delete(self, action: impl Into<Cow<'static, str>>) -> Self
pub fn on_delete(self, action: impl Into<Cow<'static, str>>) -> Self
Sets the ON DELETE action, as SQL keywords.
Source§impl ForeignKey
impl ForeignKey
Sourcepub fn to_constraint_sql(&self) -> String
pub fn to_constraint_sql(&self) -> String
Renders CONSTRAINT name FOREIGN KEY (...) REFERENCES table(...),
with ON UPDATE / ON DELETE unless they are NO ACTION.
Sourcepub fn add_fk_sql(&self) -> String
pub fn add_fk_sql(&self) -> String
Returns a SQL comment: SQLite cannot add a foreign key to an
existing table without recreating it.
Sourcepub fn drop_fk_sql(&self) -> String
pub fn drop_fk_sql(&self) -> String
Returns a SQL comment: SQLite cannot drop a foreign key without
recreating the table.