session progress
This commit is contained in:
parent
9a95725959
commit
5109659882
|
|
@ -142,10 +142,9 @@ public:
|
|||
if (pk_.is_null()) {
|
||||
entity_query_data_.pk_column_name = id;
|
||||
} 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 c = sql::column{t, id, ""};
|
||||
auto co = std::make_unique<query::condition<sql::column, V>>(c, query::basic_condition::operand_type::EQUAL, v);
|
||||
auto v = *pk_.as<V>();
|
||||
auto c = sql::column{table_info_stack_.top().table, id, ""};
|
||||
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_.pk_column_name = id;
|
||||
}
|
||||
|
|
@ -281,7 +280,6 @@ public:
|
|||
append_join(
|
||||
sql::column{relation->second, join_columns.join_column},
|
||||
sql::column{next->second, pk->name()}
|
||||
// sql::column{std::make_shared<sql::table>(info->get().name()), pk->name()}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <typeindex>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace matador::utils {
|
||||
class value;
|
||||
|
|
@ -82,14 +84,14 @@ public:
|
|||
void on_attribute(const char *id, utils::value &val, const utils::field_attributes &attr = utils::null_attributes);
|
||||
|
||||
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()) {
|
||||
x = new typename Pointer::value_type;
|
||||
}
|
||||
if (attr.fetch() == utils::fetch_type::LAZY) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -101,8 +103,8 @@ public:
|
|||
}
|
||||
if (attr.fetch() == utils::fetch_type::LAZY) {
|
||||
pk_reader_.read(*x, column_index_++);
|
||||
} else {
|
||||
access::process(*this, *x);
|
||||
} else if (const auto ti = std::type_index(typeid(*x)); processed_types_.count(ti) == 0) {
|
||||
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) {
|
||||
if ( attr.fetch() == utils::fetch_type::LAZY ) {
|
||||
// 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>();
|
||||
// typename ContainerType::value_type x(new typename ContainerType::value_type::value_type);
|
||||
access::process(*this, *obj);
|
||||
|
|
@ -145,6 +148,7 @@ public:
|
|||
if (!*fetched) {
|
||||
return false;
|
||||
}
|
||||
processed_types_.insert(typeid(Type));
|
||||
access::process(*this, obj);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -156,6 +160,7 @@ protected:
|
|||
std::vector<object::attribute_definition> prototype_;
|
||||
std::unique_ptr<query_result_reader> reader_;
|
||||
detail::pk_reader pk_reader_;
|
||||
std::unordered_set<std::type_index> processed_types_;
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include "SessionFixture.hpp"
|
||||
|
||||
#include "catch2/catch_test_macros.hpp"
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
SessionFixture::SessionFixture()
|
||||
|
|
@ -14,7 +16,7 @@ SessionFixture::~SessionFixture() {
|
|||
|
||||
void SessionFixture::drop_table_if_exists(const std::string &table_name) const {
|
||||
if (ses.table_exists(table_name)) {
|
||||
ses.drop_table(table_name);
|
||||
REQUIRE(ses.drop_table(table_name));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ struct department {
|
|||
unsigned int id{};
|
||||
std::string name;
|
||||
std::vector<object::object_ptr<employee>> employees;
|
||||
object::object_ptr<employee> manager;
|
||||
|
||||
template<typename Operator>
|
||||
void process(Operator &op) {
|
||||
|
|
@ -21,6 +22,7 @@ struct department {
|
|||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "name", name, 63);
|
||||
field::has_many(op, "employees", employees, "dep_id", utils::fetch_type::EAGER);
|
||||
field::belongs_to(op, "manager_id", manager, utils::fetch_type::EAGER);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue