本文整理汇总了Python中sqlalchemy.engine.reflection.Inspector方法的典型用法代码示例。如果您正苦于以下问题:Python reflection.Inspector方法的具体用法?Python reflection.Inspector怎么用?Python reflection.Inspector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.engine.reflection
的用法示例。
在下文中一共展示了reflection.Inspector方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_index_constraint
# 需要导入模块: from sqlalchemy.engine import reflection [as 别名]
# 或者: from sqlalchemy.engine.reflection import Inspector [as 别名]
def test_add_index_constraint(self):
def add_in_registry():
@register(Model)
class Address:
id = Integer(primary_key=True)
@register(Model)
class Person:
name = String(primary_key=True)
address = Many2One(model=Model.Address, index=True)
registry = self.init_registry(add_in_registry)
inspector = Inspector(registry.session.connection())
indexes = inspector.get_indexes(registry.Person.__tablename__)
assert len(indexes) == 1
示例2: test_add_primary_keys_constraint
# 需要导入模块: from sqlalchemy.engine import reflection [as 别名]
# 或者: from sqlalchemy.engine.reflection import Inspector [as 别名]
def test_add_primary_keys_constraint(self):
def add_in_registry():
@register(Model)
class Address:
id = Integer(primary_key=True)
@register(Model)
class Person:
name = String(primary_key=True)
address = Many2One(model=Model.Address, primary_key=True)
registry = self.init_registry(add_in_registry)
inspector = Inspector(registry.session.connection())
pks = inspector.get_primary_keys(registry.Person.__tablename__)
assert 'address_id'in pks
示例3: _show_columns
# 需要导入模块: from sqlalchemy.engine import reflection [as 别名]
# 或者: from sqlalchemy.engine.reflection import Inspector [as 别名]
def _show_columns(
cls, inspector: Inspector, table_name: str, schema: Optional[str]
) -> List[RowProxy]:
"""
Show presto column names
:param inspector: object that performs database schema inspection
:param table_name: table name
:param schema: schema name
:return: list of column objects
"""
quote = inspector.engine.dialect.identifier_preparer.quote_identifier
full_table = quote(table_name)
if schema:
full_table = "{}.{}".format(quote(schema), full_table)
columns = inspector.bind.execute("SHOW COLUMNS FROM {}".format(full_table))
return columns
示例4: __init__
# 需要导入模块: from sqlalchemy.engine import reflection [as 别名]
# 或者: from sqlalchemy.engine.reflection import Inspector [as 别名]
def __init__(self, conn):
reflection.Inspector.__init__(self, conn)
示例5: test_deprecated_get_primary_keys
# 需要导入模块: from sqlalchemy.engine import reflection [as 别名]
# 或者: from sqlalchemy.engine.reflection import Inspector [as 别名]
def test_deprecated_get_primary_keys(self):
meta = self.metadata
users = self.tables.users
insp = Inspector(meta.bind)
assert_raises_message(
sa_exc.SADeprecationWarning,
"Call to deprecated method get_primary_keys."
" Use get_pk_constraint instead.",
insp.get_primary_keys, users.name
)
示例6: detect_changed
# 需要导入模块: from sqlalchemy.engine import reflection [as 别名]
# 或者: from sqlalchemy.engine.reflection import Inspector [as 别名]
def detect_changed(self, schema_only=False):
""" Detect the difference between the metadata and the database
:rtype: MigrationReport instance
"""
inspector = Inspector(self.conn)
if schema_only:
diff = self.detect_added_new_schema(inspector)
else:
diff = compare_metadata(self.context, self.metadata)
diff.extend(
self.detect_undetected_constraint_from_alembic(inspector))
return MigrationReport(self, diff)
示例7: test_inspector_constructor_engine
# 需要导入模块: from sqlalchemy.engine import reflection [as 别名]
# 或者: from sqlalchemy.engine.reflection import Inspector [as 别名]
def test_inspector_constructor_engine(self):
with testing.expect_deprecated(
r"The __init__\(\) method on Inspector is deprecated and will "
r"be removed in a future release."
):
i1 = reflection.Inspector(testing.db)
is_(i1.bind, testing.db)
self.check_usage(i1)
示例8: test_inspector_constructor_connection
# 需要导入模块: from sqlalchemy.engine import reflection [as 别名]
# 或者: from sqlalchemy.engine.reflection import Inspector [as 别名]
def test_inspector_constructor_connection(self):
with testing.db.connect() as conn:
with testing.expect_deprecated(
r"The __init__\(\) method on Inspector is deprecated and "
r"will be removed in a future release."
):
i1 = reflection.Inspector(conn)
is_(i1.bind, conn)
is_(i1.engine, testing.db)
self.check_usage(i1)
示例9: test_inspector_from_engine
# 需要导入模块: from sqlalchemy.engine import reflection [as 别名]
# 或者: from sqlalchemy.engine.reflection import Inspector [as 别名]
def test_inspector_from_engine(self):
with testing.expect_deprecated(
r"The from_engine\(\) method on Inspector is deprecated and will "
r"be removed in a future release."
):
i1 = reflection.Inspector.from_engine(testing.db)
is_(i1.bind, testing.db)
self.check_usage(i1)
示例10: test_reflecttable
# 需要导入模块: from sqlalchemy.engine import reflection [as 别名]
# 或者: from sqlalchemy.engine.reflection import Inspector [as 别名]
def test_reflecttable(self):
inspector = inspect(testing.db)
metadata = self.metadata
table = Table("user", metadata)
with testing.expect_deprecated_20(
r"The Inspector.reflecttable\(\) function/method is considered "
):
res = inspector.reflecttable(table, None)
exp = inspector.reflect_table(table, None)
eq_(res, exp)
示例11: inspector
# 需要导入模块: from sqlalchemy.engine import reflection [as 别名]
# 或者: from sqlalchemy.engine.reflection import Inspector [as 别名]
def inspector(self) -> Inspector:
engine = self.get_sqla_engine()
return sqla.inspect(engine)
示例12: get_table_names
# 需要导入模块: from sqlalchemy.engine import reflection [as 别名]
# 或者: from sqlalchemy.engine.reflection import Inspector [as 别名]
def get_table_names(
cls, database: "Database", inspector: Inspector, schema: Optional[str]
) -> List[str]:
"""Need to disregard the schema for Sqlite"""
return sorted(inspector.get_table_names())
示例13: get_schema_names
# 需要导入模块: from sqlalchemy.engine import reflection [as 别名]
# 或者: from sqlalchemy.engine.reflection import Inspector [as 别名]
def get_schema_names(cls, inspector: Inspector) -> List[str]:
"""
Get all schemas from database
:param inspector: SqlAlchemy inspector
:return: All schemas in the database
"""
return sorted(inspector.get_schema_names())
示例14: get_table_names
# 需要导入模块: from sqlalchemy.engine import reflection [as 别名]
# 或者: from sqlalchemy.engine.reflection import Inspector [as 别名]
def get_table_names(
cls, database: "Database", inspector: Inspector, schema: Optional[str]
) -> List[str]:
"""
Get all tables from schema
:param inspector: SqlAlchemy inspector
:param schema: Schema to inspect. If omitted, uses default schema for database
:return: All tables in schema
"""
tables = inspector.get_table_names(schema)
if schema and cls.try_remove_schema_from_table_name:
tables = [re.sub(f"^{schema}\\.", "", table) for table in tables]
return sorted(tables)
示例15: get_view_names
# 需要导入模块: from sqlalchemy.engine import reflection [as 别名]
# 或者: from sqlalchemy.engine.reflection import Inspector [as 别名]
def get_view_names(
cls, database: "Database", inspector: Inspector, schema: Optional[str]
) -> List[str]:
"""
Get all views from schema
:param inspector: SqlAlchemy inspector
:param schema: Schema name. If omitted, uses default schema for database
:return: All views in schema
"""
views = inspector.get_view_names(schema)
if schema and cls.try_remove_schema_from_table_name:
views = [re.sub(f"^{schema}\\.", "", view) for view in views]
return sorted(views)