Add a get_database method (#2871)

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 = ?;
```
This commit is contained in:
Shift Right Once 2023-11-16 09:22:15 +10:00 committed by GitHub
parent 6ecb5831f4
commit 9a6ebd0a74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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.
///