mirror of
https://github.com/EQEmu/Server.git
synced 2026-09-07 00:56:58 +00:00
[Repository] Add null integer column support, instance_list notes migration, regenerate repositories (#3969)
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
/**
|
||||
* DO NOT MODIFY THIS FILE
|
||||
*
|
||||
* 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://docs.eqemu.io/developer/repositories
|
||||
*/
|
||||
|
||||
#ifndef EQEMU_BASE_VARIABLES_REPOSITORY_H
|
||||
@@ -10,10 +14,12 @@
|
||||
|
||||
#include "../../database.h"
|
||||
#include "../../strings.h"
|
||||
#include <ctime>
|
||||
|
||||
class BaseVariablesRepository {
|
||||
public:
|
||||
struct Variables {
|
||||
int32_t id;
|
||||
std::string varname;
|
||||
std::string value;
|
||||
std::string information;
|
||||
@@ -22,12 +28,24 @@ public:
|
||||
|
||||
static std::string PrimaryKey()
|
||||
{
|
||||
return std::string("varname");
|
||||
return std::string("id");
|
||||
}
|
||||
|
||||
static std::vector<std::string> Columns()
|
||||
{
|
||||
return {
|
||||
"id",
|
||||
"varname",
|
||||
"value",
|
||||
"information",
|
||||
"ts",
|
||||
};
|
||||
}
|
||||
|
||||
static std::vector<std::string> SelectColumns()
|
||||
{
|
||||
return {
|
||||
"id",
|
||||
"varname",
|
||||
"value",
|
||||
"information",
|
||||
@@ -40,19 +58,9 @@ public:
|
||||
return std::string(Strings::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(Strings::Implode(", ", insert_columns));
|
||||
return std::string(Strings::Implode(", ", SelectColumns()));
|
||||
}
|
||||
|
||||
static std::string TableName()
|
||||
@@ -64,7 +72,7 @@ public:
|
||||
{
|
||||
return fmt::format(
|
||||
"SELECT {} FROM {}",
|
||||
ColumnsRaw(),
|
||||
SelectColumnsRaw(),
|
||||
TableName()
|
||||
);
|
||||
}
|
||||
@@ -74,29 +82,30 @@ public:
|
||||
return fmt::format(
|
||||
"INSERT INTO {} ({}) ",
|
||||
TableName(),
|
||||
InsertColumnsRaw()
|
||||
ColumnsRaw()
|
||||
);
|
||||
}
|
||||
|
||||
static Variables NewEntity()
|
||||
{
|
||||
Variables entry{};
|
||||
Variables e{};
|
||||
|
||||
entry.varname = "";
|
||||
entry.value = "";
|
||||
entry.information = "";
|
||||
entry.ts = current_timestamp();
|
||||
e.id = 0;
|
||||
e.varname = "";
|
||||
e.value = "";
|
||||
e.information = "";
|
||||
e.ts = std::time(nullptr);
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static Variables GetVariablesEntry(
|
||||
static Variables GetVariables(
|
||||
const std::vector<Variables> &variabless,
|
||||
int variables_id
|
||||
)
|
||||
{
|
||||
for (auto &variables : variabless) {
|
||||
if (variables.varname == variables_id) {
|
||||
if (variables.id == variables_id) {
|
||||
return variables;
|
||||
}
|
||||
}
|
||||
@@ -105,37 +114,41 @@ public:
|
||||
}
|
||||
|
||||
static Variables FindOne(
|
||||
Database& db,
|
||||
int variables_id
|
||||
)
|
||||
{
|
||||
auto results = database.QueryDatabase(
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE id = {} LIMIT 1",
|
||||
"{} WHERE {} = {} LIMIT 1",
|
||||
BaseSelect(),
|
||||
PrimaryKey(),
|
||||
variables_id
|
||||
)
|
||||
);
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
Variables entry{};
|
||||
Variables e{};
|
||||
|
||||
entry.varname = row[0] ? row[0] : "";
|
||||
entry.value = row[1] ? row[1] : "";
|
||||
entry.information = row[2] ? row[2] : "";
|
||||
entry.ts = row[3] ? row[3] : "";
|
||||
e.id = static_cast<int32_t>(atoi(row[0]));
|
||||
e.varname = row[1] ? row[1] : "";
|
||||
e.value = row[2] ? row[2] : "";
|
||||
e.information = row[3] ? row[3] : "";
|
||||
e.ts = row[4] ? row[4] : "";
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static int DeleteOne(
|
||||
Database& db,
|
||||
int variables_id
|
||||
)
|
||||
{
|
||||
auto results = database.QueryDatabase(
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"DELETE FROM {} WHERE {} = {}",
|
||||
TableName(),
|
||||
@@ -148,25 +161,26 @@ public:
|
||||
}
|
||||
|
||||
static int UpdateOne(
|
||||
Variables variables_entry
|
||||
Database& db,
|
||||
const Variables &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> update_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
update_values.push_back(columns[0] + " = '" + Strings::Escape(variables_entry.varname) + "'");
|
||||
update_values.push_back(columns[1] + " = '" + Strings::Escape(variables_entry.value) + "'");
|
||||
update_values.push_back(columns[2] + " = '" + Strings::Escape(variables_entry.information) + "'");
|
||||
update_values.push_back(columns[3] + " = '" + Strings::Escape(variables_entry.ts) + "'");
|
||||
v.push_back(columns[1] + " = '" + Strings::Escape(e.varname) + "'");
|
||||
v.push_back(columns[2] + " = '" + Strings::Escape(e.value) + "'");
|
||||
v.push_back(columns[3] + " = '" + Strings::Escape(e.information) + "'");
|
||||
v.push_back(columns[4] + " = '" + Strings::Escape(e.ts) + "'");
|
||||
|
||||
auto results = database.QueryDatabase(
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", update_values),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
variables_entry.varname
|
||||
e.id
|
||||
)
|
||||
);
|
||||
|
||||
@@ -174,54 +188,58 @@ public:
|
||||
}
|
||||
|
||||
static Variables InsertOne(
|
||||
Variables variables_entry
|
||||
Database& db,
|
||||
Variables e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back("'" + Strings::Escape(variables_entry.varname) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(variables_entry.value) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(variables_entry.information) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(variables_entry.ts) + "'");
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back("'" + Strings::Escape(e.varname) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.value) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.information) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.ts) + "'");
|
||||
|
||||
auto results = database.QueryDatabase(
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", insert_values)
|
||||
Strings::Implode(",", v)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
variables_entry.varname = results.LastInsertedID();
|
||||
return variables_entry;
|
||||
e.id = results.LastInsertedID();
|
||||
return e;
|
||||
}
|
||||
|
||||
variables_entry = NewEntity();
|
||||
e = NewEntity();
|
||||
|
||||
return variables_entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
std::vector<Variables> variables_entries
|
||||
Database& db,
|
||||
const std::vector<Variables> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &variables_entry: variables_entries) {
|
||||
std::vector<std::string> insert_values;
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back("'" + Strings::Escape(variables_entry.varname) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(variables_entry.value) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(variables_entry.information) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(variables_entry.ts) + "'");
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back("'" + Strings::Escape(e.varname) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.value) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.information) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.ts) + "'");
|
||||
|
||||
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 = database.QueryDatabase(
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES {}",
|
||||
BaseInsert(),
|
||||
@@ -232,11 +250,11 @@ public:
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static std::vector<Variables> All()
|
||||
static std::vector<Variables> All(Database& db)
|
||||
{
|
||||
std::vector<Variables> all_entries;
|
||||
|
||||
auto results = database.QueryDatabase(
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{}",
|
||||
BaseSelect()
|
||||
@@ -246,24 +264,25 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
Variables entry{};
|
||||
Variables e{};
|
||||
|
||||
entry.varname = row[0] ? row[0] : "";
|
||||
entry.value = row[1] ? row[1] : "";
|
||||
entry.information = row[2] ? row[2] : "";
|
||||
entry.ts = row[3] ? row[3] : "";
|
||||
e.id = static_cast<int32_t>(atoi(row[0]));
|
||||
e.varname = row[1] ? row[1] : "";
|
||||
e.value = row[2] ? row[2] : "";
|
||||
e.information = row[3] ? row[3] : "";
|
||||
e.ts = row[4] ? row[4] : "";
|
||||
|
||||
all_entries.push_back(entry);
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<Variables> GetWhere(std::string where_filter)
|
||||
static std::vector<Variables> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<Variables> all_entries;
|
||||
|
||||
auto results = database.QueryDatabase(
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE {}",
|
||||
BaseSelect(),
|
||||
@@ -274,26 +293,26 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
Variables entry{};
|
||||
Variables e{};
|
||||
|
||||
entry.varname = row[0] ? row[0] : "";
|
||||
entry.value = row[1] ? row[1] : "";
|
||||
entry.information = row[2] ? row[2] : "";
|
||||
entry.ts = row[3] ? row[3] : "";
|
||||
e.id = static_cast<int32_t>(atoi(row[0]));
|
||||
e.varname = row[1] ? row[1] : "";
|
||||
e.value = row[2] ? row[2] : "";
|
||||
e.information = row[3] ? row[3] : "";
|
||||
e.ts = row[4] ? row[4] : "";
|
||||
|
||||
all_entries.push_back(entry);
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static int DeleteWhere(std::string where_filter)
|
||||
static int DeleteWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
auto results = database.QueryDatabase(
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"DELETE FROM {} WHERE {}",
|
||||
TableName(),
|
||||
PrimaryKey(),
|
||||
where_filter
|
||||
)
|
||||
);
|
||||
@@ -301,6 +320,108 @@ 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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static std::string BaseReplace()
|
||||
{
|
||||
return fmt::format(
|
||||
"REPLACE INTO {} ({}) ",
|
||||
TableName(),
|
||||
ColumnsRaw()
|
||||
);
|
||||
}
|
||||
|
||||
static int ReplaceOne(
|
||||
Database& db,
|
||||
const Variables &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back("'" + Strings::Escape(e.varname) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.value) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.information) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.ts) + "'");
|
||||
|
||||
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<Variables> &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("'" + Strings::Escape(e.varname) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.value) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.information) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.ts) + "'");
|
||||
|
||||
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_VARIABLES_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user