Skip to content

Commit

Permalink
refactor(cli): use databend-common-ast to format sql (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
andylokandy authored Jul 10, 2024
1 parent d5736a4 commit de50912
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ chrono = { version = "0.4.35", default-features = false, features = ["clock"] }
clap = { version = "4.4", features = ["derive", "env"] }
comfy-table = "7.1"
csv = "1.3"
databend-common-ast = "0.0.1"
fern = { version = "0.6", features = ["colored"] }
indicatif = "0.17"
log = "0.4"
logos = "0.13"
once_cell = "1.18"
rustyline = "12.0"
serde = { version = "1.0", features = ["derive"] }
sqlformat = "0.2"
strum = "0.25"
strum_macros = "0.25"
terminal_size = "0.3"
Expand Down
14 changes: 7 additions & 7 deletions cli/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

mod tokenizer;

use sqlformat::{Indent, QueryParams};
use databend_common_ast::{
ast::pretty_statement,
parser::{parse_sql, Dialect},
};
pub use tokenizer::*;

use crate::session::QueryKind;
Expand All @@ -24,10 +27,7 @@ pub fn format_query(query: &str) -> String {
if kind == QueryKind::Put || kind == QueryKind::Get {
return query.to_owned();
}
let options = sqlformat::FormatOptions {
indent: Indent::Spaces(2),
uppercase: true,
lines_between_queries: 1,
};
sqlformat::format(query, &QueryParams::None, options)
let tokens = databend_common_ast::parser::tokenize_sql(query).unwrap();
let (stmt, _) = parse_sql(&tokens, Dialect::Experimental).unwrap();
pretty_statement(stmt, 80).unwrap()
}

0 comments on commit de50912

Please sign in to comment.