59 lines
1.9 KiB
C++
59 lines
1.9 KiB
C++
#ifndef QUERY_KEY_VALUE_GENERATOR_HPP
|
|
#define QUERY_KEY_VALUE_GENERATOR_HPP
|
|
|
|
#include "matador/query/fk_value_extractor.hpp"
|
|
#include "matador/query/internal/column_value_pair.hpp"
|
|
|
|
#include "matador/utils/foreign_attributes.hpp"
|
|
#include "matador/utils/primary_key_attribute.hpp"
|
|
|
|
#include <vector>
|
|
|
|
namespace matador::query {
|
|
|
|
class key_value_generator
|
|
{
|
|
private:
|
|
public:
|
|
explicit key_value_generator(std::vector<internal::column_value_pair> &result);
|
|
|
|
public:
|
|
template < class Type >
|
|
static std::vector<internal::column_value_pair> generate(const Type &obj) {
|
|
std::vector<internal::column_value_pair> result;
|
|
key_value_generator generator(result);
|
|
access::process(generator, obj);
|
|
|
|
return result;
|
|
}
|
|
|
|
template < class V >
|
|
void on_primary_key(const char *id, V &x, const utils::primary_key_attribute& /*attr*/ = utils::default_pk_attributes) {
|
|
result_.emplace_back(id, x);
|
|
}
|
|
void on_revision(const char *id, uint64_t &/*rev*/);
|
|
|
|
template<typename Type>
|
|
void on_attribute(const char *id, Type &x, const utils::field_attributes &/*attr*/ = utils::null_attributes) {
|
|
result_.emplace_back(id, x);
|
|
}
|
|
|
|
template<class Type, template < class ... > class Pointer>
|
|
void on_belongs_to(const char *id, Pointer<Type> &x, const utils::foreign_attributes &/*attr*/) {
|
|
result_.emplace_back(id, fk_value_extractor_.extract(*x));
|
|
}
|
|
template<class Type, template < class ... > class Pointer>
|
|
void on_has_one(const char *id, Pointer<Type> &x, const utils::foreign_attributes &/*attr*/) {
|
|
result_.emplace_back(id, fk_value_extractor_.extract(*x));
|
|
}
|
|
template<class ContainerType>
|
|
static void on_has_many(const char *, ContainerType &, const char *, const char *, const utils::foreign_attributes &/*attr*/) {}
|
|
|
|
private:
|
|
detail::fk_value_extractor fk_value_extractor_{};
|
|
std::vector<internal::column_value_pair> &result_;
|
|
};
|
|
|
|
}
|
|
#endif //QUERY_KEY_VALUE_GENERATOR_HPP
|