5757//! The connection manager lets you get connections to a particular database. Just give it a vector of connection configs to start
5858//!
5959//! ```
60- //! let manager = MultiConnectionManager::from (configs);
60+ //! let manager = MultiConnectionManager::new (configs);
6161//! ```
6262//! ### Get a connection whenever you need it
6363//!
@@ -180,6 +180,7 @@ impl ConnectionConfig {
180180 }
181181 }
182182
183+ #[ cfg( feature = "postgres" ) ]
183184 fn pg_conn_url ( & self ) -> String {
184185 match ( & self . options , & self . schema ) {
185186 ( None , None ) => format ! (
@@ -201,6 +202,7 @@ impl ConnectionConfig {
201202 }
202203 }
203204
205+ #[ cfg( feature = "mysql" ) ]
204206 fn mysql_conn_url ( & self ) -> String {
205207 // mysql considers schema and database name the same
206208 if let Some ( configs) = & self . options {
@@ -213,6 +215,7 @@ impl ConnectionConfig {
213215 format ! ( "{}/{}" , self . database_host_url, self . database_name)
214216 }
215217
218+ #[ cfg( feature = "sqlite" ) ]
216219 fn sqlite_conn_url ( & self ) -> String {
217220 // provide a file name, file URI or :memory:
218221 if self . database_host_url . eq ( ":memory:" ) {
@@ -232,7 +235,7 @@ impl MultiConnectionManager {
232235 let pool: MultiConnectionPool = match config. database {
233236 #[ cfg( feature = "postgres" ) ]
234237 DatabaseKind :: Postgres => {
235- let manager = ConnectionManager :: < PgConnection > :: new ( config. conn_url ( ) ) ;
238+ let manager = ConnectionManager :: < PgConnection > :: new ( config. pg_conn_url ( ) ) ;
236239 MultiConnectionPool :: Pg (
237240 Pool :: builder ( )
238241 . max_size ( config. connection_count )
@@ -245,7 +248,8 @@ impl MultiConnectionManager {
245248 }
246249 #[ cfg( feature = "mysql" ) ]
247250 DatabaseKind :: MySQL => {
248- let manager = ConnectionManager :: < MysqlConnection > :: new ( config. conn_url ( ) ) ;
251+ let manager =
252+ ConnectionManager :: < MysqlConnection > :: new ( config. mysql_conn_url ( ) ) ;
249253 MultiConnectionPool :: Mysql (
250254 Pool :: builder ( )
251255 . max_size ( config. connection_count )
@@ -258,7 +262,8 @@ impl MultiConnectionManager {
258262 }
259263 #[ cfg( feature = "sqlite" ) ]
260264 DatabaseKind :: SQLite => {
261- let manager = ConnectionManager :: < SqliteConnection > :: new ( config. conn_url ( ) ) ;
265+ let manager =
266+ ConnectionManager :: < SqliteConnection > :: new ( config. sqlite_conn_url ( ) ) ;
262267 MultiConnectionPool :: Sqlite (
263268 Pool :: builder ( )
264269 . max_size ( config. connection_count )
@@ -278,7 +283,7 @@ impl MultiConnectionManager {
278283 // hello darkness my old friend
279284 // This would have been easier in haskell
280285 #[ cfg( feature = "postgres" ) ]
281- pub fn get_pg_conn ( & self , name : & ' static str ) -> ResultConnection < PgConnection > {
286+ pub fn get_pg_conn ( & self , name : & str ) -> ResultConnection < PgConnection > {
282287 let conn = match self . get ( name) . ok_or ( McmError :: InvalidConnectionNameError {
283288 db : DatabaseKind :: Postgres ,
284289 conn_name : name. into ( ) ,
@@ -288,6 +293,7 @@ impl MultiConnectionManager {
288293 conn_name : name. into ( ) ,
289294 error : err. to_string ( ) ,
290295 } ) ?,
296+ #[ cfg( any( feature = "mysql" , feature = "sqlite" ) ) ]
291297 _ => {
292298 return Err ( McmError :: InvalidConnectionTypeError {
293299 db : DatabaseKind :: Postgres ,
@@ -298,7 +304,7 @@ impl MultiConnectionManager {
298304 }
299305
300306 #[ cfg( feature = "mysql" ) ]
301- pub fn get_mysql_conn ( & self , name : & ' static str ) -> ResultConnection < MysqlConnection > {
307+ pub fn get_mysql_conn ( & self , name : & str ) -> ResultConnection < MysqlConnection > {
302308 let conn = match self . get ( name) . ok_or ( McmError :: InvalidConnectionNameError {
303309 db : DatabaseKind :: MySQL ,
304310 conn_name : name. into ( ) ,
@@ -308,6 +314,7 @@ impl MultiConnectionManager {
308314 conn_name : name. into ( ) ,
309315 error : err. to_string ( ) ,
310316 } ) ?,
317+ #[ cfg( any( feature = "postgres" , feature = "sqlite" ) ) ]
311318 _ => {
312319 return Err ( McmError :: InvalidConnectionTypeError {
313320 db : DatabaseKind :: MySQL ,
@@ -318,7 +325,7 @@ impl MultiConnectionManager {
318325 }
319326
320327 #[ cfg( feature = "sqlite" ) ]
321- pub fn get_sqlite_conn ( & self , name : & ' static str ) -> ResultConnection < SqliteConnection > {
328+ pub fn get_sqlite_conn ( & self , name : & str ) -> ResultConnection < SqliteConnection > {
322329 let conn = match self . get ( name) . ok_or ( McmError :: InvalidConnectionNameError {
323330 db : DatabaseKind :: SQLite ,
324331 conn_name : name. into ( ) ,
@@ -328,6 +335,7 @@ impl MultiConnectionManager {
328335 conn_name : name. into ( ) ,
329336 error : err. to_string ( ) ,
330337 } ) ?,
338+ #[ cfg( any( feature = "postgres" , feature = "mysql" ) ) ]
331339 _ => {
332340 return Err ( McmError :: InvalidConnectionTypeError {
333341 db : DatabaseKind :: SQLite ,
0 commit comments