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


Python sqlalchemy.desc方法代码示例

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


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

示例1: get_table

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import desc [as 别名]
def get_table(request: web.Request) -> web.Response:
    instance_id = request.match_info.get("id", "")
    instance = PluginInstance.get(instance_id, None)
    if not instance:
        return resp.instance_not_found
    elif not instance.inst_db:
        return resp.plugin_has_no_database
    tables = instance.get_db_tables()
    try:
        table = tables[request.match_info.get("table", "")]
    except KeyError:
        return resp.table_not_found
    try:
        order = [tuple(order.split(":")) for order in request.query.getall("order")]
        order = [(asc if sort.lower() == "asc" else desc)(table.columns[column])
                 if sort else table.columns[column]
                 for column, sort in order]
    except KeyError:
        order = []
    limit = int(request.query.get("limit", 100))
    return execute_query(instance, table.select().order_by(*order).limit(limit)) 
开发者ID:maubot,项目名称:maubot,代码行数:23,代码来源:instance_database.py

示例2: load_slice

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import desc [as 别名]
def load_slice(cls, context, limit, offset, *,
                         domain_name=None, group_id=None, user_id=None,
                         order_key=None, order_asc=None):
        from .user import users
        async with context['dbpool'].acquire() as conn:
            if order_key is None:
                _ordering = vfolders.c.created_at
            else:
                _order_func = sa.asc if order_asc else sa.desc
                _ordering = _order_func(getattr(vfolders.c, order_key))
            j = sa.join(vfolders, users, vfolders.c.user == users.c.uuid)
            query = (
                sa.select([vfolders])
                .select_from(j)
                .order_by(_ordering)
                .limit(limit)
                .offset(offset)
            )
            if domain_name is not None:
                query = query.where(users.c.domain_name == domain_name)
            if group_id is not None:
                query = query.where(vfolders.c.group == group_id)
            if user_id is not None:
                query = query.where(vfolders.c.user == user_id)
            return [cls.from_row(context, r) async for r in conn.execute(query)] 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:27,代码来源:vfolder.py

示例3: batch_load_by_user

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import desc [as 别名]
def batch_load_by_user(cls, context, user_uuids, *,
                                 domain_name=None, group_id=None):
        from .user import users
        async with context['dbpool'].acquire() as conn:
            # TODO: num_attached count group-by
            j = sa.join(vfolders, users, vfolders.c.user == users.c.uuid)
            query = (
                sa.select([vfolders])
                .select_from(j)
                .where(vfolders.c.user.in_(user_uuids))
                .order_by(sa.desc(vfolders.c.created_at))
            )
            if domain_name is not None:
                query = query.where(users.c.domain_name == domain_name)
            if group_id is not None:
                query = query.where(vfolders.c.group == group_id)
            return await batch_multiresult(
                context, conn, query, cls,
                user_uuids, lambda row: row['user']
            ) 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:22,代码来源:vfolder.py

示例4: get_watchlist_messages

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import desc [as 别名]
def get_watchlist_messages(session, user, limit=None):

    watched = user_watch_list(session, user.username)

    watched_list = [watch.id for watch in watched]

    events = (
        session.query(model.PagureLog)
        .filter(model.PagureLog.project_id.in_(watched_list))
        .order_by(model.PagureLog.id.desc())
    )

    if limit is not None:
        events = events.limit(limit)

    events = events.all()

    return events 
开发者ID:Pagure,项目名称:pagure,代码行数:20,代码来源:query.py

示例5: review_probable_validated

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

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import desc [as 别名]
def renderFeedsTable(page=1):

	feeds = g.session.query(db.RssFeedPost)       \
		.order_by(desc(db.RssFeedPost.published))


	feeds = feeds.options(joinedload('tag_rel'))
	feeds = feeds.options(joinedload('author_rel'))



	if feeds is None:
		flash('No feeds? Something is /probably/ broken!.')
		return redirect(url_for('renderFeedsTable'))

	feed_entries = paginate(feeds, page, app.config['FEED_ITEMS_PER_PAGE'])

	return render_template('rss-pages/feeds.html',
						   subheader = "",
						   sequence_item   = feed_entries,
						   page            = page
						   ) 
