summaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-06-24 11:45:07 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-06-24 11:45:07 +0200
commitab04d88ae84c33f3577870c10378f0166adf27bc (patch)
tree27156c65528b9b253ccc2d3fd91c88395017f0cb /src/db
parent2ebb3a00aca2eaaea5f182b1f72e21c09fcba6ee (diff)
Add spinner for establishing database connection
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/db')
-rw-r--r--src/db/connection.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/db/connection.rs b/src/db/connection.rs
index cf9a0c0..76d38c1 100644
--- a/src/db/connection.rs
+++ b/src/db/connection.rs
@@ -19,6 +19,7 @@ use getset::Getters;
use log::debug;
use crate::config::Configuration;
+use crate::util::progress::ProgressBars;
#[derive(Getters)]
pub struct DbConnectionConfig<'a> {
@@ -78,7 +79,7 @@ impl<'a> DbConnectionConfig<'a> {
})
}
- pub fn establish_connection(self) -> Result<PgConnection> {
+ pub fn establish_connection(self, progressbars: &ProgressBars) -> Result<PgConnection> {
debug!("Trying to connect to database: {:?}", self);
let database_uri: String = format!(
"postgres://{user}:{password}@{host}:{port}/{name}?connect_timeout={timeout}",
@@ -89,7 +90,17 @@ impl<'a> DbConnectionConfig<'a> {
name = self.database_name,
timeout = self.database_connection_timeout,
);
- PgConnection::establish(&database_uri).map_err(Error::from)
+
+ let bar = progressbars.spinner();
+ bar.set_message("Establishing database connection");
+
+ let conn = PgConnection::establish(&database_uri).map_err(Error::from);
+ if conn.is_err() {
+ bar.finish_with_message("Connection could not be established");
+ } else {
+ bar.finish_with_message("Connection established");
+ }
+ conn
}
}