Skip to content

Commit

Permalink
add table size for postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed Dec 20, 2024
1 parent 55552ae commit 8207de7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/drivers/postgres/postgres-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface PostgresTableRow {
table_schema: string;
table_name: string;
table_type: string;
table_size: number;
}

interface PostgresColumnRow {
Expand Down Expand Up @@ -92,7 +93,7 @@ export default abstract class PostgresLikeDriver extends CommonSQLImplement {

const tableResult = (
await this.query(
"SELECT * FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'pg_catalog', 'pg_toast') AND table_type = 'BASE TABLE';"
"SELECT *, pg_total_relation_size(quote_ident(table_schema) || '.' || quote_ident(table_name)) AS table_size FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'pg_catalog', 'pg_toast') AND table_type = 'BASE TABLE';"
)
).rows as unknown as PostgresTableRow[];

Expand Down Expand Up @@ -145,6 +146,9 @@ WHERE
type: table.table_type === "BASE TABLE" ? "table" : "view",
tableName: table.table_name,
tableSchema: {
stats: {
sizeInByte: table.table_size,
},
columns: [],
constraints: [],
pk: [],
Expand Down

0 comments on commit 8207de7

Please sign in to comment.