mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-13 18:51:29 +00:00
[Repositories] Add Cereal support to repository generator (#2660)
* [Repositories] Add Cereal support to repository generator * Update base_repository.template
This commit is contained in:
parent
51c62d3b3e
commit
0d1fa9e96e
@ -15,6 +15,7 @@
|
|||||||
#include "../../database.h"
|
#include "../../database.h"
|
||||||
#include "../../strings.h"
|
#include "../../strings.h"
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
{{ADDITIONAL_INCLUDES}}
|
||||||
|
|
||||||
class Base{{TABLE_NAME_CLASS}}Repository {
|
class Base{{TABLE_NAME_CLASS}}Repository {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -111,6 +111,10 @@ if ($requested_table_to_generate ne "all") {
|
|||||||
@tables = ($requested_table_to_generate);
|
@tables = ($requested_table_to_generate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my @cereal_enabled_tables = (
|
||||||
|
"player_event_logs"
|
||||||
|
);
|
||||||
|
|
||||||
my $generated_base_repository_files = "";
|
my $generated_base_repository_files = "";
|
||||||
my $generated_repository_files = "";
|
my $generated_repository_files = "";
|
||||||
|
|
||||||
@ -156,6 +160,11 @@ foreach my $table_to_generate (@tables) {
|
|||||||
$table_found_in_schema = 0;
|
$table_found_in_schema = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $cereal_enabled = 0;
|
||||||
|
if ($table_to_generate ~~ @cereal_enabled_tables) {
|
||||||
|
$cereal_enabled = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if ($table_found_in_schema == 0 && ($requested_table_to_generate eq "" || $requested_table_to_generate eq "all")) {
|
if ($table_found_in_schema == 0 && ($requested_table_to_generate eq "" || $requested_table_to_generate eq "all")) {
|
||||||
print "Table [$table_to_generate] not found in schema, skipping\n";
|
print "Table [$table_to_generate] not found in schema, skipping\n";
|
||||||
next;
|
next;
|
||||||
@ -210,6 +219,7 @@ foreach my $table_to_generate (@tables) {
|
|||||||
my $column_names_quoted = "";
|
my $column_names_quoted = "";
|
||||||
my $select_column_names_quoted = "";
|
my $select_column_names_quoted = "";
|
||||||
my $table_struct_columns = "";
|
my $table_struct_columns = "";
|
||||||
|
my $cereal_columns = "";
|
||||||
my $update_one_entries = "";
|
my $update_one_entries = "";
|
||||||
my $all_entries = "";
|
my $all_entries = "";
|
||||||
my $index = 0;
|
my $index = 0;
|
||||||
@ -259,6 +269,10 @@ foreach my $table_to_generate (@tables) {
|
|||||||
# struct
|
# struct
|
||||||
$table_struct_columns .= sprintf("\t\t\%-${longest_data_type_length}s %s;\n", $struct_data_type, $column_name_formatted);
|
$table_struct_columns .= sprintf("\t\t\%-${longest_data_type_length}s %s;\n", $struct_data_type, $column_name_formatted);
|
||||||
|
|
||||||
|
if ($cereal_enabled == 1) {
|
||||||
|
$cereal_columns .= sprintf("\t\t\t\tCEREAL_NVP(%s),\n", $column_name_formatted);
|
||||||
|
}
|
||||||
|
|
||||||
# new entity
|
# new entity
|
||||||
$default_entries .= sprintf("\t\te.%-${longest_column_length}s = %s;\n", $column_name_formatted, $default_value);
|
$default_entries .= sprintf("\t\te.%-${longest_column_length}s = %s;\n", $column_name_formatted, $default_value);
|
||||||
|
|
||||||
@ -400,6 +414,22 @@ foreach my $table_to_generate (@tables) {
|
|||||||
$database_connection = "content_db";
|
$database_connection = "content_db";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $additional_includes = "";
|
||||||
|
if ($cereal_enabled) {
|
||||||
|
chomp($cereal_columns);
|
||||||
|
# remove the last comma "," from string
|
||||||
|
$cereal_columns = substr($cereal_columns, 0, -1);
|
||||||
|
|
||||||
|
$table_struct_columns .= "
|
||||||
|
// cereal
|
||||||
|
template<class Archive>
|
||||||
|
void serialize(Archive &ar)
|
||||||
|
{
|
||||||
|
ar(\n" . $cereal_columns . "\n\t\t\t);\n\t\t}";
|
||||||
|
|
||||||
|
$additional_includes .= "#include <cereal/cereal.hpp>";
|
||||||
|
}
|
||||||
|
|
||||||
chomp($column_names_quoted);
|
chomp($column_names_quoted);
|
||||||
chomp($select_column_names_quoted);
|
chomp($select_column_names_quoted);
|
||||||
chomp($table_struct_columns);
|
chomp($table_struct_columns);
|
||||||
@ -435,6 +465,7 @@ foreach my $table_to_generate (@tables) {
|
|||||||
$new_base_repository =~ s/\{\{INSERT_MANY_ENTRIES}}/$insert_many_entries/g;
|
$new_base_repository =~ s/\{\{INSERT_MANY_ENTRIES}}/$insert_many_entries/g;
|
||||||
$new_base_repository =~ s/\{\{ALL_ENTRIES}}/$all_entries/g;
|
$new_base_repository =~ s/\{\{ALL_ENTRIES}}/$all_entries/g;
|
||||||
$new_base_repository =~ s/\{\{GENERATED_DATE}}/$generated_date/g;
|
$new_base_repository =~ s/\{\{GENERATED_DATE}}/$generated_date/g;
|
||||||
|
$new_base_repository =~ s/\{\{ADDITIONAL_INCLUDES}}/$additional_includes/g;
|
||||||
|
|
||||||
# Extended repository
|
# Extended repository
|
||||||
my $new_repository = $repository_template;
|
my $new_repository = $repository_template;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user