71 lines
2.0 KiB
C++
71 lines
2.0 KiB
C++
#ifndef QUERY_COLUMN_GENERATOR_HPP
|
|
#define QUERY_COLUMN_GENERATOR_HPP
|
|
|
|
#include "matador/sql/column.hpp"
|
|
#include "matador/sql/types.hpp"
|
|
|
|
#include "matador/utils/access.hpp"
|
|
#include "matador/utils/field_attributes.hpp"
|
|
|
|
#include <vector>
|
|
|
|
namespace matador::utils {
|
|
class identifiable;
|
|
enum class cascade_type;
|
|
}
|
|
|
|
namespace matador::sql {
|
|
|
|
class column_generator
|
|
{
|
|
private:
|
|
explicit column_generator(std::vector<column> &columns);
|
|
|
|
public:
|
|
~column_generator() = default;
|
|
|
|
template < class Type >
|
|
static std::vector<column> generate()
|
|
{
|
|
std::vector<column> columns;
|
|
column_generator gen(columns);
|
|
Type obj;
|
|
matador::utils::access::process(gen, obj);
|
|
return std::move(columns);
|
|
}
|
|
|
|
template < class V >
|
|
void on_primary_key(const char *, V &x, typename std::enable_if<std::is_integral<V>::value && !std::is_same<bool, V>::value>::type* = 0);
|
|
void on_primary_key(const char *id, std::string &pk, size_t size);
|
|
void on_revision(const char *id, unsigned long long &/*rev*/);
|
|
|
|
template<typename Type>
|
|
void on_attribute(const char *id, Type &x, const utils::field_attributes &attr = utils::null_attributes);
|
|
|
|
void on_belongs_to(const char *id, utils::identifiable &x, utils::cascade_type);
|
|
void on_has_one(const char *id, utils::identifiable &x, utils::cascade_type);
|
|
// void on_has_many(const char *, abstract_container &, const char *, const char *, cascade_type) {}
|
|
// void on_has_many(const char *, abstract_container &, cascade_type) {}
|
|
|
|
private:
|
|
size_t index_ = 0;
|
|
std::vector<column> &columns_;
|
|
|
|
// typed_column_identifier_serializer column_identifier_serializer_;
|
|
};
|
|
|
|
template<typename V>
|
|
void column_generator::on_primary_key(const char *id, V &x, typename std::enable_if<std::is_integral<V>::value && !std::is_same<bool, V>::value>::type*)
|
|
{
|
|
on_attribute(id, x, { utils::constraints::PRIMARY_KEY });
|
|
}
|
|
|
|
template<typename Type>
|
|
void column_generator::on_attribute(const char *id, Type &x, const utils::field_attributes &attr)
|
|
{
|
|
columns_.emplace_back(id, x, attr);
|
|
}
|
|
|
|
}
|
|
#endif //QUERY_COLUMN_GENERATOR_HPP
|