什么是SQLAlchemy上下文中的“instrumentation”?

2024-06-03 09:28:55 发布

您现在位置:Python中文网/ 问答频道 /正文

SQLAlchemy's tutorial中,它提到了“instrumentation”,但似乎没有正确定义什么是instrumentation:

These class attributes exist as Python descriptors, and define instrumentation for the mapped class. The functionality of this instrumentation includes the ability to fire on change events, track modifications, and to automatically load new data from the database when needed.

在这种情况下,什么是仪器?在


Tags: andthetofor定义sqlalchemyastutorial
1条回答
网友
1楼 · 发布于 2024-06-03 09:28:55

插装是将属性附加到类的过程,这些属性被实现为Python Descriptors(这句话中提到了这个链接),这样任何属性都可以进行get、set或delete操作,即:

# __get__
print myobject.someattribute

# __set__
myobject.someattribute = "foo"

# __del__
del myoject.someattribute

。。。将为每个事件调用Python代码,而不是直接使用Python的默认行为访问/操作myobject.__dict__。为了实现unit of work模式,SQLAlchemy利用这些钩子提供诸如lazy loading之类的行为,以及记录属性值何时发生更改,在这种模式中,只有那些已更改的元素被卷进更新语句中,以便在刷新时发送到数据库。在

相关问题 更多 >