[Character] Convert Delete/Load/Save of Character Bandolier to Repositories (#3845)

* [Character] Convert Delete/Load/Save of Character Bandolier to Repositories

- Converts `DeleteCharacterBandolier`, `LoadCharacterBandolier`, and `SaveCharacterBandolier` to repositories.

* Update zonedb.cpp

* Update zonedb.cpp

* Update zonedb.cpp

* Update zonedb.cpp

* Update zonedb.cpp
This commit is contained in:
Alex King
2024-01-07 00:25:13 -05:00
committed by GitHub
parent f8de9b9167
commit 397096996c
3 changed files with 132 additions and 36 deletions
@@ -6,7 +6,7 @@
* Any modifications to base repositories are to be made by the generator only
*
* @generator ./utils/scripts/generators/repository-generator.pl
* @docs https://eqemu.gitbook.io/server/in-development/developer-area/repositories
* @docs https://docs.eqemu.io/developer/repositories
*/
#ifndef EQEMU_BASE_CHARACTER_BANDOLIER_REPOSITORY_H
@@ -16,6 +16,7 @@
#include "../../strings.h"
#include <ctime>
class BaseCharacterBandolierRepository {
public:
struct CharacterBandolier {
@@ -124,8 +125,9 @@ public:
{
auto results = db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
"{} WHERE {} = {} LIMIT 1",
BaseSelect(),
PrimaryKey(),
character_bandolier_id
)
);
@@ -368,6 +370,72 @@ public:
return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0);
}
static std::string BaseReplace()
{
return fmt::format(
"REPLACE INTO {} ({}) ",
TableName(),
ColumnsRaw()
);
}
static int ReplaceOne(
Database& db,
const CharacterBandolier &e
)
{
std::vector<std::string> v;
v.push_back(std::to_string(e.id));
v.push_back(std::to_string(e.bandolier_id));
v.push_back(std::to_string(e.bandolier_slot));
v.push_back(std::to_string(e.item_id));
v.push_back(std::to_string(e.icon));
v.push_back("'" + Strings::Escape(e.bandolier_name) + "'");
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseReplace(),
Strings::Implode(",", v)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int ReplaceMany(
Database& db,
const std::vector<CharacterBandolier> &entries
)
{
std::vector<std::string> insert_chunks;
for (auto &e: entries) {
std::vector<std::string> v;
v.push_back(std::to_string(e.id));
v.push_back(std::to_string(e.bandolier_id));
v.push_back(std::to_string(e.bandolier_slot));
v.push_back(std::to_string(e.item_id));
v.push_back(std::to_string(e.icon));
v.push_back("'" + Strings::Escape(e.bandolier_name) + "'");
insert_chunks.push_back("(" + Strings::Implode(",", v) + ")");
}
std::vector<std::string> v;
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseReplace(),
Strings::Implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
};
#endif //EQEMU_BASE_CHARACTER_BANDOLIER_REPOSITORY_H