Skip to content

Commit 01978c5

Browse files
committed
Reuse DropBehavior Display
1 parent 0f6c71b commit 01978c5

File tree

1 file changed

+29
-37
lines changed

1 file changed

+29
-37
lines changed

src/ast/ddl.rs

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -649,59 +649,51 @@ impl fmt::Display for AlterTableOperation {
649649
} => {
650650
write!(
651651
f,
652-
"DROP CONSTRAINT {}{}{}",
652+
"DROP CONSTRAINT {}{}",
653653
if *if_exists { "IF EXISTS " } else { "" },
654-
name,
655-
match drop_behavior {
656-
None => "",
657-
Some(DropBehavior::Restrict) => " RESTRICT",
658-
Some(DropBehavior::Cascade) => " CASCADE",
659-
}
660-
)
654+
name
655+
)?;
656+
if let Some(drop_behavior) = drop_behavior {
657+
write!(f, " {drop_behavior}")?;
658+
}
659+
Ok(())
661660
}
662661
AlterTableOperation::DropPrimaryKey { drop_behavior } => {
663-
write!(
664-
f,
665-
"DROP PRIMARY KEY{}",
666-
match drop_behavior {
667-
None => "",
668-
Some(DropBehavior::Restrict) => " RESTRICT",
669-
Some(DropBehavior::Cascade) => " CASCADE",
670-
}
671-
)
662+
write!(f, "DROP PRIMARY KEY")?;
663+
if let Some(drop_behavior) = drop_behavior {
664+
write!(f, " {drop_behavior}")?;
665+
}
666+
Ok(())
672667
}
673668
AlterTableOperation::DropForeignKey {
674669
name,
675670
drop_behavior,
676671
} => {
677-
write!(
678-
f,
679-
"DROP FOREIGN KEY {name}{}",
680-
match drop_behavior {
681-
None => "",
682-
Some(DropBehavior::Restrict) => " RESTRICT",
683-
Some(DropBehavior::Cascade) => " CASCADE",
684-
}
685-
)
672+
write!(f, "DROP FOREIGN KEY {name}")?;
673+
if let Some(drop_behavior) = drop_behavior {
674+
write!(f, " {drop_behavior}")?;
675+
}
676+
Ok(())
686677
}
687678
AlterTableOperation::DropIndex { name } => write!(f, "DROP INDEX {name}"),
688679
AlterTableOperation::DropColumn {
689680
has_column_keyword,
690681
column_names: column_name,
691682
if_exists,
692683
drop_behavior,
693-
} => write!(
694-
f,
695-
"DROP {}{}{}{}",
696-
if *has_column_keyword { "COLUMN " } else { "" },
697-
if *if_exists { "IF EXISTS " } else { "" },
698-
display_comma_separated(column_name),
699-
match drop_behavior {
700-
None => "",
701-
Some(DropBehavior::Restrict) => " RESTRICT",
702-
Some(DropBehavior::Cascade) => " CASCADE",
684+
} => {
685+
write!(
686+
f,
687+
"DROP {}{}{}",
688+
if *has_column_keyword { "COLUMN " } else { "" },
689+
if *if_exists { "IF EXISTS " } else { "" },
690+
display_comma_separated(column_name),
691+
)?;
692+
if let Some(drop_behavior) = drop_behavior {
693+
write!(f, " {drop_behavior}")?;
703694
}
704-
),
695+
Ok(())
696+
}
705697
AlterTableOperation::AttachPartition { partition } => {
706698
write!(f, "ATTACH {partition}")
707699
}

0 commit comments

Comments
 (0)