mirror of
https://github.com/dbcli/pgcli.git
synced 2024-10-04 01:08:51 +03:00
Add pretty printing of table data.
This commit is contained in:
parent
4fa728e929
commit
d3f88eb65c
2
TODO
2
TODO
@ -1,4 +1,4 @@
|
||||
* [ ] Prettify the output into nice columnar tables.
|
||||
* [X] Prettify the output into nice columnar tables.
|
||||
* [ ] Add a lot more SQL keywords to auto-completion.
|
||||
* [ ] Add context sensitive auto-completion.
|
||||
* Check how sqlpython is doing it.
|
||||
|
6
pgcli.py
6
pgcli.py
@ -16,7 +16,8 @@ from prompt_toolkit.layout.prompt import DefaultPrompt
|
||||
from prompt_toolkit.layout.menus import CompletionsMenu
|
||||
from prompt_toolkit.history import FileHistory
|
||||
|
||||
from pygments.lexers import SqlLexer
|
||||
from pygments.lexers.sql import SqlLexer
|
||||
from tabulate import tabulate
|
||||
|
||||
@click.command()
|
||||
@click.option('-h', '--host', default='localhost')
|
||||
@ -45,7 +46,8 @@ def pgcli(database, user, password, host, port):
|
||||
while True:
|
||||
document = cli.read_input(on_exit=AbortAction.RAISE_EXCEPTION)
|
||||
try:
|
||||
print(pgexecute.run(document.text))
|
||||
print(tabulate(*pgexecute.run(document.text),
|
||||
tablefmt='orgtbl'))
|
||||
except Exception as e:
|
||||
click.secho("Does not compute!", fg='red')
|
||||
click.secho(e.message, err=True, fg='red')
|
||||
|
@ -21,7 +21,8 @@ class PGExecute(object):
|
||||
cur.execute(self.special_commands[sql])
|
||||
else:
|
||||
cur.execute(sql)
|
||||
return cur.fetchall()
|
||||
headers = [x[0] for x in cur.description]
|
||||
return cur.fetchall(), headers
|
||||
|
||||
def tables(self):
|
||||
with self.conn.cursor() as cur:
|
||||
|
Loading…
Reference in New Issue
Block a user