Update 'deadpool' dependencies in 'db_pools'.

This commit is contained in:
Sergio Benitez 2022-02-16 10:54:08 -08:00
parent 6345d2b888
commit 543560a1f2
3 changed files with 15 additions and 13 deletions

View File

@ -34,19 +34,19 @@ path = "../codegen"
version = "0.1.0-rc" version = "0.1.0-rc"
[dependencies.deadpool] [dependencies.deadpool]
version = "0.8" version = "0.9"
default-features = false default-features = false
features = ["rt_tokio_1", "managed"] features = ["rt_tokio_1", "managed"]
optional = true optional = true
[dependencies.deadpool-postgres] [dependencies.deadpool-postgres]
version = "0.9" version = "0.10"
default-features = false default-features = false
features = ["rt_tokio_1"] features = ["rt_tokio_1"]
optional = true optional = true
[dependencies.deadpool-redis] [dependencies.deadpool-redis]
version = "0.8.1" version = "0.10"
default-features = false default-features = false
features = ["rt_tokio_1"] features = ["rt_tokio_1"]
optional = true optional = true

View File

@ -101,7 +101,7 @@
//! At present, this crate supports _three_ drivers: [`deadpool`], [`sqlx`], //! At present, this crate supports _three_ drivers: [`deadpool`], [`sqlx`],
//! and [`mongodb`]. Each driver may support multiple databases. //! and [`mongodb`]. Each driver may support multiple databases.
//! //!
//! ## `deadpool` (v0.8) //! ## `deadpool` (v0.9)
//! //!
//! | Database | Feature | [`Pool`] Type | [`Connection`] Deref | //! | Database | Feature | [`Pool`] Type | [`Connection`] Deref |
//! |----------|---------------------|-----------------------------|---------------------------------------| //! |----------|---------------------|-----------------------------|---------------------------------------|

View File

@ -137,7 +137,7 @@ pub trait Pool: Sized + Send + Sync + 'static {
#[cfg(feature = "deadpool")] #[cfg(feature = "deadpool")]
mod deadpool_postgres { mod deadpool_postgres {
use deadpool::managed::{Manager, Pool, PoolConfig, PoolError, Object}; use deadpool::{managed::{Manager, Pool, PoolError, Object, BuildError}, Runtime};
use super::{Duration, Error, Config, Figment}; use super::{Duration, Error, Config, Figment};
pub trait DeadManager: Manager + Sized + Send + Sync + 'static { pub trait DeadManager: Manager + Sized + Send + Sync + 'static {
@ -162,20 +162,22 @@ mod deadpool_postgres {
impl<M: DeadManager, C: From<Object<M>>> crate::Pool for Pool<M, C> impl<M: DeadManager, C: From<Object<M>>> crate::Pool for Pool<M, C>
where M::Type: Send, C: Send + Sync + 'static, M::Error: std::error::Error where M::Type: Send, C: Send + Sync + 'static, M::Error: std::error::Error
{ {
type Error = Error<M::Error, PoolError<M::Error>>; type Error = Error<BuildError<M::Error>, PoolError<M::Error>>;
type Connection = C; type Connection = C;
async fn init(figment: &Figment) -> Result<Self, Self::Error> { async fn init(figment: &Figment) -> Result<Self, Self::Error> {
let config: Config = figment.extract()?; let config: Config = figment.extract()?;
let manager = M::new(&config).map_err(Error::Init)?; let manager = M::new(&config).map_err(|e| Error::Init(BuildError::Backend(e)))?;
let mut pool = PoolConfig::new(config.max_connections); Pool::builder(manager)
pool.timeouts.create = Some(Duration::from_secs(config.connect_timeout)); .max_size(config.max_connections)
pool.timeouts.wait = Some(Duration::from_secs(config.connect_timeout)); .wait_timeout(Some(Duration::from_secs(config.connect_timeout)))
pool.timeouts.recycle = config.idle_timeout.map(Duration::from_secs); .create_timeout(Some(Duration::from_secs(config.connect_timeout)))
pool.runtime = deadpool::Runtime::Tokio1; .recycle_timeout(config.idle_timeout.map(Duration::from_secs))
Ok(Pool::from_config(manager, pool)) .runtime(Runtime::Tokio1)
.build()
.map_err(Error::Init)
} }
async fn get(&self) -> Result<Self::Connection, Self::Error> { async fn get(&self) -> Result<Self::Connection, Self::Error> {