diff --git a/src/database/mod.rs b/src/database/mod.rs index 4a24ec88..dda7dd02 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -38,6 +38,8 @@ pub struct ConnectOptions { /// Maximum idle time for a particular connection to prevent /// network resource exhaustion pub(crate) idle_timeout: Option, + /// Set the maximum amount of time to spend waiting for acquiring a connection + pub(crate) acquire_timeout: Option, /// Set the maximum lifetime of individual connections pub(crate) max_lifetime: Option, /// Enable SQLx statement logging @@ -107,6 +109,7 @@ impl ConnectOptions { min_connections: None, connect_timeout: None, idle_timeout: None, + acquire_timeout: None, max_lifetime: None, sqlx_logging: true, sqlx_logging_level: log::LevelFilter::Info, @@ -137,6 +140,9 @@ impl ConnectOptions { if let Some(idle_timeout) = self.idle_timeout { opt = opt.idle_timeout(Some(idle_timeout)); } + if let Some(acquire_timeout) = self.acquire_timeout { + opt = opt.acquire_timeout(acquire_timeout); + } if let Some(max_lifetime) = self.max_lifetime { opt = opt.max_lifetime(Some(max_lifetime)); } @@ -192,6 +198,17 @@ impl ConnectOptions { self.idle_timeout } + /// Set the maximum amount of time to spend waiting for acquiring a connection + pub fn acquire_timeout(&mut self, value: Duration) -> &mut Self { + self.acquire_timeout = Some(value); + self + } + + /// Get the maximum amount of time to spend waiting for acquiring a connection + pub fn get_acquire_timeout(&self) -> Option { + self.acquire_timeout + } + /// Set the maximum lifetime of individual connections pub fn max_lifetime(&mut self, lifetime: Duration) -> &mut Self { self.max_lifetime = Some(lifetime);