开发者ID:fake-name,项目名称:ReadableWebProxy,代码行数:24,代码来源:rss_views.py

示例7: renderFeedsSourceTable

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import desc [as 别名]
def renderFeedsSourceTable(source, page=1):
	feeds = g.session.query(db.RssFeedPost) \
		.filter(db.RssFeedPost.srcname == source)  \
		.order_by(desc(db.RssFeedPost.published))

	if feeds is None:
		flash('No feeds? Something is /probably/ broken!.')
		return redirect(url_for('renderFeedsTable'))

	feed_entries = paginate(feeds, page, app.config['FEED_ITEMS_PER_PAGE'])

	return render_template('rss-pages/feeds.html',
						   subheader = "Source = '%s'" % source,
						   sequence_item   = feed_entries,
						   page            = page
						   ) 
开发者ID:fake-name,项目名称:ReadableWebProxy,代码行数:18,代码来源:rss_views.py

示例8: exposed_db_count_netlocs

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import desc [as 别名]
def exposed_db_count_netlocs():
	'''
	Select and count the number of instances for each netloc in
	the database.

	Returns the netlocs sorted by count in decending order.
	'''

	with db.session_context() as sess:
		q = sess.query(db.WebPages.netloc, func.count(db.WebPages.netloc).label("count")) \
			.group_by(db.WebPages.netloc)\
			.order_by(desc(func.count(db.WebPages.netloc)))
		print("Doing query.")
		res = q.all()
		res = list(res)
		for row in res:
			print("Row: ", row)

		with open("nl_counts.json", "w") as fp:
			json.dump(res, fp) 
开发者ID:fake-name,项目名称:ReadableWebProxy,代码行数:22,代码来源:WebMirrorManage.py

示例9: get_all

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import desc [as 别名]
def get_all(cls, include_disabled=True):
        """Returns a list of all accounts of a given type

        Args:
            include_disabled (`bool`): Include disabled accounts. Default: `True`

        Returns:
            list of account objects
        """
        if cls == BaseAccount:
            raise InquisitorError('get_all on BaseAccount is not supported')

        account_type_id = db.AccountType.find_one(account_type=cls.account_type).account_type_id
        qry = db.Account.order_by(desc(Account.enabled), Account.account_type_id, Account.account_name)

        if not include_disabled:
            qry = qry.filter(Account.enabled == 1)

        accounts = qry.find(Account.account_type_id == account_type_id)

        return {res.account_id: cls(res) for res in accounts} 
开发者ID:RiotGames,项目名称:cloud-inquisitor,代码行数:23,代码来源:accounts.py

示例10: index

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import desc [as 别名]
def index():
    sorter = request.args.get("sorter", None)
    if sorter is None:
        sorter = "random"
        initial_sorting = True
    else:
        initial_sorting = False
    order = request.args.get("order", None)
    criterion = SORTER.get(sorter, DEFAULT_SORTER)
    if order == DEFAULT_ORDER:
        criterion = desc(criterion)

    projects = Project.query.filter(Project.is_active.is_(True)).order_by(
        nullslast(criterion)
    )
    return {
        "projects": projects,
        "sorter": sorter,
        "initial_sorting": initial_sorting,
        "order": order,
        "DEFAULT_ORDER": DEFAULT_ORDER,
    } 
开发者ID:jazzband-roadies,项目名称:website,代码行数:24,代码来源:views.py

