Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose PoolOptions for reading #2113

Merged
merged 1 commit into from
Feb 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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