MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _get_reflection_info

Method _get_reflection_info

lib/sqlalchemy/engine/reflection.py:1964–2040  ·  view source on GitHub ↗
(
        self,
        schema: Optional[str] = None,
        filter_names: Optional[Collection[str]] = None,
        available: Optional[Collection[str]] = None,
        _reflect_info: Optional[_ReflectionInfo] = None,
        **kw: Any,
    )

Source from the content-addressed store, hash-verified

1962 table.comment = comment_dict["text"]
1963
1964 def _get_reflection_info(
1965 self,
1966 schema: Optional[str] = None,
1967 filter_names: Optional[Collection[str]] = None,
1968 available: Optional[Collection[str]] = None,
1969 _reflect_info: Optional[_ReflectionInfo] = None,
1970 **kw: Any,
1971 ) -> _ReflectionInfo:
1972 kw["schema"] = schema
1973
1974 if filter_names and available and len(filter_names) > 100:
1975 fraction = len(filter_names) / len(available)
1976 else:
1977 fraction = None
1978
1979 unreflectable: Dict[TableKey, exc.UnreflectableTableError]
1980 kw["unreflectable"] = unreflectable = {}
1981
1982 has_result: bool = True
1983
1984 def run(
1985 meth: Any,
1986 *,
1987 optional: bool = False,
1988 check_filter_names_from_meth: bool = False,
1989 ) -> Any:
1990 nonlocal has_result
1991 # simple heuristic to improve reflection performance if a
1992 # dialect implements multi_reflection:
1993 # if more than 50% of the tables in the db are in filter_names
1994 # load all the tables, since it's most likely faster to avoid
1995 # a filter on that many tables.
1996 if (
1997 fraction is None
1998 or fraction <= 0.5
1999 or not self.dialect._overrides_default(meth.__name__)
2000 ):
2001 _fn = filter_names
2002 else:
2003 _fn = None
2004 try:
2005 if has_result:
2006 res = meth(filter_names=_fn, **kw)
2007 if check_filter_names_from_meth and not res:
2008 # method returned no result data.
2009 # skip any future call methods
2010 has_result = False
2011 else:
2012 res = {}
2013 except NotImplementedError:
2014 if not optional:
2015 raise
2016 res = {}
2017 return res
2018
2019 info = _ReflectionInfo(
2020 columns=run(
2021 self.get_multi_columns, check_filter_names_from_meth=True

Callers 2

reflect_tableMethod · 0.95
reflectMethod · 0.80

Calls 3

_ReflectionInfoClass · 0.85
runFunction · 0.85
updateMethod · 0.45

Tested by

no test coverage detected