added column generator and tests
This commit is contained in:
@@ -17,7 +17,11 @@ public:
|
||||
|
||||
template<typename Type>
|
||||
explicit column(std::string name, utils::field_attributes attr = utils::null_attributes)
|
||||
: column(std::move(name), data_type_traits<Type>::data_type(), attr)
|
||||
: column(std::move(name), data_type_traits<Type>::builtin_type(attr.size()), attr)
|
||||
{}
|
||||
template<typename Type>
|
||||
column(std::string name, const Type &, utils::field_attributes attr = utils::null_attributes)
|
||||
: column(std::move(name), data_type_traits<Type>::builtin_type(attr.size()), attr)
|
||||
{}
|
||||
column(std::string name, data_type_t type, utils::field_attributes attr = utils::null_attributes);
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
#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
|
||||
@@ -100,6 +100,7 @@ public:
|
||||
query_builder& remove();
|
||||
|
||||
query_builder& table(const std::string &table, std::initializer_list<column> columns);
|
||||
query_builder& table(const std::string &table, const std::vector<column> &columns);
|
||||
query_builder& table(const std::string &table);
|
||||
query_builder& into(const std::string &table, std::initializer_list<std::string> column_names);
|
||||
query_builder& values(std::initializer_list<any_type> values);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define QUERY_QUERY_INTERMEDIATES_HPP
|
||||
|
||||
#include "matador/sql/column.hpp"
|
||||
#include "matador/sql/column_generator.hpp"
|
||||
#include "matador/sql/key_value_pair.hpp"
|
||||
#include "matador/sql/query_result.hpp"
|
||||
#include "matador/sql/record.hpp"
|
||||
@@ -136,6 +137,11 @@ public:
|
||||
using query_intermediate::query_intermediate;
|
||||
|
||||
query_execute_finish table(const std::string &table, std::initializer_list<column> columns);
|
||||
template<class Type>
|
||||
query_execute_finish table(const std::string &table)
|
||||
{
|
||||
return {db(), query().table(table, column_generator::generate<Type>())};
|
||||
}
|
||||
};
|
||||
|
||||
class query_drop_intermediate : query_intermediate
|
||||
|
||||
Reference in New Issue
Block a user