+
Skip to content

Conversation

Huliiiiii
Copy link
Member

@Huliiiiii
Copy link
Member Author

@chungwong What do you think of this API?

@chungwong
Copy link

Originally I thought impl core::fmt::Debug for ConnectOptions is quite annoying and I went on the journey and see if the following is feasible.

diff --git a/src/driver/sqlx_mysql.rs b/src/driver/sqlx_mysql.rs
index 872bc1f5..505a0bed 100644
--- a/src/driver/sqlx_mysql.rs
+++ b/src/driver/sqlx_mysql.rs
@@ -60,6 +60,17 @@ impl SqlxMySqlConnector {
     /// Add configuration options for the MySQL database
     #[instrument(level = "trace")]
     pub async fn connect(options: ConnectOptions) -> Result<DatabaseConnection, DbErr> {
+        Self::connect_and_then(options, |o| o).await
+    }
+
+    #[instrument(level = "trace")]
+    pub async fn connect_and_then<F>(
+        options: ConnectOptions,
+        and_then: F,
+    ) -> Result<DatabaseConnection, DbErr>
+    where
+        F: FnOnce(MySqlConnectOptions) -> MySqlConnectOptions + std::fmt::Debug,
+    {
         let mut opt = options
             .url
             .parse::<MySqlConnectOptions>()

And no, FnOnce and its friends don't implement Debug and it won't work. Now I might understand why you went with *_opts_fn

@tyt2y3 tyt2y3 merged commit 39121d0 into SeaQL:1.1.x Sep 23, 2025
34 of 36 checks passed
tyt2y3 pushed a commit that referenced this pull request Sep 23, 2025
* Support map sqlx connect options

* Add derive_more to simplify debug implementation
@Huliiiiii Huliiiiii deleted the conn-opt branch September 23, 2025 21:55
Copy link

github-actions bot commented Oct 9, 2025

🎉 Released In 1.1.17 🎉

Thank you everyone for the contribution!
This feature is now available in the latest release. Now is a good time to upgrade!
Your participation is what makes us unique; your adoption is what drives us forward.
You can support SeaQL 🌊 by starring our repos, sharing our libraries and becoming a sponsor ⭐.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support adding connection opts to sqlx::{Pg,MySql,Sqlite}ConnectOptions

3 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载