anchor.diff:      q(SQL),
       KeyValue.
   
  -%% proplist query
  -plq(Q) ->
  -    Db = db(),
  -    db_q(proplist,Db,Q).
  -
  -plq(Q,ParamList) ->
  -    Db = db(),
  -    db_q(proplist,Db,Q,ParamList).
  -
  -%% dict query
  -dq(Q) ->
  -    Db = db(),
  -    db_q(dict,Db,Q).
  -
  -dq(Q,ParamList) ->
  -    Db = db(),
  -    db_q(dict,Db,Q,ParamList).
  -
  -%% tuple query
  -tq(Q) ->
  -    Db = db(),
  -    db_q(tuple,Db,Q).
  -
  -tq(Q,ParamList) ->
  -    Db = db(),
  -    db_q(tuple,Db,Q,ParamList).
  -
  -format_result(Type,Res) ->
  -    Json = emysql_util:as_json(Res),
  -    case Type of
  -        list ->
  -            format_list_result(Json);
  -        tuple ->
  -            format_tuple_result(Json);
  -        proplist ->
  -            format_proplist_result(Json);
  -        dict ->
  -            format_dict_result(Json)
  -    end.
  -
  -format_value(null) ->
  -    undefined;
  -format_value(V) when is_binary(V) ->
  -    binary_to_list(V);
  -format_value(V) ->
  -    V.
  -
  -format_key(K) when is_atom(K) ->
  -    K;
  -format_key(K) when is_binary(K) ->
  -    format_key(binary_to_list(K));
  -format_key(K) when is_list(K) ->
  -    list_to_atom(K).
  -
  -format_list_result(Json) ->
  -    [
  -        [format_value(Value) || {_,Value} <- Row]
  -    || Row <- Json].
  -
  -format_tuple_result(Json) ->
  -    [list_to_tuple(Row) || Row <- format_list_result(Json)].
  -
  -format_proplist_result(Json) ->
  -    [
  -        [{format_key(F), format_value(V)} || {F,V} <- Row]
  -    || Row <-Json].
  -
  -format_dict_result(Json) ->
  -    [dict:from_list(PL) || PL <- format_proplist_result(Json)].
  -
  -%% Query from the specified Database pool (Db)
  -%% This will connect to the specified Database Pool
  -%% Type must be atoms: proplist, dict, list, or tuple
  +-spec db_q(Type :: return_type(), Db :: db(), Q :: sql()) ->  insert_id() 
  +                                                            | update_id()
  +                                                            | [list() | dict() | tuple() | proplist()].
  +%% @doc Query from the specified Database pool (Db) This will connect to the
  +%% specified Database Pool Type must be atoms: proplist, dict, list, or tuple
   %% Type can also be atom 'insert' in which case, it'll return the insert value
  -
   db_q(Type,Db,Q) ->
       try 
           Res = emysql:execute(Db,Q),
  
positive.code:     TableFields = table_fields(Table),
      [{K,V} || {K,V} <- PropList,lists:member(atomize(K),TableFields)].
  
  %% Inserts a proplist into the table
  -spec pli(Table :: table(), PropList :: proplist()) -> insert_id().
  pli(Table,PropList) when is_atom(Table) ->
      pli(atom_to_list(Table),PropList);
  pli(Table,InitPropList) ->
  
negative.code:             db_q(Type, Db, Q)
      end.
  
  -spec db_q(Type :: return_type(), Db :: db(),
             Q :: sql(), ParamList :: [value()]) ->   insert_id() 
                                                    | update_id()
                                                    | [list() | dict() | tuple() | proplist()].
  
  db_q(Type,Db,Q,ParamList) ->
      NewQ = q_prep(Q,ParamList),
      db_q(Type,Db,NewQ).
  
  -spec format_result(Type :: return_type(), Res :: sql_result()) ->   list()
                                                                     | dict()
                                                                     | tuple()
                                                                     | proplist().
  format_result(Type,Res) ->
      Json = emysql_util:as_json(Res),
      case Type of
          list ->
              format_list_result(Json);
          tuple ->
              format_tuple_result(Json);
          proplist ->
              format_proplist_result(Json);
          dict ->
              format_dict_result(Json)
      end.
  
  -spec format_value(V :: term()) -> undefined | string() | any().
  format_value(null) ->
      undefined;
  format_value(V) when is_binary(V) ->
      binary_to_list(V);
  format_value(V) ->
      V.
  
  -spec format_key(K :: field()) -> atom().
  format_key(K) when is_atom(K) ->
      K;
  format_key(K) when is_binary(K) ->
      format_key(binary_to_list(K));
  format_key(K) when is_list(K) ->
      list_to_atom(K).
  
  format_list_result(Json) ->
      [
          [format_value(Value) || {_,Value} <- Row]
      || Row <- Json].
  
  format_tuple_result(Json) ->
      [list_to_tuple(Row) || Row <- format_list_result(Json)].
  
  format_proplist_result(Json) ->
      [
          [{format_key(F), format_value(V)} || {F,V} <- Row]
      || Row <-Json].
  
  format_dict_result(Json) ->
      [dict:from_list(PL) || PL <- format_proplist_result(Json)].
  
  
  %%  A special Query function just for inserting.
  %%  Inserts the record(s) and returns the insert_id
  qi(Q) ->
  