-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAsteroidLootRepository.cc
39 lines (28 loc) · 986 Bytes
/
AsteroidLootRepository.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "AsteroidLootRepository.hh"
namespace bsgo {
AsteroidLootRepository::AsteroidLootRepository(const DbConnectionShPtr &connection)
: AbstractRepository("loot", connection)
{
addModule("asteroid");
}
namespace {
constexpr auto FIND_ONE_QUERY_NAME = "asteroid_loot_find_one";
constexpr auto FIND_ONE_QUERY = "SELECT resource, amount FROM asteroid_loot WHERE asteroid = $1";
} // namespace
void AsteroidLootRepository::initialize()
{
m_connection->prepare(FIND_ONE_QUERY_NAME, FIND_ONE_QUERY);
}
namespace {} // namespace
auto AsteroidLootRepository::findOneById(const Uuid asteroid) const -> AsteroidLoot
{
const auto query = [asteroid](pqxx::nontransaction &work) {
return work.exec_prepared1(FIND_ONE_QUERY_NAME, toDbId(asteroid));
};
const auto record = m_connection->executeQueryReturningSingleRow(query);
AsteroidLoot out;
out.resource = fromDbId(record[0].as<int>());
out.amount = record[1].as<float>();
return out;
}
} // namespace bsgo