More adjustments [skip ci[

This commit is contained in:
Akkadius
2020-04-05 23:11:25 -05:00
parent 725ad9ddf5
commit be57c57029
8 changed files with 1216 additions and 183 deletions
@@ -0,0 +1,363 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* 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 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
*/
#ifndef EQEMU_BASE_GRID_ENTRIES_REPOSITORY_H
#define EQEMU_BASE_GRID_ENTRIES_REPOSITORY_H
#include "../../database.h"
#include "../../string_util.h"
class BaseGridEntriesRepository {
public:
struct GridEntries {
int gridid;
int zoneid;
int number;
float x;
float y;
float z;
float heading;
int pause;
int8 centerpoint;
};
static std::string PrimaryKey()
{
return std::string("number");
}
static std::vector<std::string> Columns()
{
return {
"gridid",
"zoneid",
"number",
"x",
"y",
"z",
"heading",
"pause",
"centerpoint",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
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));
}
static std::string TableName()
{
return std::string("grid_entries");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static GridEntries NewEntity()
{
GridEntries entry{};
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;
return entry;
}
static GridEntries GetGridEntriesEntry(
const std::vector<GridEntries> &grid_entriess,
int grid_entries_id
)
{
for (auto &grid_entries : grid_entriess) {
if (grid_entries.number == grid_entries_id) {
return grid_entries;
}
}
return NewEntity();
}
static GridEntries FindOne(
int grid_entries_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
grid_entries_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
GridEntries entry{};
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]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int grid_entries_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
grid_entries_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
GridEntries grid_entries_entry
)
{
std::vector<std::string> update_values;
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));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
grid_entries_entry.number
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static GridEntries InsertOne(
GridEntries grid_entries_entry
)
{
std::vector<std::string> insert_values;
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));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
grid_entries_entry.id = results.LastInsertedID();
return grid_entries_entry;
}
grid_entries_entry = NewEntity();
return grid_entries_entry;
}
static int InsertMany(
std::vector<GridEntries> grid_entries_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &grid_entries_entry: grid_entries_entries) {
std::vector<std::string> insert_values;
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));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<GridEntries> All()
{
std::vector<GridEntries> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
GridEntries entry{};
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]);
all_entries.push_back(entry);
}
return all_entries;
}
static std::vector<GridEntries> GetWhere(std::string where_filter)
{
std::vector<GridEntries> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE {}",
BaseSelect(),
where_filter
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
GridEntries entry{};
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]);
all_entries.push_back(entry);
}
return all_entries;
}
static int DeleteWhere(std::string where_filter)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {}",
TableName(),
PrimaryKey(),
where_filter
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
};
#endif //EQEMU_BASE_GRID_ENTRIES_REPOSITORY_H
@@ -0,0 +1,321 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* 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 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
*/
#ifndef EQEMU_BASE_GRID_REPOSITORY_H
#define EQEMU_BASE_GRID_REPOSITORY_H
#include "../../database.h"
#include "../../string_util.h"
class BaseGridRepository {
public:
struct Grid {
int id;
int zoneid;
int type;
int type2;
};
static std::string PrimaryKey()
{
return std::string("zoneid");
}
static std::vector<std::string> Columns()
{
return {
"id",
"zoneid",
"type",
"type2",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
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));
}
static std::string TableName()
{
return std::string("grid");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Grid NewEntity()
{
Grid entry{};
entry.id = 0;
entry.zoneid = 0;
entry.type = 0;
entry.type2 = 0;
return entry;
}
static Grid GetGridEntry(
const std::vector<Grid> &grids,
int grid_id
)
{
for (auto &grid : grids) {
if (grid.zoneid == grid_id) {
return grid;
}
}
return NewEntity();
}
static Grid FindOne(
int grid_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
grid_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Grid entry{};
entry.id = atoi(row[0]);
entry.zoneid = atoi(row[1]);
entry.type = atoi(row[2]);
entry.type2 = atoi(row[3]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int grid_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
grid_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Grid grid_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(grid_entry.type));
update_values.push_back(columns[3] + " = " + std::to_string(grid_entry.type2));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
grid_entry.zoneid
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Grid InsertOne(
Grid grid_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(grid_entry.type));
insert_values.push_back(std::to_string(grid_entry.type2));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
grid_entry.id = results.LastInsertedID();
return grid_entry;
}
grid_entry = NewEntity();
return grid_entry;
}
static int InsertMany(
std::vector<Grid> grid_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &grid_entry: grid_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(grid_entry.type));
insert_values.push_back(std::to_string(grid_entry.type2));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Grid> All()
{
std::vector<Grid> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Grid entry{};
entry.id = atoi(row[0]);
entry.zoneid = atoi(row[1]);
entry.type = atoi(row[2]);
entry.type2 = atoi(row[3]);
all_entries.push_back(entry);
}
return all_entries;
}
static std::vector<Grid> GetWhere(std::string where_filter)
{
std::vector<Grid> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE {}",
BaseSelect(),
where_filter
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Grid entry{};
entry.id = atoi(row[0]);
entry.zoneid = atoi(row[1]);
entry.type = atoi(row[2]);
entry.type2 = atoi(row[3]);
all_entries.push_back(entry);
}
return all_entries;
}
static int DeleteWhere(std::string where_filter)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {}",
TableName(),
PrimaryKey(),
where_filter
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
};
#endif //EQEMU_BASE_GRID_REPOSITORY_H
@@ -0,0 +1,414 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* 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 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
*/
#ifndef EQEMU_BASE_TRADESKILL_RECIPE_REPOSITORY_H
#define EQEMU_BASE_TRADESKILL_RECIPE_REPOSITORY_H
#include "../../database.h"
#include "../../string_util.h"
class BaseTradeskillRecipeRepository {
public:
struct TradeskillRecipe {
int id;
std::string name;
int16 tradeskill;
int16 skillneeded;
int16 trivial;
int8 nofail;
int8 replace_container;
std::string notes;
int8 must_learn;
int8 quest;
int8 enabled;
int8 min_expansion;
int8 max_expansion;
std::string content_flags;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"name",
"tradeskill",
"skillneeded",
"trivial",
"nofail",
"replace_container",
"notes",
"must_learn",
"quest",
"enabled",
"min_expansion",
"max_expansion",
"content_flags",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
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));
}
static std::string TableName()
{
return std::string("tradeskill_recipe");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static TradeskillRecipe NewEntity()
{
TradeskillRecipe entry{};
entry.id = 0;
entry.name = "";
entry.tradeskill = 0;
entry.skillneeded = 0;
entry.trivial = 0;
entry.nofail = 0;
entry.replace_container = 0;
entry.notes = "";
entry.must_learn = 0;
entry.quest = 0;
entry.enabled = 1;
entry.min_expansion = 0;
entry.max_expansion = 0;
entry.content_flags = "";
return entry;
}
static TradeskillRecipe GetTradeskillRecipeEntry(
const std::vector<TradeskillRecipe> &tradeskill_recipes,
int tradeskill_recipe_id
)
{
for (auto &tradeskill_recipe : tradeskill_recipes) {
if (tradeskill_recipe.id == tradeskill_recipe_id) {
return tradeskill_recipe;
}
}
return NewEntity();
}
static TradeskillRecipe FindOne(
int tradeskill_recipe_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
tradeskill_recipe_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
TradeskillRecipe entry{};
entry.id = atoi(row[0]);
entry.name = row[1] ? row[1] : "";
entry.tradeskill = atoi(row[2]);
entry.skillneeded = atoi(row[3]);
entry.trivial = atoi(row[4]);
entry.nofail = atoi(row[5]);
entry.replace_container = atoi(row[6]);
entry.notes = row[7] ? row[7] : "";
entry.must_learn = atoi(row[8]);
entry.quest = atoi(row[9]);
entry.enabled = atoi(row[10]);
entry.min_expansion = atoi(row[11]);
entry.max_expansion = atoi(row[12]);
entry.content_flags = row[13] ? row[13] : "";
return entry;
}
return NewEntity();
}
static int DeleteOne(
int tradeskill_recipe_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
tradeskill_recipe_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
TradeskillRecipe tradeskill_recipe_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(tradeskill_recipe_entry.name) + "'");
update_values.push_back(columns[2] + " = " + std::to_string(tradeskill_recipe_entry.tradeskill));
update_values.push_back(columns[3] + " = " + std::to_string(tradeskill_recipe_entry.skillneeded));
update_values.push_back(columns[4] + " = " + std::to_string(tradeskill_recipe_entry.trivial));
update_values.push_back(columns[5] + " = " + std::to_string(tradeskill_recipe_entry.nofail));
update_values.push_back(columns[6] + " = " + std::to_string(tradeskill_recipe_entry.replace_container));
update_values.push_back(columns[7] + " = '" + EscapeString(tradeskill_recipe_entry.notes) + "'");
update_values.push_back(columns[8] + " = " + std::to_string(tradeskill_recipe_entry.must_learn));
update_values.push_back(columns[9] + " = " + std::to_string(tradeskill_recipe_entry.quest));
update_values.push_back(columns[10] + " = " + std::to_string(tradeskill_recipe_entry.enabled));
update_values.push_back(columns[11] + " = " + std::to_string(tradeskill_recipe_entry.min_expansion));
update_values.push_back(columns[12] + " = " + std::to_string(tradeskill_recipe_entry.max_expansion));
update_values.push_back(columns[13] + " = '" + EscapeString(tradeskill_recipe_entry.content_flags) + "'");
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
tradeskill_recipe_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static TradeskillRecipe InsertOne(
TradeskillRecipe tradeskill_recipe_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(tradeskill_recipe_entry.name) + "'");
insert_values.push_back(std::to_string(tradeskill_recipe_entry.tradeskill));
insert_values.push_back(std::to_string(tradeskill_recipe_entry.skillneeded));
insert_values.push_back(std::to_string(tradeskill_recipe_entry.trivial));
insert_values.push_back(std::to_string(tradeskill_recipe_entry.nofail));
insert_values.push_back(std::to_string(tradeskill_recipe_entry.replace_container));
insert_values.push_back("'" + EscapeString(tradeskill_recipe_entry.notes) + "'");
insert_values.push_back(std::to_string(tradeskill_recipe_entry.must_learn));
insert_values.push_back(std::to_string(tradeskill_recipe_entry.quest));
insert_values.push_back(std::to_string(tradeskill_recipe_entry.enabled));
insert_values.push_back(std::to_string(tradeskill_recipe_entry.min_expansion));
insert_values.push_back(std::to_string(tradeskill_recipe_entry.max_expansion));
insert_values.push_back("'" + EscapeString(tradeskill_recipe_entry.content_flags) + "'");
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
tradeskill_recipe_entry.id = results.LastInsertedID();
return tradeskill_recipe_entry;
}
tradeskill_recipe_entry = NewEntity();
return tradeskill_recipe_entry;
}
static int InsertMany(
std::vector<TradeskillRecipe> tradeskill_recipe_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &tradeskill_recipe_entry: tradeskill_recipe_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(tradeskill_recipe_entry.name) + "'");
insert_values.push_back(std::to_string(tradeskill_recipe_entry.tradeskill));
insert_values.push_back(std::to_string(tradeskill_recipe_entry.skillneeded));
insert_values.push_back(std::to_string(tradeskill_recipe_entry.trivial));
insert_values.push_back(std::to_string(tradeskill_recipe_entry.nofail));
insert_values.push_back(std::to_string(tradeskill_recipe_entry.replace_container));
insert_values.push_back("'" + EscapeString(tradeskill_recipe_entry.notes) + "'");
insert_values.push_back(std::to_string(tradeskill_recipe_entry.must_learn));
insert_values.push_back(std::to_string(tradeskill_recipe_entry.quest));
insert_values.push_back(std::to_string(tradeskill_recipe_entry.enabled));
insert_values.push_back(std::to_string(tradeskill_recipe_entry.min_expansion));
insert_values.push_back(std::to_string(tradeskill_recipe_entry.max_expansion));
insert_values.push_back("'" + EscapeString(tradeskill_recipe_entry.content_flags) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<TradeskillRecipe> All()
{
std::vector<TradeskillRecipe> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
TradeskillRecipe entry{};
entry.id = atoi(row[0]);
entry.name = row[1] ? row[1] : "";
entry.tradeskill = atoi(row[2]);
entry.skillneeded = atoi(row[3]);
entry.trivial = atoi(row[4]);
entry.nofail = atoi(row[5]);
entry.replace_container = atoi(row[6]);
entry.notes = row[7] ? row[7] : "";
entry.must_learn = atoi(row[8]);
entry.quest = atoi(row[9]);
entry.enabled = atoi(row[10]);
entry.min_expansion = atoi(row[11]);
entry.max_expansion = atoi(row[12]);
entry.content_flags = row[13] ? row[13] : "";
all_entries.push_back(entry);
}
return all_entries;
}
static std::vector<TradeskillRecipe> GetWhere(std::string where_filter)
{
std::vector<TradeskillRecipe> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE {}",
BaseSelect(),
where_filter
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
TradeskillRecipe entry{};
entry.id = atoi(row[0]);
entry.name = row[1] ? row[1] : "";
entry.tradeskill = atoi(row[2]);
entry.skillneeded = atoi(row[3]);
entry.trivial = atoi(row[4]);
entry.nofail = atoi(row[5]);
entry.replace_container = atoi(row[6]);
entry.notes = row[7] ? row[7] : "";
entry.must_learn = atoi(row[8]);
entry.quest = atoi(row[9]);
entry.enabled = atoi(row[10]);
entry.min_expansion = atoi(row[11]);
entry.max_expansion = atoi(row[12]);
entry.content_flags = row[13] ? row[13] : "";
all_entries.push_back(entry);
}
return all_entries;
}
static int DeleteWhere(std::string where_filter)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {}",
TableName(),
PrimaryKey(),
where_filter
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
};
#endif //EQEMU_BASE_TRADESKILL_RECIPE_REPOSITORY_H
+36 -49
View File
@@ -23,58 +23,45 @@
#include "../database.h"
#include "../string_util.h"
#include "base/base_grid_repository.h"
class GridRepository {
class GridRepository : public BaseGridRepository {
public:
struct Grid {
int id;
int zoneid;
int type;
int type2;
};
static std::vector<std::string> Columns()
{
return {
"id",
"zoneid",
"type",
"type2",
};
}
/**
* This file was auto generated on Apr 5, 2020 and can be modified and extended upon
*
* Base repository methods are automatically
* generated in the "base" version of this repository. The base repository
* is immutable and to be left untouched, while methods in this class
* are used as extension methods for more specific persistence-layer
* accessors or mutators
*
* Base Methods (Subject to be expanded upon in time)
*
* InsertOne
* UpdateOne
* DeleteOne
* FindOne
* GetWhere(std::string where_filter)
* DeleteWhere(std::string where_filter)
* InsertMany
* All
*
* Example custom methods in a repository
*
* GridRepository::GetByZoneAndVersion(int zone_id, int zone_version)
* GridRepository::GetWhereNeverExpires()
* GridRepository::GetWhereXAndY()
* GridRepository::DeleteWhereXAndY()
*
* Most of the above could be covered by base methods, but if you as a developer
* find yourself re-using logic for other parts of the code, its best to just make a
* method that can be re-used easily elsewhere especially if it can use a base repository
* method and encapsulate filters there
*/
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string TableName()
{
return std::string("grid");
}
static std::string BaseSelect()
{
return std::string(
fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
)
);
}
static Grid NewEntity()
{
Grid entry{};
entry.id = 0;
entry.zoneid = 0;
entry.type = 0;
entry.type2 = 0;
return entry;
}
// Custom extended repository methods here
static std::vector<Grid> GetZoneGrids(int zone_id)
{
@@ -118,4 +105,4 @@ public:
};
#endif
#endif //EQEMU_GRID_REPOSITORY_H
@@ -23,112 +23,48 @@
#include "../database.h"
#include "../string_util.h"
#include "base/base_tradeskill_recipe_repository.h"
class TradeskillRecipeRepository {
class TradeskillRecipeRepository: public BaseTradeskillRecipeRepository {
public:
struct TradeskillRecipe {
int id;
std::string name;
int tradeskill;
int skillneeded;
int trivial;
uint8 nofail;
int replace_container;
std::string notes;
uint8 must_learn;
uint8 quest;
uint8 enabled;
};
static std::vector<std::string> Columns()
{
return {
"id",
"name",
"tradeskill",
"skillneeded",
"trivial",
"nofail",
"replace_container",
"notes",
"must_learn",
"quest",
"enabled",
};
}
/**
* This file was auto generated on Apr 5, 2020 and can be modified and extended upon
*
* Base repository methods are automatically
* generated in the "base" version of this repository. The base repository
* is immutable and to be left untouched, while methods in this class
* are used as extension methods for more specific persistence-layer
* accessors or mutators
*
* Base Methods (Subject to be expanded upon in time)
*
* InsertOne
* UpdateOne
* DeleteOne
* FindOne
* GetWhere(std::string where_filter)
* DeleteWhere(std::string where_filter)
* InsertMany
* All
*
* Example custom methods in a repository
*
* TradeskillRecipeRepository::GetByZoneAndVersion(int zone_id, int zone_version)
* TradeskillRecipeRepository::GetWhereNeverExpires()
* TradeskillRecipeRepository::GetWhereXAndY()
* TradeskillRecipeRepository::DeleteWhereXAndY()
*
* Most of the above could be covered by base methods, but if you as a developer
* find yourself re-using logic for other parts of the code, its best to just make a
* method that can be re-used easily elsewhere especially if it can use a base repository
* method and encapsulate filters there
*/
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
// Custom extended repository methods here
static std::string TableName()
{
return std::string("tradeskill_recipe");
}
static std::string BaseSelect()
{
return std::string(
fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
)
);
}
static TradeskillRecipe NewEntity()
{
TradeskillRecipe entry;
entry.id = 0;
entry.name = "";
entry.tradeskill = 0;
entry.skillneeded = 0;
entry.trivial = 0;
entry.nofail = 0;
entry.replace_container = 0;
entry.notes = "";
entry.must_learn = 0;
entry.quest = 0;
entry.enabled = 0;
return entry;
}
static TradeskillRecipe GetRecipe(int recipe_id)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {}",
BaseSelect(),
recipe_id
)
);
TradeskillRecipe tradeskill_recipe = NewEntity();
auto row = results.begin();
if (results.RowCount() == 0) {
return tradeskill_recipe;
}
tradeskill_recipe.id = atoi(row[0]);
tradeskill_recipe.name = (row[1] ? row[1] : "");
tradeskill_recipe.tradeskill = atoi(row[2]);
tradeskill_recipe.skillneeded = atoi(row[3]);
tradeskill_recipe.trivial = atoi(row[4]);
tradeskill_recipe.nofail = atoi(row[5]);
tradeskill_recipe.replace_container = atoi(row[6]);
tradeskill_recipe.notes = (row[7] ? row[7] : "");
tradeskill_recipe.must_learn = atoi(row[8]);
tradeskill_recipe.quest = atoi(row[9]);
tradeskill_recipe.enabled = atoi(row[10]);
return tradeskill_recipe;
}
};
#endif
#endif //EQEMU_TRADESKILL_RECIPE_REPOSITORY_H