fkg-api-proxy/source/dataMixins.d

36 lines
1.1 KiB
D
Raw Normal View History

module dataMixins;
template applyMasterTranslation(string Table, uint IdFieldIndex, Translations...)
{
2017-09-29 16:17:28 +02:00
static assert(Translations.length >= 2 && Translations.length % 2 == 0);
2017-09-29 16:17:28 +02:00
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 = "";
}
}
2017-09-29 16:17:28 +02:00
enum applyMasterTranslation = "
foreach(row; getMasterResponse.master" ~ Table ~ ")
{
import std.conv : to;
auto id = row[" ~ IdFieldIndex.to!string ~ "].to!uint;
2017-09-29 16:17:28 +02:00
import translations." ~ Table[0].toLower.to!string ~ Table[1 .. $] ~ ";
2017-09-29 16:17:28 +02:00
if(id in " ~ Translations[1] ~ ")
{
" ~ getMasterColumnTranslations!(Translations) ~ "
}
}";
}