mirror of
https://github.com/dbcli/pgcli.git
synced 2024-10-06 10:17:15 +03:00
Add Exit and Quit commands.
This commit is contained in:
parent
6633ca882d
commit
091d7f97f7
3
TODO
3
TODO
@ -1,7 +1,10 @@
|
||||
* [] Vendor in tabulate.
|
||||
* [] Add MySQL commands (use, describe etc)
|
||||
* [X] Add exit keyword.
|
||||
* [] Show only table sensitive columns.
|
||||
* [] Add logging.
|
||||
* [] Add some tests. Sanity, Unit, Completion, Config.
|
||||
* [] Setup the pgcli.com website.
|
||||
* [ ] Add a new trigger for M-/ that does dumb completion.
|
||||
* [] Improve the smart completion for Insert statement.
|
||||
* [] Improve the smart completion for Update statement.
|
||||
|
@ -60,6 +60,13 @@ def cli(database, user, password, host, port):
|
||||
try:
|
||||
while True:
|
||||
document = cli.read_input(on_exit=AbortAction.RAISE_EXCEPTION)
|
||||
|
||||
# The reason we check here instead of inside the pgexecute is
|
||||
# because we want to raise the Exit exception which will be caught
|
||||
# by the try/except block that wraps the pgexecute.run() statement.
|
||||
if (document.text.strip() == 'exit'
|
||||
or document.text.strip() == 'quit'):
|
||||
raise Exit
|
||||
try:
|
||||
rows, headers, status = pgexecute.run(document.text)
|
||||
if rows:
|
||||
|
@ -10,7 +10,7 @@ class PGLine(Line):
|
||||
Dynamically determine whether we're in multiline mode.
|
||||
"""
|
||||
|
||||
if self.text.rstrip().endswith(';'):
|
||||
if _multiline_exception(self.text):
|
||||
return False
|
||||
|
||||
return True
|
||||
@ -18,3 +18,12 @@ class PGLine(Line):
|
||||
@is_multiline.setter
|
||||
def is_multiline(self, value):
|
||||
pass
|
||||
|
||||
|
||||
def _multiline_exception(text):
|
||||
text = text.strip()
|
||||
return (text.startswith('\\') or # Special Command
|
||||
text.endswith(';') or # Ended with a semi-colon
|
||||
(text == 'exit') or # Exit and Quit doesn't need semi-colon
|
||||
(text == 'quit')
|
||||
)
|
||||
|
@ -25,15 +25,21 @@ def describe_table_details(cur, pattern, verbose):
|
||||
"""
|
||||
Returns (rows, headers, status)
|
||||
"""
|
||||
schema, relname = sql_name_pattern(pattern)
|
||||
|
||||
sql = '''SELECT c.oid, n.nspname, c.relname FROM pg_catalog.pg_class c LEFT
|
||||
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace '''
|
||||
if relname:
|
||||
sql += ' WHERE c.relname ~ ' + relname
|
||||
if schema:
|
||||
sql += ' AND n.nspname ~ ' + schema
|
||||
|
||||
sql += ' AND pg_catalog.pg_table_is_visible(c.oid) '
|
||||
if pattern:
|
||||
schema, relname = sql_name_pattern(pattern)
|
||||
if relname:
|
||||
sql += ' WHERE c.relname ~ ' + relname
|
||||
if schema:
|
||||
sql += ' AND n.nspname ~ ' + schema
|
||||
sql += ' AND pg_catalog.pg_table_is_visible(c.oid) '
|
||||
else:
|
||||
sql += """WHERE n.nspname <> 'pg_catalog'
|
||||
AND n.nspname <> 'information_schema'"""
|
||||
|
||||
sql += ' ORDER BY 2,3'
|
||||
|
||||
# Execute the sql, get the results and call describe_one_table_details on each table.
|
||||
@ -248,4 +254,5 @@ if __name__ == '__main__':
|
||||
import psycopg2
|
||||
con = psycopg2.connect(database='misago_testforum')
|
||||
cur = con.cursor()
|
||||
print describe_table_details(cur, 'django_migrations', False)
|
||||
#print describe_table_details(cur, 'django_migrations', False)
|
||||
print describe_table_details(cur, None, False)
|
||||
|
Loading…
Reference in New Issue
Block a user