query/include/matador/query/query_collection_resolver.hpp

46 lines
1.3 KiB
C++

#ifndef MATADOR_QUERY_CONTAINER_RESOLVER_HPP
#define MATADOR_QUERY_CONTAINER_RESOLVER_HPP
#include "matador/object/collection_resolver.hpp"
#include "matador/sql/internal/identifier_statement_binder.hpp"
#include "matador/sql/statement.hpp"
namespace matador::sql {
class executor;
}
namespace matador::query {
template<typename Type>
class query_collection_resolver : public object::collection_resolver<Type> {
public:
explicit query_collection_resolver(sql::statement &&stmt, const std::type_index& root_type, std::string join_column)
: object::collection_resolver<Type>(root_type, join_column)
, stmt_(std::move(stmt))
{}
std::vector<Type> resolve(const utils::identifier &id) override;
protected:
sql::statement stmt_;
std::type_index index{typeid(Type)};
};
template<typename Type>
std::vector<Type> query_collection_resolver<Type>::resolve(const utils::identifier &id) {
sql::identifier_statement_binder binder(stmt_);
binder.bind(id);
auto result = stmt_.fetch();
if (!result) {
return {};
}
std::vector<Type> out;
for (const auto &i: *result) {
// Todo: convert the first value of record into an utils::identifier
// then create a object_proxy<Type>(resolver, identifier)
// out.emplace_back(resolver, identifier);
}
return out;
}
}
#endif //MATADOR_QUERY_CONTAINER_RESOLVER_HPP