proxy lazy resolve progress

This commit is contained in:
Sascha Kühl 2025-08-18 16:21:24 +02:00
parent 466977b620
commit 1370eafac4
5 changed files with 15 additions and 45 deletions

View File

@ -2,6 +2,7 @@
#define OBJECT_PROXY_HPP
#include <memory>
#include <functional>
namespace matador::object {
@ -13,7 +14,7 @@ public:
};
template<class Type>
class object_proxy : public basic_object_proxy {
class object_proxy final : public basic_object_proxy {
public:
object_proxy() = default;
explicit object_proxy(Type* obj)
@ -21,20 +22,26 @@ public:
explicit object_proxy(std::unique_ptr<Type> obj)
: obj_(std::move(obj)) {}
[[nodiscard]] void *get() const override { return static_cast<void*>(obj_.get()); }
[[nodiscard]] void *get() const override { return static_cast<void*>(pointer()); }
Type* operator->() const { return obj_.get(); }
Type& operator*() { return *obj_; }
const Type& operator*() const { return *obj_; }
Type* operator->() const { return pointer(); }
Type& operator*() { return *pointer(); }
const Type& operator*() const { return *pointer(); }
Type* pointer() const { return obj_.get(); }
Type* pointer() const { return resolve(); }
Type& ref() { return *obj_; }
const Type& ref() const { return *obj_; }
Type& ref() { return *pointer(); }
const Type& ref() const { return *pointer(); }
void reset(Type* obj) { obj_.reset(obj); }
private:
Type* resolve() const {
return resolver_(*this);
}
private:
std::function<Type*(const object_proxy&)> resolver_{[](const object_proxy &proxy){ return proxy.obj_.get();}};
std::unique_ptr<Type> obj_{};
};

View File

@ -9,8 +9,6 @@
#include <cstdint>
#include <string>
#include <type_traits>
namespace matador::object {

View File

@ -96,26 +96,6 @@ public:
return build_select_query(data.release()).template fetch_all<Type>(*this);
}
// template<typename Type>
// utils::result<query::query_from_intermediate, utils::error> select() {
// auto c = pool_.acquire();
// if (!c.valid()) {
// return utils::failure(make_error(error_code::NoConnectionAvailable, "Failed to acquire connection."));
// }
// auto info = schema_->info<Type>();
// if (!info) {
// return utils::failure(make_error(error_code::UnknownType, "Failed to determine requested type."));
// }
//
// session_query_builder eqb(*schema_);
// auto data = eqb.build<Type>();
// if (!data.is_ok()) {
// return utils::failure(make_error(error_code::FailedToBuildQuery, "Failed to build query for type " + info->get().name() + "."));
// }
//
// return utils::ok(build_select_query(data.release()).template fetch_all<Type>(*c));
// }
//
template<typename Type>
utils::result<void, utils::error> drop_table();
utils::result<void, utils::error> drop_table(const std::string &table_name) const;

View File

@ -152,10 +152,6 @@ utils::result<query_result<Type>, utils::error> statement::fetch() {
return statement_proxy_->fetch(*bindings_).and_then([](std::unique_ptr<query_result_impl> &&value) {
return utils::ok(query_result<Type>(std::forward<decltype(value)>(value)));
});
// if (!result.is_ok()) {
// return utils::error(result.err());
// }
// return query_result<Type>(result.release());
}
template<class Type>

View File

@ -54,18 +54,7 @@ utils::result<size_t, utils::error> statement::execute() const {
return statement_proxy_->execute(*bindings_);
}
//bool is_unknown(const std::vector<object::column_definition> &columns) {
// return std::all_of(std::begin(columns), std::end(columns), [](const auto &col) {
// return col.is_unknown();
// });
//}
utils::result<query_result<record>, utils::error> statement::fetch() const {
// if (is_unknown(statement_->query_.prototype)) {
//
// }
auto result = statement_proxy_->fetch(*bindings_);
if (!result.is_ok()) {
return utils::failure(result.err());