attaching schema nodes progress
This commit is contained in:
@@ -97,7 +97,6 @@ public:
|
||||
columns_.push_back(fk_column_generator_.generate(id, temp_val, *result));
|
||||
} else {
|
||||
columns_.push_back(fk_column_generator_.generate(id, *x, *result));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,6 +121,9 @@ private:
|
||||
static void link_relation_endpoints(const endpoint_ptr &endpoint,
|
||||
const endpoint_ptr &other_endpoint);
|
||||
|
||||
template<typename ValueType>
|
||||
void ensure_type_is_known();
|
||||
|
||||
private:
|
||||
std::shared_ptr<schema_node> node_;
|
||||
schema &schema_;
|
||||
@@ -143,7 +146,7 @@ public:
|
||||
template<typename Type>
|
||||
[[nodiscard]] utils::result<void, utils::error> attach(const std::string &name, const std::string &parent = "") {
|
||||
// if (has_node(name)) {
|
||||
// return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + name + "' already exists"));
|
||||
// return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + name + "' already exists"));
|
||||
// }
|
||||
auto node = schema_node::make_node<Type>(*this, name);
|
||||
relation_completer<Type>::complete(node);
|
||||
@@ -241,10 +244,14 @@ private:
|
||||
const std::type_index &type_index);
|
||||
[[nodiscard]] utils::result<node_ptr, utils::error> find_node(const std::string &name) const;
|
||||
[[nodiscard]] utils::result<node_ptr, utils::error> find_node(const std::type_index &type_index) const;
|
||||
template<typename Type>
|
||||
[[nodiscard]] utils::result<node_ptr, utils::error> find_node() const {
|
||||
return find_node(std::type_index(typeid(Type)));
|
||||
}
|
||||
|
||||
[[nodiscard]] bool has_node(const std::string &name) const;
|
||||
[[nodiscard]] bool has_node(const std::type_index &index) const;
|
||||
[[nodiscard]] bool has_node(const std::type_index &index, const std::string &name) const;
|
||||
[[nodiscard]] bool has_node(const node_ptr& node) const;
|
||||
|
||||
static void insert_node(const node_ptr &parent, const node_ptr &child);
|
||||
void remove_node(const node_ptr &node);
|
||||
@@ -266,13 +273,15 @@ template<class CollectionType>
|
||||
void relation_completer<Type>::on_has_many(const char *id, CollectionType &,
|
||||
const char *join_column,
|
||||
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*/) {
|
||||
// Shortcut to value type of object_ptr::value_type in collection
|
||||
using value_type = typename CollectionType::value_type::value_type;
|
||||
|
||||
// Check if the object_ptr type is already inserted in the schema (by id)
|
||||
if (auto result = schema_.find_node(id); !result) {
|
||||
// Type was not found.
|
||||
// Ensure value_type is known to the schema. Name will be added later
|
||||
ensure_type_is_known<value_type>();
|
||||
// Create and attach the relation node.
|
||||
const std::type_index ti = typeid(many_to_many_relation<value_type, Type>);
|
||||
if (const auto endpoint = node_->info().find_relation_endpoint(ti); endpoint == node_->info().endpoint_end()) {
|
||||
@@ -479,11 +488,20 @@ void relation_completer<Type>::register_relation_endpoints(const endpoint_ptr &e
|
||||
}
|
||||
|
||||
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);
|
||||
other_endpoint->link_foreign_endpoint(endpoint);
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
template<typename ValueType>
|
||||
void relation_completer<Type>::ensure_type_is_known() {
|
||||
if (auto result = schema_.find_node<ValueType>(); result) {
|
||||
return;
|
||||
}
|
||||
auto result = schema_.attach_node(schema_node::make_node<Type>(schema_, ""), "");
|
||||
relation_completer<ValueType>::complete(result.value());
|
||||
}
|
||||
}
|
||||
|
||||
#endif //SCHEMA_HPP
|
||||
|
||||
@@ -27,6 +27,8 @@ public:
|
||||
|
||||
template<typename Type>
|
||||
[[nodiscard]] utils::result<void, utils::error> attach(const std::string &table_name) const;
|
||||
template<typename Type, typename SuperType>
|
||||
[[nodiscard]] utils::result<void, utils::error> attach(const std::string &table_name) const;
|
||||
|
||||
utils::result<void, utils::error> create_schema() const;
|
||||
|
||||
@@ -137,6 +139,11 @@ template<typename Type>
|
||||
return schema_->attach<Type>(table_name);
|
||||
}
|
||||
|
||||
template<typename Type, typename SuperType>
|
||||
utils::result<void, utils::error> session::attach( const std::string& table_name ) const {
|
||||
return schema_->attach<Type, SuperType>(table_name);
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
utils::result<object::object_ptr<Type>, utils::error> session::insert(Type *obj)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user