11use std:: { sync:: Arc , time:: Duration } ;
22
3+ #[ cfg( not( feature = "sync" ) ) ]
34#[ cfg( feature = "sqlx-mysql" ) ]
45use sqlx:: mysql:: MySqlConnectOptions ;
56#[ cfg( feature = "sqlx-postgres" ) ]
@@ -53,6 +54,19 @@ pub struct Database;
5354#[ cfg( feature = "sync" ) ]
5455type BoxFuture < ' a , T > = T ;
5556
57+ #[ cfg( feature = "sqlx-mysql" ) ]
58+ type MapMySqlPoolOptsFn =
59+ Arc < dyn Fn ( sqlx:: pool:: PoolOptions < sqlx:: MySql > ) -> sqlx:: pool:: PoolOptions < sqlx:: MySql > > ;
60+
61+ #[ cfg( feature = "sqlx-postgres" ) ]
62+ type MapPgPoolOptsFn =
63+ Arc < dyn Fn ( sqlx:: pool:: PoolOptions < sqlx:: Postgres > ) -> sqlx:: pool:: PoolOptions < sqlx:: Postgres > > ;
64+
65+ #[ cfg( feature = "sqlx-sqlite" ) ]
66+ type MapSqlitePoolOptsFn = Option <
67+ Arc < dyn Fn ( sqlx:: pool:: PoolOptions < sqlx:: Sqlite > ) -> sqlx:: pool:: PoolOptions < sqlx:: Sqlite > > ,
68+ > ;
69+
5670type AfterConnectCallback =
5771 Option < Arc < dyn Fn ( DatabaseConnection ) -> BoxFuture < ' static , Result < ( ) , DbErr > > + ' static > > ;
5872
@@ -99,6 +113,15 @@ pub struct ConnectOptions {
99113 #[ debug( skip) ]
100114 pub ( crate ) after_connect : AfterConnectCallback ,
101115
116+ #[ cfg( feature = "sqlx-mysql" ) ]
117+ #[ debug( skip) ]
118+ pub ( crate ) mysql_pool_opts_fn : Option < MapMySqlPoolOptsFn > ,
119+ #[ cfg( feature = "sqlx-postgres" ) ]
120+ #[ debug( skip) ]
121+ pub ( crate ) pg_pool_opts_fn : Option < MapPgPoolOptsFn > ,
122+ #[ cfg( feature = "sqlx-sqlite" ) ]
123+ #[ debug( skip) ]
124+ pub ( crate ) sqlite_pool_opts_fn : MapSqlitePoolOptsFn ,
102125 #[ cfg( feature = "sqlx-mysql" ) ]
103126 #[ debug( skip) ]
104127 pub ( crate ) mysql_opts_fn : Option < Arc < dyn Fn ( MySqlConnectOptions ) -> MySqlConnectOptions > > ,
@@ -219,6 +242,12 @@ impl ConnectOptions {
219242 connect_lazy : false ,
220243 after_connect : None ,
221244 #[ cfg( feature = "sqlx-mysql" ) ]
245+ mysql_pool_opts_fn : None ,
246+ #[ cfg( feature = "sqlx-postgres" ) ]
247+ pg_pool_opts_fn : None ,
248+ #[ cfg( feature = "sqlx-sqlite" ) ]
249+ sqlite_pool_opts_fn : None ,
250+ #[ cfg( feature = "sqlx-mysql" ) ]
222251 mysql_opts_fn : None ,
223252 #[ cfg( feature = "sqlx-postgres" ) ]
224253 pg_opts_fn : None ,
@@ -431,6 +460,19 @@ impl ConnectOptions {
431460 self
432461 }
433462
463+ #[ cfg( feature = "sqlx-mysql" ) ]
464+ #[ cfg_attr( docsrs, doc( cfg( feature = "sqlx-mysql" ) ) ) ]
465+ /// Apply a function to modify the underlying [`sqlx::pool::PoolOptions<sqlx::MySql>`]
466+ /// before creating the connection pool.
467+ pub fn map_sqlx_mysql_pool_opts < F > ( & mut self , f : F ) -> & mut Self
468+ where
469+ F : Fn ( sqlx:: pool:: PoolOptions < sqlx:: MySql > ) -> sqlx:: pool:: PoolOptions < sqlx:: MySql >
470+ + ' static ,
471+ {
472+ self . mysql_pool_opts_fn = Some ( Arc :: new ( f) ) ;
473+ self
474+ }
475+
434476 #[ cfg( feature = "sqlx-postgres" ) ]
435477 #[ cfg_attr( docsrs, doc( cfg( feature = "sqlx-postgres" ) ) ) ]
436478 /// Apply a function to modify the underlying [`PgConnectOptions`] before
@@ -443,6 +485,19 @@ impl ConnectOptions {
443485 self
444486 }
445487
488+ #[ cfg( feature = "sqlx-postgres" ) ]
489+ #[ cfg_attr( docsrs, doc( cfg( feature = "sqlx-postgres" ) ) ) ]
490+ /// Apply a function to modify the underlying [`sqlx::pool::PoolOptions<sqlx::Postgres>`]
491+ /// before creating the connection pool.
492+ pub fn map_sqlx_postgres_pool_opts < F > ( & mut self , f : F ) -> & mut Self
493+ where
494+ F : Fn ( sqlx:: pool:: PoolOptions < sqlx:: Postgres > ) -> sqlx:: pool:: PoolOptions < sqlx:: Postgres >
495+ + ' static ,
496+ {
497+ self . pg_pool_opts_fn = Some ( Arc :: new ( f) ) ;
498+ self
499+ }
500+
446501 #[ cfg( feature = "sqlx-sqlite" ) ]
447502 #[ cfg_attr( docsrs, doc( cfg( feature = "sqlx-sqlite" ) ) ) ]
448503 /// Apply a function to modify the underlying [`SqliteConnectOptions`] before
@@ -454,4 +509,17 @@ impl ConnectOptions {
454509 self . sqlite_opts_fn = Some ( Arc :: new ( f) ) ;
455510 self
456511 }
512+
513+ #[ cfg( feature = "sqlx-sqlite" ) ]
514+ #[ cfg_attr( docsrs, doc( cfg( feature = "sqlx-sqlite" ) ) ) ]
515+ /// Apply a function to modify the underlying [`sqlx::pool::PoolOptions<sqlx::Sqlite>`]
516+ /// before creating the connection pool.
517+ pub fn map_sqlx_sqlite_pool_opts < F > ( & mut self , f : F ) -> & mut Self
518+ where
519+ F : Fn ( sqlx:: pool:: PoolOptions < sqlx:: Sqlite > ) -> sqlx:: pool:: PoolOptions < sqlx:: Sqlite >
520+ + ' static ,
521+ {
522+ self . sqlite_pool_opts_fn = Some ( Arc :: new ( f) ) ;
523+ self
524+ }
457525}
0 commit comments