fkg-api-proxy/source/dataMixins.d

36 lines
1.1 KiB
D

module dataMixins;
template applyMasterTranslation(string Table, uint IdFieldIndex, Translations...)
{
static assert(Translations.length >= 2 && Translations.length % 2 == 0);
import std.conv : to;
import std.uni : toLower;
private template getMasterColumnTranslations(Translations...)
{
static if(Translations.length > 0)
{
enum getMasterColumnTranslations = "row[" ~ Translations[0].to!string ~ "] = " ~ Translations[1] ~ "[id]; "
~ getMasterColumnTranslations!(Translations[2 .. $]);
}
else
{
enum getMasterColumnTranslations = "";
}
}
enum applyMasterTranslation = "
foreach(row; getMasterResponse.master" ~ Table ~ ")
{
import std.conv : to;
auto id = row[" ~ IdFieldIndex.to!string ~ "].to!uint;
import translations." ~ Table[0].toLower.to!string ~ Table[1 .. $] ~ ";
if(id in " ~ Translations[1] ~ ")
{
" ~ getMasterColumnTranslations!(Translations) ~ "
}
}";
}