mirror of
https://github.com/dbcli/pgcli.git
synced 2024-10-06 02:07:53 +03:00
parent
38a710a8db
commit
4a94556d64
@ -185,18 +185,24 @@ def suggest_based_on_last_token(token, text_before_cursor, full_text, identifier
|
||||
else:
|
||||
return [{'type': 'column', 'tables': extract_tables(full_text)},
|
||||
{'type': 'function', 'schema': []}]
|
||||
elif token_v in ('copy', 'from', 'update', 'into', 'describe') or (
|
||||
token_v.endswith('join') and token.ttype in Keyword):
|
||||
elif (token_v.endswith('join') and token.ttype in Keyword) or (token_v in
|
||||
('copy', 'from', 'update', 'into', 'describe', 'truncate')):
|
||||
schema = (identifier and identifier.get_parent_name()) or []
|
||||
if schema:
|
||||
# If already schema-qualified, suggest only tables/views
|
||||
return [{'type': 'table', 'schema': schema},
|
||||
{'type': 'view', 'schema': schema}]
|
||||
else:
|
||||
# Suggest schemas OR public tables/views
|
||||
return [{'type': 'schema'},
|
||||
{'type': 'table', 'schema': []},
|
||||
{'type': 'view', 'schema': []}]
|
||||
|
||||
# Suggest tables from either the currently-selected schema or the
|
||||
# public schema if no schema has been specified
|
||||
suggest = [{'type': 'table', 'schema': schema}]
|
||||
|
||||
if not schema:
|
||||
# Suggest schemas
|
||||
suggest.insert(0, {'type': 'schema'})
|
||||
|
||||
# Only tables can be TRUNCATED, otherwise suggest views
|
||||
if token_v != 'truncate':
|
||||
suggest.append({'type': 'view', 'schema': schema})
|
||||
|
||||
return suggest
|
||||
|
||||
elif token_v in ('table', 'view', 'function'):
|
||||
# E.g. 'DROP FUNCTION <funcname>', 'ALTER TABLE <tablname>'
|
||||
rel_type = token_v
|
||||
|
@ -32,9 +32,9 @@ class PGCompleter(Completer):
|
||||
'RAW', 'RENAME', 'RESOURCE', 'REVOKE', 'RIGHT', 'ROW', 'ROWID',
|
||||
'ROWNUM', 'ROWS', 'SELECT', 'SESSION', 'SET', 'SHARE', 'SIZE',
|
||||
'SMALLINT', 'START', 'SUCCESSFUL', 'SYNONYM', 'SYSDATE', 'TABLE',
|
||||
'TEMPLATE', 'THEN', 'TO', 'TRIGGER', 'UID', 'UNION', 'UNIQUE',
|
||||
'UPDATE', 'USE', 'USER', 'USING', 'VALIDATE', 'VALUES', 'VARCHAR',
|
||||
'VARCHAR2', 'VIEW', 'WHEN', 'WHENEVER', 'WHERE', 'WITH', ]
|
||||
'TEMPLATE', 'THEN', 'TO', 'TRIGGER', 'TRUNCATE', 'UID', 'UNION',
|
||||
'UNIQUE', 'UPDATE', 'USE', 'USER', 'USING', 'VALIDATE', 'VALUES',
|
||||
'VARCHAR', 'VARCHAR2', 'VIEW', 'WHEN', 'WHENEVER', 'WHERE', 'WITH']
|
||||
|
||||
functions = ['AVG', 'COUNT', 'FIRST', 'FORMAT', 'LAST', 'LCASE', 'LEN',
|
||||
'MAX', 'MIN', 'MID', 'NOW', 'ROUND', 'SUM', 'TOP', 'UCASE']
|
||||
|
Loading…
Reference in New Issue
Block a user