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


Python func.count方法代码示例

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


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

示例1: get_top_logins

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import count [as 别名]
def get_top_logins(limit=10):
    """ Return most popular logins for auto-completion """

    count_ = func.count('*')

    results = get_session().query(SecretModel.login, count_).\
        filter(SecretModel.login != '').\
        group_by(SecretModel.login).\
        order_by(count_.desc()).\
        limit(limit).\
        all()

    if results:
        return [result.login for result in results]

    return [] 
开发者ID:gabfl,项目名称:vault,代码行数:18,代码来源:secrets.py

示例2: get_count_of_expired_temporary_dids

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import count [as 别名]
def get_count_of_expired_temporary_dids(rse_id, session=None):
    """
    List expired temporary DIDs.

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

    :returns: a count number.
    """
    is_none = None
    count = session.query(func.count(models.TemporaryDataIdentifier.scope)).\
        with_hint(models.TemporaryDataIdentifier, "INDEX(tmp_dids TMP_DIDS_EXPIRED_AT_IDX)", 'oracle').\
        filter(case([(models.TemporaryDataIdentifier.expired_at != is_none, models.TemporaryDataIdentifier.rse_id), ]) == rse_id).\
        one()

    return count[0] or 0 
开发者ID:rucio,项目名称:rucio,代码行数:18,代码来源:temporary_did.py

示例3: list_payload_counts

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import count [as 别名]
def list_payload_counts(executable, older_than=600, hash_executable=None, session=None):
    """
    Give the counts of number of threads per payload for a certain executable.

    :param executable: Executable name as a string, e.g., conveyor-submitter
    :param older_than: Removes specified heartbeats older than specified nr of seconds
    :param hash_executable: Hash of the executable.
    :param session: The database session in use.

    :returns: List of tuples
    """

    if not hash_executable:
        hash_executable = calc_hash(executable)
    query = session.query(Heartbeats.payload,
                          func.count(Heartbeats.payload))\
                   .filter(Heartbeats.executable == hash_executable)\
                   .filter(Heartbeats.updated_at >= datetime.datetime.utcnow() - datetime.timedelta(seconds=older_than))\
                   .group_by(Heartbeats.payload)\
                   .order_by(Heartbeats.payload)

    return dict(query.all()) 
开发者ID:rucio,项目名称:rucio,代码行数:24,代码来源:heartbeat.py

示例4: count

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import count [as 别名]
def count(column, value, glob=False):
    """Counts number of rows with value in a column. This function is case-insensitive.

    Positional arguments:
    column -- the SQLAlchemy column object to search in (e.g. Table.a_column).
    value -- the value to search for, any string.

    Keyword arguments:
    glob -- enable %globbing% search (default False).

    Returns:
    Number of rows that match. Equivalent of SELECT count(*) FROM.
    """
    query = db.session.query(func.count('*'))
    if glob:
        query = query.filter(column.ilike(value))
    else:
        query = query.filter(func.lower(column) == value.lower())
    return query.one()[0] 
开发者ID:Robpol86,项目名称:Flask-Large-Application-Example,代码行数:21,代码来源:helpers.py

示例5: review_probable_validated

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import count [as 别名]
def review_probable_validated(self):
		self.log.info("Doing optional validation")
		with db.session_context() as db_sess:
			new_items = db_sess.query(db.NuReleaseItem)           \
					.filter(db.NuReleaseItem.validated == True)        \
					.filter(db.NuReleaseItem.reviewed == 'unverified') \
					.filter(db.NuReleaseItem.actual_target != None)    \
					.order_by(desc(db.NuReleaseItem.first_seen))       \
					.all()


			unverified = db_sess.query(db.NuReleaseItem)           \
					.filter(db.NuReleaseItem.validated == False)        \
					.filter(db.NuReleaseItem.actual_target != None)    \
					.count()

			self.log.info("Have %s items to do validity checks on", len(new_items))
			self.log.info("%s items needing checking", unverified)

			for row in new_items:
				self.review_probable_validated_row(row)

			db_sess.commit() 
开发者ID:fake-name,项目名称:ReadableWebProxy,代码行数:25,代码来源:NuHeader.py

示例6: get_samples

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import count [as 别名]
def get_samples(filters=None, count=False, ids=False):
    if not filters:
        filters = []
    if count:
        sample_query = db.session.query(func.count(distinct(Sample.sample_name)))
        sample_query = build_filter(sample_query, filters, Sample)
        return sample_query.one()[0]
    elif ids:
        sample_query = db.session.query(distinct(Sample.sample_id))
        sample_query = build_filter(sample_query, filters, Sample)
        samples = [x[0] for x in sample_query.all()]
        return samples
    else:
        sample_query = db.session.query(distinct(Sample.sample_name))
        sample_query = build_filter(sample_query, filters, Sample)
        samples = [x[0] for x in sample_query.all()]
        return samples 
开发者ID:ewels,项目名称:MegaQC,代码行数:19,代码来源:utils.py

示例7: input_prepare_query_object

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import count [as 别名]
def input_prepare_query_object(self, query_object):
        # When we count, we don't care about certain things
        if query_object.get('count', False):
            # Performance: do not sort when counting
            query_object.pop('sort', None)
            # We don't care about projections either
            query_object.pop('project', None)
            # Also, remove all skips & limits
            query_object.pop('skip', None)
            query_object.pop('limit', None)
            # Remove all join, but not joinf (as it may filter)
            query_object.pop('join', None)
            # Finally, when we count, we have to remove `max_items` setting from MongoLimit.
            # Only MongoLimit can do it, and it will do it for us.
            # See: MongoLimit.input_prepare_query_object

        return query_object 
