fixed linux build for relation completer

This commit is contained in:
Sascha Kühl 2025-07-07 20:51:59 +02:00
parent e85543719c
commit 3374aba5ab
11 changed files with 72 additions and 59 deletions

View File

@ -17,7 +17,7 @@ struct ingredient
{ {
unsigned int id{}; unsigned int id{};
std::string name; std::string name;
matador::object::collection<matador::object::object_ptr<recipe>> recipes{}; matador::object::collection<matador::object::object_ptr<demo::recipe>> recipes{};
ingredient()= default; ingredient()= default;
ingredient(const unsigned int id, std::string name) ingredient(const unsigned int id, std::string name)
@ -36,7 +36,7 @@ struct recipe
{ {
unsigned int id{}; unsigned int id{};
std::string name; std::string name;
matador::object::collection<matador::object::object_ptr<ingredient>> ingredients{}; matador::object::collection<matador::object::object_ptr<demo::ingredient>> ingredients{};
recipe()= default; recipe()= default;
recipe(const unsigned int id, std::string name) recipe(const unsigned int id, std::string name)

View File

@ -74,7 +74,7 @@ struct profile {
unsigned int id{}; unsigned int id{};
std::string first_name; std::string first_name;
std::string last_name; std::string last_name;
matador::object::object_ptr<user> user; matador::object::object_ptr<demo::user> user;
template<typename Operator> template<typename Operator>
void process(Operator &op) { void process(Operator &op) {
@ -88,7 +88,7 @@ struct profile {
struct user { struct user {
unsigned int id{}; unsigned int id{};
std::string username; std::string username;
matador::object::object_ptr<profile> profile; matador::object::object_ptr<demo::profile> profile;
template<typename Operator> template<typename Operator>
void process(Operator &op) { void process(Operator &op) {
@ -137,7 +137,7 @@ int main() {
// has_many_to_many (with join columns first) // has_many_to_many (with join columns first)
object::schema schema; object::schema schema;
auto result = schema.attach<ingredient>("ingredients") auto result = schema.attach<demo::ingredient>("ingredients")
.and_then([&schema] { return schema.attach<recipe>("recipes"); }); .and_then([&schema] { return schema.attach<recipe>("recipes"); });
schema.dump(std::cout); schema.dump(std::cout);
@ -146,7 +146,7 @@ int main() {
// has_many_to_many (with join columns last) // has_many_to_many (with join columns last)
object::schema schema; object::schema schema;
auto result = schema.attach<recipe>("recipes") auto result = schema.attach<demo::recipe>("recipes")
.and_then([&schema] { return schema.attach<ingredient>("ingredients"); }); .and_then([&schema] { return schema.attach<ingredient>("ingredients"); });
schema.dump(std::cout); schema.dump(std::cout);

View File

@ -25,20 +25,20 @@
template <> struct matador::utils::data_type_traits<work::core::timestamp, void> { template <> struct matador::utils::data_type_traits<work::core::timestamp, void> {
static basic_type type(std::size_t /*size*/) { return basic_type::type_uint64; } 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<work::core::UserInfo, void> { template <> struct matador::utils::data_type_traits<work::core::UserInfo, void> {
static basic_type type(std::size_t /*size*/) { return basic_type::type_uint64; } 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*/) {
} }
}; };

View File

@ -3,10 +3,12 @@
#include "matador/utils/access.hpp" #include "matador/utils/access.hpp"
#include <cstdint>
namespace work::core { namespace work::core {
struct Model { struct Model {
unsigned long long id; uint64_t id;
unsigned long long version; uint64_t version;
template<typename Operator> template<typename Operator>
void process( Operator& op ) { void process( Operator& op ) {

View File

@ -9,12 +9,12 @@
namespace work::models::jobs { namespace work::models::jobs {
struct IdListPayload : Payload { struct IdListPayload : Payload {
matador::object::collection<unsigned long long> ids; matador::object::collection<uint64_t> payload_ids;
template<typename Operator> template<typename Operator>
void process( Operator& op ) { void process( Operator& op ) {
namespace field = matador::access; namespace field = matador::access;
field::process( op, *matador::base_class<Payload>( this ) ); field::process( op, *matador::base_class<Payload>( 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 );
} }
}; };
} }

View File

@ -5,12 +5,12 @@
namespace work::models::jobs { namespace work::models::jobs {
struct IdPayload : Payload { struct IdPayload : Payload {
unsigned long long id; uint64_t payload_id{};
template<typename Operator> template<typename Operator>
void process( Operator& op ) { void process( Operator& op ) {
namespace field = matador::access; namespace field = matador::access;
field::process( op, *matador::base_class<Payload>( this ) ); field::process( op, *matador::base_class<Payload>( this ) );
field::attribute( op, "id", id ); field::attribute( op, "payload_id", payload_id );
} }
}; };
} }

View File

@ -20,7 +20,7 @@ struct Task : core::Model {
JobMode job_mode; JobMode job_mode;
core::timestamp start_delay; core::timestamp start_delay;
core::timestamp interval; core::timestamp interval;
unsigned long long user_session_id; uint64_t user_session_id;
template<typename Operator> template<typename Operator>
void process( Operator& op ) { void process( Operator& op ) {

View File

@ -1,13 +1,12 @@
#ifndef QUERY_COLUMN_DEFINITION_HPP #ifndef QUERY_COLUMN_DEFINITION_HPP
#define QUERY_COLUMN_DEFINITION_HPP #define QUERY_COLUMN_DEFINITION_HPP
#include <memory>
#include "matador/utils/basic_types.hpp" #include "matador/utils/basic_types.hpp"
#include "matador/utils/default_type_traits.hpp" #include "matador/utils/default_type_traits.hpp"
#include "matador/utils/field_attributes.hpp" #include "matador/utils/field_attributes.hpp"
#include "matador/utils/value.hpp" #include "matador/utils/value.hpp"
#include <memory>
#include <vector> #include <vector>
namespace matador::object { namespace matador::object {

View File

@ -9,6 +9,7 @@
#include "matador/utils/field_attributes.hpp" #include "matador/utils/field_attributes.hpp"
#include "matador/utils/foreign_attributes.hpp" #include "matador/utils/foreign_attributes.hpp"
#include <memory>
#include <typeindex> #include <typeindex>
#include <vector> #include <vector>
@ -32,7 +33,7 @@ public:
type_ = utils::data_type_traits<ValueType>::type(0); type_ = utils::data_type_traits<ValueType>::type(0);
} }
void on_primary_key(const char * /*id*/, std::string &/*pk*/, size_t size); 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 > 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*/, 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) {} static void on_attribute(const char * /*id*/, char * /*x*/, const utils::field_attributes &/*attr*/ = utils::null_attributes) {}

View File

@ -5,7 +5,6 @@
#include "matador/object/join_columns_collector.hpp" #include "matador/object/join_columns_collector.hpp"
#include "matador/object/many_to_many_relation.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/error_code.hpp"
#include "matador/object/schema_node.hpp" #include "matador/object/schema_node.hpp"
#include "matador/object/schema_node_iterator.hpp" #include "matador/object/schema_node_iterator.hpp"
@ -121,6 +120,7 @@ private:
const endpoint_ptr &other_endpoint); const endpoint_ptr &other_endpoint);
static void link_relation_endpoints(const endpoint_ptr &endpoint, static void link_relation_endpoints(const endpoint_ptr &endpoint,
const endpoint_ptr &other_endpoint); const endpoint_ptr &other_endpoint);
private: private:
std::shared_ptr<schema_node> node_; std::shared_ptr<schema_node> node_;
schema &schema_; schema &schema_;
@ -275,8 +275,7 @@ void relation_completer<Type>::on_has_many(const char *id, CollectionType &,
// Type was not found. // Type was not found.
// Create and attach the relation node. // Create and attach the relation node.
const std::type_index ti = typeid(many_to_many_relation<value_type, Type>); const std::type_index ti = typeid(many_to_many_relation<value_type, Type>);
const auto endpoint = node_->info().find_relation_endpoint(ti); if (const auto endpoint = node_->info().find_relation_endpoint(ti); endpoint == node_->info().endpoint_end()) {
if (endpoint == node_->info().endpoint_end()) {
// Endpoint was not found // Endpoint was not found
log_.debug("node '%s' has has many foreign keys '%s' mapped by '%s'", node_->name().c_str(), id, join_column); 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<many_to_many_relation<value_type, Type> >( const auto node = schema_node::make_relation_node<many_to_many_relation<value_type, Type> >(
@ -293,13 +292,13 @@ void relation_completer<Type>::on_has_many(const char *id, CollectionType &,
node_->info_->register_relation_endpoint(typeid(value_type), local_endpoint); node_->info_->register_relation_endpoint(typeid(value_type), local_endpoint);
foreign_endpoint->node_->info_->register_relation_endpoint(node_->type_index(), foreign_endpoint); foreign_endpoint->node_->info_->register_relation_endpoint(node_->type_index(), foreign_endpoint);
link_relation_endpoints(local_endpoint, foreign_endpoint); link_relation_endpoints(local_endpoint, foreign_endpoint);
} }
} else { } else {
// Type was found. // Type was found.
// Check if the relation node is already attached. // Check if the relation node is already attached.
const auto &foreign_node = result.value(); 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()) { if (rit->second->is_belongs_to()) {
rit->second->node_ = foreign_node; rit->second->node_ = foreign_node;
const auto endpoint = std::make_shared<relation_endpoint>(id, relation_type::HAS_MANY, node_); const auto endpoint = std::make_shared<relation_endpoint>(id, relation_type::HAS_MANY, node_);
@ -318,7 +317,8 @@ template<typename Type>
template<class CollectionType> template<class CollectionType>
void relation_completer<Type>::on_has_many(const char *id, CollectionType &, const char *join_column, void relation_completer<Type>::on_has_many(const char *id, CollectionType &, const char *join_column,
const utils::foreign_attributes &, const utils::foreign_attributes &,
std::enable_if_t<!is_object_ptr<typename CollectionType::value_type>::value>* /*unused*/) { std::enable_if_t<!is_object_ptr<typename CollectionType::value_type>::value>
* /*unused*/) {
using value_type = typename CollectionType::value_type; using value_type = typename CollectionType::value_type;
using relation_value_type = many_to_relation<Type, value_type>; using relation_value_type = many_to_relation<Type, value_type>;
@ -348,9 +348,9 @@ void relation_completer<Type>::on_has_many_to_many(const char *id,
const utils::foreign_attributes &/*attr*/) { const utils::foreign_attributes &/*attr*/) {
auto result = schema_.find_node(id); auto result = schema_.find_node(id);
if (result) { if (result) {
const auto foreign_node = result.value(); const auto &foreign_node = result.value();
const auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HAS_MANY, node_); const auto local_endpoint = std::make_shared<relation_endpoint>(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()); const auto it = foreign_node->info_->find_relation_endpoint(node_->type_index());
if (it == foreign_node->info().endpoint_end()) { if (it == foreign_node->info().endpoint_end()) {
// Todo: Throw error // Todo: Throw error
@ -367,11 +367,13 @@ void relation_completer<Type>::on_has_many_to_many(const char *id,
auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HAS_MANY, node_); auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HAS_MANY, node_);
auto join_endpoint = std::make_shared<relation_endpoint>(join_column, relation_type::BELONGS_TO, node); auto join_endpoint = std::make_shared<relation_endpoint>(join_column, relation_type::BELONGS_TO, node);
auto inverse_join_endpoint = std::make_shared<relation_endpoint>(inverse_join_column, relation_type::BELONGS_TO, node); auto inverse_join_endpoint = std::make_shared<relation_endpoint>(inverse_join_column, relation_type::BELONGS_TO,
node_->info_->register_relation_endpoint(typeid(CollectionType::value_type::value_type), local_endpoint); 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); node->info_->register_relation_endpoint(node_->type_index(), join_endpoint);
link_relation_endpoints(local_endpoint, 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, ""); result = schema_.attach_node(node, "");
if (!result) { if (!result) {
// Todo: throw internal error // Todo: throw internal error
@ -397,20 +399,21 @@ void relation_completer<Type>::on_has_many_to_many(const char *id,
auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HAS_MANY, node_); auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HAS_MANY, node_);
auto join_endpoint = std::make_shared<relation_endpoint>(join_columns.join_column, relation_type::BELONGS_TO, node); auto join_endpoint = std::make_shared<relation_endpoint>(join_columns.join_column, relation_type::BELONGS_TO, node);
auto inverse_join_endpoint = std::make_shared<relation_endpoint>(join_columns.inverse_join_column, relation_type::BELONGS_TO, node); auto inverse_join_endpoint = std::make_shared<relation_endpoint>(join_columns.inverse_join_column,
node_->info_->register_relation_endpoint(typeid(CollectionType::value_type::value_type), local_endpoint); 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); node->info_->register_relation_endpoint(node_->type_index(), inverse_join_endpoint);
link_relation_endpoints(local_endpoint, 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, ""); result = schema_.attach_node(node, "");
if (!result) { if (!result) {
// Todo: throw internal error // Todo: throw internal error
return; return;
} }
} else { } else {
const auto foreign_node = result.value(); const auto &foreign_node = result.value();
const auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HAS_MANY, node_); const auto local_endpoint = std::make_shared<relation_endpoint>(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()); const auto it = foreign_node->info_->find_relation_endpoint(node_->type_index());
if (it == foreign_node->info().endpoint_end()) { if (it == foreign_node->info().endpoint_end()) {
// Todo: Throw internal error // Todo: Throw internal error
@ -425,15 +428,17 @@ template<class ForeignPointerType>
void relation_completer<Type>::on_has_one(const char *id, void relation_completer<Type>::on_has_one(const char *id,
ForeignPointerType &/*obj*/, ForeignPointerType &/*obj*/,
const utils::foreign_attributes &/*attr*/) { 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()) { if (const auto result = schema_.find_node(ti); !result.is_ok()) {
// Node was not found // Node was not found
// Create node without the foreign relation endpoint // 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()); 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<relation_endpoint>(id, relation_type::HAS_ONE, node_)); node_->info_->
register_relation_endpoint(ti, std::make_shared<relation_endpoint>(id, relation_type::HAS_ONE, node_));
} else { } else {
const auto &foreign_node = result.value(); 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()) { if (it->second->is_belongs_to()) {
it->second->node_ = foreign_node; it->second->node_ = foreign_node;
const auto endpoint = std::make_shared<relation_endpoint>(id, relation_type::HAS_ONE, node_); const auto endpoint = std::make_shared<relation_endpoint>(id, relation_type::HAS_ONE, node_);
@ -458,18 +463,21 @@ void relation_completer<Type>::on_belongs_to(const char *id,
// Type was not found // Type was not found
// Create node without the foreign relation endpoint // 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()); 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<relation_endpoint>(id, relation_type::BELONGS_TO, schema::node_ptr{})); node_->info_->register_relation_endpoint(
ti, std::make_shared<relation_endpoint>(id, relation_type::BELONGS_TO, schema::node_ptr{}));
} else { } else {
// Type was found // Type was found
const auto &foreign_node = result.value(); const auto &foreign_node = result.value();
// Check foreign node and relation endpoint // 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 // Found corresponding relation endpoint in the foreign node
if (it->second->is_has_one()) { if (it->second->is_has_one()) {
const auto endpoint = std::make_shared<relation_endpoint>(id, relation_type::BELONGS_TO, node_); const auto endpoint = std::make_shared<relation_endpoint>(id, relation_type::BELONGS_TO, node_);
node_->info_->register_relation_endpoint(ti, endpoint); node_->info_->register_relation_endpoint(ti, endpoint);
link_relation_endpoints(endpoint, it->second); link_relation_endpoints(endpoint, it->second);
} else if (it->second->foreign_endpoint()->node().type_index() == typeid(many_to_many_relation<Type, value_type>)) { } else if (it->second->foreign_endpoint()->node().type_index() == typeid(many_to_many_relation<Type,
value_type>)) {
// Endpoint is a "many_to_many_relation". This means there // Endpoint is a "many_to_many_relation". This means there
// is a "many_to_many_relation" node attached. Because of being a // is a "many_to_many_relation" node attached. Because of being a
// "belongs_to"-relation the "many_to_many_relation" can be removed // "belongs_to"-relation the "many_to_many_relation" can be removed
@ -490,14 +498,16 @@ void relation_completer<Type>::on_belongs_to(const char *id,
} }
template<typename Type> template<typename Type>
void relation_completer<Type>::register_relation_endpoints(const endpoint_ptr &endpoint, const endpoint_ptr &other_endpoint) { void relation_completer<Type>::register_relation_endpoints(const endpoint_ptr &endpoint,
const endpoint_ptr &other_endpoint) {
endpoint->node_->info_->register_relation_endpoint(other_endpoint->node_->type_index(), 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); other_endpoint->node_->info_->register_relation_endpoint(endpoint->node_->type_index(), other_endpoint);
link_relation_endpoints(endpoint, other_endpoint); link_relation_endpoints(endpoint, other_endpoint);
} }
template<typename Type> template<typename Type>
void relation_completer<Type>::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); endpoint->link_foreign_endpoint(other_endpoint);
other_endpoint->link_foreign_endpoint(endpoint); other_endpoint->link_foreign_endpoint(endpoint);
} }

View File

@ -1,6 +1,7 @@
#ifndef OOS_ACCESS_HPP #ifndef OOS_ACCESS_HPP
#define OOS_ACCESS_HPP #define OOS_ACCESS_HPP
#include <cstdint>
#include <string> #include <string>
#include <optional> #include <optional>
@ -38,7 +39,7 @@ void primary_key(Operator &op, const char *id, std::string &value, size_t size )
} }
template<class Operator> template<class Operator>
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); op.on_revision(id, value);
} }