當前位置: 首頁>>代碼示例>>Python>>正文


Python mapper.column_attrs方法代碼示例

本文整理匯總了Python中sqlalchemy.orm.mapper.column_attrs方法的典型用法代碼示例。如果您正苦於以下問題:Python mapper.column_attrs方法的具體用法?Python mapper.column_attrs怎麽用?Python mapper.column_attrs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sqlalchemy.orm.mapper的用法示例。


在下文中一共展示了mapper.column_attrs方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: associate_with

# 需要導入模塊: from sqlalchemy.orm import mapper [as 別名]
# 或者: from sqlalchemy.orm.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.orm import mapper [as 別名]
# 或者: from sqlalchemy.orm.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.orm import mapper [as 別名]
# 或者: from sqlalchemy.orm.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.orm import mapper [as 別名]
# 或者: from sqlalchemy.orm.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.orm import mapper [as 別名]
# 或者: from sqlalchemy.orm.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.orm.mapper.column_attrs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。