1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use diesel::prelude::*;
use config::Config;
use log::error;
pub fn establish_connection() -> MysqlConnection {
let secret_config = Config::builder()
.add_source(config::File::with_name("secret.config.toml"))
.build()
.expect("Missing Secret Config File");
let database_url: String = secret_config
.get("DATABASE_URL")
.expect("DATABASE_URL must be set");
match MysqlConnection::establish(&database_url) {
Ok(msc) => msc,
Err(e) => {
error!("Error connecting to {}", e);
panic!("No DB")
}
}
}