renamed class attribute_definition_generator to attribute_generator
This commit is contained in:
parent
758284c2b3
commit
a146dce321
|
|
@ -52,18 +52,17 @@ private:
|
|||
utils::basic_type type_{};
|
||||
};
|
||||
|
||||
class attribute_definition_generator final {
|
||||
class attribute_generator final {
|
||||
private:
|
||||
attribute_definition_generator(std::vector<attribute> &columns, const repository &repo);
|
||||
attribute_generator(std::vector<attribute> &columns, const repository &repo);
|
||||
|
||||
public:
|
||||
~attribute_definition_generator() = default;
|
||||
~attribute_generator() = default;
|
||||
|
||||
template < class Type >
|
||||
static std::vector<attribute> generate(const repository &repo)
|
||||
{
|
||||
static std::vector<attribute> generate(const repository &repo) {
|
||||
std::vector<attribute> columns;
|
||||
attribute_definition_generator gen(columns, repo);
|
||||
attribute_generator gen(columns, repo);
|
||||
Type obj;
|
||||
access::process(gen, obj);
|
||||
return columns;
|
||||
|
|
@ -72,7 +71,7 @@ public:
|
|||
template < class Type >
|
||||
static std::vector<attribute> generate(const Type& obj, const repository &repo) {
|
||||
std::vector<attribute> columns;
|
||||
attribute_definition_generator gen(columns, repo);
|
||||
attribute_generator gen(columns, repo);
|
||||
access::process(gen, obj);
|
||||
return columns;
|
||||
}
|
||||
|
|
@ -133,17 +132,17 @@ private:
|
|||
};
|
||||
|
||||
template<typename ValueType>
|
||||
void attribute_definition_generator::on_primary_key(const char *id, ValueType &x, const utils::primary_key_attribute& attr) {
|
||||
void attribute_generator::on_primary_key(const char *id, ValueType &x, const utils::primary_key_attribute& attr) {
|
||||
on_attribute(id, x, { attr.size(), utils::constraints::PRIMARY_KEY });
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
void attribute_definition_generator::on_attribute(const char *id, Type &x, const utils::field_attributes &attr) {
|
||||
void attribute_generator::on_attribute(const char *id, Type &x, const utils::field_attributes &attr) {
|
||||
columns_.emplace_back(id, utils::data_type_traits<Type>::type(attr.size()), attr, null_option_type::NOT_NULL);
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
void attribute_definition_generator::on_attribute(const char *id, std::optional<Type> & /*x*/, const utils::field_attributes &attr)
|
||||
void attribute_generator::on_attribute(const char *id, std::optional<Type> & /*x*/, const utils::field_attributes &attr)
|
||||
{
|
||||
columns_.emplace_back(id, utils::data_type_traits<Type>::type(attr.size()), attr, null_option_type::NULLABLE);
|
||||
}
|
||||
|
|
@ -178,7 +178,7 @@ private:
|
|||
private:
|
||||
friend class internal::shadow_repository;
|
||||
friend class repository_node;
|
||||
friend class attribute_definition_generator;
|
||||
friend class attribute_generator;
|
||||
|
||||
std::string name_;
|
||||
std::shared_ptr<repository_node> root_;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef SCHEMA_NODE_HPP
|
||||
#define SCHEMA_NODE_HPP
|
||||
|
||||
#include "matador/object/attribute_definition_generator.hpp"
|
||||
#include "matador/object/attribute_generator.hpp"
|
||||
#include "matador/object/object_info.hpp"
|
||||
#include "matador/object/primary_key_resolver.hpp"
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ public:
|
|||
primary_key_resolver resolver;
|
||||
auto pk_info = resolver.resolve<Type>();
|
||||
auto ref_column = determine_reference_column(typeid(Type), name, pk_info, repo);
|
||||
const auto attributes = attribute_definition_generator::generate<Type>(repo);
|
||||
const auto attributes = attribute_generator::generate<Type>(repo);
|
||||
auto info = std::make_unique<object_info<Type>>(
|
||||
node,
|
||||
attributes,
|
||||
|
|
@ -47,7 +47,7 @@ public:
|
|||
auto obj = creator();
|
||||
auto info = std::make_unique<object_info<Type>>(
|
||||
result.value(),
|
||||
attribute_definition_generator::generate(*obj, repo),
|
||||
attribute_generator::generate(*obj, repo),
|
||||
std::move(creator)
|
||||
);
|
||||
result.value()->info_ = std::move(info);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include "matador/query/intermediates/executable_query.hpp"
|
||||
|
||||
#include "matador/object/attribute_definition_generator.hpp"
|
||||
#include "matador/object/attribute_generator.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ public:
|
|||
executable_query table(const query::table &tab, const std::vector<object::attribute> &columns);
|
||||
template<class Type>
|
||||
executable_query table(const matador::query::table &tab, const object::repository &schema) {
|
||||
return this->table(tab, object::attribute_definition_generator::generate<Type>(schema));
|
||||
return this->table(tab, object::attribute_generator::generate<Type>(schema));
|
||||
}
|
||||
executable_query schema(const std::string &schema_name);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ add_library(matador-core STATIC
|
|||
../../include/matador/net/select_fd_sets.hpp
|
||||
../../include/matador/net/socket_interrupter.hpp
|
||||
../../include/matador/object/attribute.hpp
|
||||
../../include/matador/object/attribute_definition_generator.hpp
|
||||
../../include/matador/object/attribute_generator.hpp
|
||||
../../include/matador/object/basic_object_info.hpp
|
||||
../../include/matador/object/error_code.hpp
|
||||
../../include/matador/object/foreign_node_completer.hpp
|
||||
|
|
@ -75,7 +75,7 @@ add_library(matador-core STATIC
|
|||
logger/logger.cpp
|
||||
logger/rotating_file_sink.cpp
|
||||
object/attribute.cpp
|
||||
object/attribute_definition_generator.cpp
|
||||
object/attribute_generator.cpp
|
||||
object/basic_object_info.cpp
|
||||
object/error_code.cpp
|
||||
object/foreign_node_completer.cpp
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
#include "matador/object/attribute_definition_generator.hpp"
|
||||
#include "matador/object/repository.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
|
||||
attribute_definition_generator::attribute_definition_generator(std::vector<attribute> &columns, const repository &repo)
|
||||
: columns_(columns)
|
||||
, repo_(repo)
|
||||
{}
|
||||
|
||||
void attribute_definition_generator::on_revision(const char *id, uint64_t &rev) {
|
||||
on_attribute(id, rev);
|
||||
}
|
||||
|
||||
utils::result<std::shared_ptr<attribute>, utils::error> attribute_definition_generator::determine_foreign_ref(const std::type_index &ti) const {
|
||||
return repo_.reference_column(ti);
|
||||
}
|
||||
|
||||
void attribute_definition_generator::insert_missing_reference_column(const std::type_index& ti, const std::shared_ptr<attribute>& ref_column) const {
|
||||
const_cast<repository&>(repo_).missing_references_.insert({ti, ref_column});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#include "matador/object/attribute_generator.hpp"
|
||||
#include "matador/object/repository.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
|
||||
attribute_generator::attribute_generator(std::vector<attribute> &columns, const repository &repo)
|
||||
: columns_(columns)
|
||||
, repo_(repo)
|
||||
{}
|
||||
|
||||
void attribute_generator::on_revision(const char *id, uint64_t &rev) {
|
||||
on_attribute(id, rev);
|
||||
}
|
||||
|
||||
utils::result<std::shared_ptr<attribute>, utils::error> attribute_generator::determine_foreign_ref(const std::type_index &ti) const {
|
||||
return repo_.reference_column(ti);
|
||||
}
|
||||
|
||||
void attribute_generator::insert_missing_reference_column(const std::type_index& ti, const std::shared_ptr<attribute>& ref_column) const {
|
||||
const_cast<repository&>(repo_).missing_references_.insert({ti, ref_column});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "matador/object/attribute_definition_generator.hpp"
|
||||
#include "matador/object/attribute_generator.hpp"
|
||||
#include "matador/object/repository.hpp"
|
||||
|
||||
#include "../test/models/product.hpp"
|
||||
|
|
@ -17,7 +17,7 @@ TEST_CASE("Generate column definitions from object", "[column][definition][gener
|
|||
.and_then([&repo] { return repo.attach<matador::test::category>("categories"); });
|
||||
REQUIRE(result);
|
||||
|
||||
auto columns = attribute_definition_generator::generate<matador::test::product>(repo);
|
||||
auto columns = attribute_generator::generate<matador::test::product>(repo);
|
||||
|
||||
const std::vector expected_columns = {
|
||||
attribute{"product_name", basic_type::type_varchar, constraints::PRIMARY_KEY, null_option_type::NOT_NULL },
|
||||
|
|
@ -43,7 +43,7 @@ TEST_CASE("Generate column definitions from object", "[column][definition][gener
|
|||
TEST_CASE("Generate columns from object with nullable columns", "[column generator]") {
|
||||
repository repo("main");
|
||||
|
||||
auto columns = attribute_definition_generator::generate<matador::test::optional>(repo);
|
||||
auto columns = attribute_generator::generate<matador::test::optional>(repo);
|
||||
|
||||
const std::vector expected_columns = {
|
||||
attribute{"id", basic_type::type_uint32, constraints::PRIMARY_KEY, null_option_type::NOT_NULL },
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#include <matador/query/query.hpp>
|
||||
#include "matador/query/table.hpp"
|
||||
|
||||
#include "matador/object/attribute_definition_generator.hpp"
|
||||
#include "matador/object/attribute_generator.hpp"
|
||||
|
||||
#include "matador/sql/connection.hpp"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue