38 lines
941 B
C++
38 lines
941 B
C++
#ifndef MATADOR_QUERY_OBJECT_LOADER_HPP
|
|
#define MATADOR_QUERY_OBJECT_LOADER_HPP
|
|
|
|
#include "matador/sql/internal/identifier_statement_binder.hpp"
|
|
#include "matador/sql/statement.hpp"
|
|
|
|
#include "matador/object/object_resolver.hpp"
|
|
|
|
namespace matador::sql {
|
|
class executor;
|
|
}
|
|
|
|
namespace matador::query {
|
|
template<typename Type>
|
|
class query_object_resolver : public object::object_resolver<Type> {
|
|
public:
|
|
explicit query_object_resolver(sql::statement &&stmt)
|
|
: stmt_(std::move(stmt)) {}
|
|
|
|
std::shared_ptr<Type> resolve(const utils::identifier &id) override;
|
|
protected:
|
|
sql::statement stmt_;
|
|
};
|
|
|
|
template<typename Type>
|
|
std::shared_ptr<Type> query_object_resolver<Type>::resolve(const utils::identifier &id) {
|
|
sql::identifier_statement_binder binder(stmt_);
|
|
binder.bind(id);
|
|
|
|
auto result = stmt_.template fetch_one_raw<Type>();
|
|
if (!result) {
|
|
return nullptr;
|
|
}
|
|
return *result;
|
|
}
|
|
|
|
}
|
|
#endif //MATADOR_QUERY_OBJECT_LOADER_HPP
|