本文整理汇总了Python中sqlalchemy.ext.mutable.MutableComposite方法的典型用法代码示例。如果您正苦于以下问题:Python mutable.MutableComposite方法的具体用法?Python mutable.MutableComposite怎么用?Python mutable.MutableComposite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.ext.mutable
的用法示例。
在下文中一共展示了mutable.MutableComposite方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_listen_keys
# 需要导入模块: from sqlalchemy.ext import mutable [as 别名]
# 或者: from sqlalchemy.ext.mutable import MutableComposite [as 别名]
def _get_listen_keys(cls, attribute):
"""Given a descriptor attribute, return a ``set()`` of the attribute
keys which indicate a change in the state of this attribute.
This is normally just ``set([attribute.key])``, but can be overridden
to provide for additional keys. E.g. a :class:`.MutableComposite`
augments this set with the attribute keys associated with the columns
that comprise the composite value.
This collection is consulted in the case of intercepting the
:meth:`.InstanceEvents.refresh` and
:meth:`.InstanceEvents.refresh_flush` events, which pass along a list
of attribute names that have been refreshed; the list is compared
against this set to determine if action needs to be taken.
.. versionadded:: 1.0.5
"""
return set([attribute.key])
示例2: _get_listen_keys
# 需要导入模块: from sqlalchemy.ext import mutable [as 别名]
# 或者: from sqlalchemy.ext.mutable import MutableComposite [as 别名]
def _get_listen_keys(cls, attribute):
"""Given a descriptor attribute, return a ``set()`` of the attribute
keys which indicate a change in the state of this attribute.
This is normally just ``set([attribute.key])``, but can be overridden
to provide for additional keys. E.g. a :class:`.MutableComposite`
augments this set with the attribute keys associated with the columns
that comprise the composite value.
This collection is consulted in the case of intercepting the
:meth:`.InstanceEvents.refresh` and
:meth:`.InstanceEvents.refresh_flush` events, which pass along a list
of attribute names that have been refreshed; the list is compared
against this set to determine if action needs to be taken.
.. versionadded:: 1.0.5
"""
return {attribute.key}
示例3: coerce
# 需要导入模块: from sqlalchemy.ext import mutable [as 别名]
# 或者: from sqlalchemy.ext.mutable import MutableComposite [as 别名]
def coerce(cls, key, value):
"""Given a value, coerce it into the target type.
Can be overridden by custom subclasses to coerce incoming
data into a particular type.
By default, raises ``ValueError``.
This method is called in different scenarios depending on if
the parent class is of type :class:`.Mutable` or of type
:class:`.MutableComposite`. In the case of the former, it is called
for both attribute-set operations as well as during ORM loading
operations. For the latter, it is only called during attribute-set
operations; the mechanics of the :func:`.composite` construct
handle coercion during load operations.
:param key: string name of the ORM-mapped attribute being set.
:param value: the incoming value.
:return: the method should return the coerced value, or raise
``ValueError`` if the coercion cannot be completed.
"""
if value is None:
return None
msg = "Attribute '%s' does not accept objects of type %s"
raise ValueError(msg % (key, type(value)))
示例4: _setup_composite_listener
# 需要导入模块: from sqlalchemy.ext import mutable [as 别名]
# 或者: from sqlalchemy.ext.mutable import MutableComposite [as 别名]
def _setup_composite_listener():
def _listen_for_type(mapper, class_):
for prop in mapper.iterate_properties:
if (hasattr(prop, 'composite_class') and
isinstance(prop.composite_class, type) and
issubclass(prop.composite_class, MutableComposite)):
prop.composite_class._listen_on_attribute(
getattr(class_, prop.key), False, class_)
if not event.contains(Mapper, "mapper_configured", _listen_for_type):
event.listen(Mapper, 'mapper_configured', _listen_for_type)
示例5: _setup_composite_listener
# 需要导入模块: from sqlalchemy.ext import mutable [as 别名]
# 或者: from sqlalchemy.ext.mutable import MutableComposite [as 别名]
def _setup_composite_listener():
def _listen_for_type(mapper, class_):
for prop in mapper.iterate_properties:
if (
hasattr(prop, "composite_class")
and isinstance(prop.composite_class, type)
and issubclass(prop.composite_class, MutableComposite)
):
prop.composite_class._listen_on_attribute(
getattr(class_, prop.key), False, class_
)
if not event.contains(Mapper, "mapper_configured", _listen_for_type):
event.listen(Mapper, "mapper_configured", _listen_for_type)
示例6: setup_mappers
# 需要导入模块: from sqlalchemy.ext import mutable [as 别名]
# 或者: from sqlalchemy.ext.mutable import MutableComposite [as 别名]
def setup_mappers(cls):
foo = cls.tables.foo
Point = cls._type_fixture()
# in this case, this is not actually a MutableComposite.
# so we don't expect it to track changes
mapper(
Foo,
foo,
properties={
"data": composite(lambda x, y: Point(x, y), foo.c.x, foo.c.y)
},
)
示例7: _setup_composite_listener
# 需要导入模块: from sqlalchemy.ext import mutable [as 别名]
# 或者: from sqlalchemy.ext.mutable import MutableComposite [as 别名]
def _setup_composite_listener():
def _listen_for_type(mapper, class_):
for prop in mapper.iterate_properties:
if (hasattr(prop, 'composite_class') and
isinstance(prop.composite_class, type) and
issubclass(prop.composite_class, MutableComposite)):
prop.composite_class._listen_on_attribute(
getattr(class_, prop.key), False, class_)
if not event.contains(Mapper, "mapper_configured", _listen_for_type):
event.listen(Mapper, 'mapper_configured', _listen_for_type)