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


Python sqlalchemy.and_方法代码示例

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


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

示例1: __and__

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import and_ [as 别名]
def __and__(self, other):
        """Implement the ``&`` operator.

        When used with SQL expressions, results in an
        AND operation, equivalent to
        :func:`~.expression.and_`, that is::

            a & b

        is equivalent to::

            from sqlalchemy import and_
            and_(a, b)

        Care should be taken when using ``&`` regarding
        operator precedence; the ``&`` operator has the highest precedence.
        The operands should be enclosed in parenthesis if they contain
        further sub expressions::

            (a == 2) & (b == 4)

        """
        return self.operate(and_, other) 
开发者ID:jpush,项目名称:jbox,代码行数:25,代码来源:operators.py

示例2: get_rse

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import and_ [as 别名]
def get_rse(rse_id, session=None):
    """
    Get a RSE or raise if it does not exist.

    :param rse_id:  The rse id.
    :param session: The database session in use.

    :raises RSENotFound: If referred RSE was not found in the database.
    """

    false_value = False  # To make pep8 checker happy ...
    try:
        tmp = session.query(models.RSE).\
            filter(sqlalchemy.and_(models.RSE.deleted == false_value,
                                   models.RSE.id == rse_id))\
            .one()
        tmp['type'] = tmp.rse_type
        return tmp
    except sqlalchemy.orm.exc.NoResultFound:
        raise exception.RSENotFound('RSE with id \'%s\' cannot be found' % rse_id) 
开发者ID:rucio,项目名称:rucio,代码行数:22,代码来源:rse.py

示例3: set_tombstone

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import and_ [as 别名]
def set_tombstone(rse_id, scope, name, tombstone=OBSOLETE, session=None):
    """
    Sets a tombstone on a replica.

    :param rse_id: ID of RSE.
    :param scope: scope of the replica DID.
    :param name: name of the replica DID.
    :param tombstone: the tombstone to set. Default is OBSOLETE
    :param session: database session in use.
    """
    stmt = update(models.RSEFileAssociation).where(and_(models.RSEFileAssociation.rse_id == rse_id, models.RSEFileAssociation.name == name, models.RSEFileAssociation.scope == scope,
                                                        ~session.query(models.ReplicaLock).filter_by(scope=scope, name=name, rse_id=rse_id).exists()))\
                                            .values(tombstone=tombstone)
    result = session.execute(stmt)
    if not result.rowcount:
        try:
            session.query(models.RSEFileAssociation).filter_by(scope=scope, name=name, rse_id=rse_id).one()
            raise exception.ReplicaIsLocked('Replica %s:%s on RSE %s is locked.' % (scope, name, get_rse_name(rse_id=rse_id, session=session)))
        except NoResultFound:
            raise exception.ReplicaNotFound('Replica %s:%s on RSE %s could not be found.' % (scope, name, get_rse_name(rse_id=rse_id, session=session))) 
开发者ID:rucio,项目名称:rucio,代码行数:22,代码来源:replica.py

示例4: delete_temporary_dids

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import and_ [as 别名]
def delete_temporary_dids(dids, session=None):
    """
    Delete temporary file replicas.

    :param dids: the list of files to delete.
    :param session
    """
    where_clause = []
    for did in dids:
        where_clause.append(and_(models.TemporaryDataIdentifier.scope == did['scope'],
                                 models.TemporaryDataIdentifier.name == did['name']))

    if where_clause:
        return session.query(models.TemporaryDataIdentifier).\
            with_hint(models.TemporaryDataIdentifier, "INDEX(tmp_dids TMP_DIDS_PK)", 'oracle').\
            filter(or_(*where_clause)).delete(synchronize_session=False)
    return 
开发者ID:rucio,项目名称:rucio,代码行数:19,代码来源:temporary_did.py

示例5: release_waiting_requests_per_deadline

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import and_ [as 别名]
def release_waiting_requests_per_deadline(rse_id=None, deadline=1, session=None):
    """
    Release waiting requests that were waiting too long and exceeded the maximum waiting time to be released.
    If the DID of a request is attached to a dataset, the oldest requested_at date of all requests related to the dataset will be used for checking and all requests of this dataset will be released.
    :param rse_id:           The source RSE id.
    :param deadline:         Maximal waiting time in hours until a dataset gets released.
    :param session:          The database session.
    """
    amount_released_requests = 0
    if deadline:
        grouped_requests_subquery, filtered_requests_subquery = create_base_query_grouped_fifo(rse_id, filter_by_rse='source', session=session)
        old_requests_subquery = session.query(grouped_requests_subquery.c.name,
                                              grouped_requests_subquery.c.scope,
                                              grouped_requests_subquery.c.oldest_requested_at)\
                                       .filter(grouped_requests_subquery.c.oldest_requested_at < datetime.datetime.now() - datetime.timedelta(hours=deadline))\
                                       .subquery()
        old_requests_subquery = session.query(filtered_requests_subquery.c.id)\
                                       .join(old_requests_subquery, and_(filtered_requests_subquery.c.dataset_name == old_requests_subquery.c.name, filtered_requests_subquery.c.dataset_scope == old_requests_subquery.c.scope))
        old_requests_subquery = old_requests_subquery.subquery()
        statement = update(models.Request).where(models.Request.id.in_(old_requests_subquery)).values(state=RequestState.QUEUED)
        amount_released_requests = session.execute(statement).rowcount
    return amount_released_requests 
