1
0
mirror of https://github.com/actix/examples synced 2024-12-02 18:02:22 +01:00
examples/graphql/juniper-advanced/src/db.rs
2021-02-26 00:57:58 +00:00

13 lines
471 B
Rust

use r2d2_mysql::mysql::{Opts, OptsBuilder};
use r2d2_mysql::MysqlConnectionManager;
pub type Pool = r2d2::Pool<MysqlConnectionManager>;
pub fn get_db_pool() -> Pool {
let db_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
let opts = Opts::from_url(&db_url).unwrap();
let builder = OptsBuilder::from_opts(opts);
let manager = MysqlConnectionManager::new(builder);
r2d2::Pool::new(manager).expect("Failed to create DB Pool")
}