mirror of
https://github.com/flibusta-apps/book_library_server.git
synced 2025-12-06 07:05:36 +01:00
22 lines
540 B
Rust
22 lines
540 B
Rust
use crate::config::CONFIG;
|
|
|
|
use sqlx::{postgres::PgPoolOptions, PgPool};
|
|
|
|
pub async fn get_postgres_pool() -> PgPool {
|
|
let database_url: String = format!(
|
|
"postgresql://{}:{}@{}:{}/{}",
|
|
CONFIG.postgres_user,
|
|
CONFIG.postgres_password,
|
|
CONFIG.postgres_host,
|
|
CONFIG.postgres_port,
|
|
CONFIG.postgres_db
|
|
);
|
|
|
|
PgPoolOptions::new()
|
|
.max_connections(10)
|
|
.acquire_timeout(std::time::Duration::from_secs(300))
|
|
.connect(&database_url)
|
|
.await
|
|
.unwrap()
|
|
}
|