Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from psycopg2.extensions import cursor | ||
from rich.console import Console | ||
from rich.table import Column, Table | ||
|
||
|
||
def query_to_rich_table(cursor: cursor, query: str): | ||
cursor.execute(query) | ||
columns = [desc[0] for desc in cursor.description] | ||
data = cursor.fetchall() | ||
|
||
table = Table(show_header=True, header_style="bold magenta") | ||
for col in columns: | ||
table.add_column(col) | ||
|
||
for row in data: | ||
table.add_row(*[str(item) for item in row]) | ||
|
||
return table |