Skip to content

Commit

Permalink
Add a get_database method (#2871)
Browse files Browse the repository at this point in the history
The Postgres implementation has this method. It is also
helpful for queries that require the current datbase name.
example:

```sql
SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_name = ? &&
table_schema = ?;
```
  • Loading branch information
shiftrightonce authored Nov 15, 2023
1 parent 6ecb583 commit 9a6ebd0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sqlx-mysql/src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@ impl MySqlConnectOptions {
self
}

/// Get the current database name.
///
/// # Example
///
/// ```rust
/// # use sqlx_core::mysql::MySqlConnectOptions;
/// let options = MySqlConnectOptions::new()
/// .database("mysqldb");
/// 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 9a6ebd0

Please sign in to comment.