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


Python orm.synonym方法代碼示例

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


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

示例1: test_evaluate_double_synonym_attr

# 需要導入模塊: from sqlalchemy import orm [as 別名]
# 或者: from sqlalchemy.orm import synonym [as 別名]
def test_evaluate_double_synonym_attr(self):
        class Foo(object):
            pass

        mapper(
            Foo,
            self.tables.users,
            properties={"uname": synonym("name"), "ufoo": synonym("uname")},
        )

        s = Session()
        jill = s.query(Foo).get(3)
        s.query(Foo).update(
            {Foo.ufoo: "moonbeam"}, synchronize_session="evaluate"
        )
        eq_(jill.ufoo, "moonbeam") 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:18,代碼來源:test_update_delete.py

示例2: test_column_prefix

# 需要導入模塊: from sqlalchemy import orm [as 別名]
# 或者: from sqlalchemy.orm import synonym [as 別名]
def test_column_prefix(self):
        users, User = self.tables.users, self.classes.User

        mapper(
            User,
            users,
            column_prefix="_",
            properties={"user_name": synonym("_name")},
        )

        s = create_session()
        u = s.query(User).get(7)
        eq_(u._name, "jack")
        eq_(u._id, 7)
        u2 = s.query(User).filter_by(user_name="jack").one()
        assert u is u2 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:18,代碼來源:test_mapper.py

示例3: test_info

# 需要導入模塊: from sqlalchemy import orm [as 別名]
# 或者: from sqlalchemy.orm import synonym [as 別名]
def test_info(self):
        users = self.tables.users
        Address = self.classes.Address

        class MyComposite(object):
            pass

        for constructor, args in [
            (column_property, (users.c.name,)),
            (relationship, (Address,)),
            (composite, (MyComposite, "id", "name")),
            (synonym, "foo"),
        ]:
            obj = constructor(info={"x": "y"}, *args)
            eq_(obj.info, {"x": "y"})
            obj.info["q"] = "p"
            eq_(obj.info, {"x": "y", "q": "p"})

            obj = constructor(*args)
            eq_(obj.info, {})
            obj.info["q"] = "p"
            eq_(obj.info, {"q": "p"}) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:24,代碼來源:test_mapper.py

示例4: test_synonym_nonexistent_attr

# 需要導入模塊: from sqlalchemy import orm [as 別名]
# 或者: from sqlalchemy.orm import synonym [as 別名]
def test_synonym_nonexistent_attr(self):
        # test [ticket:4767].
        # synonym points to non-existent attrbute that hasn't been mapped yet.
        users = self.tables.users

        class User(object):
            def _x(self):
                return self.id

            x = property(_x)

        m = mapper(
            User,
            users,
            properties={"x": synonym("some_attr", descriptor=User.x)},
        )

        # object gracefully handles this condition
        assert not hasattr(User.x, "__name__")
        assert not hasattr(User.x, "comparator")

        m.add_property("some_attr", column_property(users.c.name))

        assert not hasattr(User.x, "__name__")
        assert hasattr(User.x, "comparator") 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:27,代碼來源:test_mapper.py

示例5: test_synonym_column_location

