Skip to main content

schema_reverse_engineer/postgres/
tables.rs

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