开发者ID:rucio,项目名称:rucio,代码行数:24,代码来源:request.py

示例6: search_vulnerabilities_for_description

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import and_ [as 别名]
def search_vulnerabilities_for_description(word_list, db_table):
    """
    Search vulnerabilities for description.
    :param word_list: the list of words searched by the user.
    :param db_table: the database table in which perform the search.
    :return: the list containing the results of the performed search.
    """
    session = start_session()

    if db_table == 'searcher_exploit':
        queryset = session.query(Exploit).filter(and_(Exploit.description.contains(word) for word in word_list))
    else:
        queryset = session.query(Shellcode).filter(
            and_(Shellcode.description.contains(word) for word in word_list))

    session.close()
    return queryset2list(queryset) 
开发者ID:nicolas-carolo,项目名称:houndsploit,代码行数:19,代码来源:search_engine.py

示例7: search_vulnerabilities_for_file

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import and_ [as 别名]
def search_vulnerabilities_for_file(word_list, db_table):
    """
    Search vulnerabilities for file.
    :param word_list: the list of words searched by the user.
    :param db_table: the database table in which perform the search.
    :return: the list containing the results of the performed search.
    """
    session = start_session()

    if db_table == 'searcher_exploit':
        queryset = session.query(Exploit).filter(and_(Exploit.file.contains(word) for word in word_list))
    else:
        queryset = session.query(Shellcode).filter(
            and_(Shellcode.file.contains(word) for word in word_list))

    session.close()
    return queryset2list(queryset) 
开发者ID:nicolas-carolo,项目名称:houndsploit,代码行数:19,代码来源:search_engine.py

示例8: search_vulnerabilities_for_author

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import and_ [as 别名]
def search_vulnerabilities_for_author(word_list, db_table):
    """
    Search vulnerabilities for author.
    :param word_list: the list of words searched by the user.
    :param db_table: the database table in which perform the search.
    :return: the list containing the results of the performed search.
    """
    session = start_session()

    if db_table == 'searcher_exploit':
        queryset = session.query(Exploit).filter(and_(Exploit.author.contains(word) for word in word_list))
    else:
        queryset = session.query(Shellcode).filter(
            and_(Shellcode.author.contains(word) for word in word_list))

    session.close()
    return queryset2list(queryset) 
开发者ID:nicolas-carolo,项目名称:houndsploit,代码行数:19,代码来源:search_engine.py

示例9: search_exploits_version

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import and_ [as 别名]
def search_exploits_version(software_name, num_version):
    """
    Perform a search based on exploits' description for an input search that contains a number of version.
    This function is called by 'search_vulnerabilities_version' method.
    :param software_name: the name of the software that the user is searching for.
    :param num_version: the specific number of version the user is searching for.
    :return: a queryset with search result found in 'searcher_exploit' DB table.
    """
    session = start_session()
    queryset = session.query(Exploit).filter(and_(Exploit.description.contains(software_name)))
    query_result_set = queryset2list(queryset)
    session.close()
    # limit the time spent for searching useless results.
    if queryset.count() > N_MAX_RESULTS_NUMB_VERSION:
        return void_result_set()
    final_result_set = []
    for exploit in query_result_set:
        # if exploit not contains '<'
        if not str(exploit.description).__contains__('<'):
            final_result_set = filter_exploits_without_comparator(exploit, num_version, software_name, final_result_set)
        # if exploit contains '<'
        else:
            final_result_set = filter_exploits_with_comparator(exploit, num_version, software_name, final_result_set)
    return final_result_set 
开发者ID:nicolas-carolo,项目名称:houndsploit,代码行数:26,代码来源:search_engine.py

示例10: search_shellcodes_version

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import and_ [as 别名]
def search_shellcodes_version(software_name, num_version):
    """
    Perform a search based on exploits' description for an input search that contains a number of version.
    This function is called by 'search_vulnerabilities_version' method.
    :param software_name: the name of the software that the user is searching for.
    :param num_version: the specific number of version the user is searching for.
    :return: a queryset with search result found in 'searcher_exploit' DB table.
    """
    session = start_session()
    queryset = session.query(Shellcode).filter(and_(Shellcode.description.contains(software_name)))
    query_result_set = queryset2list(queryset)
    session.close()
    # limit the time spent for searching useless results.
    if queryset.count() > N_MAX_RESULTS_NUMB_VERSION:
        # return Exploit.objects.none()
        return void_result_set()
    final_result_set = []
    for shellcode in query_result_set:
        # if exploit not contains '<'
        if not str(shellcode.description).__contains__('<'):
            final_result_set = filter_shellcodes_without_comparator(shellcode, num_version, software_name, final_result_set)
        # if exploit contains '<'
        else:
            final_result_set = filter_shellcodes_with_comparator(shellcode, num_version, software_name, final_result_set)
    return final_result_set 
