当前位置: 首页>>代码示例>>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;未经允许,请勿转载。