mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
35 lines
1.1 KiB
Rust
35 lines
1.1 KiB
Rust
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")
|
|
}
|