athena_rs 3.18.0

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

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

use super::super::catalog_errors::schema_internal_fetch_error;
use super::super::catalog_service_loader::load_schema_table_rows;
use super::super::presentation::schema_tables as build_schema_tables_payload;

/// Builds a `/schema/tables` response for a resolved schema client pool.
pub(in super::super) async fn schema_tables_response(pool: &Pool<Postgres>) -> HttpResponse {
    let relations = match load_schema_table_rows(pool).await {
        Ok(rows) => rows,
        Err(err) => return schema_internal_fetch_error("tables", &err),
    };

    HttpResponse::Ok().json(json!({ "tables": build_schema_tables_payload(relations) }))
}