當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。