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


Python orm.contains_eager方法代码示例

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


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

示例1: get_dragents_hosting_bgp_speakers

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import contains_eager [as 别名]
def get_dragents_hosting_bgp_speakers(self, context, bgp_speaker_ids,
                                          active=None, admin_state_up=None):
        query = context.session.query(BgpSpeakerDrAgentBinding)
        query = query.options(orm.contains_eager(
                              BgpSpeakerDrAgentBinding.dragent))
        query = query.join(BgpSpeakerDrAgentBinding.dragent)

        if len(bgp_speaker_ids) == 1:
            query = query.filter(
                BgpSpeakerDrAgentBinding.bgp_speaker_id == (
                    bgp_speaker_ids[0]))
        elif bgp_speaker_ids:
            query = query.filter(
                BgpSpeakerDrAgentBinding.bgp_speaker_id in bgp_speaker_ids)
        if admin_state_up is not None:
            query = query.filter(agent_model.Agent.admin_state_up ==
                                 admin_state_up)

        return [binding.dragent
                for binding in query
                if as_db.AgentSchedulerDbMixin.is_eligible_agent(
                                                active, binding.dragent)] 
开发者ID:openstack,项目名称:neutron-dynamic-routing,代码行数:24,代码来源:bgp_dragentscheduler_db.py

