From 3ebb8563a11e312ff46bac5c87dce974f14ae7ac Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Thu, 22 Sep 2022 13:17:14 +0200 Subject: [PATCH] Expose PoolOptions for reading This allows reading back PoolOptions that have already been set. --- sqlx-core/src/pool/options.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/sqlx-core/src/pool/options.rs b/sqlx-core/src/pool/options.rs index 18f8106886..cfb1bb737e 100644 --- a/sqlx-core/src/pool/options.rs +++ b/sqlx-core/src/pool/options.rs @@ -141,6 +141,11 @@ impl PoolOptions { 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. @@ -168,6 +173,11 @@ impl PoolOptions { 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: @@ -186,6 +196,11 @@ impl PoolOptions { 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. @@ -205,6 +220,11 @@ impl PoolOptions { self } + /// Get the maximum lifetime of individual connections. + pub fn get_max_lifetime(&self) -> Option { + 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. @@ -215,6 +235,11 @@ impl PoolOptions { self } + /// Get the maximum idle duration for individual connections. + pub fn get_idle_timeout(&self) -> Option { + self.idle_timeout + } + /// If true, the health of a connection will be verified by a call to [`Connection::ping`] /// before returning the connection. /// @@ -224,6 +249,11 @@ impl PoolOptions { 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.