Skip to content

Commit

Permalink
Expose PoolOptions for reading
Browse files Browse the repository at this point in the history
This allows reading back PoolOptions that have already been set.
  • Loading branch information
FSMaxB committed Feb 2, 2023
1 parent 0e708b6 commit 3ebb856
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions sqlx-core/src/pool/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ impl<DB: Database> PoolOptions<DB> {
self
}

/// Get the maximum number of connections that this pool should maintain
pub fn get_max_connections(&self) -> u32 {
self.max_connections
}

/// Set the minimum number of connections to maintain at all times.
///
/// When the pool is built, this many connections will be automatically spun up.
Expand Down Expand Up @@ -168,6 +173,11 @@ impl<DB: Database> PoolOptions<DB> {
self
}

/// Get the minimum number of connections to maintain at all times.
pub fn get_min_connections(&self) -> u32 {
self.min_connections
}

/// Set the maximum amount of time to spend waiting for a connection in [`Pool::acquire()`].
///
/// Caps the total amount of time `Pool::acquire()` can spend waiting across multiple phases:
Expand All @@ -186,6 +196,11 @@ impl<DB: Database> PoolOptions<DB> {
self
}

/// Get the maximum amount of time to spend waiting for a connection in [`Pool::acquire()`].
pub fn get_acquire_timeout(&self) -> Duration {
self.acquire_timeout
}

/// Set the maximum lifetime of individual connections.
///
/// Any connection with a lifetime greater than this will be closed.
Expand All @@ -205,6 +220,11 @@ impl<DB: Database> PoolOptions<DB> {
self
}

/// Get the maximum lifetime of individual connections.
pub fn get_max_lifetime(&self) -> Option<Duration> {
self.max_lifetime
}

/// Set a maximum idle duration for individual connections.
///
/// Any connection that remains in the idle queue longer than this will be closed.
Expand All @@ -215,6 +235,11 @@ impl<DB: Database> PoolOptions<DB> {
self
}

/// Get the maximum idle duration for individual connections.
pub fn get_idle_timeout(&self) -> Option<Duration> {
self.idle_timeout
}

/// If true, the health of a connection will be verified by a call to [`Connection::ping`]
/// before returning the connection.
///
Expand All @@ -224,6 +249,11 @@ impl<DB: Database> PoolOptions<DB> {
self
}

/// Get's whether `test_before_acquire` is currently set.
pub fn get_test_before_acquire(&self) -> bool {
self.test_before_acquire
}

/// If set to `true`, calls to `acquire()` are fair and connections are issued
/// in first-come-first-serve order. If `false`, "drive-by" tasks may steal idle connections
/// ahead of tasks that have been waiting.
Expand Down

0 comments on commit 3ebb856

Please sign in to comment.