athena_rs 3.26.3

Hyper performant polyglot Database driver
//! Constraint fetch execution for schema catalog introspection.
//!
//! This module owns direct execution of unique-constraint catalog queries and
//! row mapping.

use sqlx::postgres::PgPool;

use super::service_contracts::SchemaConstraintRecord;
use super::service_queries::unique_constraints_query;
use super::service_row_mapper::map_unique_constraint_rows;

/// Fetches unique-constraint column rows for one table.
pub async fn fetch_unique_constraints(
    pool: &PgPool,
    table_name: &str,
    table_schema: &str,
) -> Result<Vec<SchemaConstraintRecord>, sqlx::Error> {
    let rows = sqlx::query(unique_constraints_query())
        .bind(table_name)
        .bind(table_schema)
        .fetch_all(pool)
        .await?;

    Ok(map_unique_constraint_rows(rows))
}