daster/source/data.d

68 lines
1.7 KiB
D
Raw Normal View History

module data;
import pgdb;
import singlog;
import structures;
import std.conv;
GroupDB[] getListGroups() {
GroupDB[] groups;
try {
auto queryResult = pgsql.sql(
"select distinct
n.da_group,
g.da_comment
from da_numbers n
left join da_groups g ON g.da_name = n.da_group"
);
foreach (row; queryResult) {
GroupDB data;
data.name = row["da_group"];
data.comment = row["da_comment"];
groups ~= data;
}
} catch (Exception e) {
log.e("Не удалось выполнить запрос к БД. " ~ e.msg);
}
return groups;
}
NumberDB[] getListNumbers(string group) {
NumberDB[] numbers;
try {
auto queryResult = pgsql.sql(
"select
dan.da_number,
dal.da_comment da_list,
dan.da_all_cc,
dan.da_white_cc,
dan.da_black_cc,
dan.da_comment
from da_numbers dan
left join da_lists dal on dal.da_name = dan.da_list
where da_group = ?",
group
);
foreach (row; queryResult) {
NumberDB data;
data.number = row["da_number"];
data.list = row["da_list"];
data.all_cc = row["da_all_cc"].to!int;
data.white_cc = row["da_white_cc"].to!int;
data.black_cc = row["da_black_cc"].to!int;
data.comment = row["da_comment"];
numbers ~= data;
}
} catch (Exception e) {
log.e("Не удалось выполнить запрос к БД. " ~ e.msg);
}
return numbers;
}