Skip to content

Commit 3e880b5

Browse files
committed
Use consistent style for Display impls
1 parent d0db8a2 commit 3e880b5

1 file changed

Lines changed: 33 additions & 51 deletions

File tree

src/ast/mod.rs

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl fmt::Display for Expr {
299299
results,
300300
else_result,
301301
} => {
302-
f.write_str("CASE")?;
302+
write!(f, "CASE")?;
303303
if let Some(operand) = operand {
304304
write!(f, " {}", operand)?;
305305
}
@@ -310,7 +310,7 @@ impl fmt::Display for Expr {
310310
if let Some(else_result) = else_result {
311311
write!(f, " ELSE {}", else_result)?;
312312
}
313-
f.write_str(" END")
313+
write!(f, " END")
314314
}
315315
Expr::Exists(s) => write!(f, "EXISTS ({})", s),
316316
Expr::Subquery(s) => write!(f, "({})", s),
@@ -626,8 +626,7 @@ impl fmt::Display for Statement {
626626
} => {
627627
write!(f, "UPDATE {}", table_name)?;
628628
if !assignments.is_empty() {
629-
write!(f, " SET ")?;
630-
write!(f, "{}", display_comma_separated(assignments))?;
629+
write!(f, " SET {}", display_comma_separated(assignments))?;
631630
}
632631
if let Some(selection) = selection {
633632
write!(f, " WHERE {}", selection)?;
@@ -652,26 +651,19 @@ impl fmt::Display for Statement {
652651
materialized,
653652
with_options,
654653
} => {
655-
write!(f, "CREATE")?;
656-
657-
if *or_replace {
658-
write!(f, " OR REPLACE")?;
659-
}
660-
661-
if *materialized {
662-
write!(f, " MATERIALIZED")?;
663-
}
664-
665-
write!(f, " VIEW {}", name)?;
666-
654+
write!(
655+
f,
656+
"CREATE {or_replace}{materialized}VIEW {name}",
657+
or_replace = if *or_replace { "OR REPLACE " } else { "" },
658+
materialized = if *materialized { "MATERIALIZED " } else { "" },
659+
name = name
660+
)?;
667661
if !with_options.is_empty() {
668662
write!(f, " WITH ({})", display_comma_separated(with_options))?;
669663
}
670-
671664
if !columns.is_empty() {
672665
write!(f, " ({})", display_comma_separated(columns))?;
673666
}
674-
675667
write!(f, " AS {}", query)
676668
}
677669
Statement::CreateTable {
@@ -716,7 +708,6 @@ impl fmt::Display for Statement {
716708
if *without_rowid {
717709
write!(f, " WITHOUT ROWID")?;
718710
}
719-
720711
if *external {
721712
write!(
722713
f,
@@ -757,22 +748,15 @@ impl fmt::Display for Statement {
757748
columns,
758749
unique,
759750
if_not_exists,
760-
} => {
761-
write!(
762-
f,
763-
"CREATE{}INDEX{}{} ON {}({}",
764-
if *unique { " UNIQUE " } else { " " },
765-
if *if_not_exists {
766-
" IF NOT EXISTS "
767-
} else {
768-
" "
769-
},
770-
name,
771-
table_name,
772-
display_separated(columns, ",")
773-
)?;
774-
write!(f, ");")
775-
}
751+
} => write!(
752+
f,
753+
"CREATE {unique}INDEX {if_not_exists}{name} ON {table_name}({columns});",
754+
unique = if *unique { "UNIQUE " } else { "" },
755+
if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
756+
name = name,
757+
table_name = table_name,
758+
columns = display_separated(columns, ",")
759+
),
776760
Statement::AlterTable { name, operation } => {
777761
write!(f, "ALTER TABLE {} {}", name, operation)
778762
}
@@ -793,28 +777,27 @@ impl fmt::Display for Statement {
793777
local,
794778
variable,
795779
value,
796-
} => {
797-
f.write_str("SET ")?;
798-
if *local {
799-
f.write_str("LOCAL ")?;
800-
}
801-
write!(f, "{} = {}", variable, value)
802-
}
780+
} => write!(
781+
f,
782+
"SET{local} {variable} = {value}",
783+
local = if *local { " LOCAL" } else { "" },
784+
variable = variable,
785+
value = value
786+
),
803787
Statement::ShowVariable { variable } => write!(f, "SHOW {}", variable),
804788
Statement::ShowColumns {
805789
extended,
806790
full,
807791
table_name,
808792
filter,
809793
} => {
810-
f.write_str("SHOW ")?;
811-
if *extended {
812-
f.write_str("EXTENDED ")?;
813-
}
814-
if *full {
815-
f.write_str("FULL ")?;
816-
}
817-
write!(f, "COLUMNS FROM {}", table_name)?;
794+
write!(
795+
f,
796+
"SHOW {extended}{full}COLUMNS FROM {table_name}",
797+
extended = if *extended { "EXTENDED " } else { "" },
798+
full = if *full { "FULL " } else { "" },
799+
table_name = table_name,
800+
)?;
818801
if let Some(filter) = filter {
819802
write!(f, " {}", filter)?;
820803
}
@@ -843,7 +826,6 @@ impl fmt::Display for Statement {
843826
Statement::CreateSchema { schema_name } => write!(f, "CREATE SCHEMA {}", schema_name),
844827
Statement::Assert { condition, message } => {
845828
write!(f, "ASSERT {}", condition)?;
846-
847829
if let Some(m) = message {
848830
write!(f, " AS {}", m)?;
849831
}

0 commit comments

Comments
 (0)