starchart/src/db.rs

18 lines
502 B
Rust

use sqlx::{postgres::PgPoolOptions, PgPool};
use tokio::sync::OnceCell;
static DB_CONN: OnceCell<PgPool> = OnceCell::const_new();
pub async fn pool() -> &'static sqlx::postgres::PgPool {
DB_CONN
.get_or_init(|| async {
PgPoolOptions::new()
.min_connections(1)
.max_connections(5)
.connect(&crate::config::CONFIG.db_url)
.await
.expect("failed to connect to database")
})
.await
}