object generation progress

This commit is contained in:
2025-12-01 22:03:07 +01:00
parent 422df82b7c
commit c156ab5e74
10 changed files with 62 additions and 77 deletions
+26 -23
View File
@@ -114,27 +114,28 @@ public:
template<class ContainerType>
void on_has_many(const char * /*id*/, ContainerType &, const char *join_column, const utils::foreign_attributes &attr) {
if (attr.fetch() == utils::fetch_type::EAGER) {
const auto info = schema_.info<typename ContainerType::value_type::value_type>();
if (!info) {
const auto result = schema_.basic_info(typeid(typename ContainerType::value_type::value_type));
if (!result) {
throw query_builder_exception{query_build_error::UnknownType};
}
auto next = processed_tables_.find(info->get().name());
const auto &info = result.value().get();
auto next = processed_tables_.find(info.name());
if (next != processed_tables_.end()) {
return;
}
table_info_stack_.push({info.value(), std::make_shared<query::table>(info->get().name(), build_alias('t', ++table_index))});
next = processed_tables_.insert({info->get().name(), table_info_stack_.top().table}).first;
table_info_stack_.push({*result, std::make_shared<query::table>(info.name(), build_alias('t', ++table_index))});
next = processed_tables_.insert({info.name(), table_info_stack_.top().table}).first;
typename ContainerType::value_type::value_type obj;
access::process(*this , obj);
table_info_stack_.pop();
if (!info->get().has_primary_key()) {
if (!info.has_primary_key()) {
throw query_builder_exception{query_build_error::MissingPrimaryKey};
}
append_join(
query::column{table_info_stack_.top().table, table_info_stack_.top().info.get().reference_column()->name()},
query::column{table_info_stack_.top().table, table_info_stack_.top().info.get().primary_key_attribute()->name()},
query::column{next->second, join_column}
);
}
@@ -145,12 +146,13 @@ public:
if (attr.fetch() != utils::fetch_type::EAGER) {
return;
}
const auto info = schema_.info<typename ContainerType::value_type::value_type>();
if (!info) {
const auto result = schema_.basic_info(typeid(typename ContainerType::value_type::value_type));
if (!result) {
throw query_builder_exception{query_build_error::UnknownType};
}
auto next = processed_tables_.find(info->get().name());
const auto &info = result.value().get();
auto next = processed_tables_.find(info.name());
if (next != processed_tables_.end()) {
return;
}
@@ -159,23 +161,23 @@ public:
relation = processed_tables_.insert({id, std::make_shared<query::table>(id, build_alias('t', ++table_index))}).first;
}
table_info_stack_.push({info.value(), std::make_shared<query::table>(info->get().name(), build_alias('t', ++table_index))});
next = processed_tables_.insert({info->get().name(), table_info_stack_.top().table}).first;
table_info_stack_.push({*result, std::make_shared<query::table>(info.name(), build_alias('t', ++table_index))});
next = processed_tables_.insert({info.name(), table_info_stack_.top().table}).first;
typename ContainerType::value_type::value_type obj;
access::process(*this , obj);
table_info_stack_.pop();
if (!info->get().has_primary_key()) {
if (!info.has_primary_key()) {
throw query_builder_exception{query_build_error::MissingPrimaryKey};
}
append_join(
query::column{table_info_stack_.top().table, table_info_stack_.top().info.get().reference_column()->name()},
query::column{table_info_stack_.top().table, table_info_stack_.top().info.get().primary_key_attribute()->name()},
query::column{relation->second, join_column}
);
append_join(
query::column{relation->second, inverse_join_column},
query::column{next->second, info->get().reference_column()->name()}
query::column{next->second, info.primary_key_attribute()->name()}
);
}
@@ -184,12 +186,13 @@ public:
if (attr.fetch() != utils::fetch_type::EAGER) {
return;
}
const auto info = schema_.info<typename ContainerType::value_type::value_type>();
if (!info) {
const auto result = schema_.basic_info(typeid(typename ContainerType::value_type::value_type));
if (!result) {
throw query_builder_exception{query_build_error::UnknownType};
}
auto next = processed_tables_.find(info->get().name());
const auto &info = result.value().get();
auto next = processed_tables_.find(info.name());
if (next != processed_tables_.end()) {
return;
}
@@ -198,25 +201,25 @@ public:
if (relation == processed_tables_.end()) {
relation = processed_tables_.insert({id, std::make_shared<query::table>(id, build_alias('t', ++table_index))}).first;
}
table_info_stack_.push({info.value(), std::make_shared<query::table>(info->get().name(), build_alias('t', ++table_index))});
next = processed_tables_.insert({info->get().name(), table_info_stack_.top().table}).first;
table_info_stack_.push({*result, std::make_shared<query::table>(info.name(), build_alias('t', ++table_index))});
next = processed_tables_.insert({info.name(), table_info_stack_.top().table}).first;
typename ContainerType::value_type::value_type obj;
access::process(*this , obj);
table_info_stack_.pop();
if (!info->get().has_primary_key()) {
if (!info.has_primary_key()) {
throw query_builder_exception{query_build_error::MissingPrimaryKey};
}
const auto join_columns = join_columns_collector_.collect<typename ContainerType::value_type::value_type>();
append_join(
query::column{table_info_stack_.top().table, table_info_stack_.top().info.get().reference_column()->name()},
query::column{table_info_stack_.top().table, table_info_stack_.top().info.get().primary_key_attribute()->name()},
query::column{relation->second, join_columns.inverse_join_column}
);
append_join(
query::column{relation->second, join_columns.join_column},
query::column{next->second, info->get().reference_column()->name()}
query::column{next->second, info.primary_key_attribute()->name()}
);
}