-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathdb.rs
19 lines (17 loc) · 708 Bytes
/
db.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use diesel::pg::PgConnection;
use diesel::r2d2::ConnectionManager;
use dotenv::dotenv;
use r2d2::Pool;
use std::env;
// The Postgres-specific connection pool managing all database connections.
pub type PostgresPool = Pool<ConnectionManager<PgConnection>>;
pub fn get_pool() -> PostgresPool {
// TODO: pass the connection URL into this function rather than extracting
// it from the environment within this function
dotenv().ok();
let url = env::var("DATABASE_URL").expect("no DB URL"); // TODO: handle errors
let mgr = ConnectionManager::<PgConnection>::new(url);
r2d2::Pool::builder()
.build(mgr)
.expect("could not build connection pool") // TODO: handle errors
}