pub struct PoolSettings {
pub url: String,
pub max_connections: u32,
pub min_connections: u32,
pub acquire_timeout: Duration,
pub idle_timeout: Option<Duration>,
pub max_lifetime: Option<Duration>,
pub test_before_acquire: bool,
}Expand description
Connection-pool tuning resolved from the database.* configuration namespace.
Every field except url is optional in configuration and falls
back to the same default sqlx itself uses, so an application that only sets
database.url keeps sqlx’s well-chosen defaults. The recognised keys are:
| Config key | Type | Default | Meaning |
|---|---|---|---|
database.url | string | (required) | Connection string passed to sqlx. |
database.max_connections | u32 | 10 | Hard cap on open connections. |
database.min_connections | u32 | 0 | Connections kept warm when idle. |
database.acquire_timeout_seconds | u64 | 30 | How long acquire waits before erroring. |
database.idle_timeout_seconds | u64 | 600 | Reap idle connections after this long. 0 disables. |
database.max_lifetime_seconds | u64 | 1800 | Recycle connections older than this. 0 disables. |
database.test_before_acquire | bool | true | Ping a connection before handing it out. |
Fields§
§url: StringDatabase connection string (e.g. mysql://user:pass@host/db).
max_connections: u32Maximum number of connections the pool will open.
min_connections: u32Minimum number of connections kept open while the pool is idle.
acquire_timeout: DurationMaximum time to wait when acquiring a connection from the pool.
idle_timeout: Option<Duration>Close a connection after it has been idle for this long. None disables.
max_lifetime: Option<Duration>Close a connection once it reaches this age. None disables.
test_before_acquire: boolWhether to validate a connection (with a ping) before handing it out.
Implementations§
Source§impl PoolSettings
impl PoolSettings
Sourcepub fn from_config() -> Self
pub fn from_config() -> Self
Reads pool settings from the registered database configuration block.
§Panics
Panics if database.url is not configured.
Sourcepub fn to_pool_options(&self) -> PoolOptions<Db>
pub fn to_pool_options(&self) -> PoolOptions<Db>
Builds PoolOptions for the selected backend from these settings, without
opening any connections.
Trait Implementations§
Source§impl Clone for PoolSettings
impl Clone for PoolSettings
Source§fn clone(&self) -> PoolSettings
fn clone(&self) -> PoolSettings
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PoolSettings
impl Debug for PoolSettings
impl Eq for PoolSettings
Source§impl PartialEq for PoolSettings
impl PartialEq for PoolSettings
Source§fn eq(&self, other: &PoolSettings) -> bool
fn eq(&self, other: &PoolSettings) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for PoolSettings
Auto Trait Implementations§
impl Freeze for PoolSettings
impl RefUnwindSafe for PoolSettings
impl Send for PoolSettings
impl Sync for PoolSettings
impl Unpin for PoolSettings
impl UnsafeUnpin for PoolSettings
impl UnwindSafe for PoolSettings
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more