本文整理汇总了Python中sqlalchemy.sql.expression.desc方法的典型用法代码示例。如果您正苦于以下问题:Python expression.desc方法的具体用法?Python expression.desc怎么用?Python expression.desc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.sql.expression
的用法示例。
在下文中一共展示了expression.desc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apply
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import desc [as 别名]
def apply(self, q, bindings, ordering, distinct=None):
""" Sort on a set of field specifications of the type (ref, direction)
in order of the submitted list. """
info = []
for (ref, direction) in self.parse(ordering):
info.append((ref, direction))
table, column = self.cube.model[ref].bind(self.cube)
if distinct is not None and distinct != ref:
column = asc(ref) if direction == 'asc' else desc(ref)
else:
column = column.label(column.name)
column = column.asc() if direction == 'asc' else column.desc()
bindings.append(Binding(table, ref))
if self.cube.is_postgresql:
column = column.nullslast()
q = q.order_by(column)
if not len(self.results):
for column in q.columns:
column = column.asc()
if self.cube.is_postgresql:
column = column.nullslast()
q = q.order_by(column)
return info, q, bindings
示例2: metadata_trend
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import desc [as 别名]
def metadata_trend(num_days):
results = db.session.query(
RepoMean.repo_id, func.substring_index(
func.group_concat(
RepoMean.value.op('ORDER BY')(expression.desc(RepoMean.created_at))
), ',', 2)
)\
.filter(RepoMean.created_at >= datetime.now() + timedelta(days=num_days * -1))\
.group_by(RepoMean.repo_id)\
.all()
for result in filter(lambda x: ',' in x[1], results):
curr, prev = map(lambda v: float(v), result[1].split(','))
if is_worth_decreased(curr, prev):
log.info(
'Mean value of {0} is {1}, previous was {2}. The "worth" has been decreased by 1'
.format(result[0], curr, prev)
)
db.session.query(Repo)\
.filter(Repo.id == result[0])\
.update({Repo.worth: Repo.worth - 1})
db.session.commit()
示例3: scheduled_operation_log_delete_oldest
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import desc [as 别名]
def scheduled_operation_log_delete_oldest(context, operation_id,
retained_num, excepted_states):
table = models.ScheduledOperationLog
session = get_session()
with session.begin():
result = model_query(context, table, session=session).filter_by(
operation_id=operation_id).order_by(
expression.desc(table.created_at)).limit(retained_num).all()
if not result or len(result) < retained_num:
return
oldest_create_time = result[-1]['created_at']
if excepted_states and isinstance(excepted_states, list):
filters = expression.and_(
table.operation_id == operation_id,
table.created_at < oldest_create_time,
table.state.notin_(excepted_states))
else:
filters = expression.and_(
table.operation_id == operation_id,
table.created_at < oldest_create_time)
model_query(context, table, session=session).filter(
filters).delete(synchronize_session=False)
示例4: get_server_stats_log
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import desc [as 别名]
def get_server_stats_log(self, before=None, after=None, limit=None, skip=0):
meta = get_metadata_template()
query = []
if before:
query.append(ServerStatsLogORM.timestamp <= before)
if after:
query.append(ServerStatsLogORM.timestamp >= after)
with self.session_scope() as session:
pose = session.query(ServerStatsLogORM).filter(*query).order_by(desc("timestamp"))
meta["n_found"] = get_count_fast(pose)
data = pose.limit(self.get_limit(limit)).offset(skip).all()
data = [d.to_dict() for d in data]
meta["success"] = True
return {"data": data, "meta": meta}
示例5: actions_get
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import desc [as 别名]
def actions_get(self, context, container_uuid):
"""Get all container actions for the provided uuid."""
query = model_query(models.ContainerAction).\
filter_by(container_uuid=container_uuid)
actions = _paginate_query(models.ContainerAction, sort_dir='desc',
sort_key='created_at', query=query)
return actions
示例6: _action_get_last_created_by_container_uuid
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import desc [as 别名]
def _action_get_last_created_by_container_uuid(self, context,
container_uuid):
result = model_query(models.ContainerAction).\
filter_by(container_uuid=container_uuid).\
order_by(desc("created_at"), desc("id")).\
first()
return result
示例7: action_events_get
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import desc [as 别名]
def action_events_get(self, context, action_id):
query = model_query(models.ContainerActionEvent).\
filter_by(action_id=action_id)
events = _paginate_query(models.ContainerActionEvent, sort_dir='desc',
sort_key='created_at', query=query)
return events
示例8: get_one_vm_list_by_uuid_create_at_last
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import desc [as 别名]
def get_one_vm_list_by_uuid_create_at_last(session, uuid):
# SELECT progress, create_at, retry_cnt FROM vm_list \
# WHERE uuid = :uuid ORDER BY create_at DESC LIMIT 1
with _sqlalchemy_error():
res = session.query(VmList).filter_by(uuid=uuid).order_by(
desc(VmList.create_at)).first()
return res
示例9: get_one_vm_list_by_uuid_and_progress_create_at_last
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import desc [as 别名]
def get_one_vm_list_by_uuid_and_progress_create_at_last(session,
notification_uuid):
# SELECT * FROM vm_list WHERE uuid = :notification_uuid \
# AND (progress = 0 OR progress = 1) \
# ORDER BY create_at DESC LIMIT 1
with _sqlalchemy_error():
res = session.query(VmList).filter_by(uuid=notification_uuid).filter(
or_(VmList.progress == 0, VmList.progress == 1)).order_by(
desc(VmList.create_at)).first()
return res
示例10: get_vm_list_by_uuid_and_progress_sorted
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import desc [as 别名]
def get_vm_list_by_uuid_and_progress_sorted(session, notification_uuid):
# sql = "SELECT id, uuid FROM vm_list " \
# "WHERE uuid = '%s' " \
# "AND (progress = 0 OR progress = 1) " \
# "ORDER BY recover_by ASC, create_at DESC" \
# % (row.get("uuid"))
with _sqlalchemy_error():
res = session.query(VmList).filter_by(
uuid=notification_uuid).filter(or_(
VmList.progress == 0, VmList.progress == 1)).order_by(
asc(VmList.recover_by), desc(VmList.create_at)
).all()
return res
示例11: get_reprocessing_records_list
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import desc [as 别名]
def get_reprocessing_records_list(session, notification_uuid):
# sql = "SELECT id, notification_id, notification_hostname, "
# "notification_uuid, notification_cluster_port, recover_by "
# "FROM notification_list "
# "WHERE progress = 0 AND notification_uuid = '%s' "
# "ORDER BY create_at DESC, id DESC"
# % (row.get("notification_uuid"))
with _sqlalchemy_error():
res = session.query(NotificationList).filter_by(
progress=0).filter_by(notification_uuid=notification_uuid).order_by(
desc(NotificationList.create_at),
desc(NotificationList.id)).all()
return res
示例12: get_notification_list_by_hostname
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import desc [as 别名]
def get_notification_list_by_hostname(session, notification_hostname):
# sql = "SELECT id, notification_id, notification_hostname, "
# "notification_uuid, notification_cluster_port, recover_by "
# "FROM notification_list "
# "WHERE progress = 0 AND notification_hostname = '%s' "
# "ORDER BY create_at DESC, id DESC"
# % ("notification_hostname")
with _sqlalchemy_error():
res = session.query(NotificationList).filter_by(progress=0).filter_by(
notification_hostname=notification_hostname).order_by(
desc(NotificationList.create_at),
desc(NotificationList.id)).all()
return res
示例13: _sort_query
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import desc [as 别名]
def _sort_query(self):
''' Sort the SQLA query object by a given parameter '''
if not isinstance(self.sort, type(None)):
# set the sort variable ModelClass parameter
if '.' in self.sort:
param = self.datamodel.parameters[str(self.sort)].full
else:
param = self.datamodel.parameters.get_full_from_remote(self.sort)
sortparam = self._marvinform._param_form_lookup.mapToColumn(param)
# check if sort param actually in the parameter list
if sortparam.class_ not in self._modellist:
return
# If order is specified, then do the sort
if self.order:
assert self.order in ['asc', 'desc'], 'Sort order parameter must be either "asc" or "desc"'
# Check if order by already applied
if 'ORDER' in str(self.query.statement):
self.query = self.query.order_by(None)
# Do the sorting
if 'desc' in self.order:
self.query = self.query.order_by(desc(sortparam))
else:
self.query = self.query.order_by(sortparam)
示例14: collection_get
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import desc [as 别名]
def collection_get(self):
"""
---
get:
security:
- Bearer: [read]
- Basic: [read]
tags:
- "v1"
summary: "return all lectures"
description: ""
operationId: "lecture_collection_get"
consumes:
- "application/json"
produces:
- "application/json"
responses:
200:
description: "response for 200 code"
schema:
$ref: "#/definitions/CollectionLecture"
"""
lectures = (
self.db.query(models.Lecture)
.order_by(desc(models.Lecture.term), models.Lecture.name)
.options(joinedload(models.Lecture.assistants))
.filter(models.Lecture.is_visible == True) # pylint: disable=C0121
.all()
)
schema = models.LectureSchema(many=True, only=allowed_attributes.collection_lecture())
return schema.dump(lectures)
示例15: __call__
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import desc [as 别名]
def __call__(self):
lectures = self.db.query(models.Lecture).order_by(desc(models.Lecture.term), models.Lecture.name).options(joinedload(models.Lecture.assistants))
if self.request.GET.get('show_all', '0')=='0':
lectures = lectures.filter(models.Lecture.is_visible == True)
lectures = lectures.all()
sticky_lectures = []
if lectures:
newest_term = lectures[0].term
sticky_lectures = [l for l in lectures if l.term == newest_term and self.is_ana_or_la(l)]
lectures = [l for l in lectures if not l in sticky_lectures]
return {'lectures': lectures,
'sticky_lectures': sticky_lectures}