aboutsummaryrefslogtreecommitdiffstats
path: root/src/remote/database.rs
diff options
context:
space:
mode:
authorEllie Huxtable <e@elm.sh>2021-04-14 18:40:50 +0100
committerGitHub <noreply@github.com>2021-04-14 17:40:50 +0000
commitf6de558070c4ed4dbecf4bbbf4693e396a5577dc (patch)
tree174dcd5f1341e2845ea30cff6521e36170e8a0d5 /src/remote/database.rs
parentBump reqwest from 0.11.2 to 0.11.3 (#33) (diff)
downloadatuin-f6de558070c4ed4dbecf4bbbf4693e396a5577dc.zip
Optimise docker (#34)
* Smaller dockerfile, better error handling * Add config dir
Diffstat (limited to '')
-rw-r--r--src/remote/database.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/remote/database.rs b/src/remote/database.rs
index ddcffda0..03973ca1 100644
--- a/src/remote/database.rs
+++ b/src/remote/database.rs
@@ -1,5 +1,6 @@
use diesel::pg::PgConnection;
use diesel::prelude::*;
+use eyre::{eyre, Result};
use crate::settings::Settings;
@@ -7,8 +8,15 @@ use crate::settings::Settings;
pub struct AtuinDbConn(diesel::PgConnection);
// TODO: connection pooling
-pub fn establish_connection(settings: &Settings) -> PgConnection {
- let database_url = &settings.server.db_uri;
- PgConnection::establish(database_url)
- .unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
+pub fn establish_connection(settings: &Settings) -> Result<PgConnection> {
+ if settings.server.db_uri == "default_uri" {
+ Err(eyre!(
+ "Please configure your database! Set db_uri in config.toml"
+ ))
+ } else {
+ let database_url = &settings.server.db_uri;
+ let conn = PgConnection::establish(database_url)?;
+
+ Ok(conn)
+ }
}