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


Python orm.column_property方法代码示例

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


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

示例1: _memoized_attr_info

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import column_property [as 别名]
def _memoized_attr_info(self):
        """Info dictionary associated with the object, allowing user-defined
        data to be associated with this :class:`.InspectionAttr`.

        The dictionary is generated when first accessed.  Alternatively,
        it can be specified as a constructor argument to the
        :func:`.column_property`, :func:`.relationship`, or :func:`.composite`
        functions.

        .. versionadded:: 0.8  Added support for .info to all
           :class:`.MapperProperty` subclasses.

        .. versionchanged:: 1.0.0 :attr:`.MapperProperty.info` is also
           available on extension types via the
           :attr:`.InspectionAttrInfo.info` attribute, so that it can apply
           to a wider variety of ORM and extension constructs.

        .. seealso::

            :attr:`.QueryableAttribute.info`

            :attr:`.SchemaItem.info`

        """
        return {} 
开发者ID:jpush,项目名称:jbox,代码行数:27,代码来源:interfaces.py

示例2: get_inherited_denormalized_columns

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import column_property [as 别名]
def get_inherited_denormalized_columns(self, table):
        parent_models = list(versioned_parents(self.manager, self.model))
        mapper = sa.inspect(self.model)
        args = {}

        if parent_models and not (mapper.single or mapper.concrete):
            columns = [
                self.manager.option(self.model, 'operation_type_column_name'),
                self.manager.option(self.model, 'transaction_column_name')
            ]
            if self.manager.option(self.model, 'strategy') == 'validity':
                columns.append(
                    self.manager.option(
                        self.model,
                        'end_transaction_column_name'
                    )
                )

            for column in columns:
                args[column] = column_property(
                    table.c[column],
                    *[m.__table__.c[column] for m in parent_models]
                )
        return args 
开发者ID:fake-name,项目名称:ReadableWebProxy,代码行数:26,代码来源:model_builder.py

示例3: info

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import column_property [as 别名]
def info(self):
        """Info dictionary associated with the object, allowing user-defined
        data to be associated with this :class:`.MapperProperty`.

        The dictionary is generated when first accessed.  Alternatively,
        it can be specified as a constructor argument to the
        :func:`.column_property`, :func:`.relationship`, or :func:`.composite`
        functions.

        .. versionadded:: 0.8  Added support for .info to all
           :class:`.MapperProperty` subclasses.

        .. seealso::

            :attr:`.QueryableAttribute.info`

            :attr:`.SchemaItem.info`

        """
        return {} 
开发者ID:gltn,项目名称:stdm,代码行数:22,代码来源:interfaces.py

示例4: _memoized_attr_info

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import column_property [as 别名]
def _memoized_attr_info(self):
        """Info dictionary associated with the object, allowing user-defined
        data to be associated with this :class:`.InspectionAttr`.

        The dictionary is generated when first accessed.  Alternatively,
        it can be specified as a constructor argument to the
        :func:`.column_property`, :func:`_orm.relationship`, or
        :func:`.composite`
        functions.

        .. versionchanged:: 1.0.0 :attr:`.MapperProperty.info` is also
           available on extension types via the
           :attr:`.InspectionAttrInfo.info` attribute, so that it can apply
           to a wider variety of ORM and extension constructs.

        .. seealso::

            :attr:`.QueryableAttribute.info`

            :attr:`.SchemaItem.info`

        """
        return {} 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:25,代码来源:interfaces.py

