anchor.diff:  %% @spec define_custom_pivot(Module, columns(), Context) -> ok
   %% @doc Let a module define a custom pivot
   %% columns() -> [column()]
  -%% column()  -> {ColumName::atom(), ColSpec::string()}
  +%% column()  -> {ColumName::atom(), ColSpec::string()} | {atom(), string(), options::list()}
   define_custom_pivot(Module, Columns, Context) ->
       TableName = "pivot_" ++ z_convert:to_list(Module),
       case z_db:table_exists(TableName, Context) of
  
positive.code:         false ->
              Fields = custom_columns(Columns),
              Sql = "CREATE TABLE " ++ TableName ++ "(" ++
                  "id int NOT NULL," ++ Fields ++ ")",
              z_db:q(lists:flatten(Sql), Context),
              z_db:q("ALTER TABLE " ++ TableName ++ " ADD CONSTRAINT fk_" ++ TableName ++ "_id FOREIGN KEY (id) REFERENCES rsc(id) ON UPDATE CASCADE ON DELETE CASCADE", Context),
              
              Idx = ["CREATE INDEX " ++ z_convert:to_list(K) ++ "_key ON " ++ TableName ++ "(" ++ z_convert:to_list(K) ++ ")" || {K,_} <- Columns],
              [z_db:q(Sql1, Context) || Sql1 <- Idx]
      end,
      ok.
  
negative.code: 
  custom_columns(Cols) ->
      custom_columns(Cols, []).
  
  custom_columns([], Acc) ->
      lists:reverse(Acc);
  custom_columns([{Name, Spec}|Rest], Acc) ->
      custom_columns(Rest, [ [z_convert:to_list(Name), " ", Spec, ","] |  Acc]);
  custom_columns([{Name, Spec, _Opts}|Rest], Acc) ->
      custom_columns(Rest, [ [z_convert:to_list(Name), " ", Spec, ","] |  Acc]).
  
  
  
  