mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-01 14:21:37 +00:00
[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:
@@ -85,17 +85,17 @@ public:
|
||||
|
||||
static Expeditions NewEntity()
|
||||
{
|
||||
Expeditions entry{};
|
||||
Expeditions e{};
|
||||
|
||||
entry.id = 0;
|
||||
entry.dynamic_zone_id = 0;
|
||||
entry.add_replay_on_join = 1;
|
||||
entry.is_locked = 0;
|
||||
e.id = 0;
|
||||
e.dynamic_zone_id = 0;
|
||||
e.add_replay_on_join = 1;
|
||||
e.is_locked = 0;
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static Expeditions GetExpeditionsEntry(
|
||||
static Expeditions GetExpeditions(
|
||||
const std::vector<Expeditions> &expeditionss,
|
||||
int expeditions_id
|
||||
)
|
||||
@@ -124,14 +124,14 @@ public:
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
Expeditions entry{};
|
||||
Expeditions e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.dynamic_zone_id = atoi(row[1]);
|
||||
entry.add_replay_on_join = atoi(row[2]);
|
||||
entry.is_locked = atoi(row[3]);
|
||||
e.id = atoi(row[0]);
|
||||
e.dynamic_zone_id = atoi(row[1]);
|
||||
e.add_replay_on_join = atoi(row[2]);
|
||||
e.is_locked = atoi(row[3]);
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
@@ -156,24 +156,24 @@ public:
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
Expeditions expeditions_entry
|
||||
const Expeditions &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> update_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
update_values.push_back(columns[1] + " = " + std::to_string(expeditions_entry.dynamic_zone_id));
|
||||
update_values.push_back(columns[2] + " = " + std::to_string(expeditions_entry.add_replay_on_join));
|
||||
update_values.push_back(columns[3] + " = " + std::to_string(expeditions_entry.is_locked));
|
||||
v.push_back(columns[1] + " = " + std::to_string(e.dynamic_zone_id));
|
||||
v.push_back(columns[2] + " = " + std::to_string(e.add_replay_on_join));
|
||||
v.push_back(columns[3] + " = " + std::to_string(e.is_locked));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", update_values),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
expeditions_entry.id
|
||||
e.id
|
||||
)
|
||||
);
|
||||
|
||||
@@ -182,53 +182,53 @@ public:
|
||||
|
||||
static Expeditions InsertOne(
|
||||
Database& db,
|
||||
Expeditions expeditions_entry
|
||||
Expeditions e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(expeditions_entry.id));
|
||||
insert_values.push_back(std::to_string(expeditions_entry.dynamic_zone_id));
|
||||
insert_values.push_back(std::to_string(expeditions_entry.add_replay_on_join));
|
||||
insert_values.push_back(std::to_string(expeditions_entry.is_locked));
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.dynamic_zone_id));
|
||||
v.push_back(std::to_string(e.add_replay_on_join));
|
||||
v.push_back(std::to_string(e.is_locked));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", insert_values)
|
||||
Strings::Implode(",", v)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
expeditions_entry.id = results.LastInsertedID();
|
||||
return expeditions_entry;
|
||||
e.id = results.LastInsertedID();
|
||||
return e;
|
||||
}
|
||||
|
||||
expeditions_entry = NewEntity();
|
||||
e = NewEntity();
|
||||
|
||||
return expeditions_entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
std::vector<Expeditions> expeditions_entries
|
||||
const std::vector<Expeditions> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &expeditions_entry: expeditions_entries) {
|
||||
std::vector<std::string> insert_values;
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(expeditions_entry.id));
|
||||
insert_values.push_back(std::to_string(expeditions_entry.dynamic_zone_id));
|
||||
insert_values.push_back(std::to_string(expeditions_entry.add_replay_on_join));
|
||||
insert_values.push_back(std::to_string(expeditions_entry.is_locked));
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.dynamic_zone_id));
|
||||
v.push_back(std::to_string(e.add_replay_on_join));
|
||||
v.push_back(std::to_string(e.is_locked));
|
||||
|
||||
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(
|
||||
@@ -255,20 +255,20 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
Expeditions entry{};
|
||||
Expeditions e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.dynamic_zone_id = atoi(row[1]);
|
||||
entry.add_replay_on_join = atoi(row[2]);
|
||||
entry.is_locked = atoi(row[3]);
|
||||
e.id = atoi(row[0]);
|
||||
e.dynamic_zone_id = atoi(row[1]);
|
||||
e.add_replay_on_join = atoi(row[2]);
|
||||
e.is_locked = atoi(row[3]);
|
||||
|
||||
all_entries.push_back(entry);
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<Expeditions> GetWhere(Database& db, std::string where_filter)
|
||||
static std::vector<Expeditions> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<Expeditions> all_entries;
|
||||
|
||||
@@ -283,20 +283,20 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
Expeditions entry{};
|
||||
Expeditions e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.dynamic_zone_id = atoi(row[1]);
|
||||
entry.add_replay_on_join = atoi(row[2]);
|
||||
entry.is_locked = atoi(row[3]);
|
||||
e.id = atoi(row[0]);
|
||||
e.dynamic_zone_id = atoi(row[1]);
|
||||
e.add_replay_on_join = atoi(row[2]);
|
||||
e.is_locked = atoi(row[3]);
|
||||
|
||||
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(
|
||||
@@ -321,6 +321,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_EXPEDITIONS_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user