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


Python orm.aliased方法代码示例

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


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

示例1: correlate

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import aliased [as 别名]
def correlate(self, *args):
        """Return a :class:`.Query` construct which will correlate the given
        FROM clauses to that of an enclosing :class:`.Query` or
        :func:`~.expression.select`.

        The method here accepts mapped classes, :func:`.aliased` constructs,
        and :func:`.mapper` constructs as arguments, which are resolved into
        expression constructs, in addition to appropriate expression
        constructs.

        The correlation arguments are ultimately passed to
        :meth:`.Select.correlate` after coercion to expression constructs.

        The correlation arguments take effect in such cases
        as when :meth:`.Query.from_self` is used, or when
        a subquery as returned by :meth:`.Query.subquery` is
        embedded in another :func:`~.expression.select` construct.

         """

        self._correlate = self._correlate.union(
            _interpret_as_from(s)
            if s is not None else None
            for s in args) 
开发者ID:jpush,项目名称:jbox,代码行数:26,代码来源:query.py

示例2: _get_issues_by_account

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import aliased [as 别名]
def _get_issues_by_account(self):
        acct_alias = aliased(IssueProperty)

        issues = (
            db.query(func.count(Issue.issue_id), Account.account_name)
                .join(acct_alias, Issue.issue_id == acct_alias.issue_id)
                .join(Account, acct_alias.value == Account.account_id)
                .filter(
                Account.account_type_id == aws_account_type_id,
                Account.enabled == 1,
                Issue.issue_type_id == reqtag_type_id,
                acct_alias.name == 'account_id'
            )
                .group_by(Account.account_name)
                .all()
        )

        return defaultdict(int, map(reversed, issues)) 
开发者ID:RiotGames,项目名称:cloud-inquisitor,代码行数:20,代码来源:stats.py

示例3: get_sequences_for_project

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import aliased [as 别名]
def get_sequences_for_project(project_id):
    """
    Return all sequences for given project and for which current user has
    a task assigned to a shot.
    """
    shot_type = shots_service.get_shot_type()
    sequence_type = shots_service.get_sequence_type()

    Shot = aliased(Entity, name="shot")
    query = (
        Entity.query.join(Shot, Shot.parent_id == Entity.id)
        .join(Task, Task.entity_id == Shot.id)
        .join(EntityType, EntityType.id == Entity.entity_type_id)
        .join(Project, Project.id == Entity.project_id)
        .join(ProjectStatus)
        .filter(Shot.entity_type_id == shot_type["id"])
        .filter(Entity.entity_type_id == sequence_type["id"])
        .filter(Project.id == project_id)
        .filter(build_assignee_filter())
        .filter(build_open_project_filter())
    )

    return Entity.serialize_list(query.all(), obj_type="Sequence") 
开发者ID:cgwire,项目名称:zou,代码行数:25,代码来源:user_service.py

示例4: get_sequences_for_project

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import aliased [as 别名]
def get_sequences_for_project(project_id, only_assigned=False):
    """
    Retrieve all sequences related to given project.
    """
    if only_assigned:
        Shot = aliased(Entity, name="shot")
        query = (
            Entity.query
            .join(Shot, Entity.id == Shot.parent_id)
            .join(Task, Shot.id == Task.entity_id)
            .filter(Entity.project_id == project_id)
            .filter(user_service.build_assignee_filter())
        )
        return fields.serialize_models(query.all())
    else:
        return entities_service.get_entities_for_project(
            project_id, get_sequence_type()["id"], "Sequence"
        ) 
开发者ID:cgwire,项目名称:zou,代码行数:20,代码来源:shots_service.py