示例2: test_contains_eager_outermost

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import contains_eager [as 别名]
def test_contains_eager_outermost(self, plain_fixture):
        User, Address = plain_fixture

        stmt = (
            select(Address)
            .join(Address.user)
            .options(contains_eager(Address.user))
        )

        # render joined eager loads with stringify
        self.assert_compile(
            stmt,
            "SELECT users.id, users.name, addresses.id AS id_1, "
            "addresses.user_id, "
            "addresses.email_address "
            "FROM addresses JOIN users ON users.id = addresses.user_id",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_core_compilation.py

示例3: test_with_polymorphic_join_exec_contains_eager_one

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import contains_eager [as 别名]
def test_with_polymorphic_join_exec_contains_eager_one(self):
        sess = Session()

        def go():
            wp = with_polymorphic(
                Person, [Engineer, Manager], aliased=True, flat=True
            )
            eq_(
                sess.query(Company)
                .join(Company.employees.of_type(wp))
                .order_by(Company.company_id, wp.person_id)
                .options(contains_eager(Company.employees.of_type(wp)))
                .all(),
                [self.c1, self.c2],
            )

        self.assert_sql_count(testing.db, go, 1) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_of_type.py

示例4: test_contains_eager_wpoly

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import contains_eager [as 别名]
def test_contains_eager_wpoly(self):
        DataContainer, Job, SubJob = (
            self.classes.DataContainer,
            self.classes.Job,
            self.classes.SubJob,
        )

        Job_P = with_polymorphic(Job, SubJob, aliased=True)

        s = Session(testing.db)
        q = (
            s.query(DataContainer)
            .join(DataContainer.jobs.of_type(Job_P))
            .options(contains_eager(DataContainer.jobs.of_type(Job_P)))
        )

        def go():
            eq_(q.all(), self._dc_fixture())

        self.assert_sql_count(testing.db, go, 5) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:22,代码来源:test_of_type.py

示例5: test_poly_query_on_correlate_except

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import contains_eager [as 别名]
def test_poly_query_on_correlate_except(self):
        Common, Superclass = self._fixture(True)

        poly = with_polymorphic(Superclass, "*")

        s = Session()
        q = (
            s.query(poly)
            .options(contains_eager(poly.common_relationship))
            .join(poly.common_relationship)
            .filter(Common.id == 1)
        )

        self.assert_compile(
            q,
            "SELECT c.id AS c_id, (SELECT count(s1.id) AS count_1 "
            "FROM s1 LEFT OUTER JOIN s2 ON s1.id = s2.id "
            "WHERE s1.common_id = c.id) AS anon_1, "
            "s1.id AS s1_id, "
            "s1.common_id AS s1_common_id, "
            "s1.discriminator_field AS s1_discriminator_field, "
            "s2.id AS s2_id FROM s1 "
            "LEFT OUTER JOIN s2 ON s1.id = s2.id "
            "JOIN c ON c.id = s1.common_id WHERE c.id = :id_1",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:27,代码来源:test_assorted_poly.py

示例6: test_contains_eager_two

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

        sess = create_session()

        adalias = addresses.alias()
        q = (
            sess.query(User)
            .select_entity_from(users.outerjoin(adalias))
            .options(contains_eager(User.addresses, alias=adalias))
            .order_by(User.id, adalias.c.id)
        )

        def go():
            eq_(self.static.user_address_result, q.all())

        self.assert_sql_count(testing.db, go, 1) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:23,代码来源:test_froms.py

示例7: test_columns_multi_table_uselabels_cols_contains_eager

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import contains_eager [as 别名]
def test_columns_multi_table_uselabels_cols_contains_eager(self):
        # test that columns using column._label match, as well as that
        # ordering doesn't matter.
        User = self.classes.User
        Address = self.classes.Address

        s = create_session()
        q = (
            s.query(User)
            .from_statement(
                text(
                    "select users.name AS users_name, users.id AS users_id, "
                    "addresses.id AS addresses_id FROM users JOIN addresses "
                    "ON users.id = addresses.user_id WHERE users.id=8 "
                    "ORDER BY addresses.id"
                ).columns(User.name, User.id, Address.id)
            )
            .options(contains_eager(User.addresses))
        )

        def go():
            r = q.all()
            eq_(r[0].addresses, [Address(id=2), Address(id=3), Address(id=4)])

        self.assert_sql_count(testing.db, go, 1) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:27,代码来源:test_query.py

示例8: list_inventories

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import contains_eager [as 别名]
def list_inventories(self, context, filters=None, limit=None,
                         marker=None, sort_key=None, sort_dir=None):
        session = get_session()
        query = model_query(models.Inventory, session=session)
        query = self._add_inventories_filters(query, filters)
        query = query.join(models.Inventory.resource_provider)
        query = query.options(contains_eager('resource_provider'))
        return _paginate_query(models.Inventory, limit, marker,
                               sort_key, sort_dir, query) 
开发者ID:openstack,项目名称:zun,代码行数:11,代码来源:api.py

示例9: get_inventory

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import contains_eager [as 别名]
def get_inventory(self, context, inventory_id):
        session = get_session()
        query = model_query(models.Inventory, session=session)
        query = query.join(models.Inventory.resource_provider)
        query = query.options(contains_eager('resource_provider'))
        query = query.filter_by(id=inventory_id)
        try:
            return query.one()
        except NoResultFound:
            raise exception.InventoryNotFound(inventory=inventory_id) 
开发者ID:openstack,项目名称:zun,代码行数:12,代码来源:api.py

示例10: list_allocations

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import contains_eager [as 别名]
def list_allocations(self, context, filters=None, limit=None,
                         marker=None, sort_key=None, sort_dir=None):
        session = get_session()
        query = model_query(models.Allocation, session=session)
        query = self._add_allocations_filters(query, filters)
        query = query.join(models.Allocation.resource_provider)
        query = query.options(contains_eager('resource_provider'))
        return _paginate_query(models.Allocation, limit, marker,
                               sort_key, sort_dir, query) 
开发者ID:openstack,项目名称:zun,代码行数:11,代码来源:api.py

示例11: get_allocation

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import contains_eager [as 别名]
def get_allocation(self, context, allocation_id):
        session = get_session()
        query = model_query(models.Allocation, session=session)
        query = query.join(models.Allocation.resource_provider)
        query = query.options(contains_eager('resource_provider'))
        query = query.filter_by(id=allocation_id)
        try:
            return query.one()
        except NoResultFound:
            raise exception.AllocationNotFound(allocation=allocation_id) 
开发者ID:openstack,项目名称:zun,代码行数:12,代码来源:api.py

示例12: with_my_activities

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import contains_eager [as 别名]
def with_my_activities(self):
        if not current_user or not current_user.is_authenticated:
            return self

        from .activity import Activity

        my_activities = aliased(Activity.query.filter(
            Activity.subject_id == current_user.id
            ).cte(name="my_activities"), "my_activities")

        return self.outerjoin(my_activities).options(contains_eager(
            Object.my_activities, alias=my_activities)) 
开发者ID:beavyHQ,项目名称:beavy,代码行数:14,代码来源:object.py

示例13: create_query

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import contains_eager [as 别名]
def create_query(self):
        """Called in the build_query() template method."""
        return DBSession.query(self.queried_model_class)

    ## commented out, as the necessary join is already in
    ## generate_query_results()
    #def query__client_join(self, query):
    #    """Called in the build_query() template method."""
    #    if self.client_relationship is not None:
    #        relationship_obj = getattr(self.queried_model_class,
    #                                   self.client_relationship)
    #        query = query.outerjoin(relationship_obj)
    #        query = query.options(contains_eager(relationship_obj))
    #    return query 
开发者ID:CERT-Polska,项目名称:n6,代码行数:16,代码来源:data_backend_api.py

示例14: data_source

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import contains_eager [as 别名]
def data_source(request):
    try:
        hazardset_id = request.matchdict.get("hazardset")
        hazardset = (
            request.dbsession.query(HazardSet)
            .join(Layer)
            .filter(HazardSet.id == hazardset_id)
            .order_by(Layer.return_period)
            .options(contains_eager(HazardSet.layers))
            .one()
        )
    except:
        raise HTTPBadRequest(detail="incorrect value for parameter " '"hazardset"')

    return {"hazardset": hazardset} 
开发者ID:GFDRR,项目名称:thinkhazard,代码行数:17,代码来源:report.py

示例15: admindiv_hazardsets_hazardtype

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import contains_eager [as 别名]
def admindiv_hazardsets_hazardtype(request):

    try:
        hazardtype = request.matchdict.get("hazardtype")
    except:
        raise HTTPBadRequest(detail="incorrect value for parameter " '"hazardtype"')

    if HazardType.get(request.dbsession, hazardtype) is None:
        raise HTTPBadRequest(detail="hazardtype doesn't exist")

    query = (
        request.dbsession.query(AdministrativeDivision)
        .join(HazardCategoryAdministrativeDivisionAssociation)
        .join(HazardCategory)
        .join(HazardType)
        .filter(HazardType.mnemonic == hazardtype)
        .join(AdminLevelType)
        .filter(AdminLevelType.id == 3)
        .order_by(AdministrativeDivision.name)
        .options(contains_eager(AdministrativeDivision.hazardcategories))
    )

    data = [
        {
            "code": row.code,
            "name": row.name,
            "level_2": row.parent.name,
            "level_1": row.parent.parent.name,
            "hazardset": row.hazardcategories[0].hazardsets[0].id
            if row.hazardcategories[0].hazardsets
            else None,
            "hazard_level": row.hazardcategories[0].hazardcategory.hazardlevel.mnemonic,
        }
        for row in query
    ]

    return data 
开发者ID:GFDRR,项目名称:thinkhazard,代码行数:39,代码来源:admin.py


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