collection_resolver progress
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#define MATADOR_QUERY_CONTAINER_RESOLVER_HPP
|
||||
|
||||
#include "matador/object/collection_resolver.hpp"
|
||||
#include "matador/object/object_resolver.hpp"
|
||||
|
||||
#include "matador/sql/internal/identifier_statement_binder.hpp"
|
||||
#include "matador/sql/statement.hpp"
|
||||
@@ -25,6 +26,38 @@ protected:
|
||||
std::type_index index{typeid(Type)};
|
||||
};
|
||||
|
||||
struct value_to_identifier{
|
||||
void operator()(const int8_t &x) { assign(x); }
|
||||
void operator()(const int16_t &x) { assign(x); }
|
||||
void operator()(const int32_t &x) { assign(x); }
|
||||
void operator()(const int64_t &x) { assign(x); }
|
||||
void operator()(const uint8_t &x) { assign(x); }
|
||||
void operator()(const uint16_t &x) { assign(x); }
|
||||
void operator()(const uint32_t &x) { assign(x); }
|
||||
void operator()(const uint64_t &x) { assign(x); }
|
||||
void operator()(const bool &x) {}
|
||||
void operator()(const float &x) {}
|
||||
void operator()(const double &x) { /* assign(x);*/ }
|
||||
void operator()(const char *x) {}
|
||||
void operator()(const std::string &x) { assign(x); }
|
||||
void operator()(const utils::date_type_t &x) {}
|
||||
void operator()(const utils::time_type_t &x) {}
|
||||
void operator()(const utils::timestamp_type_t &x) {}
|
||||
void operator()(const utils::blob_type_t &x) {}
|
||||
|
||||
template<typename Type>
|
||||
void assign(const Type &x) { id_ = x; }
|
||||
|
||||
utils::identifier id_;
|
||||
};
|
||||
|
||||
struct identifier_creator {
|
||||
value_to_identifier visitor;
|
||||
void on_attribute(const char*, const utils::value &val, const utils::field_attributes &/*attr*/) {
|
||||
std::visit(visitor, val.raw_value());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
std::vector<Type> query_collection_resolver<Type>::resolve(const utils::identifier &id) {
|
||||
sql::identifier_statement_binder binder(stmt_);
|
||||
@@ -35,10 +68,16 @@ std::vector<Type> query_collection_resolver<Type>::resolve(const utils::identifi
|
||||
return {};
|
||||
}
|
||||
std::vector<Type> out;
|
||||
for (const auto &i: *result) {
|
||||
for (auto &r : *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);
|
||||
if (r.size() != 1) {
|
||||
continue;
|
||||
}
|
||||
identifier_creator creator;
|
||||
r.at(0).process(creator);
|
||||
const auto op = std::make_shared<object::object_proxy<typename Type::value_type>>(std::shared_ptr<object::object_resolver<typename Type::value_type>>{}, creator.visitor.id_);
|
||||
out.emplace_back(op);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user