[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:
Chris Miles
2022-08-13 18:40:56 -05:00
committed by GitHub
parent b79e1947f1
commit 79285b1002
374 changed files with 26837 additions and 26020 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 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
*
* 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 on Apr 5, 2020 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
* @generator ./utils/scripts/generators/repository-generator.pl
* @docs https://eqemu.gitbook.io/server/in-development/developer-area/repositories
*/
#ifndef EQEMU_BASE_GRID_ENTRIES_REPOSITORY_H
@@ -31,6 +14,7 @@
#include "../../database.h"
#include "../../strings.h"
#include <ctime>
class BaseGridEntriesRepository {
public:
@@ -43,12 +27,12 @@ public:
float z;
float heading;
int pause;
int8 centerpoint;
int centerpoint;
};
static std::string PrimaryKey()
{
return std::string("number");
return std::string("gridid");
}
static std::vector<std::string> Columns()
@@ -66,24 +50,29 @@ public:
};
}
static std::vector<std::string> SelectColumns()
{
return {
"gridid",
"zoneid",
"number",
"x",
"y",
"z",
"heading",
"pause",
"centerpoint",
};
}
static std::string ColumnsRaw()
{
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()
@@ -95,7 +84,7 @@ public:
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
SelectColumnsRaw(),
TableName()
);
}
@@ -105,34 +94,34 @@ public:
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
ColumnsRaw()
);
}
static GridEntries NewEntity()
{
GridEntries entry{};
GridEntries e{};
entry.gridid = 0;
entry.zoneid = 0;
entry.number = 0;
entry.x = 0;
entry.y = 0;
entry.z = 0;
entry.heading = 0;
entry.pause = 0;
entry.centerpoint = 0;
e.gridid = 0;
e.zoneid = 0;
e.number = 0;
e.x = 0;
e.y = 0;
e.z = 0;
e.heading = 0;
e.pause = 0;
e.centerpoint = 0;
return entry;
return e;
}
static GridEntries GetGridEntriesEntry(
static GridEntries GetGridEntries(
const std::vector<GridEntries> &grid_entriess,
int grid_entries_id
)
{
for (auto &grid_entries : grid_entriess) {
if (grid_entries.number == grid_entries_id) {
if (grid_entries.gridid == grid_entries_id) {
return grid_entries;
}
}
@@ -141,10 +130,11 @@ public:
}
static GridEntries FindOne(
Database& db,
int grid_entries_id
)
{
auto results = content_db.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
@@ -154,29 +144,30 @@ public:
auto row = results.begin();
if (results.RowCount() == 1) {
GridEntries entry{};
GridEntries e{};
entry.gridid = atoi(row[0]);
entry.zoneid = atoi(row[1]);
entry.number = atoi(row[2]);
entry.x = atof(row[3]);
entry.y = atof(row[4]);
entry.z = atof(row[5]);
entry.heading = atof(row[6]);
entry.pause = atoi(row[7]);
entry.centerpoint = atoi(row[8]);
e.gridid = atoi(row[0]);
e.zoneid = atoi(row[1]);
e.number = atoi(row[2]);
e.x = static_cast<float>(atof(row[3]));
e.y = static_cast<float>(atof(row[4]));
e.z = static_cast<float>(atof(row[5]));
e.heading = static_cast<float>(atof(row[6]));
e.pause = atoi(row[7]);
e.centerpoint = atoi(row[8]);
return entry;
return e;
}
return NewEntity();
}
static int DeleteOne(
Database& db,
int grid_entries_id
)
{
auto results = content_db.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
@@ -189,27 +180,31 @@ public:
}
static int UpdateOne(
GridEntries grid_entries_entry
Database& db,
const GridEntries &e
)
{
std::vector<std::string> update_values;
std::vector<std::string> v;
auto columns = Columns();
update_values.push_back(columns[3] + " = " + std::to_string(grid_entries_entry.x));
update_values.push_back(columns[4] + " = " + std::to_string(grid_entries_entry.y));
update_values.push_back(columns[5] + " = " + std::to_string(grid_entries_entry.z));
update_values.push_back(columns[6] + " = " + std::to_string(grid_entries_entry.heading));
update_values.push_back(columns[7] + " = " + std::to_string(grid_entries_entry.pause));
update_values.push_back(columns[8] + " = " + std::to_string(grid_entries_entry.centerpoint));
v.push_back(columns[0] + " = " + std::to_string(e.gridid));
v.push_back(columns[1] + " = " + std::to_string(e.zoneid));
v.push_back(columns[2] + " = " + std::to_string(e.number));
v.push_back(columns[3] + " = " + std::to_string(e.x));
v.push_back(columns[4] + " = " + std::to_string(e.y));
v.push_back(columns[5] + " = " + std::to_string(e.z));
v.push_back(columns[6] + " = " + std::to_string(e.heading));
v.push_back(columns[7] + " = " + std::to_string(e.pause));
v.push_back(columns[8] + " = " + std::to_string(e.centerpoint));
auto results = content_db.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
Strings::Implode(", ", update_values),
Strings::Implode(", ", v),
PrimaryKey(),
grid_entries_entry.number
e.gridid
)
);
@@ -217,58 +212,66 @@ public:
}
static GridEntries InsertOne(
GridEntries grid_entries_entry
Database& db,
GridEntries e
)
{
std::vector<std::string> insert_values;
std::vector<std::string> v;
insert_values.push_back(std::to_string(grid_entries_entry.x));
insert_values.push_back(std::to_string(grid_entries_entry.y));
insert_values.push_back(std::to_string(grid_entries_entry.z));
insert_values.push_back(std::to_string(grid_entries_entry.heading));
insert_values.push_back(std::to_string(grid_entries_entry.pause));
insert_values.push_back(std::to_string(grid_entries_entry.centerpoint));
v.push_back(std::to_string(e.gridid));
v.push_back(std::to_string(e.zoneid));
v.push_back(std::to_string(e.number));
v.push_back(std::to_string(e.x));
v.push_back(std::to_string(e.y));
v.push_back(std::to_string(e.z));
v.push_back(std::to_string(e.heading));
v.push_back(std::to_string(e.pause));
v.push_back(std::to_string(e.centerpoint));
auto results = content_db.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
Strings::Implode(",", insert_values)
Strings::Implode(",", v)
)
);
if (results.Success()) {
grid_entries_entry.id = results.LastInsertedID();
return grid_entries_entry;
e.gridid = results.LastInsertedID();
return e;
}
grid_entries_entry = NewEntity();
e = NewEntity();
return grid_entries_entry;
return e;
}
static int InsertMany(
std::vector<GridEntries> grid_entries_entries
Database& db,
const std::vector<GridEntries> &entries
)
{
std::vector<std::string> insert_chunks;
for (auto &grid_entries_entry: grid_entries_entries) {
std::vector<std::string> insert_values;
for (auto &e: entries) {
std::vector<std::string> v;
insert_values.push_back(std::to_string(grid_entries_entry.x));
insert_values.push_back(std::to_string(grid_entries_entry.y));
insert_values.push_back(std::to_string(grid_entries_entry.z));
insert_values.push_back(std::to_string(grid_entries_entry.heading));
insert_values.push_back(std::to_string(grid_entries_entry.pause));
insert_values.push_back(std::to_string(grid_entries_entry.centerpoint));
v.push_back(std::to_string(e.gridid));
v.push_back(std::to_string(e.zoneid));
v.push_back(std::to_string(e.number));
v.push_back(std::to_string(e.x));
v.push_back(std::to_string(e.y));
v.push_back(std::to_string(e.z));
v.push_back(std::to_string(e.heading));
v.push_back(std::to_string(e.pause));
v.push_back(std::to_string(e.centerpoint));
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 = content_db.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
@@ -279,11 +282,11 @@ public:
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<GridEntries> All()
static std::vector<GridEntries> All(Database& db)
{
std::vector<GridEntries> all_entries;
auto results = content_db.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
@@ -293,29 +296,29 @@ public:
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
GridEntries entry{};
GridEntries e{};
entry.gridid = atoi(row[0]);
entry.zoneid = atoi(row[1]);
entry.number = atoi(row[2]);
entry.x = atof(row[3]);
entry.y = atof(row[4]);
entry.z = atof(row[5]);
entry.heading = atof(row[6]);
entry.pause = atoi(row[7]);
entry.centerpoint = atoi(row[8]);
e.gridid = atoi(row[0]);
e.zoneid = atoi(row[1]);
e.number = atoi(row[2]);
e.x = static_cast<float>(atof(row[3]));
e.y = static_cast<float>(atof(row[4]));
e.z = static_cast<float>(atof(row[5]));
e.heading = static_cast<float>(atof(row[6]));
e.pause = atoi(row[7]);
e.centerpoint = atoi(row[8]);
all_entries.push_back(entry);
all_entries.push_back(e);
}
return all_entries;
}
static std::vector<GridEntries> GetWhere(std::string where_filter)
static std::vector<GridEntries> GetWhere(Database& db, const std::string &where_filter)
{
std::vector<GridEntries> all_entries;
auto results = content_db.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"{} WHERE {}",
BaseSelect(),
@@ -326,31 +329,30 @@ public:
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
GridEntries entry{};
GridEntries e{};
entry.gridid = atoi(row[0]);
entry.zoneid = atoi(row[1]);
entry.number = atoi(row[2]);
entry.x = atof(row[3]);
entry.y = atof(row[4]);
entry.z = atof(row[5]);
entry.heading = atof(row[6]);
entry.pause = atoi(row[7]);
entry.centerpoint = atoi(row[8]);
e.gridid = atoi(row[0]);
e.zoneid = atoi(row[1]);
e.number = atoi(row[2]);
e.x = static_cast<float>(atof(row[3]));
e.y = static_cast<float>(atof(row[4]));
e.z = static_cast<float>(atof(row[5]));
e.heading = static_cast<float>(atof(row[6]));
e.pause = atoi(row[7]);
e.centerpoint = atoi(row[8]);
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 = content_db.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {}",
TableName(),
PrimaryKey(),
where_filter
)
);
@@ -358,6 +360,44 @@ 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);
}
};
#endif //EQEMU_BASE_GRID_ENTRIES_REPOSITORY_H