Use deadpool-diesel to create a Pool with a Manager configured for your database and runtime, then retrieve connections via pool.get().await.
use deadpool_diesel::postgres::{Manager, Pool};
let manager = Manager::new(db_url, deadpool_diesel::Runtime::Tokio1);
let pool = Pool::builder(manager).build().unwrap();
let conn = pool.get().await.unwrap();
- Add the
deadpool-dieselcrate with thepostgresfeature to yourCargo.toml. - Create a
Managerusing yourDATABASE_URLand theTokio1runtime. - Build the
Poolfrom the manager usingPool::builder. - Retrieve a connection from the pool by calling
pool.get().awaitinside your async handler.