implemented lazy loading for object_ptr and belongs_to

This commit is contained in:
2026-01-15 12:40:54 +01:00
parent db8e137c11
commit 7626331866
81 changed files with 1790 additions and 927 deletions
@@ -0,0 +1,35 @@
#ifndef MATADOR_STATEMENT_OBJECT_RESOLVER_HPP
#define MATADOR_STATEMENT_OBJECT_RESOLVER_HPP
#include "matador/object/object_resolver.hpp"
#include "matador/sql/statement.hpp"
#include "matador/sql/internal/identifier_statement_binder.hpp"
namespace matador::sql {
template<typename Type>
class statement_object_resolver : public object::object_resolver<Type> {
public:
explicit statement_object_resolver(statement stmt)
: statement_(std::move(stmt)) {}
std::shared_ptr<Type> resolve(const utils::identifier &id) override;
protected:
statement statement_;
std::type_index index{typeid(Type)};
};
template<typename Type>
std::shared_ptr<Type> statement_object_resolver<Type>::resolve(const utils::identifier &id) {
identifier_statement_binder binder(statement_);
binder.bind(id);
auto result = statement_.template fetch_one<Type>();
if (!result) {
return nullptr;
}
return std::make_shared<Type>(*result);
}
}
#endif //MATADOR_STATEMENT_OBJECT_RESOLVER_HPP