Release: 1.4.25 | Release Date: September 22, 2021

SQLAlchemy 1.4 Documentation

替代类仪器

可扩展类检测。

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

注解

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

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

API引用

Object Name Description

ExtendedInstrumentationRegistry

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

instrumentation_finders

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

INSTRUMENTATION_MANAGER

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

InstrumentationFactory

新ClassManager实例的工厂。

InstrumentationManager

用户定义的类检测扩展。

sqlalchemy.ext.instrumentation.INSTRUMENTATION_MANAGER = '__sa_instrumentation_manager__'

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

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

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

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

  • 一个 InstrumentationManager 或子类

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

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

  • 一个 ClassManager 或子类

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

class sqlalchemy.orm.instrumentation.InstrumentationFactory

新ClassManager实例的工厂。

class sqlalchemy.ext.instrumentation.InstrumentationManager(class_)

用户定义的类检测扩展。

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

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

method sqlalchemy.ext.instrumentation.InstrumentationManager.dict_getter(class_)
method sqlalchemy.ext.instrumentation.InstrumentationManager.get_instance_dict(class_, instance)
method sqlalchemy.ext.instrumentation.InstrumentationManager.initialize_instance_dict(class_, instance)
method sqlalchemy.ext.instrumentation.InstrumentationManager.install_descriptor(class_, key, inst)
method sqlalchemy.ext.instrumentation.InstrumentationManager.install_member(class_, key, implementation)
method sqlalchemy.ext.instrumentation.InstrumentationManager.install_state(class_, instance, state)
method sqlalchemy.ext.instrumentation.InstrumentationManager.instrument_attribute(class_, key, inst)
method sqlalchemy.ext.instrumentation.InstrumentationManager.instrument_collection_class(class_, key, collection_class)
method sqlalchemy.ext.instrumentation.InstrumentationManager.manage(class_, manager)
method sqlalchemy.ext.instrumentation.InstrumentationManager.manager_getter(class_)
method sqlalchemy.ext.instrumentation.InstrumentationManager.post_configure_attribute(class_, key, inst)
method sqlalchemy.ext.instrumentation.InstrumentationManager.remove_state(class_, instance)
method sqlalchemy.ext.instrumentation.InstrumentationManager.state_getter(class_)
method sqlalchemy.ext.instrumentation.InstrumentationManager.uninstall_descriptor(class_, key)
method sqlalchemy.ext.instrumentation.InstrumentationManager.uninstall_member(class_, key)
method sqlalchemy.ext.instrumentation.InstrumentationManager.unregister(class_, manager)
sqlalchemy.ext.instrumentation.instrumentation_finders = [<function find_native_user_instrumentation_hook>]

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

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

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

class sqlalchemy.ext.instrumentation.ExtendedInstrumentationRegistry

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

Previous: 可转位的 Next: ORM实例