# 需要導入模塊: from sqlalchemy import orm [as 別名]
# 或者: from sqlalchemy.orm import synonym [as 別名]
def test_synonym_column_location(self):
        users, User = self.tables.users, self.classes.User

        def go():
            mapper(
                User,
                users,
                properties={"not_name": synonym("_name", map_column=True)},
            )

        assert_raises_message(
            sa.exc.ArgumentError,
            (
                "Can't compile synonym '_name': no column on table "
                "'users' named 'not_name'"
            ),
            go,
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:20,代碼來源:test_mapper.py

示例6: test_synonym

# 需要導入模塊: from sqlalchemy import orm [as 別名]
# 或者: from sqlalchemy.orm import synonym [as 別名]
def test_synonym(self):
        users = self.tables.users

        class User(object):
            def _getValue(self):
                return self._value

            def _setValue(self, value):
                setattr(self, "_value", value)

            value = property(_getValue, _setValue)

        mapper(User, users, properties={"uid": synonym("id")})

        sess = create_session()
        u = User()
        u.name = "ed"
        sess.add(u)
        sess.flush()
        sess.expunge(u)
        sess.merge(u) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:23,代碼來源:test_merge.py

示例7: test_proxy_descriptor_one

# 需要導入模塊: from sqlalchemy import orm [as 別名]
# 或者: from sqlalchemy.orm import synonym [as 別名]
def test_proxy_descriptor_one(self):
        class Point(object):
            def __init__(self, x, y):
                self.x, self.y = x, y

        self._fixture(Point, properties={"x_syn": synonym("x")})
        alias = aliased(Point)

        eq_(str(Point.x_syn), "Point.x_syn")
        eq_(str(alias.x_syn), "AliasedClass_Point.x_syn")

        sess = Session()
        self.assert_compile(
            sess.query(alias.x_syn).filter(alias.x_syn > Point.x_syn),
            "SELECT point_1.x AS point_1_x FROM point AS point_1, point "
            "WHERE point_1.x > point.x",
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:19,代碼來源:test_utils.py

示例8: setup_classes

# 需要導入模塊: from sqlalchemy import orm [as 別名]
# 或者: from sqlalchemy.orm import synonym [as 別名]
def setup_classes(cls):
        from sqlalchemy.orm import synonym

        Base = cls.DeclarativeBasic

        class A(Base):
            __tablename__ = "a"

            id = Column(Integer, primary_key=True)
            data = Column(String)
            bs = relationship("B", backref="a")
            data_syn = synonym("data")

            b_data = association_proxy("bs", "data_syn")

        class B(Base):
            __tablename__ = "b"
            id = Column(Integer, primary_key=True)
            a_id = Column(ForeignKey("a.id"))
            data = Column(String)
            data_syn = synonym("data")

            a_data = association_proxy("a", "data_syn") 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:25,代碼來源:test_associationproxy.py

示例9: state

# 需要導入模塊: from sqlalchemy import orm [as 別名]
# 或者: from sqlalchemy.orm import synonym [as 別名]
def state(self):
        return synonym('_state', descriptor=property(self.get_state, self.set_state)) 
開發者ID:apache,項目名稱:airflow,代碼行數:4,代碼來源:dagrun.py

示例10: password

# 需要導入模塊: from sqlalchemy import orm [as 別名]
# 或者: from sqlalchemy.orm import synonym [as 別名]
def password(cls):   # pylint: disable=no-self-argument
        """Password. The value is decrypted/encrypted when reading/setting the value."""
        return synonym('_password',
                       descriptor=property(cls.get_password, cls.set_password)) 
開發者ID:apache,項目名稱:airflow,代碼行數:6,代碼來源:connection.py

示例11: extra

# 需要導入模塊: from sqlalchemy import orm [as 別名]
# 或者: from sqlalchemy.orm import synonym [as 別名]
def extra(cls):   # pylint: disable=no-self-argument
        """Extra data. The value is decrypted/encrypted when reading/setting the value."""
        return synonym('_extra',
                       descriptor=property(cls.get_extra, cls.set_extra)) 
開發者ID:apache,項目名稱:airflow,代碼行數:6,代碼來源:connection.py

示例12: val

# 需要導入模塊: from sqlalchemy import orm [as 別名]
# 或者: from sqlalchemy.orm import synonym [as 別名]
def val(cls):   # pylint: disable=no-self-argument
        """
        Get Airflow Variable from Metadata DB and decode it using the Fernet Key
        """
        return synonym('_val', descriptor=property(cls.get_val, cls.set_val)) 
開發者ID:apache,項目名稱:airflow,代碼行數:7,代碼來源:variable.py

示例13: answer

# 需要導入模塊: from sqlalchemy import orm [as 別名]
# 或者: from sqlalchemy.orm import synonym [as 別名]
def answer(self):
        """The answer. Could be the same as main_answer in simple cases.

        This property is the most useful representation available of the
        answer. In the simplest case it is just a synonym for main_answer.
        It could otherwise be a dictionary or another model.
        """ 
開發者ID:SEL-Columbia,項目名稱:dokomoforms,代碼行數:9,代碼來源:answer.py

示例14: test_synonym_group_bug

# 需要導入模塊: from sqlalchemy import orm [as 別名]
# 或者: from sqlalchemy.orm import synonym [as 別名]
def test_synonym_group_bug(self):
        orders, Order = self.tables.orders, self.classes.Order

        mapper(
            Order,
            orders,
            properties={
                "isopen": synonym("_isopen", map_column=True),
                "description": deferred(orders.c.description, group="foo"),
            },
        )

        sess = create_session()
        o1 = sess.query(Order).get(1)
        eq_(o1.description, "order 1") 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:17,代碼來源:test_deferred.py

示例15: test_add_property

# 需要導入模塊: from sqlalchemy import orm [as 別名]
# 或者: from sqlalchemy.orm import synonym [as 別名]
def test_add_property(self):
        users = self.tables.users

        assert_col = []

        class User(fixtures.ComparableEntity):
            def _get_name(self):
                assert_col.append(("get", self._name))
                return self._name

            def _set_name(self, name):
                assert_col.append(("set", name))
                self._name = name

            name = property(_get_name, _set_name)

        m = mapper(User, users)

        m.add_property("_name", deferred(users.c.name))
        m.add_property("name", synonym("_name"))

        sess = create_session(autocommit=False)
        assert sess.query(User).get(7)

        u = sess.query(User).filter_by(name="jack").one()

        def go():
            eq_(u.name, "jack")
            eq_(assert_col, [("get", "jack")], str(assert_col))

        self.sql_count_(1, go) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:33,代碼來源:test_deprecations.py


注:本文中的sqlalchemy.orm.synonym方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。