当前位置: 首页>>代码示例>>Python>>正文


Python mapper.column_attrs方法代码示例

本文整理汇总了Python中sqlalchemy.mapper.column_attrs方法的典型用法代码示例。如果您正苦于以下问题:Python mapper.column_attrs方法的具体用法?Python mapper.column_attrs怎么用?Python mapper.column_attrs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.mapper的用法示例。


在下文中一共展示了mapper.column_attrs方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: associate_with

# 需要导入模块: from sqlalchemy import mapper [as 别名]
# 或者: from sqlalchemy.mapper import column_attrs [as 别名]
def associate_with(cls, sqltype):
        """Associate this wrapper with all future mapped columns
        of the given type.

        This is a convenience method that calls
        ``associate_with_attribute`` automatically.

        .. warning::

           The listeners established by this method are *global*
           to all mappers, and are *not* garbage collected.   Only use
           :meth:`.associate_with` for types that are permanent to an
           application, not with ad-hoc types else this will cause unbounded
           growth in memory usage.

        """

        def listen_for_type(mapper, class_):
            for prop in mapper.column_attrs:
                if isinstance(prop.columns[0].type, sqltype):
                    cls.associate_with_attribute(getattr(class_, prop.key))

        event.listen(mapper, 'mapper_configured', listen_for_type) 
开发者ID:jpush,项目名称:jbox,代码行数:25,代码来源:mutable.py

示例2: associate_with

# 需要导入模块: from sqlalchemy import mapper [as 别名]
# 或者: from sqlalchemy.mapper import column_attrs [as 别名]
def associate_with(cls, sqltype):
        """Associate this wrapper with all future mapped columns
        of the given type.

        This is a convenience method that calls
        ``associate_with_attribute`` automatically.

        .. warning::

           The listeners established by this method are *global*
           to all mappers, and are *not* garbage collected.   Only use
           :meth:`.associate_with` for types that are permanent to an
           application, not with ad-hoc types else this will cause unbounded
           growth in memory usage.

        """

        def listen_for_type(mapper, class_):
            if mapper.non_primary:
                return
            for prop in mapper.column_attrs:
                if isinstance(prop.columns[0].type, sqltype):
                    cls.associate_with_attribute(getattr(class_, prop.key))

        event.listen(mapper, "mapper_configured", listen_for_type) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:27,代码来源:mutable.py

示例3: associate_with

# 需要导入模块: from sqlalchemy import mapper [as 别名]
# 或者: from sqlalchemy.mapper import column_attrs [as 别名]
def associate_with(cls, sqltype):
        """Associate this wrapper with all future mapped columns
        of the given type.

        This is a convenience method that calls
        ``associate_with_attribute`` automatically.

        .. warning::

           The listeners established by this method are *global*
           to all mappers, and are *not* garbage collected.   Only use
           :meth:`.associate_with` for types that are permanent to an
           application, not with ad-hoc types else this will cause unbounded
           growth in memory usage.

        """

        def listen_for_type(mapper, class_):
            if mapper.non_primary:
                return
            for prop in mapper.column_attrs:
                if isinstance(prop.columns[0].type, sqltype):
                    cls.associate_with_attribute(getattr(class_, prop.key))

        event.listen(mapper, 'mapper_configured', listen_for_type) 
开发者ID:bkerler,项目名称:android_universal,代码行数:27,代码来源:mutable.py

示例4: as_mutable

# 需要导入模块: from sqlalchemy import mapper [as 别名]
# 或者: from sqlalchemy.mapper import column_attrs [as 别名]
def as_mutable(cls, sqltype):
        """Associate a SQL type with this mutable Python type.

        This establishes listeners that will detect ORM mappings against
        the given type, adding mutation event trackers to those mappings.

        The type is returned, unconditionally as an instance, so that
        :meth:`.as_mutable` can be used inline::

            Table('mytable', metadata,
                Column('id', Integer, primary_key=True),
                Column('data', MyMutableType.as_mutable(PickleType))
            )

        Note that the returned type is always an instance, even if a class
        is given, and that only columns which are declared specifically with
        that type instance receive additional instrumentation.

        To associate a particular mutable type with all occurrences of a
        particular type, use the :meth:`.Mutable.associate_with` classmethod
        of the particular :class:`.Mutable` subclass to establish a global
        association.

        .. warning::

           The listeners established by this method are *global*
           to all mappers, and are *not* garbage collected.   Only use
           :meth:`.as_mutable` for types that are permanent to an application,
           not with ad-hoc types else this will cause unbounded growth
           in memory usage.

        """
        sqltype = types.to_instance(sqltype)

        def listen_for_type(mapper, class_):
            for prop in mapper.column_attrs:
                if prop.columns[0].type is sqltype:
                    cls.associate_with_attribute(getattr(class_, prop.key))

        event.listen(mapper, 'mapper_configured', listen_for_type)

        return sqltype 
开发者ID:jpush,项目名称:jbox,代码行数:44,代码来源:mutable.py

示例5: as_mutable

# 需要导入模块: from sqlalchemy import mapper [as 别名]
# 或者: from sqlalchemy.mapper import column_attrs [as 别名]
def as_mutable(cls, sqltype):
        """Associate a SQL type with this mutable Python type.

        This establishes listeners that will detect ORM mappings against
        the given type, adding mutation event trackers to those mappings.

        The type is returned, unconditionally as an instance, so that
        :meth:`.as_mutable` can be used inline::

            Table('mytable', metadata,
                Column('id', Integer, primary_key=True),
                Column('data', MyMutableType.as_mutable(PickleType))
            )

        Note that the returned type is always an instance, even if a class
        is given, and that only columns which are declared specifically with
        that type instance receive additional instrumentation.

        To associate a particular mutable type with all occurrences of a
        particular type, use the :meth:`.Mutable.associate_with` classmethod
        of the particular :class:`.Mutable` subclass to establish a global
        association.

        .. warning::

           The listeners established by this method are *global*
           to all mappers, and are *not* garbage collected.   Only use
           :meth:`.as_mutable` for types that are permanent to an application,
           not with ad-hoc types else this will cause unbounded growth
           in memory usage.

        """
        sqltype = types.to_instance(sqltype)

        # a SchemaType will be copied when the Column is copied,
        # and we'll lose our ability to link that type back to the original.
        # so track our original type w/ columns
        if isinstance(sqltype, SchemaEventTarget):
            @event.listens_for(sqltype, "before_parent_attach")
            def _add_column_memo(sqltyp, parent):
                parent.info['_ext_mutable_orig_type'] = sqltyp
            schema_event_check = True
        else:
            schema_event_check = False

        def listen_for_type(mapper, class_):
            for prop in mapper.column_attrs:
                if (
                        schema_event_check and
                        hasattr(prop.expression, 'info') and
                        prop.expression.info.get('_ext_mutable_orig_type')
                        is sqltype
                ) or (
                    prop.columns[0].type is sqltype
                ):
                    cls.associate_with_attribute(getattr(class_, prop.key))

        event.listen(mapper, 'mapper_configured', listen_for_type)

        return sqltype 
开发者ID:yfauser,项目名称:planespotter,代码行数:62,代码来源:mutable.py


注:本文中的sqlalchemy.mapper.column_attrs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。