athena_rs 3.18.0

Hyper performant polyglot Database driver
Documentation
//! `/schema` response orchestration helpers.
//!
//! This module composes overview loader rows with presentation/error mapping.

use actix_web::HttpResponse;
use sqlx::{Pool, Postgres};

use super::super::catalog_errors::schema_processed_query_error;
use super::super::catalog_service_loader::load_schema_overview_rows;
use super::super::presentation::schema_overview as build_schema_overview_payload;

/// Builds a `/schema` response for one validated schema name.
pub(in super::super) async fn schema_overview_response(
    pool: &Pool<Postgres>,
    schema_name: String,
) -> HttpResponse {
    let overview_rows = match load_schema_overview_rows(pool, schema_name.as_str()).await {
        Ok(rows) => rows,
        Err(err) => return schema_processed_query_error(&err, Some(schema_name.as_str())),
    };

    HttpResponse::Ok().json(build_schema_overview_payload(
        schema_name,
        overview_rows.relations,
        overview_rows.columns,
    ))
}