schema node analyze progress

This commit is contained in:
Sascha Kühl
2025-02-11 16:34:06 +01:00
parent a631a5a36c
commit 1d83abcb1b
18 changed files with 174 additions and 96 deletions
@@ -65,6 +65,10 @@ const std::string &attribute_definition::name() const {
return name_;
}
void attribute_definition::name( const std::string& n ) {
name_ = n;
}
std::string attribute_definition::full_name() const {
return table_ + "." + name_;
}
@@ -18,9 +18,8 @@ void attribute_definition_generator::on_revision(const char *id, uint64_t &rev)
on_attribute(id, rev);
}
std::shared_ptr<attribute_definition> attribute_definition_generator::determine_foreign_ref(const std::type_index &ti)
{
return repo_.reference(ti).value();
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);
}
void fk_attribute_generator::on_primary_key(const char *, std::string &, const size_t size)
+18 -10
View File
@@ -5,18 +5,26 @@
#include <algorithm>
namespace matador::object {
basic_object_info::basic_object_info(const std::type_index type_index,
object_definition &&definition,
std::shared_ptr<attribute_definition> &&reference_column)
: type_index_(type_index)
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,
object_definition &&definition)
: node_(std::move(node))
, type_index_(type_index)
, definition_(std::move(definition))
, reference_column_(std::move(reference_column)) {
, identifier_(std::move(pk))
, pk_column_(std::move(pk_column)) {
}
basic_object_info::basic_object_info(const std::type_index type_index,
std::shared_ptr<attribute_definition> &&reference_column)
: type_index_(type_index)
, reference_column_(std::move(reference_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)
: node_(std::move(node))
, type_index_(type_index)
, identifier_(std::move(pk))
, pk_column_(std::move(pk_column)) {
}
std::type_index basic_object_info::type_index() const {
@@ -32,7 +40,7 @@ const object_definition &basic_object_info::definition() const {
}
std::shared_ptr<attribute_definition> basic_object_info::reference_column() const {
return reference_column_;
return pk_column_;
}
} // namespace matador::object
+3 -1
View File
@@ -2,7 +2,9 @@
namespace matador::object {
void primary_key_resolver::on_primary_key(const char *id, const std::string &pk, size_t /*size*/) {
primary_key_info_.column_name = id;
primary_key_info_.pk_column_name = id;
primary_key_info_.type = utils::basic_type::type_varchar;
primary_key_info_.pk = pk;
}
}
+14 -13
View File
@@ -1,3 +1,5 @@
#include <utility>
#include "matador/object/schema.hpp"
namespace matador::object {
@@ -5,13 +7,13 @@ utils::error make_error(const error_code ec, const std::string &msg) {
return utils::error(ec, msg);
}
schema::schema(const std::string &name)
: name_(name)
, root_(std::shared_ptr<schema_node>(new schema_node(*this))) {
root_->first_child_ = std::shared_ptr<schema_node>(new schema_node(*this));
root_->last_child_ = std::shared_ptr<schema_node>(new schema_node(*this));
root_->first_child_->next_sibling_ = root_->last_child_;
root_->last_child_->previous_sibling_ = root_->first_child_;
schema::schema(std::string name)
: name_(std::move(name))
, root_(schema_node::make_null_node(*this)) {
root_->first_child_ = std::shared_ptr<schema_node>(new schema_node(*this));
root_->last_child_ = std::shared_ptr<schema_node>(new schema_node(*this));
root_->first_child_->next_sibling_ = root_->last_child_;
root_->last_child_->previous_sibling_ = root_->first_child_;
}
schema::const_iterator schema::begin() const {
@@ -36,16 +38,15 @@ std::string schema::name() const {
utils::result<std::shared_ptr<attribute_definition>, utils::error> schema::reference(const std::type_index &type_index) const {
const auto result = find_node(type_index);
if (!result) {
return utils::failure(result.err());
if (result) {
return utils::ok((*result)->basic_info().reference_column());
}
const auto &node = *result;
if (!node->basic_info().definition().has_primary_key()) {
return utils::failure(make_error(error_code::Failure, "Primary key not found"));
if (const auto it = expected_node_map_.find(type_index); it != expected_node_map_.end()) {
return utils::ok(it->second->basic_info().reference_column());
}
return utils::ok(std::make_shared<attribute_definition>(node->name(), node->basic_info().definition().primary_key()->name(), utils::basic_type::type_null, utils::constraints::FOREIGN_KEY));
return utils::failure(result.err());
}
utils::result<std::shared_ptr<schema_node>, utils::error> schema::attach_node(const std::shared_ptr<schema_node> &node,
+12 -6
View File
@@ -4,13 +4,11 @@
namespace matador::object {
schema_node::schema_node(schema &tree)
: schema_(tree)
, info_(std::make_unique<null_info>(object_definition{}, std::shared_ptr<attribute_definition>{})) {
: schema_(tree) {
}
schema_node::schema_node(schema &tree, std::string name, std::unique_ptr<basic_object_info> &&info)
schema_node::schema_node(schema &tree, std::string name)
: schema_(tree)
, info_(std::move(info))
, 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)) {
@@ -18,8 +16,11 @@ schema_node::schema_node(schema &tree, std::string name, std::unique_ptr<basic_o
last_child_->previous_sibling_ = first_child_;
}
std::shared_ptr<schema_node> schema_node::make_node(schema &tree, const std::string &name, std::unique_ptr<basic_object_info> &&info) {
return std::shared_ptr<schema_node>(new schema_node(tree, name, std::move(info)));
std::shared_ptr<schema_node> schema_node::make_null_node(schema &tree) {
auto node = std::shared_ptr<schema_node>(new schema_node(tree));
node->info_ = std::make_unique<null_info>(node, std::shared_ptr<attribute_definition>{});
return node;
}
std::string schema_node::name() const {
@@ -34,6 +35,11 @@ const basic_object_info &schema_node::basic_info() const {
return *info_;
}
void schema_node::update_name(const std::string& name) {
name_ = name;
info_->reference_column()->name(name);
}
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)