[Repositories] Update repositories (#2040)

This commit is contained in:
Chris Miles
2022-03-11 15:27:36 -08:00
committed by GitHub
parent f22608a43a
commit 3ed6663c4c
170 changed files with 5543 additions and 511 deletions
@@ -1,29 +1,12 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
* DO NOT MODIFY THIS FILE
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
*/
/**
* This repository was automatically generated and is NOT to be modified directly.
* Any repository modifications are meant to be made to
* the repository extending the base. Any modifications to base repositories are to
* be made by the generator only
* Any repository modifications are meant to be made to the repository extending the base.
* 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
*/
#ifndef EQEMU_BASE_HORSES_REPOSITORY_H
@@ -31,26 +14,42 @@
#include "../../database.h"
#include "../../string_util.h"
#include <ctime>
class BaseHorsesRepository {
public:
struct Horses {
int id;
std::string filename;
int16 race;
int8 gender;
int8 texture;
int race;
int gender;
int texture;
float mountspeed;
std::string notes;
};
static std::string PrimaryKey()
{
return std::string("filename");
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"filename",
"race",
"gender",
"texture",
"mountspeed",
"notes",
};
}
static std::vector<std::string> SelectColumns()
{
return {
"id",
"filename",
"race",
"gender",
@@ -65,19 +64,9 @@ public:
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
static std::string SelectColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
return std::string(implode(", ", SelectColumns()));
}
static std::string TableName()
@@ -89,7 +78,7 @@ public:
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
SelectColumnsRaw(),
TableName()
);
}
@@ -99,7 +88,7 @@ public:
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
ColumnsRaw()
);
}
@@ -107,6 +96,7 @@ public:
{
Horses entry{};
entry.id = 0;
entry.filename = "";
entry.race = 216;
entry.gender = 0;
@@ -123,7 +113,7 @@ public:
)
{
for (auto &horses : horsess) {
if (horses.filename == horses_id) {
if (horses.id == horses_id) {
return horses;
}
}
@@ -132,10 +122,11 @@ public:
}
static Horses FindOne(
Database& db,
int horses_id
)
{
auto results = content_db.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
@@ -147,12 +138,13 @@ public:
if (results.RowCount() == 1) {
Horses entry{};
entry.filename = row[0] ? row[0] : "";
entry.race = atoi(row[1]);
entry.gender = atoi(row[2]);
entry.texture = atoi(row[3]);
entry.mountspeed = atof(row[4]);
entry.notes = row[5] ? row[5] : "";
entry.id = atoi(row[0]);
entry.filename = row[1] ? row[1] : "";
entry.race = atoi(row[2]);
entry.gender = atoi(row[3]);
entry.texture = atoi(row[4]);
entry.mountspeed = static_cast<float>(atof(row[5]));
entry.notes = row[6] ? row[6] : "";
return entry;
}
@@ -161,10 +153,11 @@ public:
}
static int DeleteOne(
Database& db,
int horses_id
)
{
auto results = content_db.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
@@ -177,6 +170,7 @@ public:
}
static int UpdateOne(
Database& db,
Horses horses_entry
)
{
@@ -184,20 +178,20 @@ public:
auto columns = Columns();
update_values.push_back(columns[0] + " = '" + EscapeString(horses_entry.filename) + "'");
update_values.push_back(columns[1] + " = " + std::to_string(horses_entry.race));
update_values.push_back(columns[2] + " = " + std::to_string(horses_entry.gender));
update_values.push_back(columns[3] + " = " + std::to_string(horses_entry.texture));
update_values.push_back(columns[4] + " = " + std::to_string(horses_entry.mountspeed));
update_values.push_back(columns[5] + " = '" + EscapeString(horses_entry.notes) + "'");
update_values.push_back(columns[1] + " = '" + EscapeString(horses_entry.filename) + "'");
update_values.push_back(columns[2] + " = " + std::to_string(horses_entry.race));
update_values.push_back(columns[3] + " = " + std::to_string(horses_entry.gender));
update_values.push_back(columns[4] + " = " + std::to_string(horses_entry.texture));
update_values.push_back(columns[5] + " = " + std::to_string(horses_entry.mountspeed));
update_values.push_back(columns[6] + " = '" + EscapeString(horses_entry.notes) + "'");
auto results = content_db.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
horses_entry.filename
horses_entry.id
)
);
@@ -205,11 +199,13 @@ public:
}
static Horses InsertOne(
Database& db,
Horses horses_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(horses_entry.id));
insert_values.push_back("'" + EscapeString(horses_entry.filename) + "'");
insert_values.push_back(std::to_string(horses_entry.race));
insert_values.push_back(std::to_string(horses_entry.gender));
@@ -217,7 +213,7 @@ public:
insert_values.push_back(std::to_string(horses_entry.mountspeed));
insert_values.push_back("'" + EscapeString(horses_entry.notes) + "'");
auto results = content_db.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
@@ -226,7 +222,7 @@ public:
);
if (results.Success()) {
horses_entry.filename = results.LastInsertedID();
horses_entry.id = results.LastInsertedID();
return horses_entry;
}
@@ -236,6 +232,7 @@ public:
}
static int InsertMany(
Database& db,
std::vector<Horses> horses_entries
)
{
@@ -244,6 +241,7 @@ public:
for (auto &horses_entry: horses_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(horses_entry.id));
insert_values.push_back("'" + EscapeString(horses_entry.filename) + "'");
insert_values.push_back(std::to_string(horses_entry.race));
insert_values.push_back(std::to_string(horses_entry.gender));
@@ -256,7 +254,7 @@ public:
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
@@ -267,11 +265,11 @@ public:
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Horses> All()
static std::vector<Horses> All(Database& db)
{
std::vector<Horses> all_entries;
auto results = content_db.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
@@ -283,12 +281,13 @@ public:
for (auto row = results.begin(); row != results.end(); ++row) {
Horses entry{};
entry.filename = row[0] ? row[0] : "";
entry.race = atoi(row[1]);
entry.gender = atoi(row[2]);
entry.texture = atoi(row[3]);
entry.mountspeed = atof(row[4]);
entry.notes = row[5] ? row[5] : "";
entry.id = atoi(row[0]);
entry.filename = row[1] ? row[1] : "";
entry.race = atoi(row[2]);
entry.gender = atoi(row[3]);
entry.texture = atoi(row[4]);
entry.mountspeed = static_cast<float>(atof(row[5]));
entry.notes = row[6] ? row[6] : "";
all_entries.push_back(entry);
}
@@ -296,11 +295,11 @@ public:
return all_entries;
}
static std::vector<Horses> GetWhere(std::string where_filter)
static std::vector<Horses> GetWhere(Database& db, std::string where_filter)
{
std::vector<Horses> all_entries;
auto results = content_db.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"{} WHERE {}",
BaseSelect(),
@@ -313,12 +312,13 @@ public:
for (auto row = results.begin(); row != results.end(); ++row) {
Horses entry{};
entry.filename = row[0] ? row[0] : "";
entry.race = atoi(row[1]);
entry.gender = atoi(row[2]);
entry.texture = atoi(row[3]);
entry.mountspeed = atof(row[4]);
entry.notes = row[5] ? row[5] : "";
entry.id = atoi(row[0]);
entry.filename = row[1] ? row[1] : "";
entry.race = atoi(row[2]);
entry.gender = atoi(row[3]);
entry.texture = atoi(row[4]);
entry.mountspeed = static_cast<float>(atof(row[5]));
entry.notes = row[6] ? row[6] : "";
all_entries.push_back(entry);
}
@@ -326,13 +326,12 @@ public:
return all_entries;
}
static int DeleteWhere(std::string where_filter)
static int DeleteWhere(Database& db, std::string where_filter)
{
auto results = content_db.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {}",
TableName(),
PrimaryKey(),
where_filter
)
);
@@ -340,6 +339,18 @@ public:
return (results.Success() ? results.RowsAffected() : 0);
}
static int Truncate(Database& db)
{
auto results = db.QueryDatabase(
fmt::format(
"TRUNCATE TABLE {}",
TableName()
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
};
#endif //EQEMU_BASE_HORSES_REPOSITORY_H