[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 GuildRanks NewEntity()
{
GuildRanks entry{};
GuildRanks e{};
entry.guild_id = 0;
entry.rank = 0;
entry.title = "";
entry.can_hear = 0;
entry.can_speak = 0;
entry.can_invite = 0;
entry.can_remove = 0;
entry.can_promote = 0;
entry.can_demote = 0;
entry.can_motd = 0;
entry.can_warpeace = 0;
e.guild_id = 0;
e.rank = 0;
e.title = "";
e.can_hear = 0;
e.can_speak = 0;
e.can_invite = 0;
e.can_remove = 0;
e.can_promote = 0;
e.can_demote = 0;
e.can_motd = 0;
e.can_warpeace = 0;
return entry;
return e;
}
static GuildRanks GetGuildRanksEntry(
static GuildRanks GetGuildRanks(
const std::vector<GuildRanks> &guild_rankss,
int guild_ranks_id
)
@@ -152,21 +152,21 @@ public:
auto row = results.begin();
if (results.RowCount() == 1) {
GuildRanks entry{};
GuildRanks e{};
entry.guild_id = atoi(row[0]);
entry.rank = atoi(row[1]);
entry.title = row[2] ? row[2] : "";
entry.can_hear = atoi(row[3]);
entry.can_speak = atoi(row[4]);
entry.can_invite = atoi(row[5]);
entry.can_remove = atoi(row[6]);
entry.can_promote = atoi(row[7]);
entry.can_demote = atoi(row[8]);
entry.can_motd = atoi(row[9]);
entry.can_warpeace = atoi(row[10]);
e.guild_id = atoi(row[0]);
e.rank = atoi(row[1]);
e.title = row[2] ? row[2] : "";
e.can_hear = atoi(row[3]);
e.can_speak = atoi(row[4]);
e.can_invite = atoi(row[5]);
e.can_remove = atoi(row[6]);
e.can_promote = atoi(row[7]);
e.can_demote = atoi(row[8]);
e.can_motd = atoi(row[9]);
e.can_warpeace = atoi(row[10]);
return entry;
return e;
}
return NewEntity();
@@ -191,32 +191,32 @@ public:
static int UpdateOne(
Database& db,
GuildRanks guild_ranks_entry
const GuildRanks &e
)
{
std::vector<std::string> update_values;
std::vector<std::string> v;
auto columns = Columns();
update_values.push_back(columns[0] + " = " + std::to_string(guild_ranks_entry.guild_id));
update_values.push_back(columns[1] + " = " + std::to_string(guild_ranks_entry.rank));
update_values.push_back(columns[2] + " = '" + Strings::Escape(guild_ranks_entry.title) + "'");
update_values.push_back(columns[3] + " = " + std::to_string(guild_ranks_entry.can_hear));
update_values.push_back(columns[4] + " = " + std::to_string(guild_ranks_entry.can_speak));
update_values.push_back(columns[5] + " = " + std::to_string(guild_ranks_entry.can_invite));
update_values.push_back(columns[6] + " = " + std::to_string(guild_ranks_entry.can_remove));
update_values.push_back(columns[7] + " = " + std::to_string(guild_ranks_entry.can_promote));
update_values.push_back(columns[8] + " = " + std::to_string(guild_ranks_entry.can_demote));
update_values.push_back(columns[9] + " = " + std::to_string(guild_ranks_entry.can_motd));
update_values.push_back(columns[10] + " = " + std::to_string(guild_ranks_entry.can_warpeace));
v.push_back(columns[0] + " = " + std::to_string(e.guild_id));
v.push_back(columns[1] + " = " + std::to_string(e.rank));
v.push_back(columns[2] + " = '" + Strings::Escape(e.title) + "'");
v.push_back(columns[3] + " = " + std::to_string(e.can_hear));
v.push_back(columns[4] + " = " + std::to_string(e.can_speak));
v.push_back(columns[5] + " = " + std::to_string(e.can_invite));
v.push_back(columns[6] + " = " + std::to_string(e.can_remove));
v.push_back(columns[7] + " = " + std::to_string(e.can_promote));
v.push_back(columns[8] + " = " + std::to_string(e.can_demote));
v.push_back(columns[9] + " = " + std::to_string(e.can_motd));
v.push_back(columns[10] + " = " + std::to_string(e.can_warpeace));
auto results = db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
Strings::Implode(", ", update_values),
Strings::Implode(", ", v),
PrimaryKey(),
guild_ranks_entry.guild_id
e.guild_id
)
);
@@ -225,67 +225,67 @@ public:
static GuildRanks InsertOne(
Database& db,
GuildRanks guild_ranks_entry
GuildRanks e
)
{
std::vector<std::string> insert_values;
std::vector<std::string> v;
insert_values.push_back(std::to_string(guild_ranks_entry.guild_id));
insert_values.push_back(std::to_string(guild_ranks_entry.rank));
insert_values.push_back("'" + Strings::Escape(guild_ranks_entry.title) + "'");
insert_values.push_back(std::to_string(guild_ranks_entry.can_hear));
insert_values.push_back(std::to_string(guild_ranks_entry.can_speak));
insert_values.push_back(std::to_string(guild_ranks_entry.can_invite));
insert_values.push_back(std::to_string(guild_ranks_entry.can_remove));
insert_values.push_back(std::to_string(guild_ranks_entry.can_promote));
insert_values.push_back(std::to_string(guild_ranks_entry.can_demote));
insert_values.push_back(std::to_string(guild_ranks_entry.can_motd));
insert_values.push_back(std::to_string(guild_ranks_entry.can_warpeace));
v.push_back(std::to_string(e.guild_id));
v.push_back(std::to_string(e.rank));
v.push_back("'" + Strings::Escape(e.title) + "'");
v.push_back(std::to_string(e.can_hear));
v.push_back(std::to_string(e.can_speak));
v.push_back(std::to_string(e.can_invite));
v.push_back(std::to_string(e.can_remove));
v.push_back(std::to_string(e.can_promote));
v.push_back(std::to_string(e.can_demote));
v.push_back(std::to_string(e.can_motd));
v.push_back(std::to_string(e.can_warpeace));
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
Strings::Implode(",", insert_values)
Strings::Implode(",", v)
)
);
if (results.Success()) {
guild_ranks_entry.guild_id = results.LastInsertedID();
return guild_ranks_entry;
e.guild_id = results.LastInsertedID();
return e;
}
guild_ranks_entry = NewEntity();
e = NewEntity();
return guild_ranks_entry;
return e;
}
static int InsertMany(
Database& db,
std::vector<GuildRanks> guild_ranks_entries
const std::vector<GuildRanks> &entries
)
{
std::vector<std::string> insert_chunks;
for (auto &guild_ranks_entry: guild_ranks_entries) {
std::vector<std::string> insert_values;
for (auto &e: entries) {
std::vector<std::string> v;
insert_values.push_back(std::to_string(guild_ranks_entry.guild_id));
insert_values.push_back(std::to_string(guild_ranks_entry.rank));
insert_values.push_back("'" + Strings::Escape(guild_ranks_entry.title) + "'");
insert_values.push_back(std::to_string(guild_ranks_entry.can_hear));
insert_values.push_back(std::to_string(guild_ranks_entry.can_speak));
insert_values.push_back(std::to_string(guild_ranks_entry.can_invite));
insert_values.push_back(std::to_string(guild_ranks_entry.can_remove));
insert_values.push_back(std::to_string(guild_ranks_entry.can_promote));
insert_values.push_back(std::to_string(guild_ranks_entry.can_demote));
insert_values.push_back(std::to_string(guild_ranks_entry.can_motd));
insert_values.push_back(std::to_string(guild_ranks_entry.can_warpeace));
v.push_back(std::to_string(e.guild_id));
v.push_back(std::to_string(e.rank));
v.push_back("'" + Strings::Escape(e.title) + "'");
v.push_back(std::to_string(e.can_hear));
v.push_back(std::to_string(e.can_speak));
v.push_back(std::to_string(e.can_invite));
v.push_back(std::to_string(e.can_remove));
v.push_back(std::to_string(e.can_promote));
v.push_back(std::to_string(e.can_demote));
v.push_back(std::to_string(e.can_motd));
v.push_back(std::to_string(e.can_warpeace));
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) {
GuildRanks entry{};
GuildRanks e{};
entry.guild_id = atoi(row[0]);
entry.rank = atoi(row[1]);
entry.title = row[2] ? row[2] : "";
entry.can_hear = atoi(row[3]);
entry.can_speak = atoi(row[4]);
entry.can_invite = atoi(row[5]);
entry.can_remove = atoi(row[6]);
entry.can_promote = atoi(row[7]);
entry.can_demote = atoi(row[8]);
entry.can_motd = atoi(row[9]);
entry.can_warpeace = atoi(row[10]);
e.guild_id = atoi(row[0]);
e.rank = atoi(row[1]);
e.title = row[2] ? row[2] : "";
e.can_hear = atoi(row[3]);
e.can_speak = atoi(row[4]);
e.can_invite = atoi(row[5]);
e.can_remove = atoi(row[6]);
e.can_promote = atoi(row[7]);
e.can_demote = atoi(row[8]);
e.can_motd = atoi(row[9]);
e.can_warpeace = atoi(row[10]);
all_entries.push_back(entry);
all_entries.push_back(e);
}
return all_entries;
}
static std::vector<GuildRanks> GetWhere(Database& db, std::string where_filter)
static std::vector<GuildRanks> GetWhere(Database& db, const std::string &where_filter)
{
std::vector<GuildRanks> all_entries;
@@ -347,27 +347,27 @@ public:
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
GuildRanks entry{};
GuildRanks e{};
entry.guild_id = atoi(row[0]);
entry.rank = atoi(row[1]);
entry.title = row[2] ? row[2] : "";
entry.can_hear = atoi(row[3]);
entry.can_speak = atoi(row[4]);
entry.can_invite = atoi(row[5]);
entry.can_remove = atoi(row[6]);
entry.can_promote = atoi(row[7]);
entry.can_demote = atoi(row[8]);
entry.can_motd = atoi(row[9]);
entry.can_warpeace = atoi(row[10]);
e.guild_id = atoi(row[0]);
e.rank = atoi(row[1]);
e.title = row[2] ? row[2] : "";
e.can_hear = atoi(row[3]);
e.can_speak = atoi(row[4]);
e.can_invite = atoi(row[5]);
e.can_remove = atoi(row[6]);
e.can_promote = atoi(row[7]);
e.can_demote = atoi(row[8]);
e.can_motd = atoi(row[9]);
e.can_warpeace = 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_GUILD_RANKS_REPOSITORY_H