moved column and table class from namespace sql to query

This commit is contained in:
Sascha Kühl
2025-11-18 16:27:38 +01:00
parent 7242dc2612
commit fb4bc03da0
79 changed files with 626 additions and 496 deletions
+27 -27
View File
@@ -23,9 +23,9 @@
namespace matador::orm {
struct entity_query_data {
std::shared_ptr<sql::table> root_table;
std::shared_ptr<query::table> root_table;
std::string pk_column_name{};
std::vector<sql::column> columns{};
std::vector<query::column> columns{};
std::unordered_map<std::string, sql::statement> lazy_loading_statements{};
std::vector<query::join_data> joins{};
query::criteria_ptr where_clause{};
@@ -33,7 +33,7 @@ struct entity_query_data {
class criteria_transformer final : public query::criteria_visitor {
public:
criteria_transformer(const object::repository &repo, const std::unordered_map<std::string, std::shared_ptr<sql::table>>& tables_by_name);
criteria_transformer(const object::repository &repo, const std::unordered_map<std::string, std::shared_ptr<query::table>>& tables_by_name);
void visit( const query::between_criteria& node ) override;
void visit( const query::binary_criteria& node ) override;
void visit( const query::binary_column_criteria& node ) override;
@@ -48,7 +48,7 @@ private:
private:
const object::repository &repo_;
const std::unordered_map<std::string, std::shared_ptr<sql::table>>& tables_by_name_;
const std::unordered_map<std::string, std::shared_ptr<query::table>>& tables_by_name_;
};
class session_query_builder final {
@@ -63,7 +63,7 @@ public:
if (!info) {
return utils::failure(query_build_error::UnknownType);
}
table_info_stack_.push({info.value(), std::make_shared<sql::table>(info.value().get().name(), build_alias('t', ++table_index))});
table_info_stack_.push({info.value(), std::make_shared<query::table>(info.value().get().name(), build_alias('t', ++table_index))});
entity_query_data_ = { table_info_stack_.top().table };
processed_tables_.insert({info->get().name(), entity_query_data_.root_table});
try {
@@ -123,7 +123,7 @@ public:
if (next != processed_tables_.end()) {
return;
}
table_info_stack_.push({info.value(), std::make_shared<sql::table>(info->get().name(), build_alias('t', ++table_index))});
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;
typename ContainerType::value_type::value_type obj;
access::process(*this , obj);
@@ -135,8 +135,8 @@ public:
}
append_join(
sql::column{table_info_stack_.top().table, table_info_stack_.top().info.get().definition().primary_key()->name()},
sql::column{next->second, join_column}
query::column{table_info_stack_.top().table, table_info_stack_.top().info.get().definition().primary_key()->name()},
query::column{next->second, join_column}
);
}
}
@@ -157,10 +157,10 @@ public:
}
auto relation = processed_tables_.find(id);
if (relation == processed_tables_.end()) {
relation = processed_tables_.insert({id, std::make_shared<sql::table>(id, build_alias('t', ++table_index))}).first;
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<sql::table>(info->get().name(), build_alias('t', ++table_index))});
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;
typename ContainerType::value_type::value_type obj;
access::process(*this , obj);
@@ -172,12 +172,12 @@ public:
}
append_join(
sql::column{table_info_stack_.top().table, table_info_stack_.top().info.get().definition().primary_key()->name()},
sql::column{relation->second, join_column}
query::column{table_info_stack_.top().table, table_info_stack_.top().info.get().definition().primary_key()->name()},
query::column{relation->second, join_column}
);
append_join(
sql::column{relation->second, inverse_join_column},
sql::column{next->second, pk->name()}
query::column{relation->second, inverse_join_column},
query::column{next->second, pk->name()}
);
}
@@ -198,9 +198,9 @@ public:
auto relation = processed_tables_.find(id);
if (relation == processed_tables_.end()) {
relation = processed_tables_.insert({id, std::make_shared<sql::table>(id, build_alias('t', ++table_index))}).first;
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<sql::table>(info->get().name(), build_alias('t', ++table_index))});
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;
typename ContainerType::value_type::value_type obj;
access::process(*this , obj);
@@ -214,12 +214,12 @@ public:
const auto join_columns = join_columns_collector_.collect<typename ContainerType::value_type::value_type>();
append_join(
sql::column{table_info_stack_.top().table, table_info_stack_.top().info.get().definition().primary_key()->name()},
sql::column{relation->second, join_columns.inverse_join_column}
query::column{table_info_stack_.top().table, table_info_stack_.top().info.get().definition().primary_key()->name()},
query::column{relation->second, join_columns.inverse_join_column}
);
append_join(
sql::column{relation->second, join_columns.join_column},
sql::column{next->second, pk->name()}
query::column{relation->second, join_columns.join_column},
query::column{next->second, pk->name()}
);
}
@@ -229,16 +229,16 @@ private:
void push(const std::string &column_name);
static std::string build_alias(char prefix, unsigned int count);
[[nodiscard]] bool is_root_entity() const;
void append_join(const sql::column &left, const sql::column &right);
void append_join(const query::column &left, const query::column &right);
private:
struct table_info {
std::reference_wrapper<const object::basic_object_info> info;
std::shared_ptr<sql::table> table;
std::shared_ptr<query::table> table;
};
std::stack<table_info> table_info_stack_{};
std::unordered_map<std::string, std::shared_ptr<sql::table>> processed_tables_{};
std::unordered_map<std::string, std::shared_ptr<query::table>> processed_tables_{};
const object::repository &schema_;
entity_query_data entity_query_data_{};
unsigned int column_index{0};
@@ -258,7 +258,7 @@ void session_query_builder::on_foreign_object(const char *id, Pointer &, const u
throw query_builder_exception{query_build_error::MissingPrimaryKey};
}
const auto foreign_table = std::make_shared<sql::table>(info->get().name(), build_alias('t', ++table_index));
const auto foreign_table = std::make_shared<query::table>(info->get().name(), build_alias('t', ++table_index));
if (attr.fetch() == utils::fetch_type::EAGER) {
auto next = processed_tables_.find(info->get().name());
@@ -272,8 +272,8 @@ void session_query_builder::on_foreign_object(const char *id, Pointer &, const u
table_info_stack_.pop();
append_join(
sql::column{table_info_stack_.top().table, id},
sql::column{next->second, pk->name()}
query::column{table_info_stack_.top().table, id},
query::column{next->second, pk->name()}
);
} else {
push(id);
@@ -282,7 +282,7 @@ void session_query_builder::on_foreign_object(const char *id, Pointer &, const u
// create select query
auto result = matador::query::query::select(generator::columns<typename Pointer::value_type>(schema_, generator::column_generator_options::ForceLazy))
.from(*foreign_table)
.where(sql::column(foreign_table, pk->name(), "") == _)
.where(column(foreign_table, pk->name(), "") == _)
.prepare(executor_);
if (!result) {
throw query_builder_exception(query_build_error::QueryError, result.release_error());