[Repositories] Add Cereal support to repository generator (#2660)

* [Repositories] Add Cereal support to repository generator

* Update base_repository.template
This commit is contained in:
Chris Miles 2022-12-20 13:12:44 -06:00 committed by GitHub
parent 51c62d3b3e
commit 0d1fa9e96e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View File

@ -15,6 +15,7 @@
#include "../../database.h"
#include "../../strings.h"
#include <ctime>
{{ADDITIONAL_INCLUDES}}
class Base{{TABLE_NAME_CLASS}}Repository {
public:

View File

@ -111,6 +111,10 @@ if ($requested_table_to_generate ne "all") {
@tables = ($requested_table_to_generate);
}
my @cereal_enabled_tables = (
"player_event_logs"
);
my $generated_base_repository_files = "";
my $generated_repository_files = "";
@ -156,6 +160,11 @@ foreach my $table_to_generate (@tables) {
$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")) {
print "Table [$table_to_generate] not found in schema, skipping\n";
next;
@ -210,6 +219,7 @@ foreach my $table_to_generate (@tables) {
my $column_names_quoted = "";
my $select_column_names_quoted = "";
my $table_struct_columns = "";
my $cereal_columns = "";
my $update_one_entries = "";
my $all_entries = "";
my $index = 0;
@ -259,6 +269,10 @@ foreach my $table_to_generate (@tables) {
# struct
$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
$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";
}
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($select_column_names_quoted);
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/\{\{ALL_ENTRIES}}/$all_entries/g;
$new_base_repository =~ s/\{\{GENERATED_DATE}}/$generated_date/g;
$new_base_repository =~ s/\{\{ADDITIONAL_INCLUDES}}/$additional_includes/g;
# Extended repository
my $new_repository = $repository_template;