1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use r2d2_postgres::r2d2::{Pool, PooledConnection};
use r2d2_postgres::{postgres::NoTls, PostgresConnectionManager};
pub struct Connection {
pool: Pool<PostgresConnectionManager<NoTls>>,
}
impl Connection {
pub fn new(connection_string: &str) -> Self {
let manager = PostgresConnectionManager::new(connection_string.parse().unwrap(), NoTls);
let pool = Pool::new(manager).unwrap();
Self { pool }
}
pub fn conn(&self) -> PooledConnection<PostgresConnectionManager<NoTls>> {
self.pool.get().unwrap()
}
}