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


Python orm.object_mapper方法代码示例

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


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

示例1: __iter__

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import object_mapper [as 别名]
def __iter__(self):
        self._i = iter(object_mapper(self).columns)
        return self 
开发者ID:rucio,项目名称:rucio,代码行数:5,代码来源:models.py

示例2: __iter__

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import object_mapper [as 别名]
def __iter__(self):
        return ModelIterator(self, iter(dict(object_mapper(self).columns).keys())) 
开发者ID:xgfone,项目名称:snippet,代码行数:4,代码来源:template.py

示例3: __iter__

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import object_mapper [as 别名]
def __iter__(self):
        columns = list(dict(object_mapper(self).columns).keys())
        return ModelIterator(self, iter(columns)) 
开发者ID:xgfone,项目名称:snippet,代码行数:5,代码来源:sqlalchemy-orm-model.py

示例4: __iter__

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import object_mapper [as 别名]
def __iter__(self):
        self._i = iter(orm.object_mapper(self).sa.Columns)
        return self 
开发者ID:cloud-security-research,项目名称:sgx-kms,代码行数:5,代码来源:models.py

示例5: __iter__

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import object_mapper [as 别名]
def __iter__(self):
        self._i = iter(orm.object_mapper(self).columns)
        return self 
开发者ID:openstack,项目名称:tacker,代码行数:5,代码来源:model_base.py

示例6: __iter__

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import object_mapper [as 别名]
def __iter__(self):
        columns = list(dict(object_mapper(self).columns).keys())
        # NOTE(russellb): Allow models to specify other keys that can be looked
        # up, beyond the actual db columns.  An example would be the 'name'
        # property for an Instance.
        columns.extend(self._extra_keys)

        return ModelIterator(self, iter(columns)) 
开发者ID:openstack,项目名称:oslo.db,代码行数:10,代码来源:models.py

示例7: _assert_not_orphan

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import object_mapper [as 别名]
def _assert_not_orphan(self, c1):
        mapper = object_mapper(c1)
        state = instance_state(c1)
        assert not mapper._is_orphan(state) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:6,代码来源:test_cascade.py

示例8: _assert_is_orphan

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import object_mapper [as 别名]
def _assert_is_orphan(self, c1):
        mapper = object_mapper(c1)
        state = instance_state(c1)
        assert mapper._is_orphan(state) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:6,代码来源:test_cascade.py

示例9: create_history

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import object_mapper [as 别名]
def create_history(obj, history_cls=None):
    if not history_cls:
        history_mapper = obj.__history_mapper__
        history_cls = history_mapper.class_

    obj_mapper = object_mapper(obj)

    obj_state = attributes.instance_state(obj)
    data = {}
    for prop in obj_mapper.iterate_properties:

        # expired object attributes and also deferred cols might not
        # be in the dict.  force it them load no matter what by using getattr().
        if prop.key not in obj_state.dict:
            getattr(obj, prop.key)

        # if prop is a normal col just set it on history model
        if isinstance(prop, ColumnProperty):
            if not data.get(prop.key):
                data[prop.key] = getattr(obj, prop.key)

        # if the prop is a relationship property and there is a
        # corresponding prop on hist object then set the
        # relevant "_id" prop to the id of the current object.prop.id.
        # This is so foreign keys get set on history when
        # the source object is new and therefore property foo_id does
        # not yet have a value before insert

        elif isinstance(prop, RelationshipProperty):
            if hasattr(history_cls, prop.key + '_id'):
                foreign_obj = getattr(obj, prop.key)
                # if it's a nullable relationship, foreign_obj will be None, and we actually want to record that
                data[prop.key + '_id'] = getattr(foreign_obj, 'id', None)

    if not obj.version:
        obj.version = 1
        obj.created_at = datetime.datetime.utcnow()
    else:
        obj.version += 1
        now = datetime.datetime.utcnow()
        obj.updated_at = now
        data['updated_at'] = now

    data['version'] = obj.version
    data['created_at'] = obj.created_at

    return history_cls(**data) 
开发者ID:alphagov,项目名称:notifications-api,代码行数:49,代码来源:history_meta.py

示例10: _roundtrip

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import object_mapper [as 别名]
def _roundtrip(
        self, set_event=True, parent_ident="parent", child_ident="child"
    ):
        Parent, Child = self.classes.Parent, self.classes.Child

        # locate the "polymorphic_on" ColumnProperty.   This isn't
        # "officially" stored at the moment so do some heuristics to find it.
        parent_mapper = inspect(Parent)
        for prop in parent_mapper.column_attrs:
            if not prop.instrument:
                break
        else:
            prop = parent_mapper._columntoproperty[
                parent_mapper.polymorphic_on
            ]

        # then make sure the column we will query on matches.
        is_(parent_mapper.polymorphic_on, prop.columns[0])

        if set_event:

            @event.listens_for(Parent, "init", propagate=True)
            def set_identity(instance, *arg, **kw):
                ident = object_mapper(instance).polymorphic_identity
                if ident == "parent":
                    instance.x = parent_ident
                elif ident == "child":
                    instance.x = child_ident
                else:
                    assert False, "Got unexpected identity %r" % ident

        s = Session(testing.db)
        s.add_all([Parent(q="p1"), Child(q="c1", y="c1"), Parent(q="p2")])
        s.commit()
        s.close()

        eq_(
            [type(t) for t in s.query(Parent).order_by(Parent.id)],
            [Parent, Child, Parent],
        )

        eq_([type(t) for t in s.query(Child).all()], [Child]) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:44,代码来源:test_basic.py


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