示例5: get_sequences_for_episode

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import aliased [as 别名]
def get_sequences_for_episode(episode_id, only_assigned=False):
    """
    Retrieve all sequences related to given episode.
    """
    if only_assigned:
        Shot = aliased(Entity, name="shot")
        query = (
            Entity.query
            .join(Shot, Entity.id == Shot.parent_id)
            .join(Task, Shot.id == Task.entity_id)
            .filter(Entity.parent_id == episode_id)
            .filter(user_service.build_assignee_filter())
        )
        return fields.serialize_models(query.all())
    else:
        return get_episodes({"parent_id": episode_id}) 
开发者ID:cgwire,项目名称:zou,代码行数:18,代码来源:shots_service.py

示例6: query_singleton_edges_from_network

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import aliased [as 别名]
def query_singleton_edges_from_network(self, network: Network) -> sqlalchemy.orm.query.Query:
        """Return a query selecting all edge ids that only belong to the given network."""
        ne1 = aliased(network_edge, name='ne1')
        ne2 = aliased(network_edge, name='ne2')
        singleton_edge_ids_for_network = (
            self.session
                .query(ne1.c.edge_id)
                .outerjoin(
                    ne2, and_(
                        ne1.c.edge_id == ne2.c.edge_id,
                        ne1.c.network_id != ne2.c.network_id,
                    ),
                )
                .filter(  # noqa: E131
                    and_(
                        ne1.c.network_id == network.id,
                        ne2.c.edge_id == None,  # noqa: E711
                    ),
                )
        )
        return singleton_edge_ids_for_network 
开发者ID:pybel,项目名称:pybel,代码行数:23,代码来源:cache_manager.py

示例7: _tenant_networks_by_network_query

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import aliased [as 别名]
def _tenant_networks_by_network_query(self, context,
                                          network_id, bgp_speaker_id):
        """Return subquery for tenant networks by binding network ID"""
        address_scope = aliased(address_scope_db.AddressScope,
                                name='address_scope')
        router_attrs = aliased(l3_attrs_db.RouterExtraAttributes,
                               name='router_attrs')
        tenant_networks_query = context.session.query(
                                              l3_db.RouterPort.router_id,
                                              models_v2.Subnet.cidr,
                                              models_v2.Subnet.ip_version,
                                              address_scope.id)
        tenant_networks_query = tenant_networks_query.filter(
             l3_db.RouterPort.port_type != lib_consts.DEVICE_OWNER_ROUTER_GW,
             l3_db.RouterPort.port_type != lib_consts.DEVICE_OWNER_ROUTER_SNAT,
             l3_db.RouterPort.router_id == router_attrs.router_id,
             models_v2.IPAllocation.port_id == l3_db.RouterPort.port_id,
             models_v2.IPAllocation.subnet_id == models_v2.Subnet.id,
             models_v2.Subnet.network_id != network_id,
             models_v2.Subnet.subnetpool_id == models_v2.SubnetPool.id,
             models_v2.SubnetPool.address_scope_id == address_scope.id,
             BgpSpeaker.id == bgp_speaker_id,
             BgpSpeaker.ip_version == address_scope.ip_version,
             models_v2.Subnet.ip_version == address_scope.ip_version)
        return tenant_networks_query 
开发者ID:openstack,项目名称:neutron-dynamic-routing,代码行数:27,代码来源:bgp_db.py

示例8: _next_hop_ip_addresses_by_binding_filters

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import aliased [as 别名]
def _next_hop_ip_addresses_by_binding_filters(self,
                                                  network_id,
                                                  bgp_speaker_id):
        """Return the filters for querying nexthops by binding network"""
        address_scope = aliased(address_scope_db.AddressScope,
                                name='address_scope')
        return [models_v2.IPAllocation.port_id == l3_db.RouterPort.port_id,
            models_v2.IPAllocation.subnet_id == models_v2.Subnet.id,
            BgpSpeaker.id == bgp_speaker_id,
            BgpSpeakerNetworkBinding.bgp_speaker_id == BgpSpeaker.id,
            BgpSpeakerNetworkBinding.network_id == network_id,
            models_v2.Subnet.network_id == BgpSpeakerNetworkBinding.network_id,
            models_v2.Subnet.subnetpool_id == models_v2.SubnetPool.id,
            models_v2.SubnetPool.address_scope_id == address_scope.id,
            models_v2.Subnet.ip_version == address_scope.ip_version,
            l3_db.RouterPort.port_type == DEVICE_OWNER_ROUTER_GW] 
