anchor.diff:                  element(Ci,element(Ti,X))
           end
       end;
  +sort_fun(timestamp,Ti,Ci,<<"desc">>) -> 
  +    fun(X) -> 
  +        case element(Ci,element(Ti,X)) of 
  +            {Meg,Sec,Micro} when is_integer(Meg), is_integer(Sec), is_integer(Micro)->
  +                {-Meg,-Sec,-Micro};
  +            _ ->
  +                element(Ci,element(Ti,X))
  +        end    
  +    end;
  +sort_fun(tuple,Ti,Ci,<<"desc">>) -> 
  +    fun(X) -> 
  +        case element(Ci,element(Ti,X)) of 
  +            {T,A} when is_atom(T), is_atom(A) ->
  +                {[ -ItemT || ItemT <- atom_to_list(T)] ++ [?MaxChar]
  +                ,[ -ItemA || ItemA <- atom_to_list(A)] ++ [?MaxChar]
  +                };
  +            {T,N} when is_atom(T), is_number(N) ->
  +                {[ -Item || Item <- atom_to_list(T)] ++ [?MaxChar],-N};
  +            {T,{A,B,C,D}} when is_atom(T), is_integer(A), is_integer(B), is_integer(C), is_integer(D) ->
  +                {[ -Item || Item <- atom_to_list(T)] ++ [?MaxChar],-A,-B,-C,-D};
  +            {T,{A,B,C,D,E,F,G,H}} when is_atom(T),is_integer(A), is_integer(B), is_integer(C), is_integer(D), is_integer(E), is_integer(F), is_integer(G), is_integer(H) ->
  +                {[ -Item || Item <- atom_to_list(T)] ++ [?MaxChar],-A,-B,-C,-D,-E,-F,-G,-H};
  +            {T,R} when is_atom(T) ->
  +                {[ -Item || Item <- atom_to_list(T)] ++ [?MaxChar], R};
  +            _ ->
  +                element(Ci,element(Ti,X))
  +        end    
  +    end;
  +sort_fun(userid,Ti,Ci,<<"desc">>) ->   sort_fun(number,Ti,Ci,<<"desc">>);
   sort_fun(Type,_Ti,_Ci,<<"desc">>) ->
       ?SystemException({"Unsupported datatype for sort desc", Type});
   sort_fun(_Type,Ti,Ci,_) -> 
  
positive.code:                 element(Ci,element(Ti,X))
          end
      end;
  sort_fun(string,Ti,Ci,<<"desc">>) -> 
      fun(X) -> 
          case element(Ci,element(Ti,X)) of 
  
negative.code:             ?ClientError({"Bad sort field", Else})
      end.
  
  sort_fun(atom,Ti,Ci,<<"desc">>) -> 
      fun(X) -> 
          case element(Ci,element(Ti,X)) of 
              A when is_atom(A) ->
                  [ -Item || Item <- atom_to_list(A)] ++ [?MaxChar];
              _ ->
                  element(Ci,element(Ti,X))
          end
      end;
  sort_fun(binstr,Ti,Ci,<<"desc">>) -> 
      fun(X) -> 
          case element(Ci,element(Ti,X)) of 
              B when is_binary(B) ->
                  [ -Item || Item <- binary_to_list(B)] ++ [?MaxChar];
              _ ->
                  element(Ci,element(Ti,X))
          end
      end;
  sort_fun(boolean,Ti,Ci,<<"desc">>) ->
      fun(X) -> 
          V = element(Ci,element(Ti,X)),
          case V of
              true ->         false;
              false ->        true;
              _ ->            element(Ci,element(Ti,X))
          end 
      end;
  sort_fun(datetime,Ti,Ci,<<"desc">>) -> 
  