Skip to content

Commit

Permalink
style: progress indicator when inserting db
Browse files Browse the repository at this point in the history
  • Loading branch information
albugowy15 committed Jul 8, 2023
1 parent 23d7348 commit 569965c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[package]
name = "auto-frs-schedule"
version = "2.0.0"
version = "2.1.0"
edition = "2021"
about = "Automatically generate TC FRS schedule from Excel file"
author = "Mohamad Kholid Bughowi <[email protected]>"
description = "Automatically generate TC FRS schedule from Excel file"
authors = ["Mohamad Kholid Bughowi <[email protected]>"]
readme = "README.md"
repository = "https://github.com/albugowy15/auto-frs-schedule"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -15,7 +17,7 @@ lto = true
calamine = "0.21.2"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
cuid = "1.3.1"
clap = { version = "4.3.9", features = ["derive"] }
clap = { version = "4.3.11", features = ["derive"] }
anyhow = "1.0.71"
sqlx = { version = "0.6.3", features = [ "runtime-tokio-native-tls", "mysql" ] }
indicatif = "0.17.5"
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
};

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[command(version, about)]
struct Cli {
#[arg(
short,
Expand Down
13 changes: 11 additions & 2 deletions src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ impl ClassRepository {
let prep_class_lecturers_sql = "INSERT INTO _ClassToLecturer (A, B) VALUES (?, ?)";

let bar = ProgressBar::new(data.len() as u64);
bar.set_style(ProgressStyle::with_template("{bar:50.cyan/blue} {pos:>7}/{len:7}").unwrap());
bar.set_style(
ProgressStyle::with_template(
"{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {pos}/{len}",
)
.unwrap()
.progress_chars("#>-"),
);

for item in data.iter() {
let id_class = cuid::cuid().with_context(|| "Could not create cuid")?;
Expand Down Expand Up @@ -119,7 +125,10 @@ impl ClassRepository {
})?;
bar.inc(1);
}
bar.finish();
bar.finish_with_message(format!(
"Done inserting {} classes to Class table",
data.len()
));
Ok(())
}
}

0 comments on commit 569965c

Please sign in to comment.