Skip to content

Commit

Permalink
feat: helpfully log process
Browse files Browse the repository at this point in the history
  • Loading branch information
albugowy15 committed Jun 29, 2023
1 parent 35b7bac commit 0630934
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 0 additions & 1 deletion .env.example

This file was deleted.

5 changes: 4 additions & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ pub struct Connection {

impl Connection {
pub async fn create_connection(db_url: &str) -> Result<Self, mysql_async::Error> {
println!("\nStart db connection");
println!("Start db connection...");
let builder = mysql_async::OptsBuilder::from_opts(mysql_async::Opts::from_url(&db_url)?);
let pool = mysql_async::Pool::new(builder.ssl_opts(mysql_async::SslOpts::default()));
let conn = pool.get_conn().await?;
println!("DB Connection suceesfully establised");
Ok(Self { conn, pool })
}
pub async fn close_connection(self) -> Result<(), mysql_async::Error> {
println!("Closing DB Connection...");
drop(self.conn);
self.pool.disconnect().await?;
println!("DB Connection succesfully closed");
Ok(())
}
}
1 change: 1 addition & 0 deletions src/excel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ impl Excel {
});
}
}
println!("Succesfully parsed {} classes from excel", list_class.len());
Ok(list_class)
}
}
8 changes: 5 additions & 3 deletions src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl ClassRepository {
loaded_subject.into_iter().for_each(|subject| {
self.subjects.insert(subject.name, subject.id);
});

println!("Succesfully fetch all subjects from DB");
Ok(())
}

Expand All @@ -62,7 +62,7 @@ impl ClassRepository {
loaded_lecture.into_iter().for_each(|lecture| {
self.lecturers.insert(lecture.code, lecture.id);
});

println!("Succesfully fetch all lecturers from DB");
Ok(())
}

Expand All @@ -83,7 +83,7 @@ impl ClassRepository {
let session_start = session.session_time.split("-").collect::<Vec<&str>>()[0];
self.sessions.insert(session_start.to_string(), session.id);
});

println!("Succesfully fetch all sessions from DB");
Ok(())
}

Expand All @@ -93,6 +93,7 @@ impl ClassRepository {
conn: &mut mysql_async::Conn,
data: Vec<Class>,
) -> Result<(), mysql_async::Error> {
println!("Start insert class to DB...");
conn.query_drop("DELETE FROM Plan").await?;
conn.query_drop("DELETE FROM _ClassToPlan").await?;
conn.query_drop("DELETE FROM Class").await?;
Expand Down Expand Up @@ -122,6 +123,7 @@ impl ClassRepository {
);
conn.exec_drop(&prepared_stmt, values).await?;
}
println!("Succesfully insert {} classes to DB", data.len());
Ok(())
}
}

0 comments on commit 0630934

Please sign in to comment.