Enum TableConstraint
pub enum TableConstraint {
Unique {
name: Option<Ident>,
index_name: Option<Ident>,
index_type_display: KeyOrIndexDisplay,
index_type: Option<IndexType>,
columns: Vec<IndexColumn>,
index_options: Vec<IndexOption>,
characteristics: Option<ConstraintCharacteristics>,
nulls_distinct: NullsDistinctOption,
},
PrimaryKey {
name: Option<Ident>,
index_name: Option<Ident>,
index_type: Option<IndexType>,
columns: Vec<IndexColumn>,
index_options: Vec<IndexOption>,
characteristics: Option<ConstraintCharacteristics>,
},
ForeignKey {
name: Option<Ident>,
index_name: Option<Ident>,
columns: Vec<Ident>,
foreign_table: ObjectName,
referred_columns: Vec<Ident>,
on_delete: Option<ReferentialAction>,
on_update: Option<ReferentialAction>,
characteristics: Option<ConstraintCharacteristics>,
},
Check {
name: Option<Ident>,
expr: Box<Expr>,
enforced: Option<bool>,
},
Index {
display_as_key: bool,
name: Option<Ident>,
index_type: Option<IndexType>,
columns: Vec<IndexColumn>,
index_options: Vec<IndexOption>,
},
FulltextOrSpatial {
fulltext: bool,
index_type_display: KeyOrIndexDisplay,
opt_index_name: Option<Ident>,
columns: Vec<IndexColumn>,
},
}Expand description
A table-level constraint, specified in a CREATE TABLE or an
ALTER TABLE ADD <constraint> statement.
Variants§
Unique
MySQL definition for UNIQUE constraints statements:\
[CONSTRAINT [<name>]] UNIQUE <index_type_display> [<index_name>] [index_type] (<columns>) <index_options>
where:
- index_type is
USING {BTREE | HASH} - index_options is
{index_type | COMMENT 'string' | ... %currently unsupported stmts% } ... - index_type_display is
[INDEX | KEY]
Fields
index_type_display: KeyOrIndexDisplayWhether the type is followed by the keyword KEY, INDEX, or no keyword at all.
index_type: Option<IndexType>Optional USING of index type statement before columns.
columns: Vec<IndexColumn>Identifiers of the columns that are unique.
index_options: Vec<IndexOption>characteristics: Option<ConstraintCharacteristics>nulls_distinct: NullsDistinctOptionOptional Postgres nulls handling: [ NULLS [ NOT ] DISTINCT ]
PrimaryKey
MySQL definition for PRIMARY KEY constraints statements:\
[CONSTRAINT [<name>]] PRIMARY KEY [index_name] [index_type] (<columns>) <index_options>
Actually the specification have no [index_name] but the next query will complete successfully:
CREATE TABLE unspec_table (
xid INT NOT NULL,
CONSTRAINT p_name PRIMARY KEY index_name USING BTREE (xid)
);where:
- index_type is
USING {BTREE | HASH} - index_options is
{index_type | COMMENT 'string' | ... %currently unsupported stmts% } ...
Fields
index_type: Option<IndexType>Optional USING of index type statement before columns.
columns: Vec<IndexColumn>Identifiers of the columns that form the primary key.
index_options: Vec<IndexOption>characteristics: Option<ConstraintCharacteristics>ForeignKey
A referential integrity constraint ([ CONSTRAINT <name> ] FOREIGN KEY (<columns>) REFERENCES <foreign_table> (<referred_columns>) { [ON DELETE <referential_action>] [ON UPDATE <referential_action>] | [ON UPDATE <referential_action>] [ON DELETE <referential_action>] }).
Fields
index_name: Option<Ident>MySQL-specific field https://dev.mysql.com/doc/refman/8.4/en/create-table-foreign-keys.html
foreign_table: ObjectNameon_delete: Option<ReferentialAction>on_update: Option<ReferentialAction>characteristics: Option<ConstraintCharacteristics>Check
[ CONSTRAINT <name> ] CHECK (<expr>) [[NOT] ENFORCED]
Fields
enforced: Option<bool>MySQL-specific syntax https://dev.mysql.com/doc/refman/8.4/en/create-table.html
Index
MySQLs index definition for index creation. Not present on ANSI so, for now, the usage is restricted to MySQL, as no other dialects that support this syntax were found.
{INDEX | KEY} [index_name] [index_type] (key_part,...) [index_option]...
Fields
display_as_key: boolWhether this index starts with KEY (true) or INDEX (false), to maintain the same syntax.
index_type: Option<IndexType>Optional index type.
columns: Vec<IndexColumn>Referred column identifier list.
index_options: Vec<IndexOption>Optional index options such as USING; see IndexOption.
FulltextOrSpatial
MySQLs fulltext definition. Since the SPATIAL definition is exactly the same,
and MySQL displays both the same way, it is part of this definition as well.
Supported syntax:
{FULLTEXT | SPATIAL} [INDEX | KEY] [index_name] (key_part,...)
key_part: col_nameFields
index_type_display: KeyOrIndexDisplayWhether the type is followed by the keyword KEY, INDEX, or no keyword at all.
columns: Vec<IndexColumn>Referred column identifier list.
Trait Implementations§
§impl Clone for TableConstraint
impl Clone for TableConstraint
§fn clone(&self) -> TableConstraint
fn clone(&self) -> TableConstraint
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for TableConstraint
impl Debug for TableConstraint
§impl Display for TableConstraint
impl Display for TableConstraint
§impl Hash for TableConstraint
impl Hash for TableConstraint
§impl Ord for TableConstraint
impl Ord for TableConstraint
§impl PartialEq for TableConstraint
impl PartialEq for TableConstraint
§impl PartialOrd for TableConstraint
impl PartialOrd for TableConstraint
§impl Spanned for TableConstraint
impl Spanned for TableConstraint
§impl Visit for TableConstraint
impl Visit for TableConstraint
§impl VisitMut for TableConstraint
impl VisitMut for TableConstraint
fn visit<V>(&mut self, visitor: &mut V) -> ControlFlow<<V as VisitorMut>::Break>where
V: VisitorMut,
impl Eq for TableConstraint
impl StructuralPartialEq for TableConstraint
Auto Trait Implementations§
impl Freeze for TableConstraint
impl RefUnwindSafe for TableConstraint
impl Send for TableConstraint
impl Sync for TableConstraint
impl Unpin for TableConstraint
impl UnwindSafe for TableConstraint
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,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.