session progress

This commit is contained in:
Sascha Kühl 2025-02-17 16:07:41 +01:00
parent 9a95725959
commit 5109659882
4 changed files with 19 additions and 12 deletions

View File

@ -142,10 +142,9 @@ public:
if (pk_.is_null()) { if (pk_.is_null()) {
entity_query_data_.pk_column_name = id; entity_query_data_.pk_column_name = id;
} else if (pk_.is_integer()) { } else if (pk_.is_integer()) {
const auto t = std::make_shared<sql::table>(table_info_stack_.top().info.get().name()); auto v = *pk_.as<V>();
auto v = *pk_.as<V>(); auto c = sql::column{table_info_stack_.top().table, id, ""};
auto c = sql::column{t, id, ""}; auto co = std::make_unique<query::condition<sql::column, V>>(c, query::basic_condition::operand_type::EQUAL, v);
auto co = std::make_unique<query::condition<sql::column, V>>(c, query::basic_condition::operand_type::EQUAL, v);
entity_query_data_.where_clause = std::move(co); entity_query_data_.where_clause = std::move(co);
entity_query_data_.pk_column_name = id; entity_query_data_.pk_column_name = id;
} }
@ -281,7 +280,6 @@ public:
append_join( append_join(
sql::column{relation->second, join_columns.join_column}, sql::column{relation->second, join_columns.join_column},
sql::column{next->second, pk->name()} sql::column{next->second, pk->name()}
// sql::column{std::make_shared<sql::table>(info->get().name()), pk->name()}
); );
} }

View File

@ -12,6 +12,8 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <typeindex>
#include <unordered_set>
namespace matador::utils { namespace matador::utils {
class value; class value;
@ -82,14 +84,14 @@ public:
void on_attribute(const char *id, utils::value &val, const utils::field_attributes &attr = utils::null_attributes); void on_attribute(const char *id, utils::value &val, const utils::field_attributes &attr = utils::null_attributes);
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) {
{
if (x.empty()) { if (x.empty()) {
x = new typename Pointer::value_type; x = new typename Pointer::value_type;
} }
if (attr.fetch() == utils::fetch_type::LAZY) { if (attr.fetch() == utils::fetch_type::LAZY) {
pk_reader_.read(*x, column_index_++); pk_reader_.read(*x, column_index_++);
} else { } else if (const auto ti = std::type_index(typeid(*x)); processed_types_.count(ti) == 0) {
processed_types_.insert(ti);
access::process(*this, *x); access::process(*this, *x);
} }
} }
@ -101,8 +103,8 @@ public:
} }
if (attr.fetch() == utils::fetch_type::LAZY) { if (attr.fetch() == utils::fetch_type::LAZY) {
pk_reader_.read(*x, column_index_++); pk_reader_.read(*x, column_index_++);
} else { } else if (const auto ti = std::type_index(typeid(*x)); processed_types_.count(ti) == 0) {
access::process(*this, *x); processed_types_.insert(ti);
} }
} }
@ -114,7 +116,8 @@ public:
void on_has_many(const char * /*id*/, ContainerType &cont, const char * /*join_column*/, const utils::foreign_attributes &attr) { void on_has_many(const char * /*id*/, ContainerType &cont, const char * /*join_column*/, const utils::foreign_attributes &attr) {
if ( attr.fetch() == utils::fetch_type::LAZY ) { if ( attr.fetch() == utils::fetch_type::LAZY ) {
// pk_reader_.read(*id, column_index_++); // pk_reader_.read(*id, column_index_++);
} else { } else if (const auto ti = std::type_index(typeid(typename ContainerType::value_type::value_type)); processed_types_.count(ti) == 0) {
processed_types_.insert(ti);
auto obj = std::make_unique<typename ContainerType::value_type::value_type>(); auto obj = std::make_unique<typename ContainerType::value_type::value_type>();
// typename ContainerType::value_type x(new typename ContainerType::value_type::value_type); // typename ContainerType::value_type x(new typename ContainerType::value_type::value_type);
access::process(*this, *obj); access::process(*this, *obj);
@ -145,6 +148,7 @@ public:
if (!*fetched) { if (!*fetched) {
return false; return false;
} }
processed_types_.insert(typeid(Type));
access::process(*this, obj); access::process(*this, obj);
return true; return true;
} }
@ -156,6 +160,7 @@ protected:
std::vector<object::attribute_definition> prototype_; std::vector<object::attribute_definition> prototype_;
std::unique_ptr<query_result_reader> reader_; std::unique_ptr<query_result_reader> reader_;
detail::pk_reader pk_reader_; detail::pk_reader pk_reader_;
std::unordered_set<std::type_index> processed_types_;
}; };
namespace detail { namespace detail {

View File

@ -1,5 +1,7 @@
#include "SessionFixture.hpp" #include "SessionFixture.hpp"
#include "catch2/catch_test_macros.hpp"
namespace matador::test { namespace matador::test {
SessionFixture::SessionFixture() SessionFixture::SessionFixture()
@ -14,7 +16,7 @@ SessionFixture::~SessionFixture() {
void SessionFixture::drop_table_if_exists(const std::string &table_name) const { void SessionFixture::drop_table_if_exists(const std::string &table_name) const {
if (ses.table_exists(table_name)) { if (ses.table_exists(table_name)) {
ses.drop_table(table_name); REQUIRE(ses.drop_table(table_name));
} }
} }

View File

@ -14,6 +14,7 @@ struct department {
unsigned int id{}; unsigned int id{};
std::string name; std::string name;
std::vector<object::object_ptr<employee>> employees; std::vector<object::object_ptr<employee>> employees;
object::object_ptr<employee> manager;
template<typename Operator> template<typename Operator>
void process(Operator &op) { void process(Operator &op) {
@ -21,6 +22,7 @@ struct department {
field::primary_key(op, "id", id); field::primary_key(op, "id", id);
field::attribute(op, "name", name, 63); field::attribute(op, "name", name, 63);
field::has_many(op, "employees", employees, "dep_id", utils::fetch_type::EAGER); field::has_many(op, "employees", employees, "dep_id", utils::fetch_type::EAGER);
field::belongs_to(op, "manager_id", manager, utils::fetch_type::EAGER);
} }
}; };