preparations for object_generator (generating objects with attributes and constraints)
This commit is contained in:
@@ -147,14 +147,14 @@ attribute make_column<std::string>(const std::string &name, utils::field_attribu
|
||||
|
||||
template<>
|
||||
attribute make_pk_column<std::string>(const std::string &name, size_t size) {
|
||||
return make_column<std::string>(name, {size, utils::constraints::PRIMARY_KEY});
|
||||
return make_column<std::string>(name, {size, utils::constraints::PrimaryKey});
|
||||
}
|
||||
|
||||
template<>
|
||||
attribute make_fk_column<std::string>(const std::string &name, size_t size, const std::shared_ptr<attribute> &ref_column) {
|
||||
return {
|
||||
name, utils::data_type_traits<std::string>::type(size), 0, ref_column,
|
||||
{size, utils::constraints::FOREIGN_KEY}, null_option_type::NOT_NULL
|
||||
{size, utils::constraints::ForeignKey}, null_option_type::NOT_NULL
|
||||
};
|
||||
}
|
||||
|
||||
@@ -162,17 +162,17 @@ template<>
|
||||
attribute make_fk_column<std::string>( const std::string& name, const std::string& ref_table_name, const std::string& ref_column_name ) {
|
||||
return {
|
||||
name, utils::basic_type::type_varchar, 0,
|
||||
std::make_shared<attribute>(ref_column_name, utils::basic_type::type_varchar, ref_table_name, attribute_options{utils::constraints::FOREIGN_KEY}),
|
||||
{ 0, utils::constraints::FOREIGN_KEY }, null_option_type::NOT_NULL
|
||||
std::make_shared<attribute>(ref_column_name, utils::basic_type::type_varchar, ref_table_name, attribute_options{utils::constraints::ForeignKey}),
|
||||
{ 0, utils::constraints::ForeignKey }, null_option_type::NOT_NULL
|
||||
};
|
||||
}
|
||||
|
||||
template<>
|
||||
attribute make_fk_column<std::string>(const std::string &name, size_t size, const std::string &ref_table_name, const std::string &ref_column_name) {
|
||||
const auto ref_column = std::make_shared<attribute>(ref_column_name, utils::basic_type::type_varchar, ref_table_name, attribute_options{utils::constraints::FOREIGN_KEY});
|
||||
const auto ref_column = std::make_shared<attribute>(ref_column_name, utils::basic_type::type_varchar, ref_table_name, attribute_options{utils::constraints::ForeignKey});
|
||||
return {
|
||||
name, utils::data_type_traits<std::string>::type(size), 0, ref_column,
|
||||
{size, utils::constraints::FOREIGN_KEY}, null_option_type::NOT_NULL
|
||||
{size, utils::constraints::ForeignKey}, null_option_type::NOT_NULL
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#include "matador/object/constraint.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
constraint::constraint(std::string name)
|
||||
: name_(std::move(name)) {}
|
||||
|
||||
const std::string & constraint::name() const {
|
||||
return name_;
|
||||
}
|
||||
|
||||
constraint_builder & constraint_builder::constraint(std::string name) {
|
||||
constraint_name = std::move(name);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constraint_builder & constraint_builder::primary_key(std::string name) {
|
||||
column_name = std::move(name);
|
||||
options_ |= utils::constraints::PrimaryKey;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constraint_builder & constraint_builder::foreign_key(std::string name) {
|
||||
column_name = std::move(name);
|
||||
options_ |= utils::constraints::ForeignKey;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constraint_builder & constraint_builder::references(std::string table, std::string column) {
|
||||
ref_table_name = std::move(table);
|
||||
ref_column_name = std::move(column);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constraint_builder::operator class constraint() const {
|
||||
class constraint c;
|
||||
c.name_ = constraint_name;
|
||||
c.options_ = options_;
|
||||
c.ref_column_name_ = ref_column_name;
|
||||
c.ref_table_name_ = ref_table_name;
|
||||
return {};
|
||||
}
|
||||
|
||||
constraint_builder constraint(std::string name) {
|
||||
constraint_builder builder;
|
||||
return builder.constraint(std::move(name));
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,7 @@ std::shared_ptr<attribute> repository_node::determine_reference_column(const std
|
||||
repository& repo) {
|
||||
const auto it = repo.missing_references_.find(ti);
|
||||
if (it == repo.missing_references_.end()) {
|
||||
return std::make_shared<attribute>(pk_info.pk_column_name, pk_info.type, table_name, attribute_options{utils::constraints::FOREIGN_KEY});
|
||||
return std::make_shared<attribute>(pk_info.pk_column_name, pk_info.type, table_name, attribute_options{utils::constraints::ForeignKey});
|
||||
}
|
||||
|
||||
auto ref_column = it->second;
|
||||
@@ -118,7 +118,7 @@ std::shared_ptr<attribute> repository_node::determine_reference_column(const std
|
||||
ref_column->name(pk_info.pk_column_name);
|
||||
ref_column->table_name(table_name);
|
||||
ref_column->change_type(pk_info.type);
|
||||
ref_column->attributes() = utils::constraints::FOREIGN_KEY;
|
||||
ref_column->attributes() = utils::constraints::ForeignKey;
|
||||
|
||||
if (table_name.empty()) {
|
||||
repo.missing_references_.insert({ti, ref_column});
|
||||
|
||||
Reference in New Issue
Block a user