attaching schema nodes progress

This commit is contained in:
Sascha Kühl
2025-07-14 15:57:14 +02:00
parent 1b2847696d
commit 0d93b9b1ed
19 changed files with 182 additions and 91 deletions
@@ -77,6 +77,10 @@ std::string attribute_definition::table_name() const {
return table_;
}
void attribute_definition::table_name( const std::string& tn ) {
table_= tn;
}
int attribute_definition::index() const {
return index_;
}
@@ -85,6 +89,10 @@ const utils::field_attributes &attribute_definition::attributes() const {
return attributes_;
}
utils::field_attributes& attribute_definition::attributes() {
return attributes_;
}
bool attribute_definition::is_nullable() const {
return null_option_ == null_option::NULLABLE;
}
@@ -3,7 +3,7 @@
namespace matador::object {
attribute_definition_generator::attribute_definition_generator(std::vector<object::attribute_definition> &columns, const schema &repo)
attribute_definition_generator::attribute_definition_generator(std::vector<object::attribute_definition> &columns, schema &repo)
: columns_(columns)
, repo_(repo)
{}
@@ -19,7 +19,11 @@ void attribute_definition_generator::on_revision(const char *id, uint64_t &rev)
}
utils::result<std::shared_ptr<attribute_definition>, utils::error> attribute_definition_generator::determine_foreign_ref(const std::type_index &ti) const {
return repo_.reference(ti);
return repo_.reference_column(ti);
}
void attribute_definition_generator::insert_missing_reference_column(const std::type_index& ti, std::shared_ptr<attribute_definition> ref_column) const {
repo_.missing_references_.insert({ti, ref_column});
}
void fk_attribute_generator::on_primary_key(const char *, std::string &, const size_t size)
+5 -8
View File
@@ -8,34 +8,31 @@ namespace matador::object {
basic_object_info::basic_object_info(std::shared_ptr<schema_node> node,
const std::type_index type_index,
utils::identifier &&pk,
std::shared_ptr<attribute_definition> &&pk_column,
const std::shared_ptr<attribute_definition> &pk_column,
object_definition &&definition)
: node_(std::move(node))
, type_index_(type_index)
, definition_(std::move(definition))
, identifier_(std::move(pk))
, pk_column_(std::move(pk_column)) {
, pk_column_(pk_column) {
}
basic_object_info::basic_object_info(std::shared_ptr<schema_node> node,
const std::type_index type_index,
utils::identifier &&pk,
std::shared_ptr<attribute_definition> &&pk_column)
const std::shared_ptr<attribute_definition> &pk_column)
: node_(std::move(node))
, type_index_(type_index)
, identifier_(std::move(pk))
, pk_column_(std::move(pk_column)) {
, pk_column_(pk_column) {
}
basic_object_info::basic_object_info(std::shared_ptr<schema_node> node,
const std::type_index type_index,
object_definition &&definition)
: node_(std::move(node))
, type_index_(type_index)
, definition_(std::move(definition)) {}
std::type_index basic_object_info::type_index() const {
return type_index_;
return node_->type_index();
}
std::string basic_object_info::name() const {
+3 -3
View File
@@ -53,7 +53,7 @@ bool schema::contains( const std::type_index& index ) const {
return nodes_by_type_.count(index) > 0;
}
utils::result<std::shared_ptr<attribute_definition>, utils::error> schema::reference(const std::type_index &type_index) const {
utils::result<std::shared_ptr<attribute_definition>, utils::error> schema::reference_column(const std::type_index &type_index) const {
const auto result = find_node(type_index);
if (result) {
return utils::ok((*result)->info().reference_column());
@@ -64,8 +64,8 @@ utils::result<std::shared_ptr<attribute_definition>, utils::error> schema::refer
void schema::dump(std::ostream &os) const {
for (const auto &node : *this) {
os << "node [" << node.name() << "] (" << node.type_index().name() << ")\n";
for (auto it = node.info().endpoint_begin(); it != node.info().endpoint_end(); ++it) {
os << "node [" << node->name() << "] (" << node->type_index().name() << ")\n";
for (auto it = node->info().endpoint_begin(); it != node->info().endpoint_end(); ++it) {
os << " " << /*node.name() << "::" <<*/ it->second->field_name() << " (" << it->second->type_name() << ")";
if (it->second->foreign_endpoint()) {
os << " <---> " << it->second->foreign_endpoint()->node().name() << "::" << it->second->foreign_endpoint()->field_name() << " (" << it->second->foreign_endpoint()->type_name() << ")\n";
+40 -6
View File
@@ -1,14 +1,22 @@
#include <utility>
#include "matador/object/schema.hpp"
#include "matador/object/schema_node.hpp"
namespace matador::object {
schema_node::schema_node(object::schema &tree)
: schema_(tree) {
: schema_(tree)
, type_index_(typeid(detail::null_type)){
}
schema_node::schema_node(object::schema &tree, std::string name)
schema_node::schema_node(object::schema &tree, const std::type_index& ti)
: schema_(tree)
, type_index_(ti) {
}
schema_node::schema_node(object::schema &tree, std::string name, const std::type_index& ti)
: schema_(tree)
, type_index_(ti)
, first_child_(std::shared_ptr<schema_node>(new schema_node(tree)))
, last_child_(std::shared_ptr<schema_node>(new schema_node(tree)))
, name_(std::move(name)) {
@@ -28,7 +36,7 @@ std::string schema_node::name() const {
}
std::type_index schema_node::type_index() const {
return info_->type_index();
return type_index_;
}
const basic_object_info &schema_node::info() const {
@@ -37,7 +45,7 @@ const basic_object_info &schema_node::info() const {
void schema_node::update_name(const std::string& name) {
name_ = name;
info_->reference_column()->name(name);
info_->reference_column()->table_name(name);
}
const object::schema& schema_node::schema() const {
@@ -50,7 +58,7 @@ bool schema_node::has_children() const {
schema_node::node_ptr schema_node::next() const {
// if we have a child, child is the next iterator to return
// (if we don't do iterate over the siblings)
// (if we don't iterate over the siblings)
if (first_child_ && first_child_->next_sibling_ != last_child_) {
return first_child_->next_sibling_;
}
@@ -65,7 +73,7 @@ schema_node::node_ptr schema_node::next() const {
}
schema_node::node_ptr schema_node::prev() const {
// if node has a previous sibling, we set it
// if the node has a previous sibling, we set it
// as our next iterator. then we check if there
// are last children. if so, we set the last-last
// child as our iterator
@@ -87,4 +95,30 @@ void schema_node::unlink() {
next_sibling_.reset();
previous_sibling_.reset();
}
utils::result<schema_node::node_ptr, utils::error> schema_node::make_and_attach_node(object::schema& tree, const std::string& name, const std::type_index& ti) {
const auto node = std::shared_ptr<schema_node>(new schema_node(tree, name, ti));
return tree.attach_node(node, "");
}
std::shared_ptr<attribute_definition> schema_node::determine_reference_column(const std::type_index& ti, const std::string& name, const primary_key_info& pk_info, object::schema& tree) {
const auto it = tree.missing_references_.find(ti);
if (it == tree.missing_references_.end()) {
return std::make_shared<attribute_definition>(pk_info.pk_column_name, name, pk_info.type, utils::constraints::FOREIGN_KEY);
}
auto ref_column = it->second;
tree.missing_references_.erase(it);
ref_column->name(pk_info.pk_column_name);
ref_column->table_name(name);
ref_column->type(pk_info.type);
ref_column->attributes() = utils::constraints::FOREIGN_KEY;
if (name.empty()) {
tree.missing_references_.insert({ti, ref_column});
}
return ref_column;
}
}
+5 -5
View File
@@ -4,8 +4,8 @@
namespace matador::object {
const_schema_node_iterator::const_schema_node_iterator(std::shared_ptr<value_type> node)
: node_(std::move(node))
const_schema_node_iterator::const_schema_node_iterator(const value_type& node)
: node_(node)
{}
bool const_schema_node_iterator::operator==(const const_schema_node_iterator &i) const
@@ -25,7 +25,7 @@ const_schema_node_iterator& const_schema_node_iterator::operator++()
}
const_schema_node_iterator const_schema_node_iterator::operator++( int ) {
const std::shared_ptr<value_type> tmp = node_;
const value_type tmp = node_;
increment();
return const_schema_node_iterator(tmp);
}
@@ -38,7 +38,7 @@ const_schema_node_iterator& const_schema_node_iterator::operator--()
const_schema_node_iterator const_schema_node_iterator::operator--(int)
{
const std::shared_ptr<value_type> tmp = node_;
const value_type tmp = node_;
decrement();
return const_schema_node_iterator(tmp);
}
@@ -50,7 +50,7 @@ const_schema_node_iterator::pointer const_schema_node_iterator::operator->() con
const_schema_node_iterator::reference const_schema_node_iterator::operator*() const
{
return *node_;
return node_;
}
const_schema_node_iterator::pointer const_schema_node_iterator::get() const
+7 -4
View File
@@ -81,9 +81,12 @@ bool operator<(const error &lhs, const std::error_code &rhs) {
return lhs.ec_ < rhs;
}
// std::ostream & operator<<(std::ostream &out, const error &err) {
// out << err.ec_ << " " << err.ec_.message();
// return out;
// }
std::ostream & operator<<(std::ostream &out, const error &err) {
out << err.ec_ << " " << err.ec_.message() << "\n";
for (const auto & [key, value] : err.error_infos_) {
out << " " << key << ": " << value << "\n";
}
return out;
}
}