mirror of
https://github.com/dbcli/pgcli
synced 2024-06-16 01:42:23 +00:00
Edit last-run query in external editor.
This commit is contained in:
parent
81fb73f4b0
commit
c389f5371d
|
@ -8,6 +8,7 @@ Features:
|
|||
* Allow configurable character to be used for multi-line query continuations. (Thanks: `Owen Stephens`_)
|
||||
* Completions after ORDER BY and DISTINCT now take account of table aliases. (Thanks: `Owen Stephens`_)
|
||||
* Narrow keyword candidates based on previous keyword. (Thanks: `Étienne Bersac`_)
|
||||
* Opening an external editor will edit the last-run query. (Thanks: `Thomas Roten`_)
|
||||
|
||||
Bug fixes:
|
||||
----------
|
||||
|
@ -683,3 +684,4 @@ Improvements:
|
|||
.. _`Russell Davies`: https://github.com/russelldavies
|
||||
.. _`Dick Marinus`: https://github.com/meeuw
|
||||
.. _`Étienne Bersac`: https://github.com/bersace
|
||||
.. _`Thomas Roten`: https://github.com/tsroten
|
||||
|
|
|
@ -366,8 +366,9 @@ class PGCli(object):
|
|||
saved_callables = cli.application.pre_run_callables
|
||||
while special.editor_command(document.text):
|
||||
filename = special.get_filename(document.text)
|
||||
sql, message = special.open_external_editor(filename,
|
||||
sql=document.text)
|
||||
sql, message = special.open_external_editor(
|
||||
filename, sql=document.text,
|
||||
default_text=self.get_last_query() or '')
|
||||
if message:
|
||||
# Something went wrong. Raise an exception and bail.
|
||||
raise RuntimeError(message)
|
||||
|
@ -732,6 +733,11 @@ class PGCli(object):
|
|||
string = string.replace('\\n', "\n")
|
||||
return string
|
||||
|
||||
def get_last_query(self):
|
||||
"""Get the last query executed or None."""
|
||||
return self.query_history[-1][0] if self.query_history else None
|
||||
|
||||
|
||||
|
||||
@click.command()
|
||||
# Default host is '' so psycopg2 can default to either localhost or unix socket
|
||||
|
|
Loading…
Reference in New Issue
Block a user