开发者ID:openstack,项目名称:neutron-dynamic-routing,代码行数:18,代码来源:bgp_db.py

示例9: _tenant_prefixes_by_router_filters

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import aliased [as 别名]
def _tenant_prefixes_by_router_filters(self, router_id, bgp_speaker_id):
        binding = aliased(BgpSpeakerNetworkBinding, name='network_binding')
        subnetpool = aliased(models_v2.SubnetPool,
                             name='subnetpool')
        router_attrs = aliased(l3_attrs_db.RouterExtraAttributes,
                               name='router_attrs')
        return [models_v2.Subnet.id == models_v2.IPAllocation.subnet_id,
                models_v2.Subnet.subnetpool_id == subnetpool.id,
                l3_db.RouterPort.router_id == router_id,
                l3_db.Router.id == l3_db.RouterPort.router_id,
                l3_db.Router.id == router_attrs.router_id,
                l3_db.Router.gw_port_id == models_v2.Port.id,
                models_v2.Port.network_id == binding.network_id,
                binding.bgp_speaker_id == BgpSpeaker.id,
                l3_db.RouterPort.port_type == DEVICE_OWNER_ROUTER_INTF,
                models_v2.IPAllocation.port_id == l3_db.RouterPort.port_id] 
开发者ID:openstack,项目名称:neutron-dynamic-routing,代码行数:18,代码来源:bgp_db.py

示例10: test_retirement_insert

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import aliased [as 别名]
def test_retirement_insert(session, match_lineup):
    match_from_db, lineup_from_db = match_lineup

    withdrawal = mce.Substitutions(lineup_out_id=lineup_from_db.id, time=85)
    session.add(withdrawal)

    lineup_alias = aliased(mcm.MatchLineups)
    withdrawal_from_db = session.query(mce.Substitutions)\
        .outerjoin(mcm.MatchLineups, mcm.MatchLineups.id == mce.Substitutions.lineup_in_id)\
        .join(lineup_alias, lineup_alias.id == mce.Substitutions.lineup_out_id)\
        .join(mcm.Matches).filter(mcm.Matches.id == match_from_db.id)

    assert withdrawal_from_db.count() == 1
    assert withdrawal_from_db[0].lineup_out.full_name == u"Cristiano Ronaldo"
    assert withdrawal_from_db[0].lineup_in is None
    assert withdrawal_from_db[0].time == 85 
开发者ID:soccermetrics,项目名称:marcotti,代码行数:18,代码来源:test_events.py

示例11: get_oldest_pending_db_row_with_lock

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import aliased [as 别名]
def get_oldest_pending_db_row_with_lock(context):
    # NOTE (sai): For performance reasons, we expect this method to use baked
    # query (http://docs.sqlalchemy.org/en/latest/orm/extensions/baked.html)
    journal_dep = aliased(models.OpenDaylightJournal)
    dep_query = bakery(lambda s1: s1.query(journal_dep))
    dep_query += lambda q: q.filter(
        models.OpenDaylightJournal.seqnum == journal_dep.seqnum)
    dep_query += lambda q: q.outerjoin(
        journal_dep.depending_on, aliased=True)
    dep_query += lambda q: q.filter(
        or_(models.OpenDaylightJournal.state == odl_const.PENDING,
            models.OpenDaylightJournal.state == odl_const.PROCESSING))
    row = bakery(lambda s2: s2.query(models.OpenDaylightJournal))
    row += lambda q: q.filter(
        models.OpenDaylightJournal.state == odl_const.PENDING,
        ~ (dep_query._as_query(q.session)).exists())
    row += lambda q: q.order_by(
        asc(models.OpenDaylightJournal.last_retried))
    row = row(context.session).first()
    if row:
        update_db_row_state(context, row, odl_const.PROCESSING)

    return row 
