16 lines
444 B
Rust
16 lines
444 B
Rust
use std::time::Duration;
|
|
|
|
use diesel::pg::PgConnection;
|
|
use diesel::r2d2::{ConnectionManager, Pool};
|
|
|
|
pub type PgPool = Pool<ConnectionManager<PgConnection>>;
|
|
|
|
pub fn init_pool(database_url: &str) -> anyhow::Result<PgPool> {
|
|
let manager = ConnectionManager::<PgConnection>::new(database_url);
|
|
let pool = Pool::builder()
|
|
.max_size(16)
|
|
.connection_timeout(Duration::from_secs(10))
|
|
.build(manager)?;
|
|
Ok(pool)
|
|
}
|