nodes: 0, module; 1, function_definition; 2, function_name:sort_field; 3, parameters; 4, block; 5, identifier:self; 6, identifier:field_name; 7, identifier:direction; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, expression_statement; 13, return_statement; 14, identifier:field_vals; 15, None; 16, comment:"""
          sort this query by field_name in directrion
  
          field_name -- string -- the field to sort on
          direction -- integer -- negative for DESC, positive for ASC
          field_vals -- list -- the order the rows should be returned in
          """; 17, assignment; 18, comparison_operator:direction > 0; 19, block; 20, elif_clause; 21, else_clause; 22, call; 23, identifier:self; 24, identifier:field_name; 25, call; 26, identifier:direction; 27, integer:0; 28, expression_statement; 29, comparison_operator:direction < 0; 30, block; 31, block; 32, attribute; 33, argument_list; 34, attribute; 35, argument_list; 36, assignment; 37, identifier:direction; 38, integer:0; 39, expression_statement; 40, raise_statement; 41, attribute; 42, identifier:append; 43, identifier:field_name; 44, list; 45, identifier:self; 46, identifier:_normalize_field_name; 47, identifier:field_name; 48, identifier:direction; 49, integer:1; 50, assignment; 51, call; 52, identifier:self; 53, identifier:fields_sort; 54, identifier:direction; 55, identifier:field_name; 56, conditional_expression:list(field_vals) if field_vals else field_vals; 57, identifier:direction; 58, unary_operator; 59, identifier:ValueError; 60, argument_list; 61, call; 62, identifier:field_vals; 63, identifier:field_vals; 64, integer:1; 65, call; 66, identifier:list; 67, argument_list; 68, attribute; 69, argument_list; 70, identifier:field_vals; 71, string:"direction {} is undefined"; 72, identifier:format; 73, identifier:direction
code: def sort_field(self, field_name, direction, field_vals=None):
          """
          sort this query by field_name in directrion
  
          field_name -- string -- the field to sort on
          direction -- integer -- negative for DESC, positive for ASC
          field_vals -- list -- the order the rows should be returned in
          """
          field_name = self._normalize_field_name(field_name)
          if direction > 0:
              direction = 1
          elif direction < 0:
              direction = -1
          else:
              raise ValueError("direction {} is undefined".format(direction))
  
          self.fields_sort.append(field_name, [direction, field_name, list(field_vals) if field_vals else field_vals])
          return self