Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/database/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{ExecuteResult, Pool, TableRow, RECORDS_LIMIT_PER_PAGE};
use async_trait::async_trait;
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
use database_tree::{Child, Database, Schema, Table};
use futures::TryStreamExt;
use futures::{StreamExt, TryStreamExt};
use itertools::Itertools;
use sqlx::postgres::{PgColumn, PgPool, PgPoolOptions, PgRow};
use sqlx::{Column as _, Row as _, TypeInfo as _};
Expand Down Expand Up @@ -206,20 +206,30 @@ impl Pool for PostgresPool {
}

async fn get_tables(&self, database: String) -> anyhow::Result<Vec<Child>> {
let mut rows =
let tables =
sqlx::query("SELECT * FROM information_schema.tables WHERE table_catalog = $1")
.bind(database)
.map(|row: PgRow| Table {
name: row.get("table_name"),
create_time: None,
update_time: None,
engine: None,
schema: row.get("table_schema"),
})
.fetch(&self.pool);
let mut tables = Vec::new();
while let Some(row) = rows.try_next().await? {
tables.push(Table {
name: row.try_get("table_name")?,

let mat_views = sqlx::query("SELECT * FROM pg_matviews")
.map(|row: PgRow| Table {
name: row.get("matviewname"),
create_time: None,
update_time: None,
engine: None,
schema: row.try_get("table_schema")?,
schema: row.get("schemaname"),
})
}
.fetch(&self.pool);

let tables: Vec<Table> = tables.chain(mat_views).try_collect().await?;

let mut schemas = vec![];
for (key, group) in &tables
.iter()
Expand Down