use fraiseql_core::db::postgres::{PoolPrewarmConfig, PostgresAdapter};
use super::ServerConfig;
pub async fn build_postgres_adapter(config: &ServerConfig) -> anyhow::Result<PostgresAdapter> {
let tls = config.postgres_tls().map_err(|e| anyhow::anyhow!(e))?;
tls.warn_if_unverified();
tracing::info!(
pool_min_size = config.pool_min_size,
pool_max_size = config.pool_max_size,
pool_timeout_secs = config.pool_timeout_secs,
postgres_ssl_mode = %tls.effective_mode(),
"Initializing PostgreSQL connection pool"
);
let adapter = PostgresAdapter::with_pool_config(
&config.database_url,
PoolPrewarmConfig {
min_size: config.pool_min_size,
max_size: config.pool_max_size,
timeout_secs: Some(config.pool_timeout_secs),
search_path: None,
tls,
read_replicas: config.read_replicas(),
max_streaming_reads: config.pool_max_streaming_reads,
vector_scan: config.vector_scan(),
},
)
.await?;
tracing::info!("PostgreSQL adapter ready");
Ok(adapter)
}