[Character] Convert Clear/Delete/Get/Update of Character Item Recast to Repositories (#3857)

* [Character] Convert Clear/Delete/Get/Update of Character Item Recast to Repositories

- Convert `ClearOldRecastTimestamps`, `DeleteItemRecast`, `GetItemRecastTimeStamp`, `GetItemRecastTimestamps`, and `UpdateItemRecast` to repositories.

* Update shareddb.cpp

* Update shareddb.cpp

* Update zonedb.cpp
This commit is contained in:
Alex King
2024-01-07 01:21:14 -05:00
committed by GitHub
parent 0ea825e9a4
commit a724e92638
4 changed files with 200 additions and 108 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_ITEM_RECAST_REPOSITORY_H
@@ -16,11 +16,12 @@
#include "../../strings.h"
#include <ctime>
class BaseCharacterItemRecastRepository {
public:
struct CharacterItemRecast {
uint32_t id;
uint16_t recast_type;
uint32_t recast_type;
uint32_t timestamp;
};
@@ -112,8 +113,9 @@ public:
{
auto results = db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
"{} WHERE {} = {} LIMIT 1",
BaseSelect(),
PrimaryKey(),
character_item_recast_id
)
);
@@ -123,7 +125,7 @@ public:
CharacterItemRecast e{};
e.id = static_cast<uint32_t>(strtoul(row[0], nullptr, 10));
e.recast_type = static_cast<uint16_t>(strtoul(row[1], nullptr, 10));
e.recast_type = static_cast<uint32_t>(strtoul(row[1], nullptr, 10));
e.timestamp = static_cast<uint32_t>(strtoul(row[2], nullptr, 10));
return e;
@@ -251,7 +253,7 @@ public:
CharacterItemRecast e{};
e.id = static_cast<uint32_t>(strtoul(row[0], nullptr, 10));
e.recast_type = static_cast<uint16_t>(strtoul(row[1], nullptr, 10));
e.recast_type = static_cast<uint32_t>(strtoul(row[1], nullptr, 10));
e.timestamp = static_cast<uint32_t>(strtoul(row[2], nullptr, 10));
all_entries.push_back(e);
@@ -278,7 +280,7 @@ public:
CharacterItemRecast e{};
e.id = static_cast<uint32_t>(strtoul(row[0], nullptr, 10));
e.recast_type = static_cast<uint16_t>(strtoul(row[1], nullptr, 10));
e.recast_type = static_cast<uint32_t>(strtoul(row[1], nullptr, 10));
e.timestamp = static_cast<uint32_t>(strtoul(row[2], nullptr, 10));
all_entries.push_back(e);
@@ -338,6 +340,66 @@ 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 CharacterItemRecast &e
)
{
std::vector<std::string> v;
v.push_back(std::to_string(e.id));
v.push_back(std::to_string(e.recast_type));
v.push_back(std::to_string(e.timestamp));
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<CharacterItemRecast> &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.recast_type));
v.push_back(std::to_string(e.timestamp));
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_ITEM_RECAST_REPOSITORY_H