當前位置: 首頁>>代碼示例>>Python>>正文


Python expression.desc方法代碼示例

本文整理匯總了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 
開發者ID:openspending,項目名稱:babbage,代碼行數:26,代碼來源:ordering.py

示例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() 
開發者ID:kkamkou,項目名稱:gitmostwanted.com,代碼行數:23,代碼來源:repo_metadata.py

示例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) 
開發者ID:openstack,項目名稱:karbor,代碼行數:27,代碼來源:api.py

示例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} 
開發者ID:MolSSI,項目名稱:QCFractal,代碼行數:23,代碼來源:sqlalchemy_socket.py

示例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 
開發者ID:openstack,項目名稱:zun,代碼行數:10,代碼來源:api.py

示例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 
開發者ID:openstack,項目名稱:zun,代碼行數:9,代碼來源:api.py

示例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 
開發者ID:openstack,項目名稱:zun,代碼行數:8,代碼來源:api.py

示例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 
開發者ID:ntt-sic,項目名稱:masakari,代碼行數:9,代碼來源:api.py

示例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 
開發者ID:ntt-sic,項目名稱:masakari,代碼行數:12,代碼來源:api.py

示例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 
開發者ID:ntt-sic,項目名稱:masakari,代碼行數:15,代碼來源:api.py

示例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 
開發者ID:ntt-sic,項目名稱:masakari,代碼行數:15,代碼來源:api.py

示例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 
開發者ID:ntt-sic,項目名稱:masakari,代碼行數:15,代碼來源:api.py

示例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) 
開發者ID:sdss,項目名稱:marvin,代碼行數:29,代碼來源:query.py

示例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) 
開發者ID:muesli-hd,項目名稱:muesli,代碼行數:33,代碼來源:lectureEndpoint.py

示例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} 
開發者ID:muesli-hd,項目名稱:muesli,代碼行數:14,代碼來源:viewsLecture.py


注:本文中的sqlalchemy.sql.expression.desc方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。