Skip to content

Commit bbfe7f2

Browse files
authored
Merge pull request #1451 from dbcli/RW/grant-query-offer-database-completion
Let `GRANT ... ON` forms offer schema names as completions
2 parents 91cc1b9 + 90a6479 commit bbfe7f2

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Bug Fixes
1616
* Respect `--logfile` when using `--execute` or standard input at the shell CLI.
1717
* Gracefully catch Paramiko parsing errors on `--list-ssh-config`.
1818
* Downgrade to Paramiko 3.5.1 to avoid crashing on DSA SSH keys.
19+
* Offer schema name completions in `GRANT ... ON` forms.
1920

2021

2122
1.44.2 (2026/01/13)

mycli/packages/completion_engine.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,9 @@ def suggest_based_on_last_token(
338338

339339
# The lists of 'aliases' could be empty if we're trying to complete
340340
# a GRANT query. eg: GRANT SELECT, INSERT ON <tab>
341-
# In that case we just suggest all tables.
341+
# In that case we just suggest all schemata and all tables.
342342
if not aliases:
343+
suggest.append({"type": "database"})
343344
suggest.append({"type": "table", "schema": parent})
344345
return suggest
345346

test/test_smart_completion_public_schema_only.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,19 @@ def test_un_escaped_table_names(completer, complete_event):
456456
)
457457

458458

459+
# todo: the fixtures are insufficient; the database name should also appear in the result
460+
def test_grant_on_suggets_tables_and_schemata(completer, complete_event):
461+
text = "GRANT ALL ON "
462+
position = len(text)
463+
result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
464+
assert result == [
465+
Completion(text='users', start_position=0),
466+
Completion(text='orders', start_position=0),
467+
Completion(text='`select`', start_position=0),
468+
Completion(text='`réveillé`', start_position=0),
469+
]
470+
471+
459472
def dummy_list_path(dir_name):
460473
dirs = {
461474
"/": [

0 commit comments

Comments
 (0)