From e371dd2f952645e41cb0e30bdb391d2f3c7fcad2 Mon Sep 17 00:00:00 2001 From: Jibao Mansaray Date: Fri, 10 Nov 2023 04:54:34 +0000 Subject: [PATCH] Add a `get_database` method 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 7729d8e184..b4fe540751 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. ///