MCPcopy Index your code
hub / github.com/dbcli/mycli / _emit_on

Function _emit_on

mycli/packages/completion_engine.py:308–335  ·  view source on GitHub ↗
(ctx: SuggestContext)

Source from the content-addressed store, hash-verified

306
307
308def _emit_on(ctx: SuggestContext) -> list[Suggestion]:
309 tables = _tables(ctx) # [(schema, table, alias), ...]
310 parent = _parent_name(ctx)
311 if parent:
312 # "ON parent.<suggestion>"
313 # parent can be either a schema name or table alias
314 # todo recognize and separate schema and table suggestions
315 # todo remove function suggestions here
316 tables = [t for t in tables if identifies(parent, *t)]
317 return [
318 {'type': 'column', 'tables': tables},
319 {'type': 'table', 'schema': parent},
320 {'type': 'view', 'schema': parent},
321 {'type': 'function', 'schema': parent},
322 ]
323
324 # ON <suggestion>
325 # Use table alias if there is one, otherwise the table name
326 aliases = _aliases(tables)
327 suggest: list[Suggestion] = [{'type': 'fk_join', 'tables': tables}, {'type': 'alias', 'aliases': aliases}]
328
329 # The lists of 'aliases' could be empty if we're trying to complete
330 # a GRANT query. eg: GRANT SELECT, INSERT ON <tab>
331 # In that case we just suggest all schemata and all tables.
332 if not aliases:
333 suggest.append({'type': 'database'})
334 suggest.append({'type': 'table', 'schema': parent})
335 return suggest
336
337
338def _emit_database(_ctx: SuggestContext) -> list[Suggestion]:

Calls 4

_tablesFunction · 0.85
_parent_nameFunction · 0.85
identifiesFunction · 0.85
_aliasesFunction · 0.85