From 9a6ebd0a74516bf0056cd98b90d72eeadd12eae2 Mon Sep 17 00:00:00 2001 From: Shift Right Once Date: Thu, 16 Nov 2023 09:22:15 +1000 Subject: [PATCH] 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 = ?; ``` --- sqlx-mysql/src/options/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sqlx-mysql/src/options/mod.rs b/sqlx-mysql/src/options/mod.rs index 7729d8e1..b4fe5407 100644 --- a/sqlx-mysql/src/options/mod.rs +++ b/sqlx-mysql/src/options/mod.rs @@ -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. ///