Use consistent style for Display impls

This commit is contained in:
Nickolay Ponomarev 2020-07-27 21:23:48 +03:00
parent d0db8a224b
commit 3e880b599a

View file

@ -299,7 +299,7 @@ impl fmt::Display for Expr {
results, results,
else_result, else_result,
} => { } => {
f.write_str("CASE")?; write!(f, "CASE")?;
if let Some(operand) = operand { if let Some(operand) = operand {
write!(f, " {}", operand)?; write!(f, " {}", operand)?;
} }
@ -310,7 +310,7 @@ impl fmt::Display for Expr {
if let Some(else_result) = else_result { if let Some(else_result) = else_result {
write!(f, " ELSE {}", else_result)?; write!(f, " ELSE {}", else_result)?;
} }
f.write_str(" END") write!(f, " END")
} }
Expr::Exists(s) => write!(f, "EXISTS ({})", s), Expr::Exists(s) => write!(f, "EXISTS ({})", s),
Expr::Subquery(s) => write!(f, "({})", s), Expr::Subquery(s) => write!(f, "({})", s),
@ -626,8 +626,7 @@ impl fmt::Display for Statement {
} => { } => {
write!(f, "UPDATE {}", table_name)?; write!(f, "UPDATE {}", table_name)?;
if !assignments.is_empty() { if !assignments.is_empty() {
write!(f, " SET ")?; write!(f, " SET {}", display_comma_separated(assignments))?;
write!(f, "{}", display_comma_separated(assignments))?;
} }
if let Some(selection) = selection { if let Some(selection) = selection {
write!(f, " WHERE {}", selection)?; write!(f, " WHERE {}", selection)?;
@ -652,26 +651,19 @@ impl fmt::Display for Statement {
materialized, materialized,
with_options, with_options,
} => { } => {
write!(f, "CREATE")?; write!(
f,
if *or_replace { "CREATE {or_replace}{materialized}VIEW {name}",
write!(f, " OR REPLACE")?; or_replace = if *or_replace { "OR REPLACE " } else { "" },
} materialized = if *materialized { "MATERIALIZED " } else { "" },
name = name
if *materialized { )?;
write!(f, " MATERIALIZED")?;
}
write!(f, " VIEW {}", name)?;
if !with_options.is_empty() { if !with_options.is_empty() {
write!(f, " WITH ({})", display_comma_separated(with_options))?; write!(f, " WITH ({})", display_comma_separated(with_options))?;
} }
if !columns.is_empty() { if !columns.is_empty() {
write!(f, " ({})", display_comma_separated(columns))?; write!(f, " ({})", display_comma_separated(columns))?;
} }
write!(f, " AS {}", query) write!(f, " AS {}", query)
} }
Statement::CreateTable { Statement::CreateTable {
@ -716,7 +708,6 @@ impl fmt::Display for Statement {
if *without_rowid { if *without_rowid {
write!(f, " WITHOUT ROWID")?; write!(f, " WITHOUT ROWID")?;
} }
if *external { if *external {
write!( write!(
f, f,
@ -757,22 +748,15 @@ impl fmt::Display for Statement {
columns, columns,
unique, unique,
if_not_exists, if_not_exists,
} => { } => write!(
write!( f,
f, "CREATE {unique}INDEX {if_not_exists}{name} ON {table_name}({columns});",
"CREATE{}INDEX{}{} ON {}({}", unique = if *unique { "UNIQUE " } else { "" },
if *unique { " UNIQUE " } else { " " }, if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
if *if_not_exists { name = name,
" IF NOT EXISTS " table_name = table_name,
} else { columns = display_separated(columns, ",")
" " ),
},
name,
table_name,
display_separated(columns, ",")
)?;
write!(f, ");")
}
Statement::AlterTable { name, operation } => { Statement::AlterTable { name, operation } => {
write!(f, "ALTER TABLE {} {}", name, operation) write!(f, "ALTER TABLE {} {}", name, operation)
} }
@ -793,13 +777,13 @@ impl fmt::Display for Statement {
local, local,
variable, variable,
value, value,
} => { } => write!(
f.write_str("SET ")?; f,
if *local { "SET{local} {variable} = {value}",
f.write_str("LOCAL ")?; local = if *local { " LOCAL" } else { "" },
} variable = variable,
write!(f, "{} = {}", variable, value) value = value
} ),
Statement::ShowVariable { variable } => write!(f, "SHOW {}", variable), Statement::ShowVariable { variable } => write!(f, "SHOW {}", variable),
Statement::ShowColumns { Statement::ShowColumns {
extended, extended,
@ -807,14 +791,13 @@ impl fmt::Display for Statement {
table_name, table_name,
filter, filter,
} => { } => {
f.write_str("SHOW ")?; write!(
if *extended { f,
f.write_str("EXTENDED ")?; "SHOW {extended}{full}COLUMNS FROM {table_name}",
} extended = if *extended { "EXTENDED " } else { "" },
if *full { full = if *full { "FULL " } else { "" },
f.write_str("FULL ")?; table_name = table_name,
} )?;
write!(f, "COLUMNS FROM {}", table_name)?;
if let Some(filter) = filter { if let Some(filter) = filter {
write!(f, " {}", filter)?; write!(f, " {}", filter)?;
} }
@ -843,7 +826,6 @@ impl fmt::Display for Statement {
Statement::CreateSchema { schema_name } => write!(f, "CREATE SCHEMA {}", schema_name), Statement::CreateSchema { schema_name } => write!(f, "CREATE SCHEMA {}", schema_name),
Statement::Assert { condition, message } => { Statement::Assert { condition, message } => {
write!(f, "ASSERT {}", condition)?; write!(f, "ASSERT {}", condition)?;
if let Some(m) = message { if let Some(m) = message {
write!(f, " AS {}", m)?; write!(f, " AS {}", m)?;
} }