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
2022-12-11 15:25:15 +00:00

15 lines
468 B
Rust

use r2d2_mysql::{
mysql::{Opts, OptsBuilder},
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")
}