mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-16 06:12:37 -06:00
refactor: allow optional database in setup, use derived default
This commit is contained in:
@@ -3,14 +3,19 @@ use tracing::{info, warn};
|
||||
|
||||
pub type PgPool = Pool<Postgres>;
|
||||
|
||||
pub async fn create_pool(database_url: &str, max_connections: u32) -> PgPool {
|
||||
info!("Connecting to PostgreSQL");
|
||||
PgPoolOptions::new()
|
||||
.max_connections(max_connections)
|
||||
.connect(database_url)
|
||||
.await
|
||||
.unwrap_or_else(|e| {
|
||||
pub async fn create_pool(immediate: bool, database_url: &str, max_connections: u32) -> PgPool {
|
||||
info!(immediate, "Connecting to PostgreSQL");
|
||||
|
||||
let options = PgPoolOptions::new().max_connections(max_connections);
|
||||
|
||||
if immediate {
|
||||
options.connect(database_url).await.unwrap_or_else(|e| {
|
||||
warn!(error = %e, "Failed to connect to PostgreSQL");
|
||||
panic!("database connect failed: {}", e);
|
||||
})
|
||||
} else {
|
||||
options
|
||||
.connect_lazy(database_url)
|
||||
.expect("Failed to create lazy database pool")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user