athena_rs 3.18.0

Hyper performant polyglot Database driver
Documentation
//! Snapshot-query rows result assembly for `/debug/schema`.
//!
//! This module maps relation/column query results into one snapshot-row result
//! while delegating successful row-contract handoff to
//! `debug_snapshot_queries_result_output_handoff_assembly`.

use super::debug_snapshot_contracts::LoggingSchemaSnapshotRows;
use super::debug_snapshot_error::LoggingSchemaSnapshotError;
use super::debug_snapshot_queries_result_assembly_input_contracts::LoggingSchemaSnapshotRowsResultAssemblyInput;
use super::debug_snapshot_queries_result_output_handoff_assembly::build_debug_snapshot_query_rows_output_handoff_from_result_assembly;
use super::debug_snapshot_queries_result_output_handoff_input_contracts::LoggingSchemaSnapshotRowsResultOutputHandoffInput;

/// Builds one snapshot-row result from relation and column query results.
pub(super) fn build_logging_schema_snapshot_rows_result(
    input: LoggingSchemaSnapshotRowsResultAssemblyInput,
) -> Result<LoggingSchemaSnapshotRows, LoggingSchemaSnapshotError> {
    let LoggingSchemaSnapshotRowsResultAssemblyInput {
        relations_result,
        columns_result,
    } = input;
    let relations = relations_result?;
    let columns = columns_result?;

    Ok(
        build_debug_snapshot_query_rows_output_handoff_from_result_assembly(
            LoggingSchemaSnapshotRowsResultOutputHandoffInput { relations, columns },
        ),
    )
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::api::schema::debug_snapshot_queries_test_helpers::{
        assert_fetch_columns_snapshot_error_for_tests,
        assert_fetch_relations_snapshot_error_for_tests,
        assert_successful_snapshot_rows_result_for_tests,
        build_column_error_snapshot_rows_result_input_for_tests,
        build_relation_error_snapshot_rows_result_input_for_tests,
        build_successful_snapshot_rows_result_input_for_tests,
    };

    /// Maps successful relation/column query results into snapshot-row output.
    #[test]
    fn snapshot_queries_result_assembly_maps_success_to_snapshot_rows() {
        let result = build_logging_schema_snapshot_rows_result(
            build_successful_snapshot_rows_result_input_for_tests(),
        );
        assert_successful_snapshot_rows_result_for_tests(
            result,
            "snapshot queries result assembly",
        );
    }

    /// Preserves relation-query errors when assembling snapshot-row results.
    #[test]
    fn snapshot_queries_result_assembly_preserves_relation_error_details() {
        let result = build_logging_schema_snapshot_rows_result(
            build_relation_error_snapshot_rows_result_input_for_tests("relation query failed"),
        );
        assert_fetch_relations_snapshot_error_for_tests(
            result,
            Some("relation query failed"),
            "snapshot queries result assembly",
        );
    }

    /// Preserves column-query errors when assembling snapshot-row results.
    #[test]
    fn snapshot_queries_result_assembly_preserves_column_error_details() {
        let result = build_logging_schema_snapshot_rows_result(
            build_column_error_snapshot_rows_result_input_for_tests("column query failed"),
        );
        assert_fetch_columns_snapshot_error_for_tests(
            result,
            Some("column query failed"),
            "snapshot queries result assembly",
        );
    }
}