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

Method populate_schema_objects

mycli/sqlcompleter.py:1849–1879  ·  view source on GitHub ↗

Returns list of tables or functions for a (optional) schema

(self, schema: str | None, obj_type: str, columns: list[str] | None = None)

Source from the content-addressed store, hash-verified

1847 return "'" + value.replace("'", "''") + "'"
1848
1849 def populate_schema_objects(self, schema: str | None, obj_type: str, columns: list[str] | None = None) -> list[str]:
1850 """Returns list of tables or functions for a (optional) schema"""
1851 metadata = self.dbmetadata[obj_type]
1852 schema = schema or self.dbname
1853 try:
1854 objects = list(metadata[schema].keys())
1855 except KeyError:
1856 # schema doesn't exist
1857 objects = []
1858
1859 filtered_objects: list[str] = []
1860 remaining_objects: list[str] = []
1861
1862 # If the requested object type is tables and the user already entered
1863 # columns, return a filtered list of tables (or views) that contain
1864 # one or more of the given columns. If a table does not contain the
1865 # given columns, add it to a separate list to add to the end of the
1866 # filtered suggestions.
1867 if obj_type == "tables" and columns and objects:
1868 for obj in objects:
1869 matched = False
1870 for column in metadata[schema][obj]:
1871 if column in columns:
1872 filtered_objects.append(obj)
1873 matched = True
1874 break
1875 if not matched:
1876 remaining_objects.append(obj)
1877 else:
1878 filtered_objects = objects
1879 return filtered_objects + remaining_objects

Callers 1

get_completionsMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected