code: def query(cls, expression=None, order_by=None):
          
          if expression is not None:
              executor = Executor(cls.__database__)
              result = executor.execute(expression)
          else:
              result = cls._query.all_index()
  
          if order_by is not None:
              desc = False
              if isinstance(order_by, Desc):
                  desc = True
                  order_by = order_by.node
  
              alpha = not isinstance(order_by, _ScalarField)
              result = cls.__database__.sort(
                  result.key,
                  by='*->%s' % order_by.name,
                  alpha=alpha,
                  desc=desc)
          elif isinstance(result, ZSet):
              result = result.iterator(reverse=True)
  
          for hash_id in result:
              yield cls.load(hash_id, convert_key=False)
docs: Return model instances matching the given expression (if
          specified). Additionally, matching instances can be returned
          sorted by field value.
  
          Example::
  
              # Get administrators sorted by username.
              admin_users = User.query(
                  (User.admin == True),
                  order_by=User.username)
  
              # List blog entries newest to oldest.
              entries = Entry.query(order_by=Entry.timestamp.desc())
  
              # Perform a complex filter.
              values = StatData.query(
                  (StatData.timestamp < datetime.date.today()) &
                  ((StatData.type == 'pv') | (StatData.type == 'cv')))
  
          :param expression: A boolean expression to filter by.
          :param order_by: A field whose value should be used to
              sort returned instances.