版本:1.1.0b2 |发布日期:2016年7月1日

SQLAlchemy 1.1文档

运行时检测API

检查模块提供了inspect()函数,该函数在Core和ORM中传递有关各种SQLAlchemy对象的运行时信息。

inspect()函数是SQLAlchemy的公共API的入口点,用于查看内存中对象的配置和构造。根据传递给inspect()的对象的类型,返回值可以是提供已知接口的相关对象,或者在许多情况下它将返回对象本身。

inspect()的基本原理是双重的。One is that it replaces the need to be aware of a large variety of “information getting” functions in SQLAlchemy, such as Inspector.from_engine(), orm.attributes.instance_state(), orm.class_mapper(), and others. 另一个原因是,inspect()的返回值保证服从一个记录的API,因此允许构建在SQLAlchemy配置之上的第三方工具以前向兼容的方式构建。

0.8版中的新功能从版本0.8开始引入inspect()系统。

sqlalchemy.inspection.inspect(subject, raiseerr=True)

为给定的目标生成检查对象。

在某些情况下,返回的值可能与给定的对象相同,例如传递Mapper对象。在其他情况下,它将是给定对象的注册检查类型的实例,例如,如果传递engine.Engine,则返回一个Inspector对象。

参数:
  • subject – the subject to be inspected.
  • raiseerr – When True, if the given subject does not correspond to a known SQLAlchemy inspected type, sqlalchemy.exc.NoInspectionAvailable is raised. 如果False,则返回None

可用的检查目标

以下列出了许多最常见的检查目标。