Skip to content

Commit 258cc8c

Browse files
Folded all table_constraints/*.rs submodules into table_constraints.rs module
1 parent f13b2eb commit 258cc8c

File tree

10 files changed

+519
-713
lines changed

10 files changed

+519
-713
lines changed

src/ast/ddl.rs

Lines changed: 1 addition & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ use sqlparser_derive::{Visit, VisitMut};
3131
use crate::ast::value::escape_single_quote_string;
3232
use crate::ast::{
3333
display_comma_separated, display_separated,
34-
table_constraints::{
35-
CheckConstraint, ForeignKeyConstraint, FullTextOrSpatialConstraint, IndexConstraint,
36-
PrimaryKeyConstraint, UniqueConstraint,
37-
},
34+
table_constraints::TableConstraint,
3835
ArgMode, CommentDef, ConditionalStatements, CreateFunctionBody, CreateFunctionUsing,
3936
CreateTableLikeKind, CreateTableOptions, DataType, Expr, FileFormat, FunctionBehavior,
4037
FunctionCalledOnNull, FunctionDeterminismSpecifier, FunctionParallel, HiveDistributionStyle,
@@ -1033,123 +1030,6 @@ impl fmt::Display for AlterColumnOperation {
10331030
}
10341031
}
10351032

1036-
/// A table-level constraint, specified in a `CREATE TABLE` or an
1037-
/// `ALTER TABLE ADD <constraint>` statement.
1038-
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1039-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1040-
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1041-
pub enum TableConstraint {
1042-
/// MySQL [definition][1] for `UNIQUE` constraints statements:\
1043-
/// * `[CONSTRAINT [<name>]] UNIQUE <index_type_display> [<index_name>] [index_type] (<columns>) <index_options>`
1044-
///
1045-
/// where:
1046-
/// * [index_type][2] is `USING {BTREE | HASH}`
1047-
/// * [index_options][3] is `{index_type | COMMENT 'string' | ... %currently unsupported stmts% } ...`
1048-
/// * [index_type_display][4] is `[INDEX | KEY]`
1049-
///
1050-
/// [1]: https://dev.mysql.com/doc/refman/8.3/en/create-table.html
1051-
/// [2]: IndexType
1052-
/// [3]: IndexOption
1053-
/// [4]: KeyOrIndexDisplay
1054-
Unique(UniqueConstraint),
1055-
/// MySQL [definition][1] for `PRIMARY KEY` constraints statements:\
1056-
/// * `[CONSTRAINT [<name>]] PRIMARY KEY [index_name] [index_type] (<columns>) <index_options>`
1057-
///
1058-
/// Actually the specification have no `[index_name]` but the next query will complete successfully:
1059-
/// ```sql
1060-
/// CREATE TABLE unspec_table (
1061-
/// xid INT NOT NULL,
1062-
/// CONSTRAINT p_name PRIMARY KEY index_name USING BTREE (xid)
1063-
/// );
1064-
/// ```
1065-
///
1066-
/// where:
1067-
/// * [index_type][2] is `USING {BTREE | HASH}`
1068-
/// * [index_options][3] is `{index_type | COMMENT 'string' | ... %currently unsupported stmts% } ...`
1069-
///
1070-
/// [1]: https://dev.mysql.com/doc/refman/8.3/en/create-table.html
1071-
/// [2]: IndexType
1072-
/// [3]: IndexOption
1073-
PrimaryKey(PrimaryKeyConstraint),
1074-
/// A referential integrity constraint (`[ CONSTRAINT <name> ] FOREIGN KEY (<columns>)
1075-
/// REFERENCES <foreign_table> (<referred_columns>)
1076-
/// { [ON DELETE <referential_action>] [ON UPDATE <referential_action>] |
1077-
/// [ON UPDATE <referential_action>] [ON DELETE <referential_action>]
1078-
/// }`).
1079-
ForeignKey(ForeignKeyConstraint),
1080-
/// `[ CONSTRAINT <name> ] CHECK (<expr>) [[NOT] ENFORCED]`
1081-
Check(CheckConstraint),
1082-
/// MySQLs [index definition][1] for index creation. Not present on ANSI so, for now, the usage
1083-
/// is restricted to MySQL, as no other dialects that support this syntax were found.
1084-
///
1085-
/// `{INDEX | KEY} [index_name] [index_type] (key_part,...) [index_option]...`
1086-
///
1087-
/// [1]: https://dev.mysql.com/doc/refman/8.0/en/create-table.html
1088-
Index(IndexConstraint),
1089-
/// MySQLs [fulltext][1] definition. Since the [`SPATIAL`][2] definition is exactly the same,
1090-
/// and MySQL displays both the same way, it is part of this definition as well.
1091-
///
1092-
/// Supported syntax:
1093-
///
1094-
/// ```markdown
1095-
/// {FULLTEXT | SPATIAL} [INDEX | KEY] [index_name] (key_part,...)
1096-
///
1097-
/// key_part: col_name
1098-
/// ```
1099-
///
1100-
/// [1]: https://dev.mysql.com/doc/refman/8.0/en/fulltext-natural-language.html
1101-
/// [2]: https://dev.mysql.com/doc/refman/8.0/en/spatial-types.html
1102-
FulltextOrSpatial(FullTextOrSpatialConstraint),
1103-
}
1104-
1105-
impl From<UniqueConstraint> for TableConstraint {
1106-
fn from(constraint: UniqueConstraint) -> Self {
1107-
TableConstraint::Unique(constraint)
1108-
}
1109-
}
1110-
1111-
impl From<PrimaryKeyConstraint> for TableConstraint {
1112-
fn from(constraint: PrimaryKeyConstraint) -> Self {
1113-
TableConstraint::PrimaryKey(constraint)
1114-
}
1115-
}
1116-
1117-
impl From<ForeignKeyConstraint> for TableConstraint {
1118-
fn from(constraint: ForeignKeyConstraint) -> Self {
1119-
TableConstraint::ForeignKey(constraint)
1120-
}
1121-
}
1122-
1123-
impl From<CheckConstraint> for TableConstraint {
1124-
fn from(constraint: CheckConstraint) -> Self {
1125-
TableConstraint::Check(constraint)
1126-
}
1127-
}
1128-
1129-
impl From<IndexConstraint> for TableConstraint {
1130-
fn from(constraint: IndexConstraint) -> Self {
1131-
TableConstraint::Index(constraint)
1132-
}
1133-
}
1134-
1135-
impl From<FullTextOrSpatialConstraint> for TableConstraint {
1136-
fn from(constraint: FullTextOrSpatialConstraint) -> Self {
1137-
TableConstraint::FulltextOrSpatial(constraint)
1138-
}
1139-
}
1140-
1141-
impl fmt::Display for TableConstraint {
1142-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1143-
match self {
1144-
TableConstraint::Unique(constraint) => constraint.fmt(f),
1145-
TableConstraint::PrimaryKey(constraint) => constraint.fmt(f),
1146-
TableConstraint::ForeignKey(constraint) => constraint.fmt(f),
1147-
TableConstraint::Check(constraint) => constraint.fmt(f),
1148-
TableConstraint::Index(constraint) => constraint.fmt(f),
1149-
TableConstraint::FulltextOrSpatial(constraint) => constraint.fmt(f),
1150-
}
1151-
}
1152-
}
11531033

11541034
/// Representation whether a definition can can contains the KEY or INDEX keywords with the same
11551035
/// meaning.

src/ast/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub use self::ddl::{
6868
DropBehavior, DropTrigger, GeneratedAs, GeneratedExpressionMode, IdentityParameters,
6969
IdentityProperty, IdentityPropertyFormatKind, IdentityPropertyKind, IdentityPropertyOrder,
7070
IndexColumn, IndexOption, IndexType, KeyOrIndexDisplay, NullsDistinctOption, Owner, Partition,
71-
ProcedureParam, ReferentialAction, RenameTableNameKind, ReplicaIdentity, TableConstraint,
71+
ProcedureParam, ReferentialAction, RenameTableNameKind, ReplicaIdentity,
7272
TagsColumnOption, UserDefinedTypeCompositeAttributeDef, UserDefinedTypeRepresentation,
7373
ViewColumnDef,
7474
};
@@ -121,7 +121,7 @@ pub mod helpers;
121121
pub mod table_constraints;
122122
pub use table_constraints::{
123123
CheckConstraint, ForeignKeyConstraint, FullTextOrSpatialConstraint, IndexConstraint,
124-
PrimaryKeyConstraint, UniqueConstraint,
124+
PrimaryKeyConstraint, TableConstraint, UniqueConstraint,
125125
};
126126
mod operator;
127127
mod query;

0 commit comments

Comments
 (0)