athena_rs 3.26.3

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

mod catalog_filters;
mod schema_filters;

use sqlx::postgres::PgPool;

use super::service_contracts::SchemaRelationRecord;
use super::service_row_mapper::map_relation_rows;

/// Fetches relation metadata from `information_schema.tables`.
///
/// `schema_filter` narrows results to one schema. `exclude_system_schemas`
/// filters out `information_schema` and `pg_catalog` when true.
pub async fn fetch_relations(
    pool: &PgPool,
    schema_filter: Option<&str>,
    exclude_system_schemas: bool,
) -> Result<Vec<SchemaRelationRecord>, sqlx::Error> {
    let rows = match schema_filter {
        Some(schema) => {
            schema_filters::fetch_relations_for_schema(pool, schema, exclude_system_schemas).await?
        }
        None => catalog_filters::fetch_relations_for_catalog(pool, exclude_system_schemas).await?,
    };

    Ok(map_relation_rows(rows))
}