diff options
| author | mo khan <mo@mokhan.ca> | 2026-01-09 15:46:12 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2026-01-09 15:46:12 -0700 |
| commit | f22326157ebf8aadd4252ea1dc463b1a9c325cc9 (patch) | |
| tree | 029cb543505f70ea08b2ca254669786d48170d42 | |
| parent | 3a85631e12390a5e84a480d55068c1f6e5b11c97 (diff) | |
refactor: do not add semicolon
36 files changed, 191 insertions, 129 deletions
diff --git a/src/formatter.rs b/src/formatter.rs index 494f3f6..9e4fba6 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -31,7 +31,10 @@ fn format_query(query: &Query, indent_level: usize) -> String { OrderByKind::Expressions(exprs) if !exprs.is_empty() => { result.push('\n'); result.push_str(&format!("{}ORDER BY ", " ".repeat(indent_level))); - let order_items: Vec<String> = exprs.iter().map(format_order_by_expr).collect(); + let order_items: Vec<String> = exprs + .iter() + .map(|e| format_order_by_expr(e, indent_level)) + .collect(); result.push_str(&order_items.join(", ")); } _ => {} @@ -46,7 +49,7 @@ fn format_query(query: &Query, indent_level: usize) -> String { result.push_str(&format!( "{}LIMIT {}", " ".repeat(indent_level), - format_expr(limit) + format_expr(limit, indent_level) )); } } @@ -55,7 +58,7 @@ fn format_query(query: &Query, indent_level: usize) -> String { result.push_str(&format!( "{}LIMIT {}", " ".repeat(indent_level), - format_expr(limit) + format_expr(limit, indent_level) )); } } @@ -148,7 +151,7 @@ fn format_select(select: &Select, indent_level: usize) -> String { if select.projection.len() == 1 && is_simple_projection(&select.projection[0]) { result.push(' '); - result.push_str(&format_select_item(&select.projection[0])); + result.push_str(&format_select_item(&select.projection[0], indent_level + 2)); } else { for (i, item) in select.projection.iter().enumerate() { if i == 0 { @@ -156,7 +159,11 @@ fn format_select(select: &Select, indent_level: usize) -> String { } else { result.push_str(",\n"); } - result.push_str(&format!("{}{}", item_indent, format_select_item(item))); + result.push_str(&format!( + "{}{}", + item_indent, + format_select_item(item, indent_level + 2) + )); } } @@ -196,7 +203,10 @@ fn format_select(select: &Select, indent_level: usize) -> String { GroupByExpr::Expressions(exprs, _) if !exprs.is_empty() => { result.push('\n'); result.push_str(&format!("{}GROUP BY ", base_indent)); - let group_items: Vec<String> = exprs.iter().map(format_expr).collect(); + let group_items: Vec<String> = exprs + .iter() + .map(|e| format_expr(e, indent_level)) + .collect(); result.push_str(&group_items.join(", ")); } _ => {} @@ -204,24 +214,28 @@ fn format_select(select: &Select, indent_level: usize) -> String { if let Some(having) = &select.having { result.push('\n'); - result.push_str(&format!("{}HAVING {}", base_indent, format_expr(having))); + result.push_str(&format!( + "{}HAVING {}", + base_indent, + format_expr(having, indent_level) + )); } result } -fn format_select_item(item: &SelectItem) -> String { +fn format_select_item(item: &SelectItem, indent_level: usize) -> String { match item { - SelectItem::UnnamedExpr(expr) => format_expr(expr), + SelectItem::UnnamedExpr(expr) => format_expr(expr, indent_level), SelectItem::ExprWithAlias { expr, alias } => { - format!("{} AS {}", format_expr(expr), alias.value) + format!("{} AS {}", format_expr(expr, indent_level), alias.value) } SelectItem::QualifiedWildcard(kind, _) => match kind { SelectItemQualifiedWildcardKind::ObjectName(object_name) => { format!("{}.*", object_name) } SelectItemQualifiedWildcardKind::Expr(expr) => { - format!("{}.*", format_expr(expr)) + format!("{}.*", format_expr(expr, indent_level)) } }, SelectItem::Wildcard(_) => "*".to_string(), @@ -229,21 +243,21 @@ fn format_select_item(item: &SelectItem) -> String { } fn format_table_with_joins(table: &TableWithJoins, indent_level: usize) -> String { - let mut result = format_table_factor(&table.relation); + let mut result = format_table_factor(&table.relation, indent_level); for join in &table.joins { result.push('\n'); result.push_str(&format!( "{}{}", " ".repeat(indent_level), - format_join(join) + format_join(join, indent_level) )); } result } -fn format_table_factor(table: &TableFactor) -> String { +fn format_table_factor(table: &TableFactor, indent_level: usize) -> String { match table { TableFactor::Table { name, alias, .. } => { let mut result = name.to_string(); @@ -255,11 +269,13 @@ fn format_table_factor(table: &TableFactor) -> String { TableFactor::Derived { subquery, alias, .. } => { + let inner_indent = indent_level + 2; let mut result = String::new(); result.push('('); result.push('\n'); - result.push_str(&format_query(subquery, 4)); + result.push_str(&format_query(subquery, inner_indent)); result.push('\n'); + result.push_str(&" ".repeat(indent_level)); result.push(')'); if let Some(alias) = alias { result.push_str(&format!(" AS {}", alias.name.value)); @@ -270,69 +286,69 @@ fn format_table_factor(table: &TableFactor) -> String { } } -fn format_join(join: &Join) -> String { +fn format_join(join: &Join, indent_level: usize) -> String { let mut result = String::new(); match &join.join_operator { JoinOperator::Join(constraint) => { result.push_str("JOIN "); - result.push_str(&format_table_factor(&join.relation)); + result.push_str(&format_table_factor(&join.relation, indent_level)); if let JoinConstraint::On(expr) = constraint { - result.push_str(&format!(" ON {}", format_expr(expr))); + result.push_str(&format!(" ON {}", format_expr(expr, indent_level))); } } JoinOperator::Inner(constraint) => { result.push_str("INNER JOIN "); - result.push_str(&format_table_factor(&join.relation)); + result.push_str(&format_table_factor(&join.relation, indent_level)); if let JoinConstraint::On(expr) = constraint { - result.push_str(&format!(" ON {}", format_expr(expr))); + result.push_str(&format!(" ON {}", format_expr(expr, indent_level))); } } JoinOperator::Left(constraint) => { result.push_str("LEFT OUTER JOIN "); - result.push_str(&format_table_factor(&join.relation)); + result.push_str(&format_table_factor(&join.relation, indent_level)); if let JoinConstraint::On(expr) = constraint { - result.push_str(&format!(" ON {}", format_expr(expr))); + result.push_str(&format!(" ON {}", format_expr(expr, indent_level))); } } JoinOperator::LeftOuter(constraint) => { result.push_str("LEFT OUTER JOIN "); - result.push_str(&format_table_factor(&join.relation)); + result.push_str(&format_table_factor(&join.relation, indent_level)); if let JoinConstraint::On(expr) = constraint { - result.push_str(&format!(" ON {}", format_expr(expr))); + result.push_str(&format!(" ON {}", format_expr(expr, indent_level))); } } JoinOperator::Right(constraint) => { result.push_str("RIGHT OUTER JOIN "); - result.push_str(&format_table_factor(&join.relation)); + result.push_str(&format_table_factor(&join.relation, indent_level)); if let JoinConstraint::On(expr) = constraint { - result.push_str(&format!(" ON {}", format_expr(expr))); + result.push_str(&format!(" ON {}", format_expr(expr, indent_level))); } } JoinOperator::RightOuter(constraint) => { result.push_str("RIGHT OUTER JOIN "); - result.push_str(&format_table_factor(&join.relation)); + result.push_str(&format_table_factor(&join.relation, indent_level)); if let JoinConstraint::On(expr) = constraint { - result.push_str(&format!(" ON {}", format_expr(expr))); + result.push_str(&format!(" ON {}", format_expr(expr, indent_level))); } } JoinOperator::FullOuter(constraint) => { result.push_str("FULL OUTER JOIN "); - result.push_str(&format_table_factor(&join.relation)); + result.push_str(&format_table_factor(&join.relation, indent_level)); if let JoinConstraint::On(expr) = constraint { - result.push_str(&format!(" ON {}", format_expr(expr))); + result.push_str(&format!(" ON {}", format_expr(expr, indent_level))); } } _ => { result.push_str("JOIN "); - result.push_str(&format_table_factor(&join.relation)); + result.push_str(&format_table_factor(&join.relation, indent_level)); } } result } -fn format_expr(expr: &Expr) -> String { +fn format_expr(expr: &Expr, indent_level: usize) -> String { match expr { Expr::Identifier(ident) => ident.value.clone(), Expr::CompoundIdentifier(idents) => idents @@ -342,29 +358,36 @@ fn format_expr(expr: &Expr) -> String { .join("."), Expr::Value(value) => format_value(&value.value), Expr::BinaryOp { left, op, right } => { - format!("{} {} {}", format_expr(left), op, format_expr(right)) + format!( + "{} {} {}", + format_expr(left, indent_level), + op, + format_expr(right, indent_level) + ) } Expr::UnaryOp { op, expr } => { - format!("{} {}", op, format_expr(expr)) + format!("{} {}", op, format_expr(expr, indent_level)) } Expr::Cast { expr, data_type, .. } => { - format!("CAST({} AS {})", format_expr(expr), data_type) + format!("CAST({} AS {})", format_expr(expr, indent_level), data_type) } Expr::Case { operand, conditions, else_result, .. - } => format_case_expr(operand, conditions, else_result), - Expr::Function(function) => format_function(function), + } => format_case_expr(operand, conditions, else_result, indent_level), + Expr::Function(function) => format_function(function, indent_level), Expr::Subquery(query) => { + let inner_indent = indent_level + 2; let mut result = String::new(); result.push('('); result.push('\n'); - result.push_str(&format_query(query, 4)); + result.push_str(&format_query(query, inner_indent)); result.push('\n'); + result.push_str(&" ".repeat(indent_level)); result.push(')'); result } @@ -373,14 +396,16 @@ fn format_expr(expr: &Expr) -> String { subquery, negated, } => { - let mut result = format_expr(expr); + let inner_indent = indent_level + 2; + let mut result = format_expr(expr, indent_level); if *negated { result.push_str(" NOT"); } result.push_str(" IN ("); result.push('\n'); - result.push_str(&format_query(subquery, 4)); + result.push_str(&format_query(subquery, inner_indent)); result.push('\n'); + result.push_str(&" ".repeat(indent_level)); result.push(')'); result } @@ -390,14 +415,14 @@ fn format_expr(expr: &Expr) -> String { low, high, } => { - let mut result = format_expr(expr); + let mut result = format_expr(expr, indent_level); if *negated { result.push_str(" NOT"); } result.push_str(&format!( " BETWEEN {} AND {}", - format_expr(low), - format_expr(high) + format_expr(low, indent_level), + format_expr(high, indent_level) )); result } @@ -407,16 +432,16 @@ fn format_expr(expr: &Expr) -> String { pattern, .. } => { - let mut result = format_expr(expr); + let mut result = format_expr(expr, indent_level); if *negated { result.push_str(" NOT"); } - result.push_str(&format!(" LIKE {}", format_expr(pattern))); + result.push_str(&format!(" LIKE {}", format_expr(pattern, indent_level))); result } - Expr::IsNull(expr) => format!("{} IS NULL", format_expr(expr)), - Expr::IsNotNull(expr) => format!("{} IS NOT NULL", format_expr(expr)), - Expr::Nested(expr) => format!("({})", format_expr(expr)), + Expr::IsNull(expr) => format!("{} IS NULL", format_expr(expr, indent_level)), + Expr::IsNotNull(expr) => format!("{} IS NOT NULL", format_expr(expr, indent_level)), + Expr::Nested(expr) => format!("({})", format_expr(expr, indent_level)), _ => expr.to_string(), } } @@ -425,31 +450,38 @@ fn format_case_expr( operand: &Option<Box<Expr>>, conditions: &Vec<CaseWhen>, else_result: &Option<Box<Expr>>, + indent_level: usize, ) -> String { let mut result = String::new(); + let inner_indent = " ".repeat(indent_level + 2); result.push_str("CASE"); if let Some(operand) = operand { - result.push_str(&format!(" {}", format_expr(operand))); + result.push_str(&format!(" {}", format_expr(operand, indent_level))); } for condition in conditions { result.push_str(&format!( - "\n WHEN {} THEN {}", - format_expr(&condition.condition), - format_expr(&condition.result) + "\n{}WHEN {} THEN {}", + inner_indent, + format_expr(&condition.condition, indent_level + 2), + format_expr(&condition.result, indent_level + 2) )); } if let Some(else_result) = else_result { - result.push_str(&format!("\n ELSE {}", format_expr(else_result))); + result.push_str(&format!( + "\n{}ELSE {}", + inner_indent, + format_expr(else_result, indent_level + 2) + )); } - result.push_str("\nEND"); + result.push_str(&format!("\n{}END", " ".repeat(indent_level))); result } -fn format_function(function: &Function) -> String { +fn format_function(function: &Function, indent_level: usize) -> String { let mut result = function.name.to_string().to_uppercase(); result.push('('); @@ -461,17 +493,32 @@ fn format_function(function: &Function) -> String { let args: Vec<String> = match &function.args { FunctionArguments::None => vec![], - FunctionArguments::Subquery(_) => vec!["SUBQUERY".to_string()], + FunctionArguments::Subquery(subquery) => { + let inner_indent = indent_level + 2; + vec![format!( + "\n{}\n{}", + format_query(subquery, inner_indent), + " ".repeat(indent_level) + )] + } FunctionArguments::List(list) => list .args .iter() .map(|arg| match arg { FunctionArg::Named { name, arg, .. } => { - format!("{} => {}", name.value, format_function_arg_expr(arg)) + format!( + "{} => {}", + name.value, + format_function_arg_expr(arg, indent_level) + ) } - FunctionArg::Unnamed(arg) => format_function_arg_expr(arg), + FunctionArg::Unnamed(arg) => format_function_arg_expr(arg, indent_level), FunctionArg::ExprNamed { name, arg, .. } => { - format!("{} => {}", format_expr(name), format_function_arg_expr(arg)) + format!( + "{} => {}", + format_expr(name, indent_level), + format_function_arg_expr(arg, indent_level) + ) } }) .collect(), @@ -483,9 +530,17 @@ fn format_function(function: &Function) -> String { result } -fn format_function_arg_expr(arg: &FunctionArgExpr) -> String { +fn format_function_arg_expr(arg: &FunctionArgExpr, indent_level: usize) -> String { match arg { - FunctionArgExpr::Expr(expr) => format_expr(expr), + FunctionArgExpr::Expr(Expr::Subquery(query)) => { + let inner_indent = indent_level + 2; + format!( + "(\n{}\n{})", + format_query(query, inner_indent), + " ".repeat(indent_level) + ) + } + FunctionArgExpr::Expr(expr) => format_expr(expr, indent_level), FunctionArgExpr::QualifiedWildcard(name) => format!("{}.*", name), FunctionArgExpr::Wildcard => "*".to_string(), } @@ -502,8 +557,8 @@ fn format_value(value: &Value) -> String { } } -fn format_order_by_expr(order: &OrderByExpr) -> String { - let mut result = format_expr(&order.expr); +fn format_order_by_expr(order: &OrderByExpr, indent_level: usize) -> String { + let mut result = format_expr(&order.expr, indent_level); if let Some(asc) = order.options.asc { if asc { @@ -552,7 +607,7 @@ fn format_update( AssignmentTarget::ColumnName(object_name) => object_name.to_string(), _ => "UNKNOWN".to_string(), }, - format_expr(&assignment.value) + format_expr(&assignment.value, indent_level + 2) )); } @@ -598,7 +653,7 @@ fn format_where_expr(expr: &Expr, indent_level: usize) -> String { right_str ) } - _ => format_expr(expr), + _ => format_expr(expr, indent_level), } } @@ -661,7 +716,7 @@ mod tests { fn test_select_with_subquery() { let input = "SELECT * FROM (SELECT id, name FROM users WHERE active = true) AS active_users"; - let expected = "SELECT *\nFROM\n (\n SELECT\n id,\n name\n FROM\n users\n WHERE active = TRUE\n) AS active_users"; + let expected = "SELECT *\nFROM\n (\n SELECT\n id,\n name\n FROM\n users\n WHERE active = TRUE\n ) AS active_users"; assert_eq!(parse_and_format(input), expected); } @@ -669,7 +724,7 @@ mod tests { fn test_select_with_case_expression() { let input = "SELECT CASE WHEN age < 18 THEN 'minor' ELSE 'adult' END AS age_group FROM users"; - let expected = "SELECT\n CASE\n WHEN age < 18 THEN 'minor'\n ELSE 'adult'\nEND AS age_group\nFROM\n users"; + let expected = "SELECT\n CASE\n WHEN age < 18 THEN 'minor'\n ELSE 'adult'\n END AS age_group\nFROM\n users"; assert_eq!(parse_and_format(input), expected); } @@ -727,7 +782,7 @@ mod tests { fn test_in_subquery() { let input = "SELECT * FROM users WHERE id IN (SELECT user_id FROM orders)"; let expected = - "SELECT *\nFROM\n users\nWHERE id IN (\n SELECT user_id\n FROM\n orders\n)"; + "SELECT *\nFROM\n users\nWHERE id IN (\n SELECT user_id\n FROM\n orders\n )"; assert_eq!(parse_and_format(input), expected); } @@ -771,7 +826,7 @@ mod tests { fn test_complex_case_expression() { let input = "SELECT CASE status WHEN 'active' THEN 1 WHEN 'inactive' THEN 0 ELSE -1 END FROM users"; - let expected = "SELECT\n CASE status\n WHEN 'active' THEN 1\n WHEN 'inactive' THEN 0\n ELSE - 1\nEND\nFROM\n users"; + let expected = "SELECT\n CASE status\n WHEN 'active' THEN 1\n WHEN 'inactive' THEN 0\n ELSE - 1\n END\nFROM\n users"; assert_eq!(parse_and_format(input), expected); } } @@ -841,20 +896,24 @@ fn format_delete(delete: &Delete, indent_level: usize) -> String { } fn format_create_table(create_table: &CreateTable, indent_level: usize) -> String { - let mut result = format!("{}CREATE TABLE {} (", " ".repeat(indent_level), create_table.name); + let mut result = format!( + "{}CREATE TABLE {} (", + " ".repeat(indent_level), + create_table.name + ); result.push_str(&format_indented_list( &create_table.columns, - format_column_def, + |col| format_column_def(col, indent_level + 2), indent_level, - true + true, )); result.push(')'); result } -fn format_column_def(column: &ColumnDef) -> String { +fn format_column_def(column: &ColumnDef, indent_level: usize) -> String { let mut result = format!("{} {}", column.name.value, column.data_type); for option in &column.options { @@ -862,7 +921,7 @@ fn format_column_def(column: &ColumnDef) -> String { ColumnOption::NotNull => result.push_str(" NOT NULL"), ColumnOption::Null => result.push_str(" NULL"), ColumnOption::Default(expr) => { - result.push_str(&format!(" DEFAULT {}", format_expr(expr))); + result.push_str(&format!(" DEFAULT {}", format_expr(expr, indent_level))); } ColumnOption::Unique { is_primary, .. } => { if *is_primary { @@ -928,7 +987,7 @@ where fn format_values_row(row: &[Expr], indent_level: usize) -> String { if row.len() == 1 { - format!("({})", format_expr(&row[0])) + format!("({})", format_expr(&row[0], indent_level)) } else { let mut result = String::from("("); result.push('\n'); @@ -936,10 +995,14 @@ fn format_values_row(row: &[Expr], indent_level: usize) -> String { if i > 0 { result.push_str(",\n"); } - result.push_str(&format!("{} {}", " ".repeat(indent_level), format_expr(value))); + result.push_str(&format!( + "{} {}", + " ".repeat(indent_level), + format_expr(value, indent_level + 2) + )); } result.push('\n'); - result.push_str(&format!("{}", " ".repeat(indent_level))); + result.push_str(&" ".repeat(indent_level)); result.push(')'); result } diff --git a/src/main.rs b/src/main.rs index 4f1a7ad..a72ff2c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,6 +25,8 @@ fn run() -> Result<()> { return Ok(()); } + let has_semicolon = input.ends_with(';'); + let dialect = GenericDialect {}; match Parser::parse_sql(&dialect, input) { Ok(statements) => { @@ -35,8 +37,11 @@ fn run() -> Result<()> { } output.push(format_statement(statement, 0)); } - let formatted = output.join(""); - let formatted = ensure_semicolon_and_cleanup(&formatted); + let mut formatted = output.join(""); + formatted = cleanup_whitespace(&formatted); + if has_semicolon { + formatted.push(';'); + } println!("{}", formatted); Ok(()) } @@ -50,14 +55,8 @@ fn run() -> Result<()> { } } -fn ensure_semicolon_and_cleanup(sql: &str) -> String { - let mut result = sql.trim_end().to_string(); - - if !result.ends_with(';') { - result.push(';'); - } - - result +fn cleanup_whitespace(sql: &str) -> String { + sql.trim_end() .lines() .map(|line| line.trim_end()) .collect::<Vec<_>>() diff --git a/tests/fixtures/basic_select/output.sql b/tests/fixtures/basic_select/output.sql index c3cdcab..8565ec1 100644 --- a/tests/fixtures/basic_select/output.sql +++ b/tests/fixtures/basic_select/output.sql @@ -4,4 +4,4 @@ SELECT email FROM users -WHERE active = TRUE;
\ No newline at end of file +WHERE active = TRUE
\ No newline at end of file diff --git a/tests/fixtures/basic_select_two_columns/output.sql b/tests/fixtures/basic_select_two_columns/output.sql index 7b3b458..2720fe2 100644 --- a/tests/fixtures/basic_select_two_columns/output.sql +++ b/tests/fixtures/basic_select_two_columns/output.sql @@ -3,4 +3,4 @@ SELECT name FROM users -WHERE active = TRUE;
\ No newline at end of file +WHERE active = TRUE
\ No newline at end of file diff --git a/tests/fixtures/between_expression/output.sql b/tests/fixtures/between_expression/output.sql index bcdd5ea..b950bc6 100644 --- a/tests/fixtures/between_expression/output.sql +++ b/tests/fixtures/between_expression/output.sql @@ -1,4 +1,4 @@ SELECT * FROM products -WHERE price BETWEEN 10 AND 100;
\ No newline at end of file +WHERE price BETWEEN 10 AND 100
\ No newline at end of file diff --git a/tests/fixtures/case_expression/output.sql b/tests/fixtures/case_expression/output.sql index eb9637d..2de937f 100644 --- a/tests/fixtures/case_expression/output.sql +++ b/tests/fixtures/case_expression/output.sql @@ -1,8 +1,8 @@ SELECT CASE - WHEN age < 18 THEN 'minor' - WHEN age >= 65 THEN 'senior' - ELSE 'adult' -END AS age_group + WHEN age < 18 THEN 'minor' + WHEN age >= 65 THEN 'senior' + ELSE 'adult' + END AS age_group FROM - users;
\ No newline at end of file + users
\ No newline at end of file diff --git a/tests/fixtures/cast_expression/output.sql b/tests/fixtures/cast_expression/output.sql index 0340768..6e385bc 100644 --- a/tests/fixtures/cast_expression/output.sql +++ b/tests/fixtures/cast_expression/output.sql @@ -1,4 +1,4 @@ SELECT CAST(id AS VARCHAR) FROM - users;
\ No newline at end of file + users
\ No newline at end of file diff --git a/tests/fixtures/create_table_statement/output.sql b/tests/fixtures/create_table_statement/output.sql index 9299c61..f5f7eb1 100644 --- a/tests/fixtures/create_table_statement/output.sql +++ b/tests/fixtures/create_table_statement/output.sql @@ -3,4 +3,4 @@ CREATE TABLE users ( name VARCHAR(100) NOT NULL, email VARCHAR(255) UNIQUE, active BOOLEAN DEFAULT TRUE -);
\ No newline at end of file +)
\ No newline at end of file diff --git a/tests/fixtures/cte/output.sql b/tests/fixtures/cte/output.sql index b462520..a2dcb07 100644 --- a/tests/fixtures/cte/output.sql +++ b/tests/fixtures/cte/output.sql @@ -7,4 +7,4 @@ WITH ) SELECT * FROM - active_users;
\ No newline at end of file + active_users
\ No newline at end of file diff --git a/tests/fixtures/delete_statement/output.sql b/tests/fixtures/delete_statement/output.sql index 8a05fda..501e13c 100644 --- a/tests/fixtures/delete_statement/output.sql +++ b/tests/fixtures/delete_statement/output.sql @@ -1,3 +1,3 @@ DELETE FROM users WHERE active = FALSE - AND last_login < '2020-01-01';
\ No newline at end of file + AND last_login < '2020-01-01'
\ No newline at end of file diff --git a/tests/fixtures/distinct/output.sql b/tests/fixtures/distinct/output.sql index 96ceb8d..309ec4b 100644 --- a/tests/fixtures/distinct/output.sql +++ b/tests/fixtures/distinct/output.sql @@ -1,3 +1,3 @@ SELECT DISTINCT department FROM - employees;
\ No newline at end of file + employees
\ No newline at end of file diff --git a/tests/fixtures/function_calls/output.sql b/tests/fixtures/function_calls/output.sql index 0c1962c..cffd5b4 100644 --- a/tests/fixtures/function_calls/output.sql +++ b/tests/fixtures/function_calls/output.sql @@ -3,4 +3,4 @@ SELECT MAX(age), UPPER(name) FROM - users;
\ No newline at end of file + users
\ No newline at end of file diff --git a/tests/fixtures/in_subquery/output.sql b/tests/fixtures/in_subquery/output.sql index fb52d78..0df6869 100644 --- a/tests/fixtures/in_subquery/output.sql +++ b/tests/fixtures/in_subquery/output.sql @@ -5,4 +5,4 @@ WHERE id IN ( SELECT user_id FROM orders -);
\ No newline at end of file + )
\ No newline at end of file diff --git a/tests/fixtures/insert_no_columns/output.sql b/tests/fixtures/insert_no_columns/output.sql index f42e197..ee11710 100644 --- a/tests/fixtures/insert_no_columns/output.sql +++ b/tests/fixtures/insert_no_columns/output.sql @@ -4,4 +4,4 @@ VALUES ( 'John Doe', 'john@example.com', TRUE -);
\ No newline at end of file +)
\ No newline at end of file diff --git a/tests/fixtures/insert_statement/output.sql b/tests/fixtures/insert_statement/output.sql index c882110..d5c439d 100644 --- a/tests/fixtures/insert_statement/output.sql +++ b/tests/fixtures/insert_statement/output.sql @@ -9,4 +9,4 @@ VALUES ( 'John Doe', 'john@example.com', TRUE -);
\ No newline at end of file +)
\ No newline at end of file diff --git a/tests/fixtures/is_null/output.sql b/tests/fixtures/is_null/output.sql index e688d62..1825b0e 100644 --- a/tests/fixtures/is_null/output.sql +++ b/tests/fixtures/is_null/output.sql @@ -1,4 +1,4 @@ SELECT * FROM users -WHERE email IS NOT NULL;
\ No newline at end of file +WHERE email IS NOT NULL
\ No newline at end of file diff --git a/tests/fixtures/join_query/output.sql b/tests/fixtures/join_query/output.sql index 4a90eaa..07c7d5f 100644 --- a/tests/fixtures/join_query/output.sql +++ b/tests/fixtures/join_query/output.sql @@ -3,4 +3,4 @@ SELECT p.title FROM users AS u - INNER JOIN posts AS p ON u.id = p.user_id;
\ No newline at end of file + INNER JOIN posts AS p ON u.id = p.user_id
\ No newline at end of file diff --git a/tests/fixtures/multi_row_insert/output.sql b/tests/fixtures/multi_row_insert/output.sql index de36482..bd3c1bf 100644 --- a/tests/fixtures/multi_row_insert/output.sql +++ b/tests/fixtures/multi_row_insert/output.sql @@ -17,4 +17,4 @@ VALUES ( 3, 'Bob', 'bob@example.com' -);
\ No newline at end of file +)
\ No newline at end of file diff --git a/tests/fixtures/multiple_and_conditions/output.sql b/tests/fixtures/multiple_and_conditions/output.sql index 47c499d..e168a31 100644 --- a/tests/fixtures/multiple_and_conditions/output.sql +++ b/tests/fixtures/multiple_and_conditions/output.sql @@ -3,4 +3,4 @@ FROM users WHERE active = TRUE AND age > 18 - AND name LIKE 'A%';
\ No newline at end of file + AND name LIKE 'A%'
\ No newline at end of file diff --git a/tests/fixtures/multiple_statements/output.sql b/tests/fixtures/multiple_statements/output.sql index 569ca0d..460a98e 100644 --- a/tests/fixtures/multiple_statements/output.sql +++ b/tests/fixtures/multiple_statements/output.sql @@ -3,4 +3,4 @@ FROM users SELECT * FROM - posts;
\ No newline at end of file + posts
\ No newline at end of file diff --git a/tests/fixtures/nested_expressions/output.sql b/tests/fixtures/nested_expressions/output.sql index 01147f4..0298e7e 100644 --- a/tests/fixtures/nested_expressions/output.sql +++ b/tests/fixtures/nested_expressions/output.sql @@ -1,4 +1,4 @@ SELECT * FROM users -WHERE (active = TRUE AND age > 18) OR role = 'admin';
\ No newline at end of file +WHERE (active = TRUE AND age > 18) OR role = 'admin'
\ No newline at end of file diff --git a/tests/fixtures/new_test_example/output.sql b/tests/fixtures/new_test_example/output.sql index b01a53e..732e57d 100644 --- a/tests/fixtures/new_test_example/output.sql +++ b/tests/fixtures/new_test_example/output.sql @@ -4,4 +4,4 @@ SELECT FROM users GROUP BY department -HAVING COUNT(*) > 5;
\ No newline at end of file +HAVING COUNT(*) > 5
\ No newline at end of file diff --git a/tests/fixtures/quoted_identifiers/output.sql b/tests/fixtures/quoted_identifiers/output.sql index 2d828ad..04d61d2 100644 --- a/tests/fixtures/quoted_identifiers/output.sql +++ b/tests/fixtures/quoted_identifiers/output.sql @@ -3,4 +3,4 @@ SELECT user_name FROM "admin_users" -WHERE active = TRUE;
\ No newline at end of file +WHERE active = TRUE
\ No newline at end of file diff --git a/tests/fixtures/semicolon_addition/output.sql b/tests/fixtures/semicolon_addition/output.sql index f9201d1..294160b 100644 --- a/tests/fixtures/semicolon_addition/output.sql +++ b/tests/fixtures/semicolon_addition/output.sql @@ -1,3 +1,3 @@ SELECT * FROM - users;
\ No newline at end of file + users
\ No newline at end of file diff --git a/tests/fixtures/simple_projection/output.sql b/tests/fixtures/simple_projection/output.sql index 1b710e2..a9dc37f 100644 --- a/tests/fixtures/simple_projection/output.sql +++ b/tests/fixtures/simple_projection/output.sql @@ -1,3 +1,3 @@ SELECT 1 AS one FROM - users;
\ No newline at end of file + users
\ No newline at end of file diff --git a/tests/fixtures/simple_select_single_line/output.sql b/tests/fixtures/simple_select_single_line/output.sql index 1b710e2..a9dc37f 100644 --- a/tests/fixtures/simple_select_single_line/output.sql +++ b/tests/fixtures/simple_select_single_line/output.sql @@ -1,3 +1,3 @@ SELECT 1 AS one FROM - users;
\ No newline at end of file + users
\ No newline at end of file diff --git a/tests/fixtures/subquery/output.sql b/tests/fixtures/subquery/output.sql index 5b83d3b..70f65e0 100644 --- a/tests/fixtures/subquery/output.sql +++ b/tests/fixtures/subquery/output.sql @@ -7,5 +7,5 @@ FROM FROM users WHERE active = TRUE -) AS active_users -WHERE name LIKE 'A%';
\ No newline at end of file + ) AS active_users +WHERE name LIKE 'A%'
\ No newline at end of file diff --git a/tests/fixtures/union_query/output.sql b/tests/fixtures/union_query/output.sql index d77de15..ff885f4 100644 --- a/tests/fixtures/union_query/output.sql +++ b/tests/fixtures/union_query/output.sql @@ -4,4 +4,4 @@ FROM UNION SELECT id FROM - customers;
\ No newline at end of file + customers
\ No newline at end of file diff --git a/tests/fixtures/update_statement/output.sql b/tests/fixtures/update_statement/output.sql index d318fd3..5c2bb35 100644 --- a/tests/fixtures/update_statement/output.sql +++ b/tests/fixtures/update_statement/output.sql @@ -4,4 +4,4 @@ SET email = 'john.smith@example.com', last_updated = NOW() WHERE id = 1 - AND active = TRUE;
\ No newline at end of file + AND active = TRUE
\ No newline at end of file diff --git a/tests/fixtures/with_case_expression/output.sql b/tests/fixtures/with_case_expression/output.sql index d65418b..8c42f3f 100644 --- a/tests/fixtures/with_case_expression/output.sql +++ b/tests/fixtures/with_case_expression/output.sql @@ -1,7 +1,7 @@ SELECT CASE - WHEN age < 18 THEN 'minor' - ELSE 'adult' -END AS age_group + WHEN age < 18 THEN 'minor' + ELSE 'adult' + END AS age_group FROM - users;
\ No newline at end of file + users
\ No newline at end of file diff --git a/tests/fixtures/with_cte/output.sql b/tests/fixtures/with_cte/output.sql index b462520..a2dcb07 100644 --- a/tests/fixtures/with_cte/output.sql +++ b/tests/fixtures/with_cte/output.sql @@ -7,4 +7,4 @@ WITH ) SELECT * FROM - active_users;
\ No newline at end of file + active_users
\ No newline at end of file diff --git a/tests/fixtures/with_group_by_having/output.sql b/tests/fixtures/with_group_by_having/output.sql index 04496fe..4b788bf 100644 --- a/tests/fixtures/with_group_by_having/output.sql +++ b/tests/fixtures/with_group_by_having/output.sql @@ -4,4 +4,4 @@ SELECT FROM employees GROUP BY department -HAVING COUNT(*) > 5;
\ No newline at end of file +HAVING COUNT(*) > 5
\ No newline at end of file diff --git a/tests/fixtures/with_joins/output.sql b/tests/fixtures/with_joins/output.sql index 4a90eaa..07c7d5f 100644 --- a/tests/fixtures/with_joins/output.sql +++ b/tests/fixtures/with_joins/output.sql @@ -3,4 +3,4 @@ SELECT p.title FROM users AS u - INNER JOIN posts AS p ON u.id = p.user_id;
\ No newline at end of file + INNER JOIN posts AS p ON u.id = p.user_id
\ No newline at end of file diff --git a/tests/fixtures/with_order_by_limit/output.sql b/tests/fixtures/with_order_by_limit/output.sql index 59bf0c6..20b4834 100644 --- a/tests/fixtures/with_order_by_limit/output.sql +++ b/tests/fixtures/with_order_by_limit/output.sql @@ -2,4 +2,4 @@ SELECT * FROM users ORDER BY name ASC -LIMIT 10;
\ No newline at end of file +LIMIT 10
\ No newline at end of file diff --git a/tests/fixtures/with_subquery/output.sql b/tests/fixtures/with_subquery/output.sql index 7ef3ec5..936c839 100644 --- a/tests/fixtures/with_subquery/output.sql +++ b/tests/fixtures/with_subquery/output.sql @@ -7,4 +7,4 @@ FROM FROM users WHERE active = TRUE -) AS active_users;
\ No newline at end of file + ) AS active_users
\ No newline at end of file diff --git a/tests/fixtures/with_union/output.sql b/tests/fixtures/with_union/output.sql index d77de15..ff885f4 100644 --- a/tests/fixtures/with_union/output.sql +++ b/tests/fixtures/with_union/output.sql @@ -4,4 +4,4 @@ FROM UNION SELECT id FROM - customers;
\ No newline at end of file + customers
\ No newline at end of file |
