athena_rs 3.23.0

Hyper performant polyglot Database driver
Documentation
//! Schema-catalog column fetch execution facade.
//!
//! This module keeps a stable `fetch_columns` entrypoint while concrete SQL
//! execution paths are split by filter scope:
//! - `schema_filters` for schema-scoped fetches
//! - `table_filters` for table-only fetches
//! - `catalog_filters` for unscoped catalog scans

mod catalog_filters;
mod schema_filters;
mod table_filters;

use sqlx::postgres::PgPool;

use super::service_contracts::SchemaColumnRecord;
use super::service_row_mapper::map_column_rows;

/// Fetches column metadata from `information_schema.columns`.
///
/// Supports optional `schema_filter` and `table_filter`. When
/// `exclude_system_schemas` is true, system schemas are filtered out for broad
/// scans.
pub async fn fetch_columns(
    pool: &PgPool,
    schema_filter: Option<&str>,
    table_filter: Option<&str>,
    exclude_system_schemas: bool,
) -> Result<Vec<SchemaColumnRecord>, sqlx::Error> {
    let rows = match (schema_filter, table_filter, exclude_system_schemas) {
        (Some(schema), Some(table), _) => {
            schema_filters::fetch_columns_for_schema_table(
                pool,
                schema,
                table,
                exclude_system_schemas,
            )
            .await?
        }
        (Some(schema), None, _) => {
            schema_filters::fetch_columns_for_schema(pool, schema, exclude_system_schemas).await?
        }
        (None, Some(table), _) => {
            table_filters::fetch_columns_for_table(pool, table, exclude_system_schemas).await?
        }
        (None, None, _) => {
            catalog_filters::fetch_columns_for_catalog(pool, exclude_system_schemas).await?
        }
    };

    Ok(map_column_rows(rows))
}