session queries as statement progress

This commit is contained in:
2025-10-06 07:31:16 +02:00
parent 5490e67ecf
commit 4fd9a74ae8
10 changed files with 33 additions and 37 deletions
+7 -5
View File
@@ -121,15 +121,17 @@ public:
return utils::failure(make_error(error_code::FailedToBuildQuery, "Failed to build query for type " + info->get().name() + "."));
}
auto obj = build_select_query(data.release()).template fetch_one<Type>(*this);
auto res = build_select_query(data.release()).prepare(*this);
// auto obj = build_select_query(data.release()).template fetch_one<Type>(*this);
if (!obj) {
return utils::failure(obj.err());
if (!res) {
return utils::failure(res.err());
}
if (!obj->get()) {
auto stmt_result = res->bind(0, const_cast<PrimaryKeyType&>(pk)).template fetch_one<Type>();
if (!stmt_result) {
return utils::failure(make_error(error_code::FailedToFindObject, "Failed to find object of type " + info->get().name() + " with primary key " + std::to_string(pk) + "."));
}
return utils::ok(object::object_ptr<Type>{ obj->release() });
return utils::ok(object::object_ptr<Type>{ stmt_result->release() });
}
template<typename Type>
@@ -88,9 +88,9 @@ public:
if (pk_.is_null()) {
entity_query_data_.pk_column_name = id;
} else if (pk_.is_integer()) {
auto v = *pk_.as<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);
auto co = std::make_unique<query::condition<sql::column, utils::placeholder>>(c, query::basic_condition::operand_type::EQUAL, utils::_);
entity_query_data_.where_clause = std::move(co);
entity_query_data_.pk_column_name = id;
} else if (pk_.is_varchar()) {