mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	refactor(drainer): removed router dependency from drainer (#209)
This commit is contained in:
		
							
								
								
									
										34
									
								
								crates/drainer/src/connection.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								crates/drainer/src/connection.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,34 @@ | ||||
| use async_bb8_diesel::ConnectionManager; | ||||
| use bb8::PooledConnection; | ||||
| use diesel::PgConnection; | ||||
|  | ||||
| use crate::settings::Database; | ||||
|  | ||||
| pub type PgPool = bb8::Pool<async_bb8_diesel::ConnectionManager<PgConnection>>; | ||||
|  | ||||
| pub async fn redis_connection( | ||||
|     conf: &crate::settings::Settings, | ||||
| ) -> redis_interface::RedisConnectionPool { | ||||
|     redis_interface::RedisConnectionPool::new(&conf.redis).await | ||||
| } | ||||
|  | ||||
| #[allow(clippy::expect_used)] | ||||
| pub async fn diesel_make_pg_pool(database: &Database, _test_transaction: bool) -> PgPool { | ||||
|     let database_url = format!( | ||||
|         "postgres://{}:{}@{}:{}/{}", | ||||
|         database.username, database.password, database.host, database.port, database.dbname | ||||
|     ); | ||||
|     let manager = async_bb8_diesel::ConnectionManager::<PgConnection>::new(database_url); | ||||
|     let pool = bb8::Pool::builder().max_size(database.pool_size); | ||||
|  | ||||
|     pool.build(manager) | ||||
|         .await | ||||
|         .expect("Failed to create PostgreSQL connection pool") | ||||
| } | ||||
|  | ||||
| #[allow(clippy::expect_used)] | ||||
| pub async fn pg_connection(pool: &PgPool) -> PooledConnection<ConnectionManager<PgConnection>> { | ||||
|     pool.get() | ||||
|         .await | ||||
|         .expect("Couldn't retrieve PostgreSQL connection") | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Abhishek
					Abhishek