summaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-07-27 16:36:35 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-07-27 16:36:35 +0200
commit1b575fc3582d8105aebf372a0470cd8c57d94ec2 (patch)
treeb14a3151131ac86f83cd79b61ea1af55e67c5ccd /src/db
parent61a6427fe0fdaf894f713cac9cf23418e9708846 (diff)
parentab04d88ae84c33f3577870c10378f0166adf27bc (diff)
Merge branch 'connecting-spinner'
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
}
}