has one progress
This commit is contained in:
parent
22f6f71412
commit
57703dfb67
|
|
@ -1,24 +1,22 @@
|
||||||
#ifndef MATADOR_ABSTRACT_COLLECTION_RESOLVER_HPP
|
#ifndef MATADOR_ABSTRACT_COLLECTION_RESOLVER_HPP
|
||||||
#define MATADOR_ABSTRACT_COLLECTION_RESOLVER_HPP
|
#define MATADOR_ABSTRACT_COLLECTION_RESOLVER_HPP
|
||||||
|
|
||||||
|
#include "matador/object/abstract_type_resolver.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <typeindex>
|
#include <typeindex>
|
||||||
|
|
||||||
namespace matador::object {
|
namespace matador::object {
|
||||||
class abstract_collection_resolver {
|
class abstract_joined_resolver : public abstract_type_resolver {
|
||||||
public:
|
public:
|
||||||
virtual ~abstract_collection_resolver() = default;
|
|
||||||
|
|
||||||
[[nodiscard]] const std::type_index& root_type() const;
|
[[nodiscard]] const std::type_index& root_type() const;
|
||||||
[[nodiscard]] const std::type_index& type() const;
|
|
||||||
[[nodiscard]] const std::string& collection_name() const;
|
[[nodiscard]] const std::string& collection_name() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit abstract_collection_resolver(const std::type_index& root_type, const std::type_index& type, std::string collection_name);
|
explicit abstract_joined_resolver(const std::type_index& root_type, const std::type_index& type, std::string collection_name);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const std::type_index root_type_;
|
const std::type_index root_type_;
|
||||||
const std::type_index type_;
|
|
||||||
const std::string collection_name_;
|
const std::string collection_name_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef MATADOR_COLLECTION_RESOLVER_HPP
|
#ifndef MATADOR_COLLECTION_RESOLVER_HPP
|
||||||
#define MATADOR_COLLECTION_RESOLVER_HPP
|
#define MATADOR_COLLECTION_RESOLVER_HPP
|
||||||
|
|
||||||
#include "matador/object/abstract_collection_resolver.hpp"
|
#include "matador/object/abstract_joined_resolver.hpp"
|
||||||
|
|
||||||
#include <typeindex>
|
#include <typeindex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
@ -12,10 +12,10 @@ class identifier;
|
||||||
|
|
||||||
namespace matador::object {
|
namespace matador::object {
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
class collection_resolver : public abstract_collection_resolver {
|
class collection_resolver : public abstract_joined_resolver {
|
||||||
public:
|
public:
|
||||||
collection_resolver(const std::type_index& root_type, std::string collection_name)
|
collection_resolver(const std::type_index& root_type, std::string collection_name)
|
||||||
: abstract_collection_resolver(root_type, typeid(Type), std::move(collection_name)) {}
|
: abstract_joined_resolver(root_type, typeid(Type), std::move(collection_name)) {}
|
||||||
|
|
||||||
virtual std::vector<Type> resolve(const utils::identifier& id) = 0;
|
virtual std::vector<Type> resolve(const utils::identifier& id) = 0;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ class abstract_collection_resolver_factory {
|
||||||
public:
|
public:
|
||||||
virtual ~abstract_collection_resolver_factory() = default;
|
virtual ~abstract_collection_resolver_factory() = default;
|
||||||
|
|
||||||
[[nodiscard]] virtual std::shared_ptr<abstract_collection_resolver> acquire_collection_resolver(const std::type_index &root_type, const std::type_index &element_type, const std::string &collection_name) const = 0;
|
[[nodiscard]] virtual std::shared_ptr<abstract_joined_resolver> acquire_collection_resolver(const std::type_index &root_type, const std::type_index &element_type, const std::string &collection_name) const = 0;
|
||||||
virtual void register_collection_resolver(std::shared_ptr<abstract_collection_resolver> &&resolver) = 0;
|
virtual void register_collection_resolver(std::shared_ptr<abstract_joined_resolver> &&resolver) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class collection_resolver_factory : public abstract_collection_resolver_factory {
|
class collection_resolver_factory : public abstract_collection_resolver_factory {
|
||||||
|
|
@ -24,5 +24,26 @@ public:
|
||||||
return std::dynamic_pointer_cast<collection_resolver<Type>>(res);
|
return std::dynamic_pointer_cast<collection_resolver<Type>>(res);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class abstract_joined_object_resolver_factory {
|
||||||
|
public:
|
||||||
|
virtual ~abstract_joined_object_resolver_factory() = default;
|
||||||
|
|
||||||
|
[[nodiscard]] virtual std::shared_ptr<abstract_joined_resolver> acquire_joined_object_resolver(const std::type_index &root_type, const std::type_index &element_type, const std::string &collection_name) const = 0;
|
||||||
|
virtual void register_joined_object_resolver(std::shared_ptr<abstract_joined_resolver> &&resolver) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class joined_object_resolver_factory : public abstract_joined_object_resolver_factory {
|
||||||
|
public:
|
||||||
|
template<class Type>
|
||||||
|
[[nodiscard]] std::shared_ptr<joined_object_resolver<Type>> resolver(const std::type_index &root_type, const std::string &collection_name) const {
|
||||||
|
const auto res = acquire_joined_object_resolver(root_type, typeid(Type), collection_name);
|
||||||
|
if (!res) {
|
||||||
|
return std::dynamic_pointer_cast<joined_object_resolver<Type>>(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::dynamic_pointer_cast<joined_object_resolver<Type>>(res);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
#endif //MATADOR_CONTAINER_RESOLVER_FACTORY_HPP
|
#endif //MATADOR_CONTAINER_RESOLVER_FACTORY_HPP
|
||||||
|
|
@ -50,7 +50,7 @@ public:
|
||||||
template<class ForeignPointerType>
|
template<class ForeignPointerType>
|
||||||
void on_belongs_to(const char *id, ForeignPointerType &/*obj*/, const utils::foreign_attributes &/*attr*/);
|
void on_belongs_to(const char *id, ForeignPointerType &/*obj*/, const utils::foreign_attributes &/*attr*/);
|
||||||
template<class ForeignPointerType>
|
template<class ForeignPointerType>
|
||||||
void on_has_one(const char * /*id*/, ForeignPointerType &/*obj*/, const utils::foreign_attributes &/*attr*/);
|
void on_has_one(const char * /*id*/, ForeignPointerType &/*obj*/, const char *join_column, const utils::foreign_attributes &/*attr*/);
|
||||||
template<class CollectionType>
|
template<class CollectionType>
|
||||||
void on_has_many(const char *id, CollectionType &,
|
void on_has_many(const char *id, CollectionType &,
|
||||||
const char *join_column,
|
const char *join_column,
|
||||||
|
|
@ -134,7 +134,7 @@ void foreign_node_completer<NodeType, Observers...>::on_belongs_to(const char *
|
||||||
|
|
||||||
template<typename NodeType, template<typename> typename ...Observers>
|
template<typename NodeType, template<typename> typename ...Observers>
|
||||||
template<class ForeignPointerType>
|
template<class ForeignPointerType>
|
||||||
void foreign_node_completer<NodeType, Observers...>::on_has_one(const char * /*id*/, ForeignPointerType &, const utils::foreign_attributes &) {
|
void foreign_node_completer<NodeType, Observers...>::on_has_one(const char * /*id*/, ForeignPointerType &, const char * /*join_column*/, const utils::foreign_attributes &) {
|
||||||
attach_node<typename ForeignPointerType::value_type>();
|
attach_node<typename ForeignPointerType::value_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ public:
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
static void on_belongs_to(const char * /*id*/, Pointer &/*obj*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_belongs_to(const char * /*id*/, Pointer &/*obj*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
static void on_has_one(const char * /*id*/, Pointer &/*obj*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_one(const char * /*id*/, Pointer &/*obj*/, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
static void on_has_many(ContainerType &, const char */*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_many(ContainerType &, const char */*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ public:
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
static void on_belongs_to(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_belongs_to(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
static void on_has_many(const char * /*id*/, ContainerType &, const char *, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_many(const char * /*id*/, ContainerType &, const char *, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
|
|
@ -92,7 +92,7 @@ public:
|
||||||
create_fk_constraint<typename Pointer::value_type>(id);
|
create_fk_constraint<typename Pointer::value_type>(id);
|
||||||
}
|
}
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
|
|
||||||
template <class Pointer>
|
template <class Pointer>
|
||||||
void on_foreign_key(const char *id, Pointer &/*x*/) {
|
void on_foreign_key(const char *id, Pointer &/*x*/) {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define MATADOR_OBJECT_LOADER_HPP
|
#define MATADOR_OBJECT_LOADER_HPP
|
||||||
|
|
||||||
#include "matador/object/abstract_type_resolver.hpp"
|
#include "matador/object/abstract_type_resolver.hpp"
|
||||||
|
#include "matador/object/abstract_joined_resolver.hpp"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
|
@ -17,5 +18,12 @@ public:
|
||||||
|
|
||||||
virtual std::shared_ptr<Type> resolve(const utils::identifier& id) = 0;
|
virtual std::shared_ptr<Type> resolve(const utils::identifier& id) = 0;
|
||||||
};
|
};
|
||||||
|
template<typename Type>
|
||||||
|
class joined_object_resolver : public abstract_joined_resolver {
|
||||||
|
public:
|
||||||
|
joined_object_resolver(const std::type_index& root_type, const std::string& join_column) : abstract_joined_resolver(root_type, typeid(Type), join_column) {}
|
||||||
|
|
||||||
|
virtual std::shared_ptr<Type> resolve(const utils::identifier& id) = 0;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
#endif //MATADOR_OBJECT_LOADER_HPP
|
#endif //MATADOR_OBJECT_LOADER_HPP
|
||||||
|
|
@ -119,7 +119,7 @@ struct pk_field_locator {
|
||||||
template <typename Pointer>
|
template <typename Pointer>
|
||||||
static void on_belongs_to(const char *, Pointer &, const utils::foreign_attributes &) {}
|
static void on_belongs_to(const char *, Pointer &, const utils::foreign_attributes &) {}
|
||||||
template <typename Pointer>
|
template <typename Pointer>
|
||||||
static void on_has_one(const char *, Pointer &, const utils::foreign_attributes &) {}
|
static void on_has_one(const char *, Pointer &, const char * /*join_column*/, const utils::foreign_attributes &) {}
|
||||||
template <typename Container>
|
template <typename Container>
|
||||||
static void on_has_many(const char *, Container &, const char *, const utils::foreign_attributes &) {}
|
static void on_has_many(const char *, Container &, const char *, const utils::foreign_attributes &) {}
|
||||||
template <typename Container>
|
template <typename Container>
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ public:
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
static void on_belongs_to(const char * /*id*/, Pointer &/*val*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_belongs_to(const char * /*id*/, Pointer &/*val*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
static void on_has_one(const char * /*id*/, Pointer &/*val*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_one(const char * /*id*/, Pointer &/*val*/, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
static void on_has_many(const char * /*id*/, ContainerType &/*col*/, const char *, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_many(const char * /*id*/, ContainerType &/*col*/, const char *, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ public:
|
||||||
found_ = requested_join_column_ == id;
|
found_ = requested_join_column_ == id;
|
||||||
}
|
}
|
||||||
template<class ForeignPointerType>
|
template<class ForeignPointerType>
|
||||||
static void on_has_one(const char * /*id*/, ForeignPointerType &/*obj*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_one(const char * /*id*/, ForeignPointerType &/*obj*/, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
|
|
||||||
template<class CollectionType>
|
template<class CollectionType>
|
||||||
static void on_has_many(const char * /*id*/, CollectionType &, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_many(const char * /*id*/, CollectionType &, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
|
|
@ -117,7 +117,7 @@ public:
|
||||||
template<class ForeignPointerType>
|
template<class ForeignPointerType>
|
||||||
void on_belongs_to(const char *id, ForeignPointerType &obj, const utils::foreign_attributes &attr);
|
void on_belongs_to(const char *id, ForeignPointerType &obj, const utils::foreign_attributes &attr);
|
||||||
template<class ForeignPointerType>
|
template<class ForeignPointerType>
|
||||||
void on_has_one(const char * /*id*/, ForeignPointerType &/*obj*/, const utils::foreign_attributes &/*attr*/);
|
void on_has_one(const char * /*id*/, ForeignPointerType &/*obj*/, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/);
|
||||||
|
|
||||||
template<class CollectionType>
|
template<class CollectionType>
|
||||||
void on_has_many(const char *id, CollectionType &, const char *join_column, const utils::foreign_attributes &attr, std::enable_if_t<is_object_ptr<typename CollectionType::value_type>::value> * = nullptr);
|
void on_has_many(const char *id, CollectionType &, const char *join_column, const utils::foreign_attributes &attr, std::enable_if_t<is_object_ptr<typename CollectionType::value_type>::value> * = nullptr);
|
||||||
|
|
@ -280,6 +280,7 @@ template<typename Type, template<typename> typename... Observers>
|
||||||
template<class ForeignPointerType>
|
template<class ForeignPointerType>
|
||||||
void relation_completer<Type, Observers...>::on_has_one(const char *id,
|
void relation_completer<Type, Observers...>::on_has_one(const char *id,
|
||||||
ForeignPointerType &/*obj*/,
|
ForeignPointerType &/*obj*/,
|
||||||
|
const char * /*join_column*/,
|
||||||
const utils::foreign_attributes &/*attr*/) {
|
const utils::foreign_attributes &/*attr*/) {
|
||||||
using value_type = typename ForeignPointerType::value_type;
|
using value_type = typename ForeignPointerType::value_type;
|
||||||
const auto foreign_node = find_node(typeid(value_type));
|
const auto foreign_node = find_node(typeid(value_type));
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ public:
|
||||||
template<class P>
|
template<class P>
|
||||||
static void on_belongs_to(const char * /*id*/, P &, const utils::foreign_attributes & ) {}
|
static void on_belongs_to(const char * /*id*/, P &, const utils::foreign_attributes & ) {}
|
||||||
template<class P>
|
template<class P>
|
||||||
static void on_has_one(const char * /*id*/, P &, const utils::foreign_attributes & ) {}
|
static void on_has_one(const char * /*id*/, P &, const char * /*join_column*/, const utils::foreign_attributes & ) {}
|
||||||
template<class C>
|
template<class C>
|
||||||
static void on_has_many(const char * /*id*/, C &, const char * /*join_column*/, const utils::foreign_attributes & ) {}
|
static void on_has_many(const char * /*id*/, C &, const char * /*join_column*/, const utils::foreign_attributes & ) {}
|
||||||
template<class C>
|
template<class C>
|
||||||
|
|
@ -103,6 +103,7 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] const std::unordered_map<std::type_index, std::unique_ptr<sql::object_resolver_producer>>& resolver_producers() const;
|
[[nodiscard]] const std::unordered_map<std::type_index, std::unique_ptr<sql::object_resolver_producer>>& resolver_producers() const;
|
||||||
[[nodiscard]] const std::unordered_map<object::collection_composite_key, std::unique_ptr<sql::collection_resolver_producer>, object::collection_composite_key_hash>& collection_resolver_producers() const;
|
[[nodiscard]] const std::unordered_map<object::collection_composite_key, std::unique_ptr<sql::collection_resolver_producer>, object::collection_composite_key_hash>& collection_resolver_producers() const;
|
||||||
|
[[nodiscard]] const std::unordered_map<object::collection_composite_key, std::unique_ptr<sql::object_resolver_producer>, object::collection_composite_key_hash>& joined_object_resolver_producers() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
|
|
@ -113,6 +114,7 @@ protected:
|
||||||
std::unordered_map<std::type_index, schema_node> schema_nodes_;
|
std::unordered_map<std::type_index, schema_node> schema_nodes_;
|
||||||
std::unordered_map<std::type_index, std::unique_ptr<sql::object_resolver_producer>> resolver_producers_;
|
std::unordered_map<std::type_index, std::unique_ptr<sql::object_resolver_producer>> resolver_producers_;
|
||||||
std::unordered_map<object::collection_composite_key, std::unique_ptr<sql::collection_resolver_producer>, object::collection_composite_key_hash> collection_resolver_producers_;
|
std::unordered_map<object::collection_composite_key, std::unique_ptr<sql::collection_resolver_producer>, object::collection_composite_key_hash> collection_resolver_producers_;
|
||||||
|
std::unordered_map<object::collection_composite_key, std::unique_ptr<sql::object_resolver_producer>, object::collection_composite_key_hash> joined_object_resolver_producers_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif //MATADOR_BASIC_SCHEMA_HPP
|
#endif //MATADOR_BASIC_SCHEMA_HPP
|
||||||
|
|
@ -89,16 +89,16 @@ struct dependency_collector {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
static void on_has_one(const char*, Pointer&, const auto&) {}
|
static void on_has_one(const char*, Pointer&, const char * /*join_column*/, const utils::foreign_attributes&) {}
|
||||||
|
|
||||||
template<class Container>
|
template<class Container>
|
||||||
static void on_has_many(const char*, Container&, const char*, const auto&) {}
|
static void on_has_many(const char*, Container&, const char*, const utils::foreign_attributes&) {}
|
||||||
|
|
||||||
template<class Container>
|
template<class Container>
|
||||||
static void on_has_many_to_many(const char*, Container&, const char*, const char*, const auto&) {}
|
static void on_has_many_to_many(const char*, Container&, const char*, const char*, const utils::foreign_attributes&) {}
|
||||||
|
|
||||||
template<class Container>
|
template<class Container>
|
||||||
static void on_has_many_to_many(const char*, Container&, const auto&) {}
|
static void on_has_many_to_many(const char*, Container&, const utils::foreign_attributes&) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct flush_node {
|
struct flush_node {
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ public:
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
static void on_belongs_to(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_belongs_to(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
static void on_has_many_to_many(const char *, ContainerType &, const char * /*join_column*/, const char * /*inverse_join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_many_to_many(const char *, ContainerType &, const char * /*join_column*/, const char * /*inverse_join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ public:
|
||||||
on_foreign_key(id, x, attr);
|
on_foreign_key(id, x, attr);
|
||||||
}
|
}
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
void on_has_one(const char *id, Pointer &x, const utils::foreign_attributes &attr) {
|
void on_has_one(const char *id, Pointer &x, const char * /*join_column*/, const utils::foreign_attributes &attr) {
|
||||||
on_foreign_key(id, x, attr);
|
on_foreign_key(id, x, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -189,7 +189,7 @@ public:
|
||||||
result_.emplace_back(utils::_);
|
result_.emplace_back(utils::_);
|
||||||
}
|
}
|
||||||
template<class Type, template < class ... > class Pointer>
|
template<class Type, template < class ... > class Pointer>
|
||||||
void on_has_one(const char * /*id*/, Pointer<Type> &/*x*/, const utils::foreign_attributes &/*attr*/) {
|
void on_has_one(const char * /*id*/, Pointer<Type> &/*x*/, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {
|
||||||
result_.emplace_back(utils::_);
|
result_.emplace_back(utils::_);
|
||||||
}
|
}
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
|
|
@ -249,7 +249,7 @@ public:
|
||||||
push_back(id, fk_value_extractor_.extract(*x));
|
push_back(id, fk_value_extractor_.extract(*x));
|
||||||
}
|
}
|
||||||
template<class Type, template < class ... > class Pointer>
|
template<class Type, template < class ... > class Pointer>
|
||||||
void on_has_one(const char *id, Pointer<Type> &x, const utils::foreign_attributes &/*attr*/) {
|
void on_has_one(const char *id, Pointer<Type> &x, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {
|
||||||
push_back(id, fk_value_extractor_.extract(*x));
|
push_back(id, fk_value_extractor_.extract(*x));
|
||||||
}
|
}
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ public:
|
||||||
obj = ptr_;
|
obj = ptr_;
|
||||||
}
|
}
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
static void on_has_one(const char * /*id*/, Pointer &/*obj*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_one(const char * /*id*/, Pointer &/*obj*/, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class CollectionType>
|
template<class CollectionType>
|
||||||
static void on_has_many(const char * /*id*/, CollectionType &/*con*/, const char *, const utils::foreign_attributes &/*attr*/, std::enable_if_t<!object::is_object_ptr<typename CollectionType::value_type>::value> * = nullptr) {}
|
static void on_has_many(const char * /*id*/, CollectionType &/*con*/, const char *, const utils::foreign_attributes &/*attr*/, std::enable_if_t<!object::is_object_ptr<typename CollectionType::value_type>::value> * = nullptr) {}
|
||||||
template<class Collection>
|
template<class Collection>
|
||||||
|
|
@ -100,7 +100,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
void on_has_one(const char * /*id*/, Pointer &obj, const utils::foreign_attributes &attr) {
|
void on_has_one(const char * /*id*/, Pointer &obj, const char * /*join_column*/, const utils::foreign_attributes &attr) {
|
||||||
on_foreign_object(obj, attr);
|
on_foreign_object(obj, attr);
|
||||||
}
|
}
|
||||||
template<class CollectionType>
|
template<class CollectionType>
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ public:
|
||||||
result_.emplace_back(id, fk_value_extractor_.extract(*x));
|
result_.emplace_back(id, fk_value_extractor_.extract(*x));
|
||||||
}
|
}
|
||||||
template<class Type, template < class ... > class Pointer>
|
template<class Type, template < class ... > class Pointer>
|
||||||
void on_has_one(const char *id, Pointer<Type> &x, const utils::foreign_attributes &/*attr*/) {
|
void on_has_one(const char *id, Pointer<Type> &x, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {
|
||||||
result_.emplace_back(id, fk_value_extractor_.extract(*x));
|
result_.emplace_back(id, fk_value_extractor_.extract(*x));
|
||||||
}
|
}
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,33 @@ private:
|
||||||
std::string pk_name_;
|
std::string pk_name_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
class query_joined_object_resolver_producer : public sql::joined_object_resolver_producer {
|
||||||
|
public:
|
||||||
|
query_joined_object_resolver_producer() = default;
|
||||||
|
query_joined_object_resolver_producer(basic_schema& repo, const table& tab, std::string pk_name, const std::type_index& root_type, std::string join_column)
|
||||||
|
: joined_object_resolver_producer(root_type, typeid(Type), join_column)
|
||||||
|
, repo_(repo)
|
||||||
|
, table_(tab)
|
||||||
|
, pk_name_(std::move(pk_name)) {}
|
||||||
|
|
||||||
|
std::shared_ptr<object::abstract_joined_resolver> produce(sql::statement&& stmt) override {
|
||||||
|
return std::make_shared<query_object_resolver<Type>>(std::move(stmt));
|
||||||
|
}
|
||||||
|
|
||||||
|
utils::result<sql::query_context, utils::error> build_query(const sql::dialect& d) override {
|
||||||
|
const auto *pk_column = table_[pk_name_];
|
||||||
|
const auto *join_column = table_[collection_name()];
|
||||||
|
|
||||||
|
return utils::ok(sql::query_context{});
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
basic_schema& repo_;
|
||||||
|
const table& table_;
|
||||||
|
std::string pk_name_;
|
||||||
|
};
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
class query_collection_resolver_producer : public sql::collection_resolver_producer {
|
class query_collection_resolver_producer : public sql::collection_resolver_producer {
|
||||||
public:
|
public:
|
||||||
|
|
@ -64,7 +91,7 @@ public:
|
||||||
return utils::ok(stmt);
|
return utils::ok(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<object::abstract_collection_resolver> produce(sql::statement&& stmt, const sql::resolver_service& rs) override {
|
std::shared_ptr<object::abstract_joined_resolver> produce(sql::statement&& stmt, const sql::resolver_service& rs) override {
|
||||||
const auto object_resolver = rs.object_resolver<typename Type::value_type>();
|
const auto object_resolver = rs.object_resolver<typename Type::value_type>();
|
||||||
|
|
||||||
return std::make_shared<query_collection_resolver<Type>>(std::move(stmt), root_type(), collection_name(), object_resolver);
|
return std::make_shared<query_collection_resolver<Type>>(std::move(stmt), root_type(), collection_name(), object_resolver);
|
||||||
|
|
@ -99,7 +126,7 @@ public:
|
||||||
return utils::ok(stmt);
|
return utils::ok(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<object::abstract_collection_resolver> produce(sql::statement&& stmt, const sql::resolver_service& /*rs*/) override {
|
std::shared_ptr<object::abstract_joined_resolver> produce(sql::statement&& stmt, const sql::resolver_service& /*rs*/) override {
|
||||||
return std::make_shared<query_collection_primitive_resolver<Type>>(std::move(stmt), root_type(), collection_name()/*, object_resolver*/);
|
return std::make_shared<query_collection_primitive_resolver<Type>>(std::move(stmt), root_type(), collection_name()/*, object_resolver*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,7 +153,7 @@ public:
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
static void on_belongs_to(const char * /*id*/, Pointer & /*x*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_belongs_to(const char * /*id*/, Pointer & /*x*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
void on_has_one(const char * /*id*/, Pointer & /*x*/, const utils::foreign_attributes &/*attr*/) {
|
void on_has_one(const char * /*id*/, Pointer & /*x*/, const char *join_column, const utils::foreign_attributes &/*attr*/) {
|
||||||
const auto it = schema_.find(typeid(typename Pointer::value_type));
|
const auto it = schema_.find(typeid(typename Pointer::value_type));
|
||||||
if (it == schema_.end()) {
|
if (it == schema_.end()) {
|
||||||
throw query_builder_exception{error_code::UnknownType, "Unknown type"};
|
throw query_builder_exception{error_code::UnknownType, "Unknown type"};
|
||||||
|
|
@ -135,8 +162,12 @@ public:
|
||||||
throw query_builder_exception{error_code::MissingPrimaryKey, "Missing primary key"};
|
throw query_builder_exception{error_code::MissingPrimaryKey, "Missing primary key"};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto producer = std::make_unique<query_object_resolver_producer<typename Pointer::value_type>>(schema_, it->second.table(), it->second.node().info().primary_key_attribute()->name());
|
auto producer = std::make_unique<query_object_resolver_producer<typename Pointer::value_type>>(
|
||||||
schema_.resolver_producers_[typeid(typename Pointer::value_type)] = std::move(producer);
|
schema_,
|
||||||
|
it->second.table(),
|
||||||
|
join_column);
|
||||||
|
const object::collection_composite_key key{root_type_, typeid(Pointer), join_column};
|
||||||
|
schema_.joined_object_resolver_producers_[key] = std::move(producer);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class CollectionType>
|
template<class CollectionType>
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
void on_has_one(const char *id, Pointer &obj, const utils::foreign_attributes &attr) {
|
void on_has_one(const char *id, Pointer &obj, const char * /*join_column*/, const utils::foreign_attributes &attr) {
|
||||||
on_foreign_object(id, obj, attr, false);
|
on_foreign_object(id, obj, attr, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ public:
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
static void on_belongs_to(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_belongs_to(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
|
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
static void on_has_many(const char * /*id*/,
|
static void on_has_many(const char * /*id*/,
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,7 @@ public:
|
||||||
values_.emplace_back(fk_value_extractor_.extract(*x));
|
values_.emplace_back(fk_value_extractor_.extract(*x));
|
||||||
}
|
}
|
||||||
template<class Type, template < class ... > class Pointer>
|
template<class Type, template < class ... > class Pointer>
|
||||||
void on_has_one(const char * /*id*/, Pointer<Type> &x, const utils::foreign_attributes &/*attr*/)
|
void on_has_one(const char * /*id*/, Pointer<Type> &x, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {
|
||||||
{
|
|
||||||
values_.emplace_back(fk_value_extractor_.extract(*x));
|
values_.emplace_back(fk_value_extractor_.extract(*x));
|
||||||
}
|
}
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ public:
|
||||||
on_foreign_key(id, x, attr);
|
on_foreign_key(id, x, attr);
|
||||||
}
|
}
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
void on_has_one(const char *id, Pointer &x, const utils::foreign_attributes &attr) {
|
void on_has_one(const char *id, Pointer &x, const char * /*join_column*/, const utils::foreign_attributes &attr) {
|
||||||
on_foreign_key(id, x, attr);
|
on_foreign_key(id, x, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef MATADOR_COLLECTION_RESOLVER_PRODUCER_HPP
|
#ifndef MATADOR_COLLECTION_RESOLVER_PRODUCER_HPP
|
||||||
#define MATADOR_COLLECTION_RESOLVER_PRODUCER_HPP
|
#define MATADOR_COLLECTION_RESOLVER_PRODUCER_HPP
|
||||||
|
|
||||||
#include "matador/object/abstract_collection_resolver.hpp"
|
#include "matador/object/abstract_joined_resolver.hpp"
|
||||||
|
|
||||||
#include "matador/sql/query_context.hpp"
|
#include "matador/sql/query_context.hpp"
|
||||||
|
|
||||||
|
|
@ -18,7 +18,7 @@ class collection_resolver_producer {
|
||||||
public:
|
public:
|
||||||
virtual ~collection_resolver_producer() = default;
|
virtual ~collection_resolver_producer() = default;
|
||||||
virtual utils::result<query_context, utils::error> build_query(const dialect& d) = 0;
|
virtual utils::result<query_context, utils::error> build_query(const dialect& d) = 0;
|
||||||
virtual std::shared_ptr<object::abstract_collection_resolver> produce(statement&& stmt, const resolver_service& rs) = 0;
|
virtual std::shared_ptr<object::abstract_joined_resolver> produce(statement&& stmt, const resolver_service& rs) = 0;
|
||||||
|
|
||||||
[[nodiscard]] const std::type_index& root_type() const;
|
[[nodiscard]] const std::type_index& root_type() const;
|
||||||
[[nodiscard]] const std::type_index& type() const;
|
[[nodiscard]] const std::type_index& type() const;
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ public:
|
||||||
template < class Pointer >
|
template < class Pointer >
|
||||||
static void on_belongs_to(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_belongs_to(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template < class Pointer >
|
template < class Pointer >
|
||||||
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
static void on_has_many(const char * /*id*/, ContainerType &, const char *, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_many(const char * /*id*/, ContainerType &, const char *, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
|
|
|
||||||
|
|
@ -27,5 +27,24 @@ protected:
|
||||||
private:
|
private:
|
||||||
std::type_index type_;
|
std::type_index type_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class joined_object_resolver_producer {
|
||||||
|
public:
|
||||||
|
virtual ~joined_object_resolver_producer() = default;
|
||||||
|
virtual utils::result<query_context, utils::error> build_query(const dialect& d) = 0;
|
||||||
|
virtual std::shared_ptr<object::abstract_joined_resolver> produce(statement&& stmt) = 0;
|
||||||
|
|
||||||
|
[[nodiscard]] const std::type_index& root_type() const;
|
||||||
|
[[nodiscard]] const std::type_index& type() const;
|
||||||
|
[[nodiscard]] const std::string& collection_name() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
explicit joined_object_resolver_producer(const std::type_index &root_type, const std::type_index &type, std::string collection_name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::type_index root_type_;
|
||||||
|
std::type_index type_;
|
||||||
|
std::string collection_name_;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
#endif //MATADOR_RESOLVER_PRODUCER_HPP
|
#endif //MATADOR_RESOLVER_PRODUCER_HPP
|
||||||
|
|
@ -38,7 +38,7 @@ public:
|
||||||
template < class Pointer >
|
template < class Pointer >
|
||||||
static void on_belongs_to(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_belongs_to(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template < class Pointer >
|
template < class Pointer >
|
||||||
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
|
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
static void on_has_many(const char * /*id*/,
|
static void on_has_many(const char * /*id*/,
|
||||||
|
|
@ -96,7 +96,7 @@ public:
|
||||||
fk_result_binder_.bind(*x, id, index_++, *binder_);
|
fk_result_binder_.bind(*x, id, index_++, *binder_);
|
||||||
}
|
}
|
||||||
template<class Type, template < class ... > class Pointer>
|
template<class Type, template < class ... > class Pointer>
|
||||||
void on_has_one(const char *id, Pointer<Type> &x, const utils::foreign_attributes &/*attr*/) {
|
void on_has_one(const char *id, Pointer<Type> &x, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {
|
||||||
fk_result_binder_.bind(*x, id, index_++, *binder_);
|
fk_result_binder_.bind(*x, id, index_++, *binder_);
|
||||||
}
|
}
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ public:
|
||||||
++column_index_;
|
++column_index_;
|
||||||
}
|
}
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
static void on_has_many(const char * /*id*/, ContainerType &, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_many(const char * /*id*/, ContainerType &, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
|
|
|
||||||
|
|
@ -63,15 +63,9 @@ public:
|
||||||
void on_attribute(const char *id, utils::value &val, const utils::field_attributes &attr);
|
void on_attribute(const char *id, utils::value &val, const utils::field_attributes &attr);
|
||||||
|
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
void on_belongs_to(const char * /*id*/, Pointer &x, const utils::foreign_attributes &attr) {
|
void on_belongs_to(const char * /*id*/, Pointer &x, const utils::foreign_attributes &attr);
|
||||||
on_foreign_key(x, attr);
|
template<class PointerType>
|
||||||
}
|
void on_has_one(const char * /*id*/, object::object_ptr<PointerType> &x, const char * /*join_column*/, const utils::foreign_attributes &attr);
|
||||||
|
|
||||||
template<class Pointer>
|
|
||||||
void on_has_one(const char * /*id*/, Pointer &x, const utils::foreign_attributes &attr) {
|
|
||||||
on_foreign_key(x, attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class CollectionType>
|
template<class CollectionType>
|
||||||
void on_has_many(const char * /*id*/, CollectionType &cont, const char *join_column, const utils::foreign_attributes &attr, std::enable_if_t<object::is_object_ptr<typename CollectionType::value_type>::value> * = nullptr);
|
void on_has_many(const char * /*id*/, CollectionType &cont, const char *join_column, const utils::foreign_attributes &attr, std::enable_if_t<object::is_object_ptr<typename CollectionType::value_type>::value> * = nullptr);
|
||||||
template<class CollectionType>
|
template<class CollectionType>
|
||||||
|
|
@ -103,23 +97,6 @@ private:
|
||||||
return resolver.discover(obj);
|
return resolver.discover(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Pointer>
|
|
||||||
void on_foreign_key(Pointer &x, const utils::foreign_attributes &attr) {
|
|
||||||
const auto resolver = resolver_->object_resolver<typename Pointer::value_type>();
|
|
||||||
if (attr.fetch() == utils::fetch_type::Lazy) {
|
|
||||||
typename Pointer::value_type obj;
|
|
||||||
auto pk = id_reader_.read(obj, column_index_++);
|
|
||||||
x = Pointer(std::make_shared<object::object_proxy<typename Pointer::value_type>>(resolver, pk));
|
|
||||||
} else {
|
|
||||||
auto obj = std::make_shared<typename Pointer::value_type>();
|
|
||||||
const auto ti = std::type_index(typeid(*x));
|
|
||||||
type_stack_.push(ti);
|
|
||||||
access::process(*this, *obj);
|
|
||||||
type_stack_.pop();
|
|
||||||
x = Pointer(std::make_shared<object::object_proxy<typename Pointer::value_type>>(resolver, obj));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
size_t column_index_ = 0;
|
size_t column_index_ = 0;
|
||||||
std::vector<object::attribute> prototype_;
|
std::vector<object::attribute> prototype_;
|
||||||
|
|
@ -134,6 +111,38 @@ protected:
|
||||||
std::unordered_set<object::collection_composite_key, object::collection_composite_key_hash> initialized_collections_;
|
std::unordered_set<object::collection_composite_key, object::collection_composite_key_hash> initialized_collections_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class Pointer>
|
||||||
|
void query_result_impl::on_belongs_to(const char*, Pointer& x, const utils::foreign_attributes& attr) {
|
||||||
|
const auto resolver = resolver_->object_resolver<typename Pointer::value_type>();
|
||||||
|
if (attr.fetch() == utils::fetch_type::Lazy) {
|
||||||
|
typename Pointer::value_type obj;
|
||||||
|
auto pk = id_reader_.read(obj, column_index_++);
|
||||||
|
x = Pointer(std::make_shared<object::object_proxy<typename Pointer::value_type>>(resolver, pk));
|
||||||
|
} else {
|
||||||
|
auto obj = std::make_shared<typename Pointer::value_type>();
|
||||||
|
const auto ti = std::type_index(typeid(*x));
|
||||||
|
type_stack_.push(ti);
|
||||||
|
access::process(*this, *obj);
|
||||||
|
type_stack_.pop();
|
||||||
|
x = Pointer(std::make_shared<object::object_proxy<typename Pointer::value_type>>(resolver, obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class PointerType>
|
||||||
|
void query_result_impl::on_has_one(const char*, object::object_ptr<PointerType>& x, const char *join_column, const utils::foreign_attributes& attr) {
|
||||||
|
const auto resolver = resolver_->collection_resolver<PointerType>(result_type_, join_column);
|
||||||
|
if (attr.fetch() == utils::fetch_type::Lazy) {
|
||||||
|
x = object::object_ptr<PointerType>(std::make_shared<object::object_proxy<PointerType>>(resolver, id_reader_.read(x, column_index_++)));
|
||||||
|
} else {
|
||||||
|
auto obj = std::make_shared<PointerType>();
|
||||||
|
const auto ti = std::type_index(typeid(*x));
|
||||||
|
type_stack_.push(ti);
|
||||||
|
access::process(*this, *obj);
|
||||||
|
type_stack_.pop();
|
||||||
|
x = object::object_ptr<PointerType>(std::make_shared<object::object_proxy<PointerType>>(resolver, obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <class CollectionType>
|
template <class CollectionType>
|
||||||
void query_result_impl::on_has_many(const char *, CollectionType &cont, const char *join_column, const utils::foreign_attributes &attr, std::enable_if_t<object::is_object_ptr<typename CollectionType::value_type>::value> *) {
|
void query_result_impl::on_has_many(const char *, CollectionType &cont, const char *join_column, const utils::foreign_attributes &attr, std::enable_if_t<object::is_object_ptr<typename CollectionType::value_type>::value> *) {
|
||||||
using value_type = typename CollectionType::value_type::value_type;
|
using value_type = typename CollectionType::value_type::value_type;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,8 @@ namespace matador::sql::internal {
|
||||||
|
|
||||||
class query_result_pk_resolver final {
|
class query_result_pk_resolver final {
|
||||||
public:
|
public:
|
||||||
explicit query_result_pk_resolver(query_result_reader &reader) : reader_(reader) {}
|
explicit query_result_pk_resolver(query_result_reader &reader)
|
||||||
|
: reader_(reader) {}
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
utils::identifier discover(Type &obj) {
|
utils::identifier discover(Type &obj) {
|
||||||
|
|
@ -38,16 +39,22 @@ public:
|
||||||
utils::data_type_traits<ValueType>::read_value(reader_, id, column_index_++, value, attr.size());
|
utils::data_type_traits<ValueType>::read_value(reader_, id, column_index_++, value, attr.size());
|
||||||
pk_ = value;
|
pk_ = value;
|
||||||
}
|
}
|
||||||
void on_revision(const char * /*id*/, uint64_t &/*rev*/) { ++column_index_; }
|
void on_revision(const char * /*id*/, uint64_t &/*rev*/) {
|
||||||
|
++column_index_;
|
||||||
|
}
|
||||||
|
|
||||||
template < class Type >
|
template < class Type >
|
||||||
void on_attribute(const char * /*id*/, Type &/*x*/, const utils::field_attributes &/*attr*/) { ++column_index_; }
|
void on_attribute(const char * /*id*/, Type &/*x*/, const utils::field_attributes &/*attr*/) { ++column_index_; }
|
||||||
void on_attribute(const char *id, const utils::value &x, const utils::field_attributes &attr);
|
void on_attribute(const char *id, const utils::value &x, const utils::field_attributes &attr);
|
||||||
|
|
||||||
template < class Pointer >
|
template < class Pointer >
|
||||||
void on_belongs_to(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &attr) { on_foreign_key<typename Pointer::value_type>(attr.fetch() ); }
|
void on_belongs_to(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &attr) {
|
||||||
|
on_foreign_key<typename Pointer::value_type>(attr.fetch() );
|
||||||
|
}
|
||||||
template < class Pointer >
|
template < class Pointer >
|
||||||
void on_has_one(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &attr) { on_foreign_key<typename Pointer::value_type>(attr.fetch() ); }
|
void on_has_one(const char * /*id*/, Pointer &/*x*/, const char * /*join_column*/, const utils::foreign_attributes &attr) {
|
||||||
|
on_foreign_key<typename Pointer::value_type>(attr.fetch() );
|
||||||
|
}
|
||||||
|
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
static void on_has_many(const char * /*id*/, ContainerType &, const char *, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_many(const char * /*id*/, ContainerType &, const char *, const utils::foreign_attributes &/*attr*/) {}
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ public:
|
||||||
template<class Type, template < class ... > class Pointer>
|
template<class Type, template < class ... > class Pointer>
|
||||||
static void on_has_one(const char * /*id*/,
|
static void on_has_one(const char * /*id*/,
|
||||||
Pointer<Type> &/*x*/,
|
Pointer<Type> &/*x*/,
|
||||||
|
const char * /*join_column*/,
|
||||||
const utils::foreign_attributes &/*attr*/) {}
|
const utils::foreign_attributes &/*attr*/) {}
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
static void on_has_many(const char * /*id*/,
|
static void on_has_many(const char * /*id*/,
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ public:
|
||||||
template < class Pointer >
|
template < class Pointer >
|
||||||
static void on_belongs_to(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_belongs_to(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
template < class Pointer >
|
template < class Pointer >
|
||||||
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
|
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
static void on_has_many(const char * /*id*/,
|
static void on_has_many(const char * /*id*/,
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "matador/object/abstract_collection_resolver.hpp"
|
#include "matador/object/abstract_joined_resolver.hpp"
|
||||||
#include "matador/object/object_resolver_factory.hpp"
|
#include "matador/object/object_resolver_factory.hpp"
|
||||||
#include "matador/object/collection_resolver_factory.hpp"
|
#include "matador/object/collection_resolver_factory.hpp"
|
||||||
#include "matador/object/collection_utils.hpp"
|
#include "matador/object/collection_utils.hpp"
|
||||||
|
|
@ -22,13 +22,24 @@ private:
|
||||||
|
|
||||||
class producer_collection_resolver_factory : public object::collection_resolver_factory {
|
class producer_collection_resolver_factory : public object::collection_resolver_factory {
|
||||||
public:
|
public:
|
||||||
[[nodiscard]] std::shared_ptr<object::abstract_collection_resolver> acquire_collection_resolver(const std::type_index& root_type,
|
[[nodiscard]] std::shared_ptr<object::abstract_joined_resolver> acquire_collection_resolver(const std::type_index& root_type,
|
||||||
const std::type_index& element_type,
|
const std::type_index& element_type,
|
||||||
const std::string& collection_name) const override;
|
const std::string& collection_name) const override;
|
||||||
void register_collection_resolver(std::shared_ptr<object::abstract_collection_resolver>&& resolver) override;
|
void register_collection_resolver(std::shared_ptr<object::abstract_joined_resolver>&& resolver) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<object::collection_composite_key, std::shared_ptr<object::abstract_collection_resolver>, object::collection_composite_key_hash> resolvers_;
|
std::unordered_map<object::collection_composite_key, std::shared_ptr<object::abstract_joined_resolver>, object::collection_composite_key_hash> resolvers_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class producer_joined_object_resolver_factory : public object::joined_object_resolver_factory {
|
||||||
|
public:
|
||||||
|
[[nodiscard]] std::shared_ptr<object::abstract_joined_resolver> acquire_joined_object_resolver(const std::type_index& root_type,
|
||||||
|
const std::type_index& element_type,
|
||||||
|
const std::string& collection_name) const override;
|
||||||
|
void register_joined_object_resolver(std::shared_ptr<object::abstract_joined_resolver>&& resolver) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unordered_map<object::collection_composite_key, std::shared_ptr<object::abstract_joined_resolver>, object::collection_composite_key_hash> resolvers_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif //MATADOR_RESOLVER_FACTORY_HPP
|
#endif //MATADOR_RESOLVER_FACTORY_HPP
|
||||||
|
|
@ -16,12 +16,19 @@ public:
|
||||||
return collection_resolver_factory_.resolver<Type>(root_type, collection_name);
|
return collection_resolver_factory_.resolver<Type>(root_type, collection_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
std::shared_ptr<object::collection_resolver<Type>> joined_object_resolver(const std::type_index &root_type, const std::string &join_column) const {
|
||||||
|
return joined_object_resolver_factory_.resolver<Type>(root_type, join_column);
|
||||||
|
}
|
||||||
|
|
||||||
void register_object_resolver(std::shared_ptr<object::abstract_type_resolver> &&resolver);
|
void register_object_resolver(std::shared_ptr<object::abstract_type_resolver> &&resolver);
|
||||||
void register_collection_resolver(std::shared_ptr<object::abstract_collection_resolver>&& resolver);
|
void register_collection_resolver(std::shared_ptr<object::abstract_joined_resolver>&& resolver);
|
||||||
|
void register_joined_object_resolver(std::shared_ptr<object::abstract_type_resolver>&& resolver);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sql::producer_resolver_factory object_resolver_factory_;
|
sql::producer_resolver_factory object_resolver_factory_;
|
||||||
sql::producer_collection_resolver_factory collection_resolver_factory_;
|
sql::producer_collection_resolver_factory collection_resolver_factory_;
|
||||||
|
sql::producer_resolver_factory joined_object_resolver_factory_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // MATADOR_RESOLVER_SERVICE_HPP
|
#endif // MATADOR_RESOLVER_SERVICE_HPP
|
||||||
|
|
|
||||||
|
|
@ -53,13 +53,13 @@ void attribute(Operator &op, const char *id, std::optional<Type> &value, const u
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Operator, class Type>
|
template<class Operator, class Type>
|
||||||
void has_one(Operator &op, const char *id, Type &value, const utils::foreign_attributes &attr = utils::CascadeNoneFetchLazy) {
|
void belongs_to(Operator &op, const char *id, Type &value, const utils::foreign_attributes &attr = utils::CascadeNoneFetchLazy) {
|
||||||
op.on_has_one(id, value, attr);
|
op.on_belongs_to(id, value, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Operator, class Type>
|
template<class Operator, class Type>
|
||||||
void belongs_to(Operator &op, const char *id, Type &value, const utils::foreign_attributes &attr = utils::CascadeNoneFetchLazy) {
|
void has_one(Operator &op, const char *id, Type &value, const char *join_column, const utils::foreign_attributes &attr = utils::CascadeNoneFetchLazy) {
|
||||||
op.on_belongs_to(id, value, attr);
|
op.on_has_one(id, value, join_column, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Operator, class Type, template<class ...> class ContainerType>
|
template<class Operator, class Type, template<class ...> class ContainerType>
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ public:
|
||||||
template<class P>
|
template<class P>
|
||||||
static void on_belongs_to(const char * /*id*/, P &, const foreign_attributes & ) {}
|
static void on_belongs_to(const char * /*id*/, P &, const foreign_attributes & ) {}
|
||||||
template<class P>
|
template<class P>
|
||||||
static void on_has_one(const char * /*id*/, P &, const foreign_attributes & ) {}
|
static void on_has_one(const char * /*id*/, P &, const char * /*join_column*/, const foreign_attributes & ) {}
|
||||||
template<class C>
|
template<class C>
|
||||||
static void on_has_many(const char * /*id*/, C &, const char * /*join_column*/, const foreign_attributes & ) {}
|
static void on_has_many(const char * /*id*/, C &, const char * /*join_column*/, const foreign_attributes & ) {}
|
||||||
template<class C>
|
template<class C>
|
||||||
|
|
@ -65,7 +65,7 @@ struct pk_unset_checker {
|
||||||
template<class P>
|
template<class P>
|
||||||
static void on_belongs_to(const char * /*id*/, P &, const foreign_attributes & ) {}
|
static void on_belongs_to(const char * /*id*/, P &, const foreign_attributes & ) {}
|
||||||
template<class P>
|
template<class P>
|
||||||
static void on_has_one(const char * /*id*/, P &, const foreign_attributes & ) {}
|
static void on_has_one(const char * /*id*/, P &, const char * /*join_column*/, const foreign_attributes & ) {}
|
||||||
template<class C>
|
template<class C>
|
||||||
static void on_has_many(const char * /*id*/, C &, const char * /*join_column*/, const foreign_attributes & ) {}
|
static void on_has_many(const char * /*id*/, C &, const char * /*join_column*/, const foreign_attributes & ) {}
|
||||||
template<class C>
|
template<class C>
|
||||||
|
|
@ -89,7 +89,7 @@ struct primary_key_getter {
|
||||||
template<class P>
|
template<class P>
|
||||||
static void on_belongs_to(const char * /*id*/, P &, const foreign_attributes & ) {}
|
static void on_belongs_to(const char * /*id*/, P &, const foreign_attributes & ) {}
|
||||||
template<class P>
|
template<class P>
|
||||||
static void on_has_one(const char * /*id*/, P &, const foreign_attributes & ) {}
|
static void on_has_one(const char * /*id*/, P &, const char * /*join_column*/, const foreign_attributes & ) {}
|
||||||
template<class C>
|
template<class C>
|
||||||
static void on_has_many(const char * /*id*/, C &, const char * /*join_column*/, const foreign_attributes & ) {}
|
static void on_has_many(const char * /*id*/, C &, const char * /*join_column*/, const foreign_attributes & ) {}
|
||||||
template<class C>
|
template<class C>
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ add_library(matador-core STATIC
|
||||||
../../include/matador/net/reactor.hpp
|
../../include/matador/net/reactor.hpp
|
||||||
../../include/matador/net/select_fd_sets.hpp
|
../../include/matador/net/select_fd_sets.hpp
|
||||||
../../include/matador/net/socket_interrupter.hpp
|
../../include/matador/net/socket_interrupter.hpp
|
||||||
../../include/matador/object/abstract_collection_resolver.hpp
|
../../include/matador/object/abstract_joined_resolver.hpp
|
||||||
../../include/matador/object/abstract_type_resolver.hpp
|
../../include/matador/object/abstract_type_resolver.hpp
|
||||||
../../include/matador/object/abstract_type_resolver_factory.hpp
|
../../include/matador/object/abstract_type_resolver_factory.hpp
|
||||||
../../include/matador/object/attribute.hpp
|
../../include/matador/object/attribute.hpp
|
||||||
|
|
@ -92,7 +92,7 @@ add_library(matador-core STATIC
|
||||||
logger/log_manager.cpp
|
logger/log_manager.cpp
|
||||||
logger/logger.cpp
|
logger/logger.cpp
|
||||||
logger/rotating_file_sink.cpp
|
logger/rotating_file_sink.cpp
|
||||||
object/abstract_collection_resolver.cpp
|
object/abstract_joined_resolver.cpp
|
||||||
object/attribute.cpp
|
object/attribute.cpp
|
||||||
object/basic_object_info.cpp
|
object/basic_object_info.cpp
|
||||||
object/basic_repository.cpp
|
object/basic_repository.cpp
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
#include "matador/object/abstract_collection_resolver.hpp"
|
|
||||||
|
|
||||||
namespace matador::object {
|
|
||||||
|
|
||||||
const std::type_index& abstract_collection_resolver::root_type() const {
|
|
||||||
return root_type_;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::type_index& abstract_collection_resolver::type() const {
|
|
||||||
return type_;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& abstract_collection_resolver::collection_name() const {
|
|
||||||
return collection_name_;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract_collection_resolver::abstract_collection_resolver(const std::type_index& root_type, const std::type_index& type, std::string collection_name)
|
|
||||||
: root_type_(root_type)
|
|
||||||
, type_(type)
|
|
||||||
, collection_name_(std::move(collection_name)) {}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace matador::object
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
#include "matador/object/abstract_collection_resolver.hpp"
|
||||||
|
|
||||||
|
namespace matador::object {
|
||||||
|
const std::type_index& abstract_joined_resolver::root_type() const {
|
||||||
|
return root_type_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& abstract_joined_resolver::collection_name() const {
|
||||||
|
return collection_name_;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract_joined_resolver::abstract_joined_resolver(const std::type_index& root_type, const std::type_index& type, std::string collection_name)
|
||||||
|
: abstract_type_resolver(type)
|
||||||
|
, root_type_(root_type)
|
||||||
|
, collection_name_(std::move(collection_name)) {}
|
||||||
|
} // namespace matador::object
|
||||||
|
|
@ -145,6 +145,10 @@ const std::unordered_map<object::collection_composite_key, std::unique_ptr<sql::
|
||||||
return collection_resolver_producers_;
|
return collection_resolver_producers_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::unordered_map<object::collection_composite_key, std::unique_ptr<sql::object_resolver_producer>, object::collection_composite_key_hash>& basic_schema::joined_object_resolver_producers() const {
|
||||||
|
return joined_object_resolver_producers_;
|
||||||
|
}
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
utils::result<void, utils::error> create_tables(const object::repository &repo, const sql::connection &conn) {
|
utils::result<void, utils::error> create_tables(const object::repository &repo, const sql::connection &conn) {
|
||||||
for (const auto &node: repo) {
|
for (const auto &node: repo) {
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,23 @@ session::session(session_context&& ctx, const basic_schema &scm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const auto &pair : schema_.joined_object_resolver_producers()) {
|
||||||
|
auto res = pair.second->build_query(dialect_).and_then([this](sql::query_context&& query_ctx) -> result<sql::statement, error> {
|
||||||
|
query_ctx.resolver = resolver_service_;
|
||||||
|
return cache_.acquire(query_ctx);
|
||||||
|
}).and_then([&pair, this](sql::statement&& stmt) -> result<void, error> {
|
||||||
|
resolver_service_->register_collection_resolver(pair.second->produce(std::move(stmt), *resolver_service_));
|
||||||
|
|
||||||
|
return ok<void>();
|
||||||
|
}).or_else([](const auto &err) {
|
||||||
|
return failure(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res) {
|
||||||
|
throw std::runtime_error(res.err().message());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto &pair : schema_.collection_resolver_producers()) {
|
for (const auto &pair : schema_.collection_resolver_producers()) {
|
||||||
auto res = pair.second->build_query(dialect_).and_then([this](sql::query_context&& query_ctx) -> result<sql::statement, error> {
|
auto res = pair.second->build_query(dialect_).and_then([this](sql::query_context&& query_ctx) -> result<sql::statement, error> {
|
||||||
query_ctx.resolver = resolver_service_;
|
query_ctx.resolver = resolver_service_;
|
||||||
|
|
|
||||||
|
|
@ -8,3 +8,20 @@ const std::type_index & object_resolver_producer::type() const {
|
||||||
object_resolver_producer::object_resolver_producer(const std::type_index &type)
|
object_resolver_producer::object_resolver_producer(const std::type_index &type)
|
||||||
: type_(type) {}
|
: type_(type) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::type_index& matador::sql::joined_object_resolver_producer::root_type() const {
|
||||||
|
return root_type_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::type_index& matador::sql::joined_object_resolver_producer::type() const {
|
||||||
|
return type_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& matador::sql::joined_object_resolver_producer::collection_name() const {
|
||||||
|
return collection_name_;
|
||||||
|
}
|
||||||
|
|
||||||
|
matador::sql::joined_object_resolver_producer::joined_object_resolver_producer(const std::type_index& root_type, const std::type_index& type, std::string collection_name)
|
||||||
|
: root_type_(root_type)
|
||||||
|
, type_(type)
|
||||||
|
, collection_name_(std::move(collection_name)) {}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ std::shared_ptr<object::abstract_type_resolver> producer_resolver_factory::acqui
|
||||||
void producer_resolver_factory::register_object_resolver(std::shared_ptr<object::abstract_type_resolver> &&resolver) {
|
void producer_resolver_factory::register_object_resolver(std::shared_ptr<object::abstract_type_resolver> &&resolver) {
|
||||||
resolvers_[resolver->type()] = std::move(resolver);
|
resolvers_[resolver->type()] = std::move(resolver);
|
||||||
}
|
}
|
||||||
std::shared_ptr<object::abstract_collection_resolver>
|
std::shared_ptr<object::abstract_joined_resolver>
|
||||||
producer_collection_resolver_factory::acquire_collection_resolver(const std::type_index& root_type,
|
producer_collection_resolver_factory::acquire_collection_resolver(const std::type_index& root_type,
|
||||||
const std::type_index& element_type,
|
const std::type_index& element_type,
|
||||||
const std::string& collection_name) const {
|
const std::string& collection_name) const {
|
||||||
|
|
@ -21,7 +21,22 @@ producer_collection_resolver_factory::acquire_collection_resolver(const std::typ
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
void producer_collection_resolver_factory::register_collection_resolver(std::shared_ptr<object::abstract_collection_resolver>&& resolver) {
|
void producer_collection_resolver_factory::register_collection_resolver(std::shared_ptr<object::abstract_joined_resolver>&& resolver) {
|
||||||
|
const object::collection_composite_key key{resolver->root_type(), resolver->type(), resolver->collection_name()};
|
||||||
|
resolvers_[key] = std::move(resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<object::abstract_joined_resolver> producer_joined_object_resolver_factory::acquire_joined_object_resolver(const std::type_index& root_type,
|
||||||
|
const std::type_index& element_type,
|
||||||
|
const std::string& collection_name) const {
|
||||||
|
const object::collection_composite_key key{root_type, element_type, collection_name};
|
||||||
|
if (const auto it = resolvers_.find(key); it != resolvers_.end()) {
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void producer_joined_object_resolver_factory::register_joined_object_resolver(std::shared_ptr<object::abstract_joined_resolver>&& resolver) {
|
||||||
const object::collection_composite_key key{resolver->root_type(), resolver->type(), resolver->collection_name()};
|
const object::collection_composite_key key{resolver->root_type(), resolver->type(), resolver->collection_name()};
|
||||||
resolvers_[key] = std::move(resolver);
|
resolvers_[key] = std::move(resolver);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,12 @@ namespace matador::sql {
|
||||||
void resolver_service::register_object_resolver(std::shared_ptr<object::abstract_type_resolver>&& resolver) {
|
void resolver_service::register_object_resolver(std::shared_ptr<object::abstract_type_resolver>&& resolver) {
|
||||||
object_resolver_factory_.register_object_resolver(std::move(resolver));
|
object_resolver_factory_.register_object_resolver(std::move(resolver));
|
||||||
}
|
}
|
||||||
void resolver_service::register_collection_resolver(std::shared_ptr<object::abstract_collection_resolver>&& resolver) {
|
|
||||||
|
void resolver_service::register_collection_resolver(std::shared_ptr<object::abstract_joined_resolver>&& resolver) {
|
||||||
collection_resolver_factory_.register_collection_resolver(std::move(resolver));
|
collection_resolver_factory_.register_collection_resolver(std::move(resolver));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void resolver_service::register_joined_object_resolver(std::shared_ptr<object::abstract_type_resolver>&& resolver) {
|
||||||
|
joined_object_resolver_factory_.register_object_resolver(std::move(resolver));
|
||||||
|
}
|
||||||
} // namespace matador::query
|
} // namespace matador::query
|
||||||
|
|
@ -29,5 +29,7 @@ TEST_CASE_METHOD(SessionFixture, "Test insert object with has_one relation", "[s
|
||||||
REQUIRE(us.is_persistent());
|
REQUIRE(us.is_persistent());
|
||||||
REQUIRE(u.is_persistent());
|
REQUIRE(u.is_persistent());
|
||||||
|
|
||||||
REQUIRE(u->session->session_token == "session1");
|
const auto user_result = ses.find<user_identity>(u->id);
|
||||||
|
REQUIRE(user_result.is_ok());
|
||||||
|
REQUIRE(user_result.value()->session->session_token == "session1");
|
||||||
}
|
}
|
||||||
|
|
@ -31,7 +31,7 @@ struct user_pk_generator {
|
||||||
field::primary_key(op, "id", id, PkAttribute);
|
field::primary_key(op, "id", id, PkAttribute);
|
||||||
field::attribute(op, "name", name, UniqueVarChar255);
|
field::attribute(op, "name", name, UniqueVarChar255);
|
||||||
field::attribute(op, "password", password, UniqueVarChar255);
|
field::attribute(op, "password", password, UniqueVarChar255);
|
||||||
field::has_one(op, "session", session, CascadeAllFetchLazy);
|
field::has_one(op, "session", session, "user_id", CascadeAllFetchLazy);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue