blixt 0.5.0

Blixt core framework — compile-time templates, type-safe SQL, Datastar SSE integration
Documentation
use std::time::Duration;

use sqlx::PgPool;
use sqlx::postgres::PgPoolOptions;

use crate::config::Config;
use crate::error::{Error, Result};

/// Creates a PostgreSQL connection pool from the application configuration.
pub async fn create_pool(config: &Config) -> Result<PgPool> {
    let url = config
        .database_url()
        .ok_or_else(|| Error::Internal("DATABASE_URL not configured".into()))?;

    let pool = PgPoolOptions::new()
        .max_connections(10)
        .acquire_timeout(Duration::from_secs(5))
        .idle_timeout(Duration::from_secs(300))
        .connect(url)
        .await?;

    sqlx::query("SELECT 1").execute(&pool).await?;

    tracing::info!("database connection pool established");
    Ok(pool)
}