Skip to content

Commit

Permalink
Expose connect_options for initialized pools and database on the …
Browse files Browse the repository at this point in the history
…`PgConnectOptions` (#1897)

* Expose ConnectOptions

* Expose PoolOptions
  • Loading branch information
Nukesor committed Jun 16, 2022
1 parent 664d576 commit 21590d5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sqlx-core/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,16 @@ impl<DB: Database> Pool<DB> {
pub fn num_idle(&self) -> usize {
self.0.num_idle()
}

/// Get the connection options for this pool
pub fn connect_options(&self) -> &<DB::Connection as Connection>::Options {
&self.0.connect_options
}

/// Get the options for this pool
pub fn options(&self) -> &PoolOptions<DB> {
&self.0.options
}
}

#[cfg(all(
Expand Down
14 changes: 14 additions & 0 deletions sqlx-core/src/postgres/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,20 @@ impl PgConnectOptions {
self
}

/// Get the current database name.
///
/// # Example
///
/// ```rust
/// # use sqlx_core::postgres::PgConnectOptions;
/// let options = PgConnectOptions::new()
/// .database("postgres");
/// assert!(options.get_database().is_some());
/// ```
pub fn get_database(&self) -> Option<&str> {
self.database.as_deref()
}

/// Sets whether or with what priority a secure SSL TCP/IP connection will be negotiated
/// with the server.
///
Expand Down

0 comments on commit 21590d5

Please sign in to comment.