示例11: __init__

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import desc [as 别名]
def __init__(self, params, sort_dir=constants.DEFAULT_SORT_DIR):
        """Pagination Helper takes params and a default sort direction

        :param params: Contains the following:
                       limit: maximum number of items to return
                       marker: the last item of the previous page; we return
                               the next results after this value.
                       sort: array of attr by which results should be sorted
        :param sort_dir: default direction to sort (asc, desc)
        """
        self.marker = params.get('marker')
        self.sort_dir = self._validate_sort_dir(sort_dir)
        self.limit = self._parse_limit(params)
        self.sort_keys = self._parse_sort_keys(params)
        self.params = params
        self.filters = None
        self.page_reverse = params.get('page_reverse', 'False') 
开发者ID:openstack,项目名称:octavia,代码行数:19,代码来源:pagination.py

示例12: get_working_files_for_entity

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import desc [as 别名]
def get_working_files_for_entity(entity_id, task_id=None, name=None):
    """
    Retrieve all working files for a given entity and specified parameters
    ordered by revision from biggest to smallest revision.
    """
    query = WorkingFile.query.filter_by(entity_id=entity_id)

    if task_id:
        query = query.filter(WorkingFile.task_id == task_id)
    if name:
        query = query.filter(WorkingFile.name == name)

    query = query.filter(WorkingFile.revision >= 0).order_by(
        desc(WorkingFile.revision)
    )

    working_files = query.all()
    return fields.serialize_models(working_files) 
开发者ID:cgwire,项目名称:zou,代码行数:20,代码来源:files_service.py

示例13: get_output_files_for_output_type_and_entity

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import desc [as 别名]
def get_output_files_for_output_type_and_entity(
    entity_id, output_type_id, representation=None
):
    """
    Get output files created for given entity and output type.
    """
    query = (
        OutputFile.query.filter(OutputFile.entity_id == entity_id)
        .filter(OutputFile.asset_instance_id == None)  # noqa Entity only
        .filter(OutputFile.output_type_id == output_type_id)
        .order_by(desc(OutputFile.revision))
    )

    if representation is not None:
        query = query.filter(OutputFile.representation == representation)

    output_files = query.all()
    return OutputFile.serialize_list(output_files) 
开发者ID:cgwire,项目名称:zou,代码行数:20,代码来源:files_service.py

示例14: get_output_files_for_output_type_and_asset_instance

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import desc [as 别名]
def get_output_files_for_output_type_and_asset_instance(
    asset_instance_id, temporal_entity_id, output_type_id, representation=None
):
    """
    Get output files created for given asset instance and output type.
    """
    query = OutputFile.query.filter(
        OutputFile.asset_instance_id == asset_instance_id,
        OutputFile.output_type_id == output_type_id,
        OutputFile.temporal_entity_id == temporal_entity_id,
    ).order_by(desc(OutputFile.revision))

    if representation is not None:
        query = query.filter(OutputFile.representation == representation)

    output_files = query.all()
    return OutputFile.serialize_list(output_files) 
开发者ID:cgwire,项目名称:zou,代码行数:19,代码来源:files_service.py

示例15: errors

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import desc [as 别名]
def errors(self, ctx, count : int=5, page : int=0, excludestring=None):
		"""Gets a list of the most recent errors from loggingdb"""

		for error in loggingdb.session.query(loggingdb_spec.Error).order_by(desc(loggingdb_spec.Error.timestamp)).offset(page * count):
			if count <= 0:
				return
			error_chunks = error.error_text_chunks()
			try:
				if excludestring and re.search(excludestring, "\n".join(error_chunks)):
					continue # skip this because our excludestring matches
			except Exception:
				raise UserError("Regex parsing error")
			await ctx.send(embed=error.to_embed(self))
			for chunk in error_chunks[:-1]:
				await ctx.send(chunk)
				await asyncio.sleep(0.5)

			await ctx.send(error_chunks[-1] + "\n_ _")
			await asyncio.sleep(0.5)
			count -= 1 
开发者ID:mdiller,项目名称:MangoByte,代码行数:22,代码来源:owner.py


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