Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): only print one time for multiple queries #106

Merged
merged 2 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bendsql"
version = "0.3.6"
version = "0.3.7"
edition = "2021"
license = "Apache-2.0"
description = "Databend Native Command Line Tool"
Expand Down
3 changes: 0 additions & 3 deletions cli/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@ impl<'a> FormatDisplay<'a> {
if let Some(pb) = self.progress.take() {
pb.finish_and_clear();
}
if self.settings.time {
println!("{:.3}", self.start.elapsed().as_secs_f64());
}
Ok(())
}

Expand Down
16 changes: 10 additions & 6 deletions cli/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ impl Session {
}

pub async fn handle_reader<R: BufRead>(&mut self, r: R) {
let start = Instant::now();
let mut lines = r.lines();
while let Some(Ok(line)) = lines.next() {
let queries = self.append_query(&line);
Expand All @@ -165,6 +166,9 @@ impl Session {
eprintln!("{}", e);
}
}
if self.settings.time {
println!("{:.3}", start.elapsed().as_secs_f64());
}
}

pub fn append_query(&mut self, line: &str) -> Vec<String> {
Expand Down Expand Up @@ -226,15 +230,15 @@ impl Session {
let affected = self.conn.exec(query).await?;
if is_repl {
if affected > 0 {
println!(
eprintln!(
"{} rows affected in ({:.3} sec)",
affected,
start.elapsed().as_secs_f64()
);
} else {
println!("Processed in ({:.3} sec)", start.elapsed().as_secs_f64());
eprintln!("Processed in ({:.3} sec)", start.elapsed().as_secs_f64());
}
println!();
eprintln!();
}
Ok(false)
}
Expand Down Expand Up @@ -300,13 +304,13 @@ impl Session {
self.conn = new_connection(&self.dsn)?;
if self.is_repl {
let info = self.conn.info();
println!(
eprintln!(
"Trying reconnect to {}:{} as user {}.",
info.host, info.port, info.user
);
let version = self.conn.version().await?;
println!("Connected to {}", version);
println!();
eprintln!("Connected to {}", version);
eprintln!();
}
Ok(())
}
Expand Down