use sqlx::{PgPool, Row};
pub(crate) async fn tables(pool: &PgPool) -> Result<Vec<String>, sqlx::Error> {
let rows = sqlx::query("SELECT table_name FROM information_schema.tables where table_schema not in ('information_schema', 'pg_catalog')")
.fetch_all(pool)
.await?;
let rows: Vec<String> = rows
.into_iter()
.map(|row| row.try_get("table_name").unwrap_or_default())
.collect();
Ok(rows)
}
pub(crate) async fn columns(table: &str, pool: &PgPool) -> Result<Vec<String>, sqlx::Error> {
let rows = sqlx::query("SELECT column_name FROM information_schema.columns WHERE table_schema not in ('information_schema', 'pg_catalog') AND table_name = $1")
.bind(table)
.fetch_all(pool).await?;
let rows: Vec<String> = rows
.into_iter()
.map(|row| row.try_get("column_name").unwrap_or_default())
.collect();
Ok(rows)
}