Skip to content

Commit ea8c691

Browse files
committed
Expose PoolOptions for reading
This allows reading back PoolOptions that have already been set.
1 parent 76ae286 commit ea8c691

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

sqlx-core/src/pool/options.rs

+43
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,24 @@ impl<DB: Database> PoolOptions<DB> {
141141
self
142142
}
143143

144+
/// Get the maximum number of connections that this pool should maintain
145+
pub fn get_max_connections(&self) -> u32 {
146+
self.max_connections
147+
}
148+
149+
/// Set the amount of time to attempt connecting to the database.
150+
///
151+
/// If this timeout elapses, [`Pool::acquire`] will return an error.
152+
pub fn connect_timeout(mut self, timeout: Duration) -> Self {
153+
self.connect_timeout = timeout;
154+
self
155+
}
156+
157+
/// Get the amount of time to attempt connecting to the database.
158+
pub fn get_connect_timeout(&self) -> Duration {
159+
self.connect_timeout
160+
}
161+
144162
/// Set the minimum number of connections to maintain at all times.
145163
///
146164
/// When the pool is built, this many connections will be automatically spun up.
@@ -168,6 +186,11 @@ impl<DB: Database> PoolOptions<DB> {
168186
self
169187
}
170188

189+
/// Get the minimum number of connections to maintain at all times.
190+
pub fn get_min_connections(&self) -> u32 {
191+
self.min_connections
192+
}
193+
171194
/// Set the maximum amount of time to spend waiting for a connection in [`Pool::acquire()`].
172195
///
173196
/// Caps the total amount of time `Pool::acquire()` can spend waiting across multiple phases:
@@ -186,6 +209,11 @@ impl<DB: Database> PoolOptions<DB> {
186209
self
187210
}
188211

212+
/// Get the maximum amount of time to spend waiting for a connection in [`Pool::acquire()`].
213+
pub fn get_acquire_timeout(&self) -> Duration {
214+
self.acquire_timeout
215+
}
216+
189217
/// Set the maximum lifetime of individual connections.
190218
///
191219
/// Any connection with a lifetime greater than this will be closed.
@@ -205,6 +233,11 @@ impl<DB: Database> PoolOptions<DB> {
205233
self
206234
}
207235

236+
/// Get the maximum lifetime of individual connections.
237+
pub fn get_max_lifetime(&self) -> Option<Duration> {
238+
self.max_lifetime
239+
}
240+
208241
/// Set a maximum idle duration for individual connections.
209242
///
210243
/// Any connection that remains in the idle queue longer than this will be closed.
@@ -215,6 +248,11 @@ impl<DB: Database> PoolOptions<DB> {
215248
self
216249
}
217250

251+
/// Get the maximum idle duration for individual connections.
252+
pub fn get_idle_timeout(&self) -> Option<Duration> {
253+
self.idle_timeout
254+
}
255+
218256
/// If true, the health of a connection will be verified by a call to [`Connection::ping`]
219257
/// before returning the connection.
220258
///
@@ -224,6 +262,11 @@ impl<DB: Database> PoolOptions<DB> {
224262
self
225263
}
226264

265+
/// Get's whether `test_before_acquire` is currently set.
266+
pub fn get_test_before_acquire(&self) -> bool {
267+
self.test_before_acquire
268+
}
269+
227270
/// If set to `true`, calls to `acquire()` are fair and connections are issued
228271
/// in first-come-first-serve order. If `false`, "drive-by" tasks may steal idle connections
229272
/// ahead of tasks that have been waiting.

0 commit comments

Comments
 (0)