示例5: test_column_property

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import column_property [as 别名]
def test_column_property(self):
        A = self.classes.A
        b_table, a_table = self.tables.b, self.tables.a
        cp = select([func.sum(b_table.c.value)]).where(
            b_table.c.a_id == a_table.c.id
        )

        self._fixture({"summation": column_property(cp.scalar_subquery())})
        self.assert_compile(
            create_session()
            .query(A)
            .options(joinedload("bs"))
            .order_by(A.summation)
            .limit(50),
            "SELECT anon_1.anon_2 AS anon_1_anon_2, anon_1.a_id "
            "AS anon_1_a_id, b_1.id AS b_1_id, b_1.a_id AS "
            "b_1_a_id, b_1.value AS b_1_value FROM (SELECT "
            "(SELECT sum(b.value) AS sum_1 FROM b WHERE b.a_id = a.id) "
            "AS anon_2, a.id AS a_id FROM a ORDER BY anon_2 "
            "LIMIT :param_1) AS anon_1 LEFT OUTER JOIN b AS b_1 ON "
            "anon_1.a_id = b_1.a_id ORDER BY anon_1.anon_2",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:24,代码来源:test_eager_relations.py

示例6: test_column_property_desc

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import column_property [as 别名]
def test_column_property_desc(self):
        A = self.classes.A
        b_table, a_table = self.tables.b, self.tables.a
        cp = select([func.sum(b_table.c.value)]).where(
            b_table.c.a_id == a_table.c.id
        )

        self._fixture({"summation": column_property(cp.scalar_subquery())})
        self.assert_compile(
            create_session()
            .query(A)
            .options(joinedload("bs"))
            .order_by(A.summation.desc())
            .limit(50),
            "SELECT anon_1.anon_2 AS anon_1_anon_2, anon_1.a_id "
            "AS anon_1_a_id, b_1.id AS b_1_id, b_1.a_id AS "
            "b_1_a_id, b_1.value AS b_1_value FROM (SELECT "
            "(SELECT sum(b.value) AS sum_1 FROM b WHERE b.a_id = a.id) "
            "AS anon_2, a.id AS a_id FROM a ORDER BY anon_2 DESC "
            "LIMIT :param_1) AS anon_1 LEFT OUTER JOIN b AS b_1 ON "
            "anon_1.a_id = b_1.a_id ORDER BY anon_1.anon_2 DESC",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:24,代码来源:test_eager_relations.py

示例7: test_column_property_correlated

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import column_property [as 别名]
def test_column_property_correlated(self):
        A = self.classes.A
        b_table, a_table = self.tables.b, self.tables.a
        cp = (
            select([func.sum(b_table.c.value)])
            .where(b_table.c.a_id == a_table.c.id)
            .correlate(a_table)
        )

        self._fixture({"summation": column_property(cp.scalar_subquery())})
        self.assert_compile(
            create_session()
            .query(A)
            .options(joinedload("bs"))
            .order_by(A.summation)
            .limit(50),
            "SELECT anon_1.anon_2 AS anon_1_anon_2, anon_1.a_id "
            "AS anon_1_a_id, b_1.id AS b_1_id, b_1.a_id AS "
            "b_1_a_id, b_1.value AS b_1_value FROM (SELECT "
            "(SELECT sum(b.value) AS sum_1 FROM b WHERE b.a_id = a.id) "
            "AS anon_2, a.id AS a_id FROM a ORDER BY anon_2 "
            "LIMIT :param_1) AS anon_1 LEFT OUTER JOIN b AS b_1 ON "
            "anon_1.a_id = b_1.a_id ORDER BY anon_1.anon_2",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:26,代码来源:test_eager_relations.py

示例8: test_info

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import column_property [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

示例9: test_column_prop_deannotate

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import column_property [as 别名]
def test_column_prop_deannotate(self):
        """test that column property deannotates,
        bringing expressions down to the original mapped columns.
        """
        User, users = self.classes.User, self.tables.users
        m = mapper(User, users)
        assert User.id.property.columns[0] is users.c.id
        assert User.name.property.columns[0] is users.c.name
        expr = User.name + "name"
        expr2 = sa.select([User.name, users.c.id])
        m.add_property("x", column_property(expr))
        m.add_property("y", column_property(expr2.scalar_subquery()))

        assert User.x.property.columns[0] is not expr
        assert User.x.property.columns[0].element.left is users.c.name
        # a deannotate needs to clone the base, in case
        # the original one referenced annotated elements.
        assert User.x.property.columns[0].element.right is not expr.right

        assert User.y.property.columns[0] is not expr2
        assert (
            User.y.property.columns[0].element._raw_columns[0] is users.c.name
        )
        assert User.y.property.columns[0].element._raw_columns[1] is users.c.id 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:26,代码来源:test_mapper.py

示例10: test_synonym_nonexistent_attr

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import column_property [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

示例11: test_kwarg_accepted

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import column_property [as 别名]
def test_kwarg_accepted(self):
        users, Address = self.tables.users, self.classes.Address

        class DummyComposite(object):
            def __init__(self, x, y):
                pass

        from sqlalchemy.orm.interfaces import PropComparator

        class MyFactory(PropComparator):
            pass

        for args in (
            (column_property, users.c.name),
            (deferred, users.c.name),
            (synonym, "name"),
            (composite, DummyComposite, users.c.id, users.c.name),
            (relationship, Address),
            (backref, "address"),
            (dynamic_loader, Address),
        ):
            fn = args[0]
            args = args[1:]
            fn(comparator_factory=MyFactory, *args) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:26,代码来源:test_mapper.py

示例12: _fixture

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import column_property [as 别名]
def _fixture(self, label=True, polymorphic=False):
        User, Address = self.classes("User", "Address")
        users, addresses = self.tables("users", "addresses")
        stmt = (
            select([func.max(addresses.c.email_address)])
            .where(addresses.c.user_id == users.c.id)
            .correlate(users)
        )
        if label:
            stmt = stmt.label("email_ad")
        else:
            stmt = stmt.scalar_subquery()

        mapper(
            User,
            users,
            properties={"ead": column_property(stmt)},
            with_polymorphic="*" if polymorphic else None,
        )
        mapper(Address, addresses) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:22,代码来源:test_query.py

示例13: test_column_property_select

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import column_property [as 别名]
def test_column_property_select(self):
        User = self.classes.User
        Address = self.classes.Address

        mapper = inspect(User)
        mapper.add_property(
            "score",
            column_property(
                select([func.sum(Address.id)])
                .where(Address.user_id == User.id)
                .scalar_subquery()
            ),
        )
        session = Session()

        with self._assert_bind_args(session):
            session.query(func.max(User.score)).scalar() 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_query.py

示例14: _fixture

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import column_property [as 别名]
def _fixture(self):
        User, Address = self.classes.User, self.classes.Address
        Dingaling = self.classes.Dingaling
        address_table = self.tables.addresses

        class SubAddr(Address):
            pass

        mapper(
            SubAddr,
            inherits=Address,
            properties={
                "sub_attr": column_property(address_table.c.email_address),
                "dings": relationship(Dingaling, viewonly=True),
            },
        )

        return User, Address, SubAddr 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_options.py

示例15: test_property_noncascade

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import column_property [as 别名]
def test_property_noncascade(self):
        counter = mock.Mock()

        class Mixin(object):
            @declared_attr
            def my_prop(cls):
                counter(cls)
                return column_property(cls.x + 2)

        class A(Base, Mixin):
            __tablename__ = "a"

            id = Column(Integer, primary_key=True)
            x = Column(Integer)

        class B(A):
            pass

        eq_(counter.mock_calls, [mock.call(A)]) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_mixin.py


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