开发者ID:openstack,项目名称:networking-odl,代码行数:25,代码来源:db.py

示例12: test_orm_recursive_cte

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import aliased [as 别名]
def test_orm_recursive_cte(pg_only_dburl):
    with S(pg_only_dburl, echo=ECHO) as s:
        # Start with "origins": books that don't have prequels
        seed = s.query(Book.id.label('id'), Book.id.label('origin')) \
            .filter(Book.prequel == None)

        # Recurse by picking up sequels
        sequel = aliased(Book, name='sequel')
        recursive = seed.cte(recursive=True)
        recursive = recursive.union(
            s.query(sequel.id, recursive.c.origin)
            .filter(sequel.prequel_id == recursive.c.id)
        )

        # Count total books per origin
        count = func.count().label('count')
        origin = recursive.c.origin.label('origin')
        sq = s.query(origin, count).group_by(origin).cte(recursive=False)

        # Join to full book table
        q = s.query(sq.c.count, Book) \
            .filter(Book.id == sq.c.origin) \
            .order_by(sq.c.count.desc(), Book.id)

        check_paging_orm(q=q) 
开发者ID:djrobstep,项目名称:sqlakeyset,代码行数:27,代码来源:test_paging.py

示例13: process_vote

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import aliased [as 别名]
def process_vote(self, comment_id, username, value):
        session = Session()

        subquery = session.query(CommentVote).filter(
            CommentVote.username == username).subquery()
        vote_alias = aliased(CommentVote, subquery)
        q = session.query(Comment, vote_alias).outerjoin(vote_alias).filter(
            Comment.id == comment_id)
        comment, vote = q.one()

        if vote is None:
            vote = CommentVote(comment_id, username, value)
            comment.rating += value
        else:
            comment.rating += value - vote.value
            vote.value = value

        session.add(vote)
        session.commit()
        session.close() 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:22,代码来源:sqlalchemystorage.py

示例14: rbac_filter

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import aliased [as 别名]
def rbac_filter(cls, query, mode, user):
        service_alias = aliased(models["service"])
        public_services = query.filter(models["service"].public == true())
        user_services = (
            query.join(models["service"].originals.of_type(service_alias))
            .join(models["access"], service_alias.access)
            .join(models["user"], models["access"].users)
            .filter(models["access"].services_access.contains(mode))
            .filter(models["user"].name == user.name)
        )
        user_group_services = (
            query.join(models["service"].originals.of_type(service_alias))
            .join(models["access"], service_alias.access)
            .join(models["group"], models["access"].groups)
            .join(models["user"], models["group"].users)
            .filter(models["access"].services_access.contains(mode))
            .filter(models["user"].name == user.name)
        )
        return public_services.union(user_services, user_group_services) 
开发者ID:eNMS-automation,项目名称:eNMS,代码行数:21,代码来源:automation.py

示例15: outerjoin

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import aliased [as 别名]
def outerjoin(self, *props, **kwargs):
        """Create a left outer join against this ``Query`` object's criterion
        and apply generatively, returning the newly resulting ``Query``.

        Usage is the same as the ``join()`` method.

        """
        aliased, from_joinpoint, full = kwargs.pop('aliased', False), \
            kwargs.pop('from_joinpoint', False), \
            kwargs.pop('full', False)
        if kwargs:
            raise TypeError("unknown arguments: %s" %
                            ', '.join(sorted(kwargs)))
        return self._join(props,
                          outerjoin=True, full=full, create_aliases=aliased,
                          from_joinpoint=from_joinpoint) 
开发者ID:yfauser,项目名称:planespotter,代码行数:18,代码来源:query.py


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