Created
April 1, 2015 18:02
-
-
Save toopay/a1f0dd6fcfb4e72a0db5 to your computer and use it in GitHub Desktop.
Riak injector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% @doc Prepare map data | |
prepare_map(MapData) -> | |
%% The initial map to be expanded | |
InitialMap = riakc_map:new(), | |
%% Build tuple elem | |
Definition = element(2,MapData), | |
Data = [element(Nth, MapData) || Nth <- lists:seq(3,tuple_size(MapData))], | |
%% Fill in the data based by definition | |
update_map_data(Data, Definition, InitialMap). | |
update_map_data([], [], AccMap) -> AccMap; | |
update_map_data([CurrentData|DataT],[CurrentDefinition|DefT],InitialMap) -> | |
{AtomDataKey,DataType} = CurrentDefinition, | |
DataKey = list_to_binary(atom_to_list(AtomDataKey)), | |
AccMap = case DataType of | |
register -> | |
riakc_map:update({DataKey, DataType}, | |
fun(Val) -> riakc_register:set(CurrentData, Val) end, | |
InitialMap); | |
set -> | |
append_set(CurrentData, DataKey, InitialMap); | |
counter -> | |
riakc_map:update({DataKey, DataType}, | |
fun(Val) -> riakc_counter:increment(CurrentData, Val) end, | |
InitialMap) | |
end, | |
update_map_data(DataT,DefT,AccMap). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment