From 3374aba5ab01e5caa220038c634ac3441e1a9ad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20K=C3=BChl?= Date: Mon, 7 Jul 2025 20:51:59 +0200 Subject: [PATCH] fixed linux build for relation completer --- demo/recipe.hpp | 4 +- demo/sandbox.cpp | 8 +- demo/work.cpp | 8 +- demo/work/core/Model.hpp | 6 +- demo/work/jobs/IdListPayload.hpp | 4 +- demo/work/jobs/IdPayload.hpp | 4 +- demo/work/jobs/Task.hpp | 2 +- .../matador/object/attribute_definition.hpp | 3 +- .../object/attribute_definition_generator.hpp | 3 +- include/matador/object/schema.hpp | 86 +++++++++++-------- include/matador/utils/access.hpp | 3 +- 11 files changed, 72 insertions(+), 59 deletions(-) diff --git a/demo/recipe.hpp b/demo/recipe.hpp index 1c81007..b682b9e 100644 --- a/demo/recipe.hpp +++ b/demo/recipe.hpp @@ -17,7 +17,7 @@ struct ingredient { unsigned int id{}; std::string name; - matador::object::collection> recipes{}; + matador::object::collection> recipes{}; ingredient()= default; ingredient(const unsigned int id, std::string name) @@ -36,7 +36,7 @@ struct recipe { unsigned int id{}; std::string name; - matador::object::collection> ingredients{}; + matador::object::collection> ingredients{}; recipe()= default; recipe(const unsigned int id, std::string name) diff --git a/demo/sandbox.cpp b/demo/sandbox.cpp index 564f832..eba9ee1 100644 --- a/demo/sandbox.cpp +++ b/demo/sandbox.cpp @@ -74,7 +74,7 @@ struct profile { unsigned int id{}; std::string first_name; std::string last_name; - matador::object::object_ptr user; + matador::object::object_ptr user; template void process(Operator &op) { @@ -88,7 +88,7 @@ struct profile { struct user { unsigned int id{}; std::string username; - matador::object::object_ptr profile; + matador::object::object_ptr profile; template void process(Operator &op) { @@ -137,7 +137,7 @@ int main() { // has_many_to_many (with join columns first) object::schema schema; - auto result = schema.attach("ingredients") + auto result = schema.attach("ingredients") .and_then([&schema] { return schema.attach("recipes"); }); schema.dump(std::cout); @@ -146,7 +146,7 @@ int main() { // has_many_to_many (with join columns last) object::schema schema; - auto result = schema.attach("recipes") + auto result = schema.attach("recipes") .and_then([&schema] { return schema.attach("ingredients"); }); schema.dump(std::cout); diff --git a/demo/work.cpp b/demo/work.cpp index 87d0ec3..0326e42 100644 --- a/demo/work.cpp +++ b/demo/work.cpp @@ -25,20 +25,20 @@ template <> struct matador::utils::data_type_traits { static basic_type type(std::size_t /*size*/) { return basic_type::type_uint64; } - static void read_value(attribute_reader &reader, const char *id, size_t index, nullptr_t &/*value*/) { + static void read_value(attribute_reader &/*reader*/, const char * /*id*/, size_t /*index*/, nullptr_t &/*value*/) { } - static void bind_value(attribute_writer &binder, size_t index, nullptr_t &/*value*/) { + static void bind_value(attribute_writer &/*binder*/, size_t /*index*/, nullptr_t &/*value*/) { } }; template <> struct matador::utils::data_type_traits { static basic_type type(std::size_t /*size*/) { return basic_type::type_uint64; } - static void read_value(attribute_reader &reader, const char *id, size_t index, nullptr_t &/*value*/) { + static void read_value(attribute_reader &/*reader*/, const char * /*id*/, size_t /*index*/, nullptr_t &/*value*/) { } - static void bind_value(attribute_writer &binder, size_t index, nullptr_t &/*value*/) { + static void bind_value(attribute_writer &/*binder*/, size_t /*index*/, nullptr_t &/*value*/) { } }; diff --git a/demo/work/core/Model.hpp b/demo/work/core/Model.hpp index f411912..88f2fdb 100644 --- a/demo/work/core/Model.hpp +++ b/demo/work/core/Model.hpp @@ -3,10 +3,12 @@ #include "matador/utils/access.hpp" +#include + namespace work::core { struct Model { - unsigned long long id; - unsigned long long version; + uint64_t id; + uint64_t version; template void process( Operator& op ) { diff --git a/demo/work/jobs/IdListPayload.hpp b/demo/work/jobs/IdListPayload.hpp index 19894ed..7e07072 100644 --- a/demo/work/jobs/IdListPayload.hpp +++ b/demo/work/jobs/IdListPayload.hpp @@ -9,12 +9,12 @@ namespace work::models::jobs { struct IdListPayload : Payload { - matador::object::collection ids; + matador::object::collection payload_ids; template void process( Operator& op ) { namespace field = matador::access; field::process( op, *matador::base_class( this ) ); - field::has_many( op, "payload_ids", ids, "payload_id", matador::utils::default_foreign_attributes ); + field::has_many( op, "payload_ids", payload_ids, "payload_id", matador::utils::default_foreign_attributes ); } }; } diff --git a/demo/work/jobs/IdPayload.hpp b/demo/work/jobs/IdPayload.hpp index 2470840..56a81ca 100644 --- a/demo/work/jobs/IdPayload.hpp +++ b/demo/work/jobs/IdPayload.hpp @@ -5,12 +5,12 @@ namespace work::models::jobs { struct IdPayload : Payload { - unsigned long long id; + uint64_t payload_id{}; template void process( Operator& op ) { namespace field = matador::access; field::process( op, *matador::base_class( this ) ); - field::attribute( op, "id", id ); + field::attribute( op, "payload_id", payload_id ); } }; } diff --git a/demo/work/jobs/Task.hpp b/demo/work/jobs/Task.hpp index dc3c75c..2142935 100644 --- a/demo/work/jobs/Task.hpp +++ b/demo/work/jobs/Task.hpp @@ -20,7 +20,7 @@ struct Task : core::Model { JobMode job_mode; core::timestamp start_delay; core::timestamp interval; - unsigned long long user_session_id; + uint64_t user_session_id; template void process( Operator& op ) { diff --git a/include/matador/object/attribute_definition.hpp b/include/matador/object/attribute_definition.hpp index c9925eb..75413f7 100644 --- a/include/matador/object/attribute_definition.hpp +++ b/include/matador/object/attribute_definition.hpp @@ -1,13 +1,12 @@ #ifndef QUERY_COLUMN_DEFINITION_HPP #define QUERY_COLUMN_DEFINITION_HPP -#include - #include "matador/utils/basic_types.hpp" #include "matador/utils/default_type_traits.hpp" #include "matador/utils/field_attributes.hpp" #include "matador/utils/value.hpp" +#include #include namespace matador::object { diff --git a/include/matador/object/attribute_definition_generator.hpp b/include/matador/object/attribute_definition_generator.hpp index 0615db0..c6481e6 100644 --- a/include/matador/object/attribute_definition_generator.hpp +++ b/include/matador/object/attribute_definition_generator.hpp @@ -9,6 +9,7 @@ #include "matador/utils/field_attributes.hpp" #include "matador/utils/foreign_attributes.hpp" +#include #include #include @@ -32,7 +33,7 @@ public: type_ = utils::data_type_traits::type(0); } void on_primary_key(const char * /*id*/, std::string &/*pk*/, size_t size); - static void on_revision(const char * /*id*/, unsigned long long &/*rev*/) {} + static void on_revision(const char * /*id*/, uint64_t &/*rev*/) {} template < class Type > static void on_attribute(const char * /*id*/, Type &/*x*/, const utils::field_attributes &/*attr*/ = utils::null_attributes) {} static void on_attribute(const char * /*id*/, char * /*x*/, const utils::field_attributes &/*attr*/ = utils::null_attributes) {} diff --git a/include/matador/object/schema.hpp b/include/matador/object/schema.hpp index 7103b7c..f43119b 100644 --- a/include/matador/object/schema.hpp +++ b/include/matador/object/schema.hpp @@ -5,7 +5,6 @@ #include "matador/object/join_columns_collector.hpp" #include "matador/object/many_to_many_relation.hpp" -#include "matador/object/primary_key_resolver.hpp" #include "matador/object/error_code.hpp" #include "matador/object/schema_node.hpp" #include "matador/object/schema_node_iterator.hpp" @@ -121,6 +120,7 @@ private: const endpoint_ptr &other_endpoint); static void link_relation_endpoints(const endpoint_ptr &endpoint, const endpoint_ptr &other_endpoint); + private: std::shared_ptr node_; schema &schema_; @@ -143,7 +143,7 @@ public: template [[nodiscard]] utils::result attach(const std::string &name, const std::string &parent = "") { // if (has_node(name)) { - // return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + name + "' already exists")); + // return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + name + "' already exists")); // } auto node = schema_node::make_node(*this, name); relation_completer::complete(node); @@ -167,7 +167,7 @@ public: } - [[nodiscard]] utils::result detach(const node_ptr& node); + [[nodiscard]] utils::result detach(const node_ptr &node); // [[nodiscard]] utils::result detach(const std::string& name); /** @@ -275,8 +275,7 @@ void relation_completer::on_has_many(const char *id, CollectionType &, // Type was not found. // Create and attach the relation node. const std::type_index ti = typeid(many_to_many_relation); - const auto endpoint = node_->info().find_relation_endpoint(ti); - if (endpoint == node_->info().endpoint_end()) { + if (const auto endpoint = node_->info().find_relation_endpoint(ti); endpoint == node_->info().endpoint_end()) { // Endpoint was not found log_.debug("node '%s' has has many foreign keys '%s' mapped by '%s'", node_->name().c_str(), id, join_column); const auto node = schema_node::make_relation_node >( @@ -293,13 +292,13 @@ void relation_completer::on_has_many(const char *id, CollectionType &, node_->info_->register_relation_endpoint(typeid(value_type), local_endpoint); foreign_endpoint->node_->info_->register_relation_endpoint(node_->type_index(), foreign_endpoint); link_relation_endpoints(local_endpoint, foreign_endpoint); - } } else { // Type was found. // Check if the relation node is already attached. const auto &foreign_node = result.value(); - if (const auto rit = foreign_node->info_->find_relation_endpoint(node_->type_index()); rit != foreign_node->info().endpoint_end()) { + if (const auto rit = foreign_node->info_->find_relation_endpoint(node_->type_index()); + rit != foreign_node->info().endpoint_end()) { if (rit->second->is_belongs_to()) { rit->second->node_ = foreign_node; const auto endpoint = std::make_shared(id, relation_type::HAS_MANY, node_); @@ -318,7 +317,8 @@ template template void relation_completer::on_has_many(const char *id, CollectionType &, const char *join_column, const utils::foreign_attributes &, - std::enable_if_t::value>* /*unused*/) { + std::enable_if_t::value> + * /*unused*/) { using value_type = typename CollectionType::value_type; using relation_value_type = many_to_relation; @@ -348,9 +348,9 @@ void relation_completer::on_has_many_to_many(const char *id, const utils::foreign_attributes &/*attr*/) { auto result = schema_.find_node(id); if (result) { - const auto foreign_node = result.value(); + const auto &foreign_node = result.value(); const auto local_endpoint = std::make_shared(id, relation_type::HAS_MANY, node_); - node_->info_->register_relation_endpoint(typeid(CollectionType::value_type::value_type), local_endpoint); + node_->info_->register_relation_endpoint(typeid(typename CollectionType::value_type::value_type), local_endpoint); const auto it = foreign_node->info_->find_relation_endpoint(node_->type_index()); if (it == foreign_node->info().endpoint_end()) { // Todo: Throw error @@ -367,11 +367,13 @@ void relation_completer::on_has_many_to_many(const char *id, auto local_endpoint = std::make_shared(id, relation_type::HAS_MANY, node_); auto join_endpoint = std::make_shared(join_column, relation_type::BELONGS_TO, node); - auto inverse_join_endpoint = std::make_shared(inverse_join_column, relation_type::BELONGS_TO, node); - node_->info_->register_relation_endpoint(typeid(CollectionType::value_type::value_type), local_endpoint); + auto inverse_join_endpoint = std::make_shared(inverse_join_column, relation_type::BELONGS_TO, + node); + node_->info_->register_relation_endpoint(typeid(typename CollectionType::value_type::value_type), local_endpoint); node->info_->register_relation_endpoint(node_->type_index(), join_endpoint); link_relation_endpoints(local_endpoint, join_endpoint); - node->info_->register_relation_endpoint(typeid(CollectionType::value_type::value_type), inverse_join_endpoint); + node->info_->register_relation_endpoint(typeid(typename CollectionType::value_type::value_type), + inverse_join_endpoint); result = schema_.attach_node(node, ""); if (!result) { // Todo: throw internal error @@ -390,27 +392,28 @@ void relation_completer::on_has_many_to_many(const char *id, const auto join_columns = join_columns_collector_.collect(); using relation_value_type = many_to_many_relation; auto creator = [&join_columns] { - return std::make_unique(join_columns.inverse_join_column, join_columns.join_column); + return std::make_unique(join_columns.inverse_join_column, join_columns.join_column); }; auto node = schema_node::make_relation_node(schema_, id, std::move(creator)); auto local_endpoint = std::make_shared(id, relation_type::HAS_MANY, node_); auto join_endpoint = std::make_shared(join_columns.join_column, relation_type::BELONGS_TO, node); - auto inverse_join_endpoint = std::make_shared(join_columns.inverse_join_column, relation_type::BELONGS_TO, node); - node_->info_->register_relation_endpoint(typeid(CollectionType::value_type::value_type), local_endpoint); + auto inverse_join_endpoint = std::make_shared(join_columns.inverse_join_column, + relation_type::BELONGS_TO, node); + node_->info_->register_relation_endpoint(typeid(typename CollectionType::value_type::value_type), local_endpoint); node->info_->register_relation_endpoint(node_->type_index(), inverse_join_endpoint); link_relation_endpoints(local_endpoint, inverse_join_endpoint); - node->info_->register_relation_endpoint(typeid(CollectionType::value_type::value_type), join_endpoint); + node->info_->register_relation_endpoint(typeid(typename CollectionType::value_type::value_type), join_endpoint); result = schema_.attach_node(node, ""); if (!result) { // Todo: throw internal error return; } } else { - const auto foreign_node = result.value(); + const auto &foreign_node = result.value(); const auto local_endpoint = std::make_shared(id, relation_type::HAS_MANY, node_); - node_->info_->register_relation_endpoint(typeid(CollectionType::value_type::value_type), local_endpoint); + node_->info_->register_relation_endpoint(typeid(typename CollectionType::value_type::value_type), local_endpoint); const auto it = foreign_node->info_->find_relation_endpoint(node_->type_index()); if (it == foreign_node->info().endpoint_end()) { // Todo: Throw internal error @@ -425,20 +428,22 @@ template void relation_completer::on_has_one(const char *id, ForeignPointerType &/*obj*/, const utils::foreign_attributes &/*attr*/) { - auto ti = std::type_index(typeid(typename ForeignPointerType::value_type)); + const auto ti = std::type_index(typeid(typename ForeignPointerType::value_type)); if (const auto result = schema_.find_node(ti); !result.is_ok()) { - // Node was not found - // Create node without the foreign relation endpoint - log_.debug("node '%s' has foreign key '%s' has one '%s'", node_->name().c_str(), id, ti.name()); - node_->info_->register_relation_endpoint(ti, std::make_shared(id, relation_type::HAS_ONE, node_)); + // Node was not found + // Create node without the foreign relation endpoint + log_.debug("node '%s' has foreign key '%s' has one '%s'", node_->name().c_str(), id, ti.name()); + node_->info_-> + register_relation_endpoint(ti, std::make_shared(id, relation_type::HAS_ONE, node_)); } else { const auto &foreign_node = result.value(); - if (const auto it = foreign_node->info().find_relation_endpoint(typeid(Type)); it != foreign_node->info().endpoint_end()) { + if (const auto it = foreign_node->info().find_relation_endpoint(typeid(Type)); + it != foreign_node->info().endpoint_end()) { if (it->second->is_belongs_to()) { - it->second->node_ = foreign_node; - const auto endpoint = std::make_shared(id, relation_type::HAS_ONE, node_); - node_->info_->register_relation_endpoint(ti, endpoint); - link_relation_endpoints(endpoint, it->second); + it->second->node_ = foreign_node; + const auto endpoint = std::make_shared(id, relation_type::HAS_ONE, node_); + node_->info_->register_relation_endpoint(ti, endpoint); + link_relation_endpoints(endpoint, it->second); } else { // Todo: Throw internal error return; @@ -458,18 +463,21 @@ void relation_completer::on_belongs_to(const char *id, // Type was not found // Create node without the foreign relation endpoint log_.debug("node '%s' has foreign key '%s' belongs to '%s'", node_->name().c_str(), id, ti.name()); - node_->info_->register_relation_endpoint(ti, std::make_shared(id, relation_type::BELONGS_TO, schema::node_ptr{})); + node_->info_->register_relation_endpoint( + ti, std::make_shared(id, relation_type::BELONGS_TO, schema::node_ptr{})); } else { // Type was found - const auto& foreign_node = result.value(); + const auto &foreign_node = result.value(); // Check foreign node and relation endpoint - if (const auto it = foreign_node->info_->find_relation_endpoint(typeid(Type)); it != foreign_node->info().endpoint_end()) { + if (const auto it = foreign_node->info_->find_relation_endpoint(typeid(Type)); + it != foreign_node->info().endpoint_end()) { // Found corresponding relation endpoint in the foreign node if (it->second->is_has_one()) { - const auto endpoint = std::make_shared(id, relation_type::BELONGS_TO, node_); - node_->info_->register_relation_endpoint(ti, endpoint); - link_relation_endpoints(endpoint, it->second); - } else if (it->second->foreign_endpoint()->node().type_index() == typeid(many_to_many_relation)) { + const auto endpoint = std::make_shared(id, relation_type::BELONGS_TO, node_); + node_->info_->register_relation_endpoint(ti, endpoint); + link_relation_endpoints(endpoint, it->second); + } else if (it->second->foreign_endpoint()->node().type_index() == typeid(many_to_many_relation)) { // Endpoint is a "many_to_many_relation". This means there // is a "many_to_many_relation" node attached. Because of being a // "belongs_to"-relation the "many_to_many_relation" can be removed @@ -490,14 +498,16 @@ void relation_completer::on_belongs_to(const char *id, } template -void relation_completer::register_relation_endpoints(const endpoint_ptr &endpoint, const endpoint_ptr &other_endpoint) { +void relation_completer::register_relation_endpoints(const endpoint_ptr &endpoint, + const endpoint_ptr &other_endpoint) { endpoint->node_->info_->register_relation_endpoint(other_endpoint->node_->type_index(), endpoint); other_endpoint->node_->info_->register_relation_endpoint(endpoint->node_->type_index(), other_endpoint); link_relation_endpoints(endpoint, other_endpoint); } template -void relation_completer::link_relation_endpoints(const endpoint_ptr &endpoint, const endpoint_ptr &other_endpoint) { +void relation_completer< + Type>::link_relation_endpoints(const endpoint_ptr &endpoint, const endpoint_ptr &other_endpoint) { endpoint->link_foreign_endpoint(other_endpoint); other_endpoint->link_foreign_endpoint(endpoint); } diff --git a/include/matador/utils/access.hpp b/include/matador/utils/access.hpp index 707ef77..bb8190d 100644 --- a/include/matador/utils/access.hpp +++ b/include/matador/utils/access.hpp @@ -1,6 +1,7 @@ #ifndef OOS_ACCESS_HPP #define OOS_ACCESS_HPP +#include #include #include @@ -38,7 +39,7 @@ void primary_key(Operator &op, const char *id, std::string &value, size_t size ) } template -void revision(Operator &op, const char *id, unsigned long long &value) { +void revision(Operator &op, const char *id, uint64_t &value) { op.on_revision(id, value); }