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

SQLAlchemy 1.1文档

替代类仪器

可扩展的类仪器。

sqlalchemy.ext.instrumentation包在ORM中提供了备用的类工具系统。类工具是指ORM如何在维护数据的类上放置属性,并跟踪对该数据的更改,以及安装在类上的事件挂钩。

注意

提供扩展包是为了与其他已经执行自己的仪器的对象管理包集成。它不适用于一般用途。

有关如何使用检测扩展的示例,请参阅示例Attribute Instrumentation

在版本0.8中更改: sqlalchemy.orm.instrumentation被拆分出来,以便将与非标准检测相关的所有功能移出到sqlalchemy.ext.instrumentation导入时,模块将自身安装在sqlalchemy.orm.instrumentation中,以便生效,包括识别映射类上的__sa_instrumentation_manager__以及instrumentation_finders >被用来确定类仪器的分辨率。

API参考

sqlalchemy.ext.instrumentation。 INSTRUMENTATION_MANAGER ='__sa_instrumentation_manager __'

属性,在存在于映射类上时选择自定义检测。

允许类指定一个稍微或非常不同的技术来跟踪对映射的属性和集合所做的更改。

在给定的对象继承层次结构中只允许使用一个工具实现。

该属性的值必须是可调用的,并且将传递一个类对象。可调用函数必须返回以下之一:

  • InstrumentationManager或子类的实例
  • 实现InstrumentationManager(TODO)的全部或部分对象,
  • 一个可玩的字典,实现全部或部分上述(TODO)
  • 一个ClassManager或子类的实例

一旦sqlalchemy.ext.instrumentation模块被导入后,通过SQLAlchemy工具解析来查询此属性。如果自定义查找器安装在全局instrumentation_finders列表中,则它们可能会选择或不选择此属性。

class sqlalchemy.orm.instrumentation。 InstrumentationFactory

新的ClassManager实例的工厂。

class sqlalchemy.ext.instrumentation.InstrumentationManager(class_)

用户定义的类工具扩展。

InstrumentationManager can be subclassed in order to change how class instrumentation proceeds. 此类存在用于与其他对象管理框架集成的目的,这些对象管理框架将完全修改ORM的检测方法,并且不打算用于常规用法。要拦截类工具事件,请参阅InstrumentationEvents

这个类的API应该被认为是半稳定的,并且可能会随着新版本的发布而略有变化。

dict_getter T0> ( T1> 类_ T2> ) T3> ¶ T4>
dispose(class_, manager)
get_instance_dict class_instance
initialize_instance_dict(class_, instance)
install_descriptor(class_, key, inst)
install_member(class_, key, implementation)
install_state T0> ( T1> 类_ T2>,实例 T3>,状态 T4> ) T5> ¶ T6>
instrument_attribute(class_, key, inst)
instrument_collection_class class_keycollection_class ¶ T6>
manage(class_, manager)
manager_getter T0> ( T1> 类_ T2> ) T3> ¶ T4>
post_configure_attribute(class_, key, inst)
remove_state tt> class_instance
state_getter T0> ( T1> 类_ T2> ) T3> ¶ T4>
uninstall_descriptor(class_, key)
uninstall_member(class_, key)
sqlalchemy.ext.instrumentation。 instrumentation_finders = [<函数find_native_user_instrumentation_hook at 0x7f43​​0c541230>]

可扩展的可调用序列,返回仪器实现

当一个类被注册时,每个可调用对象将被传递一个类对象。如果返回None,则会查询序列中的下一个查找器。否则,返回必须是符合sqlalchemy.ext.instrumentation.INSTRUMENTATION_MANAGER相同准则的检测工厂。

默认情况下,唯一的查找程序是find_native_user_instrumentation_hook,它搜索INSTRUMENTATION_MANAGER。如果所有查找器都返回None,则使用标准的ClassManager工具。

class sqlalchemy.ext.instrumentation。 ExtendedInstrumentationRegistry

基础:sqlalchemy.orm.instrumentation.InstrumentationFactory

扩展InstrumentationFactory以增加簿记,以适应多种类别的经理。