Skip to content

Commit 21590d5

Browse files
authored
Expose connect_options for initialized pools and database on the PgConnectOptions (#1897)
* Expose ConnectOptions * Expose PoolOptions
1 parent 664d576 commit 21590d5

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

sqlx-core/src/pool/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,16 @@ impl<DB: Database> Pool<DB> {
435435
pub fn num_idle(&self) -> usize {
436436
self.0.num_idle()
437437
}
438+
439+
/// Get the connection options for this pool
440+
pub fn connect_options(&self) -> &<DB::Connection as Connection>::Options {
441+
&self.0.connect_options
442+
}
443+
444+
/// Get the options for this pool
445+
pub fn options(&self) -> &PoolOptions<DB> {
446+
&self.0.options
447+
}
438448
}
439449

440450
#[cfg(all(

sqlx-core/src/postgres/options/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,20 @@ impl PgConnectOptions {
260260
self
261261
}
262262

263+
/// Get the current database name.
264+
///
265+
/// # Example
266+
///
267+
/// ```rust
268+
/// # use sqlx_core::postgres::PgConnectOptions;
269+
/// let options = PgConnectOptions::new()
270+
/// .database("postgres");
271+
/// assert!(options.get_database().is_some());
272+
/// ```
273+
pub fn get_database(&self) -> Option<&str> {
274+
self.database.as_deref()
275+
}
276+
263277
/// Sets whether or with what priority a secure SSL TCP/IP connection will be negotiated
264278
/// with the server.
265279
///

0 commit comments

Comments
 (0)