Skip to content

Commit

Permalink
fix: show error and db_uri when connect failed
Browse files Browse the repository at this point in the history
  • Loading branch information
zrll12 committed Mar 15, 2024
1 parent 53089fb commit 8c41fd3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,20 @@ mod config;
mod model;
mod service;

lazy_static!{
lazy_static! {
static ref CONFIG: Config = Config::new();
static ref DATABASE: DatabaseConnection = {
let mut opt = ConnectOptions::new(&CONFIG.connection.db_uri);
opt.sqlx_logging(true);
opt.sqlx_logging_level(LevelFilter::Debug);
futures::executor::block_on(Database::connect(opt)).unwrap()
futures::executor::block_on(Database::connect(opt)).unwrap_or_else(|e| {
panic!("Failed to connect to database '{}': {}", CONFIG.connection.db_uri, e)
})
};
}

#[tokio::main]
async fn main() {

let env_filter =
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(&CONFIG.trace_level));
let file_appender = RollingFileAppender::builder()
Expand Down

0 comments on commit 8c41fd3

Please sign in to comment.