开发者ID:kolypto,项目名称:py-mongosql,代码行数:19,代码来源:count.py

示例8: __init__

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import count [as 别名]
def __init__(self, query: Query):
        # The original query. We store it just in case.
        self._original_query = query

        # The current query
        # It differs from the originla query in that it is modified with a window function counting the rows
        self._query = query

        # The iterator for query results ; `None` if the query has not yet been executed
        # If the query has been executed, there is always an iterator available, even if there were no results
        self._query_iterator = None

        # The total count ; `None` if the query has not yet been executed
        self._count = None

        # Whether the query is going to return single entities
        self._single_entity = (  # copied from sqlalchemy.orm.loading.instances
            not getattr(query, '_only_return_tuples', False)  # accessing protected properties
            and len(query._entities) == 1
            and query._entities[0].supports_single_entity
        )

        # The method that will fix result rows
        self._row_fixer = self._fix_result_tuple__single_entity if self._single_entity else self._fix_result_tuple__tuple 
开发者ID:kolypto,项目名称:py-mongosql,代码行数:26,代码来源:counting_query_wrapper.py

示例9: find_tenants

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import count [as 别名]
def find_tenants(self, context):
        # returns an array of tenant_id & count of their zones
        query = select([tables.zones.c.tenant_id,
                        func.count(tables.zones.c.id)])
        query = self._apply_tenant_criteria(context, tables.zones, query)
        query = self._apply_deleted_criteria(context, tables.zones, query)
        query = query.group_by(tables.zones.c.tenant_id)

        resultproxy = self.session.execute(query)
        results = resultproxy.fetchall()

        tenant_list = objects.TenantList(
            objects=[objects.Tenant(id=t[0], zone_count=t[1]) for t in
                     results])

        tenant_list.obj_reset_changes()

        return tenant_list 
开发者ID:openstack,项目名称:designate,代码行数:20,代码来源:__init__.py

示例10: count_tenants

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import count [as 别名]
def count_tenants(self, context):
        # tenants are the owner of zones, count the number of unique tenants
        # select count(distinct tenant_id) from zones
        query = select([func.count(distinct(tables.zones.c.tenant_id))])
        query = self._apply_tenant_criteria(context, tables.zones, query)
        query = self._apply_deleted_criteria(context, tables.zones, query)

        resultproxy = self.session.execute(query)
        result = resultproxy.fetchone()

        if result is None:
            return 0

        return result[0]

    ##
    # Zone Methods
    ## 
开发者ID:openstack,项目名称:designate,代码行数:20,代码来源:__init__.py

示例11: count_recordsets

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import count [as 别名]
def count_recordsets(self, context, criterion=None):
        # Ensure that we return only active recordsets
        rjoin = tables.recordsets.join(
            tables.zones,
            tables.recordsets.c.zone_id == tables.zones.c.id)

        query = select([func.count(tables.recordsets.c.id)]).\
            select_from(rjoin).\
            where(tables.zones.c.deleted == '0')

        query = self._apply_criterion(tables.recordsets, query, criterion)
        query = self._apply_tenant_criteria(context, tables.recordsets, query)
        query = self._apply_deleted_criteria(context, tables.recordsets, query)

        resultproxy = self.session.execute(query)
        result = resultproxy.fetchone()

        if result is None:
            return 0

        return result[0]

    # Record Methods 
开发者ID:openstack,项目名称:designate,代码行数:25,代码来源:__init__.py

示例12: has_session

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import count [as 别名]
def has_session(self, session_id: str) -> bool:
        if self.core_mode:
            t = self.Session.__table__
            rows = self.db_engine.execute(select([func.count(t.c.auth_key)])
                                          .where(and_(t.c.session_id == session_id,
                                                      t.c.auth_key != b'')))
            try:
                count, = next(rows)
                return count > 0
            except StopIteration:
                return False
        else:
            return self.Session.query.filter(self.Session.session_id == session_id).count() > 0 
开发者ID:tulir,项目名称:telethon-session-sqlalchemy,代码行数:15,代码来源:sqlalchemy.py

示例13: count

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import count [as 别名]
def count():
    """
        Return a count of all secrets
    """

    return get_session().query(SecretModel).count() 
开发者ID:gabfl,项目名称:vault,代码行数:8,代码来源:secrets.py

示例14: get_count_query

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import count [as 别名]
def get_count_query(self):
        """
            Return a the count query for the model type

            A ``query(self.model).count()`` approach produces an excessive
            subquery, so ``query(func.count('*'))`` should be used instead.

            See commit ``#45a2723`` for details.
        """
        if 'polymorphic_identity' in getattr(self.model, "__mapper_args__",
                                             {}):
            return self.session.query(func.count('*')).select_from(
                self.model.query.selectable)

        return self.session.query(func.count('*')).select_from(self.model) 
开发者ID:beavyHQ,项目名称:beavy,代码行数:17,代码来源:admin_model_view.py

示例15: fast_count

# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import count [as 别名]
def fast_count(query):
    """
    It turns out the built-in SQLAlchemy function for query.count() is pretty
    slow. Alternatively, use this optimized function instead.
    """
    count_query = (query
                   .statement.with_only_columns([func.count()]).order_by(None))
    count = query.session.execute(count_query).scalar()
    return count 
开发者ID:dmsimard,项目名称:ara-archive,代码行数:11,代码来源:utils.py


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