[Repositories] Update repositories (#2040)

This commit is contained in:
Chris Miles
2022-03-11 15:27:36 -08:00
committed by GitHub
parent f22608a43a
commit 3ed6663c4c
170 changed files with 5543 additions and 511 deletions
+66 -37
View File
@@ -14,10 +14,12 @@
#include "../../database.h"
#include "../../string_util.h"
#include <ctime>
class BasePetsRepository {
public:
struct Pets {
int id;
std::string type;
int petpower;
int npcID;
@@ -30,12 +32,28 @@ public:
static std::string PrimaryKey()
{
return std::string("petpower");
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"type",
"petpower",
"npcID",
"temp",
"petcontrol",
"petnaming",
"monsterflag",
"equipmentset",
};
}
static std::vector<std::string> SelectColumns()
{
return {
"id",
"type",
"petpower",
"npcID",
@@ -52,6 +70,11 @@ public:
return std::string(implode(", ", Columns()));
}
static std::string SelectColumnsRaw()
{
return std::string(implode(", ", SelectColumns()));
}
static std::string TableName()
{
return std::string("pets");
@@ -61,7 +84,7 @@ public:
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
SelectColumnsRaw(),
TableName()
);
}
@@ -79,6 +102,7 @@ public:
{
Pets entry{};
entry.id = 0;
entry.type = "";
entry.petpower = 0;
entry.npcID = 0;
@@ -97,7 +121,7 @@ public:
)
{
for (auto &pets : petss) {
if (pets.petpower == pets_id) {
if (pets.id == pets_id) {
return pets;
}
}
@@ -122,14 +146,15 @@ public:
if (results.RowCount() == 1) {
Pets entry{};
entry.type = row[0] ? row[0] : "";
entry.petpower = atoi(row[1]);
entry.npcID = atoi(row[2]);
entry.temp = atoi(row[3]);
entry.petcontrol = atoi(row[4]);
entry.petnaming = atoi(row[5]);
entry.monsterflag = atoi(row[6]);
entry.equipmentset = atoi(row[7]);
entry.id = atoi(row[0]);
entry.type = row[1] ? row[1] : "";
entry.petpower = atoi(row[2]);
entry.npcID = atoi(row[3]);
entry.temp = atoi(row[4]);
entry.petcontrol = atoi(row[5]);
entry.petnaming = atoi(row[6]);
entry.monsterflag = atoi(row[7]);
entry.equipmentset = atoi(row[8]);
return entry;
}
@@ -163,14 +188,14 @@ public:
auto columns = Columns();
update_values.push_back(columns[0] + " = '" + EscapeString(pets_entry.type) + "'");
update_values.push_back(columns[1] + " = " + std::to_string(pets_entry.petpower));
update_values.push_back(columns[2] + " = " + std::to_string(pets_entry.npcID));
update_values.push_back(columns[3] + " = " + std::to_string(pets_entry.temp));
update_values.push_back(columns[4] + " = " + std::to_string(pets_entry.petcontrol));
update_values.push_back(columns[5] + " = " + std::to_string(pets_entry.petnaming));
update_values.push_back(columns[6] + " = " + std::to_string(pets_entry.monsterflag));
update_values.push_back(columns[7] + " = " + std::to_string(pets_entry.equipmentset));
update_values.push_back(columns[1] + " = '" + EscapeString(pets_entry.type) + "'");
update_values.push_back(columns[2] + " = " + std::to_string(pets_entry.petpower));
update_values.push_back(columns[3] + " = " + std::to_string(pets_entry.npcID));
update_values.push_back(columns[4] + " = " + std::to_string(pets_entry.temp));
update_values.push_back(columns[5] + " = " + std::to_string(pets_entry.petcontrol));
update_values.push_back(columns[6] + " = " + std::to_string(pets_entry.petnaming));
update_values.push_back(columns[7] + " = " + std::to_string(pets_entry.monsterflag));
update_values.push_back(columns[8] + " = " + std::to_string(pets_entry.equipmentset));
auto results = db.QueryDatabase(
fmt::format(
@@ -178,7 +203,7 @@ public:
TableName(),
implode(", ", update_values),
PrimaryKey(),
pets_entry.petpower
pets_entry.id
)
);
@@ -192,6 +217,7 @@ public:
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(pets_entry.id));
insert_values.push_back("'" + EscapeString(pets_entry.type) + "'");
insert_values.push_back(std::to_string(pets_entry.petpower));
insert_values.push_back(std::to_string(pets_entry.npcID));
@@ -210,7 +236,7 @@ public:
);
if (results.Success()) {
pets_entry.petpower = results.LastInsertedID();
pets_entry.id = results.LastInsertedID();
return pets_entry;
}
@@ -229,6 +255,7 @@ public:
for (auto &pets_entry: pets_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(pets_entry.id));
insert_values.push_back("'" + EscapeString(pets_entry.type) + "'");
insert_values.push_back(std::to_string(pets_entry.petpower));
insert_values.push_back(std::to_string(pets_entry.npcID));
@@ -270,14 +297,15 @@ public:
for (auto row = results.begin(); row != results.end(); ++row) {
Pets entry{};
entry.type = row[0] ? row[0] : "";
entry.petpower = atoi(row[1]);
entry.npcID = atoi(row[2]);
entry.temp = atoi(row[3]);
entry.petcontrol = atoi(row[4]);
entry.petnaming = atoi(row[5]);
entry.monsterflag = atoi(row[6]);
entry.equipmentset = atoi(row[7]);
entry.id = atoi(row[0]);
entry.type = row[1] ? row[1] : "";
entry.petpower = atoi(row[2]);
entry.npcID = atoi(row[3]);
entry.temp = atoi(row[4]);
entry.petcontrol = atoi(row[5]);
entry.petnaming = atoi(row[6]);
entry.monsterflag = atoi(row[7]);
entry.equipmentset = atoi(row[8]);
all_entries.push_back(entry);
}
@@ -302,14 +330,15 @@ public:
for (auto row = results.begin(); row != results.end(); ++row) {
Pets entry{};
entry.type = row[0] ? row[0] : "";
entry.petpower = atoi(row[1]);
entry.npcID = atoi(row[2]);
entry.temp = atoi(row[3]);
entry.petcontrol = atoi(row[4]);
entry.petnaming = atoi(row[5]);
entry.monsterflag = atoi(row[6]);
entry.equipmentset = atoi(row[7]);
entry.id = atoi(row[0]);
entry.type = row[1] ? row[1] : "";
entry.petpower = atoi(row[2]);
entry.npcID = atoi(row[3]);
entry.temp = atoi(row[4]);
entry.petcontrol = atoi(row[5]);
entry.petnaming = atoi(row[6]);
entry.monsterflag = atoi(row[7]);
entry.equipmentset = atoi(row[8]);
all_entries.push_back(entry);
}