Skip to main content

schema_reverse_engineer/postgres/
tables.rs

1use crate::error::SchemaReverseEngineerError;
2use sqlx::PgPool;
3
4pub async fn list_tables(pool: &PgPool, db_schema: &str) -> Result<Vec<String>, SchemaReverseEngineerError> {
5    let rows: Vec<(String,)> = sqlx::query_as(
6        "SELECT table_name \
7         FROM information_schema.tables \
8         WHERE table_schema = $1 AND table_type = 'BASE TABLE' \
9         ORDER BY table_name",
10    )
11    .bind(db_schema)
12    .fetch_all(pool)
13    .await
14    .map_err(|e| SchemaReverseEngineerError::Introspection(e.to_string()))?;
15
16    Ok(rows.into_iter().map(|(name,)| name).collect())
17}