/** * 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 * * @generator ./utils/scripts/generators/repository-generator.pl * @docs https://eqemu.gitbook.io/server/in-development/developer-area/repositories */ #ifndef EQEMU_BASE_ZONE_POINTS_REPOSITORY_H #define EQEMU_BASE_ZONE_POINTS_REPOSITORY_H #include "../../database.h" #include "../../strings.h" #include class BaseZonePointsRepository { public: struct ZonePoints { int id; std::string zone; int version; int number; float y; float x; float z; float heading; float target_y; float target_x; float target_z; float target_heading; int zoneinst; int target_zone_id; int target_instance; float buffer; int client_version_mask; int min_expansion; int max_expansion; std::string content_flags; std::string content_flags_disabled; int is_virtual; int height; int width; }; static std::string PrimaryKey() { return std::string("id"); } static std::vector Columns() { return { "id", "zone", "version", "number", "y", "x", "z", "heading", "target_y", "target_x", "target_z", "target_heading", "zoneinst", "target_zone_id", "target_instance", "buffer", "client_version_mask", "min_expansion", "max_expansion", "content_flags", "content_flags_disabled", "is_virtual", "height", "width", }; } static std::vector SelectColumns() { return { "id", "zone", "version", "number", "y", "x", "z", "heading", "target_y", "target_x", "target_z", "target_heading", "zoneinst", "target_zone_id", "target_instance", "buffer", "client_version_mask", "min_expansion", "max_expansion", "content_flags", "content_flags_disabled", "is_virtual", "height", "width", }; } static std::string ColumnsRaw() { return std::string(Strings::Implode(", ", Columns())); } static std::string SelectColumnsRaw() { return std::string(Strings::Implode(", ", SelectColumns())); } static std::string TableName() { return std::string("zone_points"); } static std::string BaseSelect() { return fmt::format( "SELECT {} FROM {}", SelectColumnsRaw(), TableName() ); } static std::string BaseInsert() { return fmt::format( "INSERT INTO {} ({}) ", TableName(), ColumnsRaw() ); } static ZonePoints NewEntity() { ZonePoints entry{}; entry.id = 0; entry.zone = ""; entry.version = 0; entry.number = 1; entry.y = 0; entry.x = 0; entry.z = 0; entry.heading = 0; entry.target_y = 0; entry.target_x = 0; entry.target_z = 0; entry.target_heading = 0; entry.zoneinst = 0; entry.target_zone_id = 0; entry.target_instance = 0; entry.buffer = 0; entry.client_version_mask = 4294967295; entry.min_expansion = -1; entry.max_expansion = -1; entry.content_flags = ""; entry.content_flags_disabled = ""; entry.is_virtual = 0; entry.height = 0; entry.width = 0; return entry; } static ZonePoints GetZonePointsEntry( const std::vector &zone_pointss, int zone_points_id ) { for (auto &zone_points : zone_pointss) { if (zone_points.id == zone_points_id) { return zone_points; } } return NewEntity(); } static ZonePoints FindOne( Database& db, int zone_points_id ) { auto results = db.QueryDatabase( fmt::format( "{} WHERE id = {} LIMIT 1", BaseSelect(), zone_points_id ) ); auto row = results.begin(); if (results.RowCount() == 1) { ZonePoints entry{}; entry.id = atoi(row[0]); entry.zone = row[1] ? row[1] : ""; entry.version = atoi(row[2]); entry.number = atoi(row[3]); entry.y = static_cast(atof(row[4])); entry.x = static_cast(atof(row[5])); entry.z = static_cast(atof(row[6])); entry.heading = static_cast(atof(row[7])); entry.target_y = static_cast(atof(row[8])); entry.target_x = static_cast(atof(row[9])); entry.target_z = static_cast(atof(row[10])); entry.target_heading = static_cast(atof(row[11])); entry.zoneinst = atoi(row[12]); entry.target_zone_id = atoi(row[13]); entry.target_instance = atoi(row[14]); entry.buffer = static_cast(atof(row[15])); entry.client_version_mask = atoi(row[16]); entry.min_expansion = atoi(row[17]); entry.max_expansion = atoi(row[18]); entry.content_flags = row[19] ? row[19] : ""; entry.content_flags_disabled = row[20] ? row[20] : ""; entry.is_virtual = atoi(row[21]); entry.height = atoi(row[22]); entry.width = atoi(row[23]); return entry; } return NewEntity(); } static int DeleteOne( Database& db, int zone_points_id ) { auto results = db.QueryDatabase( fmt::format( "DELETE FROM {} WHERE {} = {}", TableName(), PrimaryKey(), zone_points_id ) ); return (results.Success() ? results.RowsAffected() : 0); } static int UpdateOne( Database& db, ZonePoints zone_points_entry ) { std::vector update_values; auto columns = Columns(); update_values.push_back(columns[1] + " = '" + Strings::Escape(zone_points_entry.zone) + "'"); update_values.push_back(columns[2] + " = " + std::to_string(zone_points_entry.version)); update_values.push_back(columns[3] + " = " + std::to_string(zone_points_entry.number)); update_values.push_back(columns[4] + " = " + std::to_string(zone_points_entry.y)); update_values.push_back(columns[5] + " = " + std::to_string(zone_points_entry.x)); update_values.push_back(columns[6] + " = " + std::to_string(zone_points_entry.z)); update_values.push_back(columns[7] + " = " + std::to_string(zone_points_entry.heading)); update_values.push_back(columns[8] + " = " + std::to_string(zone_points_entry.target_y)); update_values.push_back(columns[9] + " = " + std::to_string(zone_points_entry.target_x)); update_values.push_back(columns[10] + " = " + std::to_string(zone_points_entry.target_z)); update_values.push_back(columns[11] + " = " + std::to_string(zone_points_entry.target_heading)); update_values.push_back(columns[12] + " = " + std::to_string(zone_points_entry.zoneinst)); update_values.push_back(columns[13] + " = " + std::to_string(zone_points_entry.target_zone_id)); update_values.push_back(columns[14] + " = " + std::to_string(zone_points_entry.target_instance)); update_values.push_back(columns[15] + " = " + std::to_string(zone_points_entry.buffer)); update_values.push_back(columns[16] + " = " + std::to_string(zone_points_entry.client_version_mask)); update_values.push_back(columns[17] + " = " + std::to_string(zone_points_entry.min_expansion)); update_values.push_back(columns[18] + " = " + std::to_string(zone_points_entry.max_expansion)); update_values.push_back(columns[19] + " = '" + Strings::Escape(zone_points_entry.content_flags) + "'"); update_values.push_back(columns[20] + " = '" + Strings::Escape(zone_points_entry.content_flags_disabled) + "'"); update_values.push_back(columns[21] + " = " + std::to_string(zone_points_entry.is_virtual)); update_values.push_back(columns[22] + " = " + std::to_string(zone_points_entry.height)); update_values.push_back(columns[23] + " = " + std::to_string(zone_points_entry.width)); auto results = db.QueryDatabase( fmt::format( "UPDATE {} SET {} WHERE {} = {}", TableName(), Strings::Implode(", ", update_values), PrimaryKey(), zone_points_entry.id ) ); return (results.Success() ? results.RowsAffected() : 0); } static ZonePoints InsertOne( Database& db, ZonePoints zone_points_entry ) { std::vector insert_values; insert_values.push_back(std::to_string(zone_points_entry.id)); insert_values.push_back("'" + Strings::Escape(zone_points_entry.zone) + "'"); insert_values.push_back(std::to_string(zone_points_entry.version)); insert_values.push_back(std::to_string(zone_points_entry.number)); insert_values.push_back(std::to_string(zone_points_entry.y)); insert_values.push_back(std::to_string(zone_points_entry.x)); insert_values.push_back(std::to_string(zone_points_entry.z)); insert_values.push_back(std::to_string(zone_points_entry.heading)); insert_values.push_back(std::to_string(zone_points_entry.target_y)); insert_values.push_back(std::to_string(zone_points_entry.target_x)); insert_values.push_back(std::to_string(zone_points_entry.target_z)); insert_values.push_back(std::to_string(zone_points_entry.target_heading)); insert_values.push_back(std::to_string(zone_points_entry.zoneinst)); insert_values.push_back(std::to_string(zone_points_entry.target_zone_id)); insert_values.push_back(std::to_string(zone_points_entry.target_instance)); insert_values.push_back(std::to_string(zone_points_entry.buffer)); insert_values.push_back(std::to_string(zone_points_entry.client_version_mask)); insert_values.push_back(std::to_string(zone_points_entry.min_expansion)); insert_values.push_back(std::to_string(zone_points_entry.max_expansion)); insert_values.push_back("'" + Strings::Escape(zone_points_entry.content_flags) + "'"); insert_values.push_back("'" + Strings::Escape(zone_points_entry.content_flags_disabled) + "'"); insert_values.push_back(std::to_string(zone_points_entry.is_virtual)); insert_values.push_back(std::to_string(zone_points_entry.height)); insert_values.push_back(std::to_string(zone_points_entry.width)); auto results = db.QueryDatabase( fmt::format( "{} VALUES ({})", BaseInsert(), Strings::Implode(",", insert_values) ) ); if (results.Success()) { zone_points_entry.id = results.LastInsertedID(); return zone_points_entry; } zone_points_entry = NewEntity(); return zone_points_entry; } static int InsertMany( Database& db, std::vector zone_points_entries ) { std::vector insert_chunks; for (auto &zone_points_entry: zone_points_entries) { std::vector insert_values; insert_values.push_back(std::to_string(zone_points_entry.id)); insert_values.push_back("'" + Strings::Escape(zone_points_entry.zone) + "'"); insert_values.push_back(std::to_string(zone_points_entry.version)); insert_values.push_back(std::to_string(zone_points_entry.number)); insert_values.push_back(std::to_string(zone_points_entry.y)); insert_values.push_back(std::to_string(zone_points_entry.x)); insert_values.push_back(std::to_string(zone_points_entry.z)); insert_values.push_back(std::to_string(zone_points_entry.heading)); insert_values.push_back(std::to_string(zone_points_entry.target_y)); insert_values.push_back(std::to_string(zone_points_entry.target_x)); insert_values.push_back(std::to_string(zone_points_entry.target_z)); insert_values.push_back(std::to_string(zone_points_entry.target_heading)); insert_values.push_back(std::to_string(zone_points_entry.zoneinst)); insert_values.push_back(std::to_string(zone_points_entry.target_zone_id)); insert_values.push_back(std::to_string(zone_points_entry.target_instance)); insert_values.push_back(std::to_string(zone_points_entry.buffer)); insert_values.push_back(std::to_string(zone_points_entry.client_version_mask)); insert_values.push_back(std::to_string(zone_points_entry.min_expansion)); insert_values.push_back(std::to_string(zone_points_entry.max_expansion)); insert_values.push_back("'" + Strings::Escape(zone_points_entry.content_flags) + "'"); insert_values.push_back("'" + Strings::Escape(zone_points_entry.content_flags_disabled) + "'"); insert_values.push_back(std::to_string(zone_points_entry.is_virtual)); insert_values.push_back(std::to_string(zone_points_entry.height)); insert_values.push_back(std::to_string(zone_points_entry.width)); insert_chunks.push_back("(" + Strings::Implode(",", insert_values) + ")"); } std::vector insert_values; auto results = db.QueryDatabase( fmt::format( "{} VALUES {}", BaseInsert(), Strings::Implode(",", insert_chunks) ) ); return (results.Success() ? results.RowsAffected() : 0); } static std::vector All(Database& db) { std::vector all_entries; auto results = db.QueryDatabase( fmt::format( "{}", BaseSelect() ) ); all_entries.reserve(results.RowCount()); for (auto row = results.begin(); row != results.end(); ++row) { ZonePoints entry{}; entry.id = atoi(row[0]); entry.zone = row[1] ? row[1] : ""; entry.version = atoi(row[2]); entry.number = atoi(row[3]); entry.y = static_cast(atof(row[4])); entry.x = static_cast(atof(row[5])); entry.z = static_cast(atof(row[6])); entry.heading = static_cast(atof(row[7])); entry.target_y = static_cast(atof(row[8])); entry.target_x = static_cast(atof(row[9])); entry.target_z = static_cast(atof(row[10])); entry.target_heading = static_cast(atof(row[11])); entry.zoneinst = atoi(row[12]); entry.target_zone_id = atoi(row[13]); entry.target_instance = atoi(row[14]); entry.buffer = static_cast(atof(row[15])); entry.client_version_mask = atoi(row[16]); entry.min_expansion = atoi(row[17]); entry.max_expansion = atoi(row[18]); entry.content_flags = row[19] ? row[19] : ""; entry.content_flags_disabled = row[20] ? row[20] : ""; entry.is_virtual = atoi(row[21]); entry.height = atoi(row[22]); entry.width = atoi(row[23]); all_entries.push_back(entry); } return all_entries; } static std::vector GetWhere(Database& db, std::string where_filter) { std::vector all_entries; auto results = db.QueryDatabase( fmt::format( "{} WHERE {}", BaseSelect(), where_filter ) ); all_entries.reserve(results.RowCount()); for (auto row = results.begin(); row != results.end(); ++row) { ZonePoints entry{}; entry.id = atoi(row[0]); entry.zone = row[1] ? row[1] : ""; entry.version = atoi(row[2]); entry.number = atoi(row[3]); entry.y = static_cast(atof(row[4])); entry.x = static_cast(atof(row[5])); entry.z = static_cast(atof(row[6])); entry.heading = static_cast(atof(row[7])); entry.target_y = static_cast(atof(row[8])); entry.target_x = static_cast(atof(row[9])); entry.target_z = static_cast(atof(row[10])); entry.target_heading = static_cast(atof(row[11])); entry.zoneinst = atoi(row[12]); entry.target_zone_id = atoi(row[13]); entry.target_instance = atoi(row[14]); entry.buffer = static_cast(atof(row[15])); entry.client_version_mask = atoi(row[16]); entry.min_expansion = atoi(row[17]); entry.max_expansion = atoi(row[18]); entry.content_flags = row[19] ? row[19] : ""; entry.content_flags_disabled = row[20] ? row[20] : ""; entry.is_virtual = atoi(row[21]); entry.height = atoi(row[22]); entry.width = atoi(row[23]); all_entries.push_back(entry); } return all_entries; } static int DeleteWhere(Database& db, std::string where_filter) { auto results = db.QueryDatabase( fmt::format( "DELETE FROM {} WHERE {}", TableName(), where_filter ) ); 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_ZONE_POINTS_REPOSITORY_H