开发者ID:nicolas-carolo,项目名称:houndsploit,代码行数:27,代码来源:search_engine.py

示例11: _next_prev_query

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import and_ [as 别名]
def _next_prev_query(self, obj, next_or_prev='next'):
        session = sa.orm.object_session(obj)

        return (
            session.query(obj.__class__)
            .filter(
                sa.and_(
                    getattr(
                        obj.__class__,
                        tx_column_name(obj)
                    )
                    ==
                    self._transaction_id_subquery(
                        obj, next_or_prev=next_or_prev
                    ),
                    *parent_criteria(obj)
                )
            )
        ) 
开发者ID:fake-name,项目名称:ReadableWebProxy,代码行数:21,代码来源:fetcher.py

示例12: next_query

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import and_ [as 别名]
def next_query(self, obj):
        """
        Returns the query that fetches the next version relative to this
        version in the version history.
        """
        session = sa.orm.object_session(obj)

        return (
            session.query(obj.__class__)
            .filter(
                sa.and_(
                    getattr(obj.__class__, tx_column_name(obj))
                    ==
                    getattr(obj, end_tx_column_name(obj)),
                    *parent_criteria(obj)
                )
            )
        ) 
开发者ID:fake-name,项目名称:ReadableWebProxy,代码行数:20,代码来源:fetcher.py

示例13: previous_query

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import and_ [as 别名]
def previous_query(self, obj):
        """
        Returns the query that fetches the previous version relative to this
        version in the version history.
        """
        session = sa.orm.object_session(obj)

        return (
            session.query(obj.__class__)
            .filter(
                sa.and_(
                    getattr(obj.__class__, end_tx_column_name(obj))
                    ==
                    getattr(obj, tx_column_name(obj)),
                    *parent_criteria(obj)
                )
            )
        ) 
开发者ID:fake-name,项目名称:ReadableWebProxy,代码行数:20,代码来源:fetcher.py

示例14: _unconsume_high_failed_nonces

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import and_ [as 别名]
def _unconsume_high_failed_nonces(self, signing_wallet_id, stating_nonce):
        expire_time = datetime.datetime.utcnow() - datetime.timedelta(
            seconds=self.PENDING_TRANSACTION_EXPIRY_SECONDS
        )

        highest_known_success = (self.session.query(BlockchainTransaction)
                                 .filter(and_(BlockchainTransaction.signing_wallet_id == signing_wallet_id,
                                              BlockchainTransaction.status == 'SUCCESS'))
                                 .order_by(BlockchainTransaction.id.desc()).first()
                                 )

        if highest_known_success:
            highest_known_nonce = highest_known_success.nonce or 0
        else:
            highest_known_nonce = 0

        nonce = max(stating_nonce, highest_known_nonce)

        (self.session.query(BlockchainTransaction)
         .filter(and_(BlockchainTransaction.signing_wallet_id == signing_wallet_id,
                      BlockchainTransaction.status == 'FAILED',
                      BlockchainTransaction.nonce > nonce,
                      BlockchainTransaction.submitted_date < expire_time))
         .update({BlockchainTransaction.nonce_consumed: False},
                 synchronize_session=False)) 
开发者ID:teamsempo,项目名称:SempoBlockchain,代码行数:27,代码来源:interface.py

示例15: _get_history_result_mapper

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import and_ [as 别名]
def _get_history_result_mapper(self, session, resource_type):
        mappers = self._resource_type_to_mappers(session, resource_type)
        resource_cls = mappers['resource']
        history_cls = mappers['history']

        resource_cols = {}
        history_cols = {}
        for col in sqlalchemy.inspect(history_cls).columns:
            history_cols[col.name] = col
            if col.name in ["revision", "revision_end"]:
                value = None if col.name == "revision_end" else -1
                resource_cols[col.name] = sqlalchemy.bindparam(
                    col.name, value, col.type).label(col.name)
            else:
                resource_cols[col.name] = getattr(resource_cls, col.name)
        s1 = sqlalchemy.select(history_cols.values())
        s2 = sqlalchemy.select(resource_cols.values())
        if resource_type != "generic":
            s1 = s1.where(history_cls.revision == ResourceHistory.revision)
            s2 = s2.where(resource_cls.id == Resource.id)
        union_stmt = sqlalchemy.union(s1, s2)
        stmt = union_stmt.alias("result")

        class Result(base.ResourceJsonifier, base.GnocchiBase):
            def __iter__(self):
                return iter((key, getattr(self, key)) for key in stmt.c.keys())

        sqlalchemy.orm.mapper(
            Result, stmt, primary_key=[stmt.c.id, stmt.c.revision],
            properties={
                'metrics': sqlalchemy.orm.relationship(
                    Metric,
                    primaryjoin=sqlalchemy.and_(
                        Metric.resource_id == stmt.c.id,
                        Metric.status == 'active'),
                    foreign_keys=Metric.resource_id)
            })

        return Result 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:41,代码来源:sqlalchemy.py


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