removed make_relation_node method from repository_node

This commit is contained in:
2025-12-08 19:45:35 +01:00
parent 263c202c69
commit d4ef97ef5a
15 changed files with 90 additions and 133 deletions
+5 -41
View File
@@ -92,45 +92,9 @@ bool attribute::is_null() const {
return type_ == utils::basic_type::type_null;
}
// attribute make_column(const std::string &name, utils::basic_type type, utils::field_attributes attr,
// null_option_type null_opt) {
// return {name, type, attr, null_opt};
// }
//
// template<>
// attribute make_column<std::string>(const std::string &name, utils::field_attributes attr,
// null_option_type null_opt) {
// return make_column(name, utils::data_type_traits<std::string>::type(attr.size()), attr, null_opt);
// }
//
// template<>
// attribute make_pk_column<std::string>(const std::string &name, size_t size) {
// 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::ForeignKey}, null_option_type::NOT_NULL
// };
// }
//
// 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::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::ForeignKey});
// return {
// name, utils::data_type_traits<std::string>::type(size), 0, ref_column,
// {size, utils::constraints::ForeignKey}, null_option_type::NOT_NULL
// };
// }
std::ostream & operator<<(std::ostream &os, const attribute &attr) {
os << attr.name_;
return os;
}
}
+5 -1
View File
@@ -20,7 +20,7 @@ namespace matador::object {
// : node_(std::move(node))
// , attributes_(attributes) {}
basic_object_info::basic_object_info(std::shared_ptr<repository_node> node, std::unique_ptr<object>&& obj)
basic_object_info::basic_object_info(std::shared_ptr<repository_node> node, std::unique_ptr<class object>&& obj)
: object_(std::move(obj))
, node_(std::move(node)) {}
@@ -32,6 +32,10 @@ std::string basic_object_info::name() const {
return node_->name();
}
const class object & basic_object_info::object() const {
return *object_;
}
const std::list<attribute>& basic_object_info::attributes() const {
return object_->attributes();
}
+5
View File
@@ -52,6 +52,11 @@ const std::string& constraint::ref_column_name() const {
return ref_column_name_;
}
std::ostream & operator<<(std::ostream &os, const class constraint &c) {
os << "constraint " << c.name_ << " for column " << c.column_name();
return os;
}
constraint_builder & constraint_builder::constraint(std::string name) {
constraint_name = std::move(name);
return *this;
+14 -1
View File
@@ -75,4 +75,17 @@ size_t object::constraint_count() const {
const std::list<class constraint>& object::constraints() const {
return constraints_;
}
}
std::ostream & operator<<(std::ostream &os, const object &obj) {
os << "Object " << obj.name_ << "\nAttributes:\n";
for (const auto &attr : obj.attributes_) {
os << " " << attr << "\n";
}
os << "Constraints:\n";
for (const auto &con : obj.constraints_) {
os << " " << con << "\n";
}
os << "\n";
return os;
}
}
+1 -24
View File
@@ -26,7 +26,7 @@ repository_node::repository_node(repository &repo, std::string name, const std::
std::shared_ptr<repository_node> repository_node::make_null_node(repository &repo) {
auto node = std::shared_ptr<repository_node>(new repository_node(repo));
node->info_ = std::make_unique<null_info>(node/*, std::shared_ptr<attribute_definition>{}*/);
node->info_ = std::make_unique<null_info>(node);
return node;
}
@@ -101,27 +101,4 @@ utils::result<repository_node::node_ptr, utils::error> repository_node::make_and
return repo.attach_node(node, "");
}
attribute* repository_node::determine_reference_column(const std::type_index& ti,
const std::string& table_name,
const primary_key_info& pk_info,
repository& repo) {
const auto it = repo.missing_references_.find(ti);
if (it == repo.missing_references_.end()) {
return new attribute(pk_info.pk_column_name, pk_info.type, {utils::constraints::ForeignKey}, null_option_type::NotNull);
}
auto ref_column = it->second;
repo.missing_references_.erase(it);
ref_column->name(pk_info.pk_column_name);
ref_column->owner()->update_name(table_name);
ref_column->change_type(pk_info.type);
ref_column->attributes() = utils::constraints::ForeignKey;
if (table_name.empty()) {
repo.missing_references_.insert({ti, ref_column});
}
return ref_column;
}
}