mirror of https://github.com/dbcli/pgcli
Add completion auto-refresh for create and alter statement.
This commit is contained in:
parent
a8d0c78214
commit
6633ca882d
9
TODO
9
TODO
|
@ -1,6 +1,7 @@
|
|||
* [X] Add multi-line support.
|
||||
* [] Refresh tables and columns after a create table and alter table.
|
||||
* [] Vendor in tabulate.
|
||||
* [] Show only table sensitive columns.
|
||||
* [] Add logging.
|
||||
* [] Add some tests. Sanity, Unit, Completion, Config.
|
||||
* [ ] Add a new trigger for M-/ that does dumb completion.
|
||||
* [] Improve the smart completion for Insert statement.
|
||||
* [] Improve the smart completion for Update statement.
|
||||
|
@ -15,7 +16,9 @@
|
|||
* [] Create a better framework for adding special commands.
|
||||
* A dict with special commands as keys.
|
||||
* The value can either be a string or a callable.
|
||||
* [o] Get new table style merged back to tabulate.
|
||||
* [X] Get new table style merged back to tabulate.
|
||||
* [X] Add multi-line support.
|
||||
* [X] Refresh tables and columns after a create table and alter table.
|
||||
* [x] Add a lot more SQL keywords to auto-completion (Read the postgres docs)
|
||||
* [X] Deal with commands that have no return rows (such as delete, begin transaction etc).
|
||||
* [X] Update README.
|
||||
|
|
|
@ -7,18 +7,19 @@ import os.path
|
|||
import click
|
||||
|
||||
from prompt_toolkit import CommandLineInterface, AbortAction, Exit
|
||||
from prompt_toolkit.layout import Layout
|
||||
from prompt_toolkit.layout.prompt import DefaultPrompt
|
||||
from prompt_toolkit.layout.menus import CompletionsMenu
|
||||
from prompt_toolkit.history import FileHistory
|
||||
from pygments.lexers.sql import SqlLexer
|
||||
from tabulate import tabulate
|
||||
import sqlparse
|
||||
|
||||
from .pgcompleter import PGCompleter
|
||||
from .pgstyle import PGStyle
|
||||
from .pgexecute import PGExecute
|
||||
from .pgline import PGLine
|
||||
from .config import write_default_config, load_config
|
||||
from prompt_toolkit.layout import Layout
|
||||
from prompt_toolkit.layout.prompt import DefaultPrompt
|
||||
from prompt_toolkit.layout.menus import CompletionsMenu
|
||||
from prompt_toolkit.history import FileHistory
|
||||
|
||||
from pygments.lexers.sql import SqlLexer
|
||||
from tabulate import tabulate
|
||||
|
||||
@click.command()
|
||||
@click.option('-h', '--host', default='localhost')
|
||||
|
@ -66,5 +67,14 @@ def cli(database, user, password, host, port):
|
|||
print(status)
|
||||
except Exception as e:
|
||||
click.secho(e.message, err=True, fg='red')
|
||||
|
||||
# Refresh the table names and column names if necessary.
|
||||
if need_completion_refresh(document.text):
|
||||
completer.extend_table_names(pgexecute.tables())
|
||||
completer.extend_column_names(pgexecute.all_columns())
|
||||
except Exit:
|
||||
print ('GoodBye!')
|
||||
|
||||
def need_completion_refresh(sql):
|
||||
parsed = sqlparse.parse(sql)
|
||||
return parsed and parsed[0].token_first().value in ('alter', 'create')
|
||||
|
|
|
@ -219,7 +219,7 @@ def describe_one_table_details(cur, schema_name, relation_name, oid, verbose):
|
|||
|
||||
# Make Footers
|
||||
|
||||
return res, headers, "blah"
|
||||
return cells, headers, "blah"
|
||||
|
||||
def sql_name_pattern(pattern):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue