generated from Sithas/conan_template
63 lines
1.6 KiB
C++
63 lines
1.6 KiB
C++
#include "MySQLDiariesDAO.h"
|
|
|
|
namespace uad
|
|
{
|
|
MySqlDiariesDAO::MySqlDiariesDAO(mysqlx::Session& session) : session_(session)
|
|
{
|
|
}
|
|
|
|
std::vector<diary_dto> MySqlDiariesDAO::GetDiariesByUserUUID(const std::string& user_uuid)
|
|
{
|
|
static const std::string query = R"(
|
|
SELECT
|
|
d.uuid,
|
|
UNIX_TIMESTAMP(d.time) * 1000,
|
|
d.mania_level,
|
|
d.depression_level,
|
|
d.mood_level,
|
|
d.activity_level,
|
|
d.appetite_level,
|
|
d.dream_level,
|
|
d.anxiety_level,
|
|
d.comment,
|
|
d.user_treatment_schemes_uuid
|
|
FROM up_and_down.diaries d
|
|
WHERE d.user_uuid = ?
|
|
ORDER BY d.time;
|
|
)";
|
|
|
|
mysqlx::SqlResult result = session_
|
|
.sql(query)
|
|
.bind(user_uuid)
|
|
.execute();
|
|
|
|
std::vector<diary_dto> diaries;
|
|
diaries.reserve(result.count());
|
|
|
|
for (const mysqlx::Row& row : result)
|
|
{
|
|
diary_dto dto;
|
|
|
|
dto.uuid = row[0].get<std::string>();
|
|
dto.time_ms = row[1].get<std::int64_t>();
|
|
dto.mania_level = row[2].get<int>();
|
|
dto.depression_level = row[3].get<int>();
|
|
dto.mood_level = row[4].get<int>();
|
|
dto.activity_level = row[5].get<int>();
|
|
dto.appetite_level = row[6].get<int>();
|
|
dto.dream_level = row[7].get<int>();
|
|
dto.anxiety_level = row[8].get<int>();
|
|
|
|
dto.comment =
|
|
row[9].isNull() ? "" : row[9].get<std::string>();
|
|
|
|
dto.user_treatment_scheme_uuid =
|
|
row[10].isNull() ? "" : row[10].get<std::string>();
|
|
|
|
diaries.push_back(std::move(dto));
|
|
}
|
|
|
|
return diaries;
|
|
}
|
|
}
|