替代类仪器¶

可扩展类检测。

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

注解

提供扩展包的目的是为了与其他对象管理包集成,这些对象管理包已经执行了自己的检测。不适用于一般用途。

有关如何使用工具扩展的示例,请参见示例 属性检测 .

API引用

sqlalchemy.ext.instrumentation.INSTRUMENTATION_MANAGER = '__sa_instrumentation_manager__'

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

允许类指定一种稍有不同或极为不同的技术来跟踪对映射属性和集合所做的更改。

在给定的对象继承层次结构中只允许一个检测实现。

此属性的值必须是可调用的,并且将传递一个类对象。可调用文件必须返回以下内容之一:

  • InstrumentationManager或子类的实例

  • 实现全部或部分InstrumentationManager(TODO)的对象

  • 实现上述全部或部分内容的可调用字典(TODO)

  • 类管理器或子类的实例

一旦 sqlalchemy.ext.instrumentation 模块已导入。如果自定义查找程序安装在全局检测查找程序列表中,则它们可以选择或不选择使用此属性。

class sqlalchemy.orm.instrumentation.InstrumentationFactory

新ClassManager实例的工厂。

class sqlalchemy.ext.instrumentation.InstrumentationManager(class_)

用户定义的类检测扩展。

InstrumentationManager 可以被子类化,以更改类检测的进行方式。该类的存在是为了与其他对象管理框架集成,这些框架希望完全修改ORM的检测方法,而不是为了常规使用。有关类检测事件的拦截,请参见 InstrumentationEvents .

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

dict_getter(class_)
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(class_, instance, state)
instrument_attribute(class_, key, inst)
instrument_collection_class(class_, key, collection_class)
manage(class_, manager)
manager_getter(class_)
post_configure_attribute(class_, key, inst)
remove_state(class_, instance)
state_getter(class_)
uninstall_descriptor(class_, key)
uninstall_member(class_, key)
sqlalchemy.ext.instrumentation.instrumentation_finders = [<function find_native_user_instrumentation_hook>]

返回检测实现的可扩展可调用程序序列

注册类时,每个可调用项都将传递一个类对象。如果没有返回,将查询序列中的下一个查找程序。否则,返回必须是一个仪器工厂,该工厂遵循与SQLAlchemy.ext.instruction.instruction_manager相同的准则。

默认情况下,唯一的查找工具是find_native_user_instruction_hook,它搜索instruction_manager。如果所有查找器都返回“无”,则使用标准ClassManager检测。

class sqlalchemy.ext.instrumentation.ExtendedInstrumentationRegistry

基地: sqlalchemy.orm.instrumentation.InstrumentationFactory

延伸 InstrumentationFactory 增加了簿记功能,以适应多种类型的类管理器。