[Repositories] Add GetMaxId, Count (#2371)

* [Repositories] Add GetMaxId, Count

* Update cmake with repositories, regenerate extended repos

* Remove license from files

* Simplify receivers

* Receiver simplify remaining

* Simplify receivers final

* Pass params by const reference

* Modernize grid tables

* Remove guild members since it doesn't conform as a generatable table

* PR comment
This commit is contained in:
Chris Miles
2022-08-13 18:40:56 -05:00
committed by GitHub
parent b79e1947f1
commit 79285b1002
374 changed files with 26837 additions and 26020 deletions
@@ -106,24 +106,24 @@ public:
static AdventureStats NewEntity()
{
AdventureStats entry{};
AdventureStats e{};
entry.player_id = 0;
entry.guk_wins = 0;
entry.mir_wins = 0;
entry.mmc_wins = 0;
entry.ruj_wins = 0;
entry.tak_wins = 0;
entry.guk_losses = 0;
entry.mir_losses = 0;
entry.mmc_losses = 0;
entry.ruj_losses = 0;
entry.tak_losses = 0;
e.player_id = 0;
e.guk_wins = 0;
e.mir_wins = 0;
e.mmc_wins = 0;
e.ruj_wins = 0;
e.tak_wins = 0;
e.guk_losses = 0;
e.mir_losses = 0;
e.mmc_losses = 0;
e.ruj_losses = 0;
e.tak_losses = 0;
return entry;
return e;
}
static AdventureStats GetAdventureStatsEntry(
static AdventureStats GetAdventureStats(
const std::vector<AdventureStats> &adventure_statss,
int adventure_stats_id
)
@@ -152,21 +152,21 @@ public:
auto row = results.begin();
if (results.RowCount() == 1) {
AdventureStats entry{};
AdventureStats e{};
entry.player_id = atoi(row[0]);
entry.guk_wins = atoi(row[1]);
entry.mir_wins = atoi(row[2]);
entry.mmc_wins = atoi(row[3]);
entry.ruj_wins = atoi(row[4]);
entry.tak_wins = atoi(row[5]);
entry.guk_losses = atoi(row[6]);
entry.mir_losses = atoi(row[7]);
entry.mmc_losses = atoi(row[8]);
entry.ruj_losses = atoi(row[9]);
entry.tak_losses = atoi(row[10]);
e.player_id = atoi(row[0]);
e.guk_wins = atoi(row[1]);
e.mir_wins = atoi(row[2]);
e.mmc_wins = atoi(row[3]);
e.ruj_wins = atoi(row[4]);
e.tak_wins = atoi(row[5]);
e.guk_losses = atoi(row[6]);
e.mir_losses = atoi(row[7]);
e.mmc_losses = atoi(row[8]);
e.ruj_losses = atoi(row[9]);
e.tak_losses = atoi(row[10]);
return entry;
return e;
}
return NewEntity();
@@ -191,32 +191,32 @@ public:
static int UpdateOne(
Database& db,
AdventureStats adventure_stats_entry
const AdventureStats &e
)
{
std::vector<std::string> update_values;
std::vector<std::string> v;
auto columns = Columns();
update_values.push_back(columns[0] + " = " + std::to_string(adventure_stats_entry.player_id));
update_values.push_back(columns[1] + " = " + std::to_string(adventure_stats_entry.guk_wins));
update_values.push_back(columns[2] + " = " + std::to_string(adventure_stats_entry.mir_wins));
update_values.push_back(columns[3] + " = " + std::to_string(adventure_stats_entry.mmc_wins));
update_values.push_back(columns[4] + " = " + std::to_string(adventure_stats_entry.ruj_wins));
update_values.push_back(columns[5] + " = " + std::to_string(adventure_stats_entry.tak_wins));
update_values.push_back(columns[6] + " = " + std::to_string(adventure_stats_entry.guk_losses));
update_values.push_back(columns[7] + " = " + std::to_string(adventure_stats_entry.mir_losses));
update_values.push_back(columns[8] + " = " + std::to_string(adventure_stats_entry.mmc_losses));
update_values.push_back(columns[9] + " = " + std::to_string(adventure_stats_entry.ruj_losses));
update_values.push_back(columns[10] + " = " + std::to_string(adventure_stats_entry.tak_losses));
v.push_back(columns[0] + " = " + std::to_string(e.player_id));
v.push_back(columns[1] + " = " + std::to_string(e.guk_wins));
v.push_back(columns[2] + " = " + std::to_string(e.mir_wins));
v.push_back(columns[3] + " = " + std::to_string(e.mmc_wins));
v.push_back(columns[4] + " = " + std::to_string(e.ruj_wins));
v.push_back(columns[5] + " = " + std::to_string(e.tak_wins));
v.push_back(columns[6] + " = " + std::to_string(e.guk_losses));
v.push_back(columns[7] + " = " + std::to_string(e.mir_losses));
v.push_back(columns[8] + " = " + std::to_string(e.mmc_losses));
v.push_back(columns[9] + " = " + std::to_string(e.ruj_losses));
v.push_back(columns[10] + " = " + std::to_string(e.tak_losses));
auto results = db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
Strings::Implode(", ", update_values),
Strings::Implode(", ", v),
PrimaryKey(),
adventure_stats_entry.player_id
e.player_id
)
);
@@ -225,67 +225,67 @@ public:
static AdventureStats InsertOne(
Database& db,
AdventureStats adventure_stats_entry
AdventureStats e
)
{
std::vector<std::string> insert_values;
std::vector<std::string> v;
insert_values.push_back(std::to_string(adventure_stats_entry.player_id));
insert_values.push_back(std::to_string(adventure_stats_entry.guk_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.mir_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.mmc_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.ruj_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.tak_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.guk_losses));
insert_values.push_back(std::to_string(adventure_stats_entry.mir_losses));
insert_values.push_back(std::to_string(adventure_stats_entry.mmc_losses));
insert_values.push_back(std::to_string(adventure_stats_entry.ruj_losses));
insert_values.push_back(std::to_string(adventure_stats_entry.tak_losses));
v.push_back(std::to_string(e.player_id));
v.push_back(std::to_string(e.guk_wins));
v.push_back(std::to_string(e.mir_wins));
v.push_back(std::to_string(e.mmc_wins));
v.push_back(std::to_string(e.ruj_wins));
v.push_back(std::to_string(e.tak_wins));
v.push_back(std::to_string(e.guk_losses));
v.push_back(std::to_string(e.mir_losses));
v.push_back(std::to_string(e.mmc_losses));
v.push_back(std::to_string(e.ruj_losses));
v.push_back(std::to_string(e.tak_losses));
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
Strings::Implode(",", insert_values)
Strings::Implode(",", v)
)
);
if (results.Success()) {
adventure_stats_entry.player_id = results.LastInsertedID();
return adventure_stats_entry;
e.player_id = results.LastInsertedID();
return e;
}
adventure_stats_entry = NewEntity();
e = NewEntity();
return adventure_stats_entry;
return e;
}
static int InsertMany(
Database& db,
std::vector<AdventureStats> adventure_stats_entries
const std::vector<AdventureStats> &entries
)
{
std::vector<std::string> insert_chunks;
for (auto &adventure_stats_entry: adventure_stats_entries) {
std::vector<std::string> insert_values;
for (auto &e: entries) {
std::vector<std::string> v;
insert_values.push_back(std::to_string(adventure_stats_entry.player_id));
insert_values.push_back(std::to_string(adventure_stats_entry.guk_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.mir_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.mmc_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.ruj_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.tak_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.guk_losses));
insert_values.push_back(std::to_string(adventure_stats_entry.mir_losses));
insert_values.push_back(std::to_string(adventure_stats_entry.mmc_losses));
insert_values.push_back(std::to_string(adventure_stats_entry.ruj_losses));
insert_values.push_back(std::to_string(adventure_stats_entry.tak_losses));
v.push_back(std::to_string(e.player_id));
v.push_back(std::to_string(e.guk_wins));
v.push_back(std::to_string(e.mir_wins));
v.push_back(std::to_string(e.mmc_wins));
v.push_back(std::to_string(e.ruj_wins));
v.push_back(std::to_string(e.tak_wins));
v.push_back(std::to_string(e.guk_losses));
v.push_back(std::to_string(e.mir_losses));
v.push_back(std::to_string(e.mmc_losses));
v.push_back(std::to_string(e.ruj_losses));
v.push_back(std::to_string(e.tak_losses));
insert_chunks.push_back("(" + Strings::Implode(",", insert_values) + ")");
insert_chunks.push_back("(" + Strings::Implode(",", v) + ")");
}
std::vector<std::string> insert_values;
std::vector<std::string> v;
auto results = db.QueryDatabase(
fmt::format(
@@ -312,27 +312,27 @@ public:
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
AdventureStats entry{};
AdventureStats e{};
entry.player_id = atoi(row[0]);
entry.guk_wins = atoi(row[1]);
entry.mir_wins = atoi(row[2]);
entry.mmc_wins = atoi(row[3]);
entry.ruj_wins = atoi(row[4]);
entry.tak_wins = atoi(row[5]);
entry.guk_losses = atoi(row[6]);
entry.mir_losses = atoi(row[7]);
entry.mmc_losses = atoi(row[8]);
entry.ruj_losses = atoi(row[9]);
entry.tak_losses = atoi(row[10]);
e.player_id = atoi(row[0]);
e.guk_wins = atoi(row[1]);
e.mir_wins = atoi(row[2]);
e.mmc_wins = atoi(row[3]);
e.ruj_wins = atoi(row[4]);
e.tak_wins = atoi(row[5]);
e.guk_losses = atoi(row[6]);
e.mir_losses = atoi(row[7]);
e.mmc_losses = atoi(row[8]);
e.ruj_losses = atoi(row[9]);
e.tak_losses = atoi(row[10]);
all_entries.push_back(entry);
all_entries.push_back(e);
}
return all_entries;
}
static std::vector<AdventureStats> GetWhere(Database& db, std::string where_filter)
static std::vector<AdventureStats> GetWhere(Database& db, const std::string &where_filter)
{
std::vector<AdventureStats> all_entries;
@@ -347,27 +347,27 @@ public:
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
AdventureStats entry{};
AdventureStats e{};
entry.player_id = atoi(row[0]);
entry.guk_wins = atoi(row[1]);
entry.mir_wins = atoi(row[2]);
entry.mmc_wins = atoi(row[3]);
entry.ruj_wins = atoi(row[4]);
entry.tak_wins = atoi(row[5]);
entry.guk_losses = atoi(row[6]);
entry.mir_losses = atoi(row[7]);
entry.mmc_losses = atoi(row[8]);
entry.ruj_losses = atoi(row[9]);
entry.tak_losses = atoi(row[10]);
e.player_id = atoi(row[0]);
e.guk_wins = atoi(row[1]);
e.mir_wins = atoi(row[2]);
e.mmc_wins = atoi(row[3]);
e.ruj_wins = atoi(row[4]);
e.tak_wins = atoi(row[5]);
e.guk_losses = atoi(row[6]);
e.mir_losses = atoi(row[7]);
e.mmc_losses = atoi(row[8]);
e.ruj_losses = atoi(row[9]);
e.tak_losses = atoi(row[10]);
all_entries.push_back(entry);
all_entries.push_back(e);
}
return all_entries;
}
static int DeleteWhere(Database& db, std::string where_filter)
static int DeleteWhere(Database& db, const std::string &where_filter)
{
auto results = db.QueryDatabase(
fmt::format(
@@ -392,6 +392,32 @@ public:
return (results.Success() ? results.RowsAffected() : 0);
}
static int64 GetMaxId(Database& db)
{
auto results = db.QueryDatabase(
fmt::format(
"SELECT COALESCE(MAX({}), 0) FROM {}",
PrimaryKey(),
TableName()
)
);
return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0);
}
static int64 Count(Database& db, const std::string &where_filter = "")
{
auto results = db.QueryDatabase(
fmt::format(
"SELECT COUNT(*) FROM {} {}",
TableName(),
(where_filter.empty() ? "" : "WHERE " + where_filter)
)
);
return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0);
}
};
#endif //EQEMU_BASE_ADVENTURE_STATS_REPOSITORY_H