@@ -46,29 +46,6 @@ impl DatabaseConnection {
4646 }
4747 }
4848
49- /// Creates a connection with optimized settings for better performance
50- pub async fn new_optimized (
51- datasource : & DatasourceConfig ,
52- ) -> Result < DatabaseConnection , Box < dyn Error + Send + Sync > > {
53- // Use optimized connection settings for better performance
54- match datasource. get_db_type ( ) {
55- #[ cfg( feature = "postgres" ) ]
56- DatabaseType :: PostgreSql => {
57- connection_helpers:: create_postgres_connection_optimized ( datasource) . await
58- }
59-
60- #[ cfg( feature = "mssql" ) ]
61- DatabaseType :: SqlServer => {
62- connection_helpers:: create_sqlserver_connection_optimized ( datasource) . await
63- }
64-
65- #[ cfg( feature = "mysql" ) ]
66- DatabaseType :: MySQL => {
67- connection_helpers:: create_mysql_connection_optimized ( datasource) . await
68- }
69- }
70- }
71-
7249 pub fn get_db_type ( & self ) -> DatabaseType {
7350 match self {
7451 #[ cfg( feature = "postgres" ) ]
@@ -116,28 +93,6 @@ mod connection_helpers {
11693 datasource : & DatasourceConfig ,
11794 ) -> Result < DatabaseConnection , Box < dyn Error + Send + Sync > > {
11895 let ( user, password) = auth:: extract_postgres_auth ( & datasource. auth ) ?;
119- let url = connection_string ( user, password, datasource) ;
120-
121- let ( client, connection) = tokio_postgres:: connect ( & url, tokio_postgres:: NoTls ) . await ?;
122-
123- tokio:: spawn ( async move {
124- if let Err ( e) = connection. await {
125- eprintln ! (
126- "An error occurred while trying to connect to the PostgreSQL database: {e}"
127- ) ;
128- }
129- } ) ;
130-
131- Ok ( DatabaseConnection :: Postgres ( PostgreSqlConnection {
132- client,
133- } ) )
134- }
135-
136- #[ cfg( feature = "postgres" ) ]
137- pub async fn create_postgres_connection_optimized (
138- datasource : & DatasourceConfig ,
139- ) -> Result < DatabaseConnection , Box < dyn Error + Send + Sync > > {
140- let ( user, password) = auth:: extract_postgres_auth ( & datasource. auth ) ?;
14196
14297 // Use optimized connection settings
14398 let mut config = tokio_postgres:: Config :: new ( ) ;
@@ -196,62 +151,18 @@ mod connection_helpers {
196151 } ) )
197152 }
198153
199- #[ cfg( feature = "mssql" ) ]
200- pub async fn create_sqlserver_connection_optimized (
201- datasource : & DatasourceConfig ,
202- ) -> Result < DatabaseConnection , Box < dyn Error + Send + Sync > > {
203- use async_std:: net:: TcpStream ;
204- let mut tiberius_config = tiberius:: Config :: new ( ) ;
205-
206- tiberius_config. host ( & datasource. properties . host ) ;
207- tiberius_config. port ( datasource. properties . port . unwrap_or_default ( ) ) ;
208- tiberius_config. database ( & datasource. properties . db_name ) ;
209-
210- let auth_config = auth:: extract_mssql_auth ( & datasource. auth ) ?;
211- tiberius_config. authentication ( auth_config) ;
212- tiberius_config. trust_cert ( ) ; // TODO: this should be specifically set via user input
213- tiberius_config. encryption ( tiberius:: EncryptionLevel :: NotSupported ) ; // TODO: user input
214-
215- // Optimize connection settings for better performance
216- // Note: Tiberius doesn't expose these settings directly
217- // The optimization is handled at the TCP level
218-
219- let tcp = TcpStream :: connect ( tiberius_config. get_addr ( ) ) . await ?;
220- tcp. set_nodelay ( true ) ?;
221-
222- let client = tiberius:: Client :: connect ( tiberius_config, tcp) . await ?;
223-
224- Ok ( DatabaseConnection :: SqlServer ( SqlServerConnection {
225- client : Box :: leak ( Box :: new ( client) ) ,
226- } ) )
227- }
228-
229154 #[ cfg( feature = "mysql" ) ]
230155 pub async fn create_mysql_connection (
231156 datasource : & DatasourceConfig ,
232157 ) -> Result < DatabaseConnection , Box < dyn Error + Send + Sync > > {
233158 use mysql_async:: Pool ;
234159
235- let ( user, password) = auth:: extract_mysql_auth ( & datasource. auth ) ?;
236- let url = connection_string ( user, password, datasource) ;
237- let mysql_connection = Pool :: from_url ( url) ?;
238-
239- Ok ( DatabaseConnection :: MySQL ( MysqlConnection {
240- client : mysql_connection,
241- } ) )
242- }
243-
244- #[ cfg( feature = "mysql" ) ]
245- pub async fn create_mysql_connection_optimized (
246- datasource : & DatasourceConfig ,
247- ) -> Result < DatabaseConnection , Box < dyn Error + Send + Sync > > {
248- use mysql_async:: Pool ;
249-
250160 let ( user, password) = auth:: extract_mysql_auth ( & datasource. auth ) ?;
251161 let url = connection_string ( user, password, datasource) ;
252162
253163 // Use optimized pool settings for better performance
254- let _pool_constraints = mysql_async:: PoolConstraints :: new ( 2 , 10 ) . unwrap ( ) ;
164+ let _pool_constraints = mysql_async:: PoolConstraints :: new ( 2 , 10 )
165+ . ok_or_else ( || "Failure launching the MySQL pool" ) ?;
255166
256167 let mysql_connection = Pool :: from_url ( url) ?;
257168
0 commit comments