schema node analyze progress

This commit is contained in:
Sascha Kühl
2025-02-10 16:04:49 +01:00
parent 504e111491
commit e3e0eb932c
12 changed files with 137 additions and 65 deletions
+58 -16
View File
@@ -5,23 +5,47 @@
namespace matador::object {
attribute_definition::attribute_definition(const char *name)
: name_(name)
, attributes_(utils::null_attributes) {
: name_(name)
, attributes_(utils::null_attributes) {
}
attribute_definition::attribute_definition(std::string name)
: name_(std::move(name))
, attributes_(utils::null_attributes) {
: name_(std::move(name))
, attributes_(utils::null_attributes) {
}
attribute_definition::attribute_definition(std::string name,
std::string table_name,
const utils::basic_type type,
const utils::field_attributes& attr)
: name_(std::move(name))
, table_(std::move(table_name))
, index_(0)
, attributes_(attr)
, value_(type, attr.size()) {
}
attribute_definition::attribute_definition(std::string name, const utils::basic_type type,
const utils::field_attributes &attr, const null_option null_opt,
const size_t index)
: name_(std::move(name))
, index_(index)
, attributes_(attr)
, null_option_(null_opt)
, value_(type, attr.size()) {
: name_(std::move(name))
, index_(index)
, attributes_(attr)
, null_option_(null_opt)
, value_(type, attr.size()) {
}
attribute_definition::attribute_definition(std::string name,
std::string table_name,
const utils::basic_type type,
const utils::field_attributes &attr, const null_option null_opt,
const size_t index)
: name_(std::move(name))
, table_(std::move(table_name))
, index_(index)
, attributes_(attr)
, null_option_(null_opt)
, value_(type, attr.size()) {
}
attribute_definition::attribute_definition(std::string name,
@@ -29,12 +53,12 @@ attribute_definition::attribute_definition(std::string name,
const size_t index,
const std::shared_ptr<attribute_definition> &ref_column,
const utils::field_attributes &attr, const null_option null_opt)
: name_(std::move(name))
, index_(index)
, attributes_(attr)
, null_option_(null_opt)
, value_(type, attr.size())
, reference_column_(ref_column) {
: name_(std::move(name))
, index_(index)
, attributes_(attr)
, null_option_(null_opt)
, value_(type, attr.size())
, reference_column_(ref_column) {
}
const std::string &attribute_definition::name() const {
@@ -140,7 +164,25 @@ attribute_definition make_pk_column<std::string>(const std::string &name, size_t
}
template<>
[[maybe_unused]] attribute_definition make_fk_column<std::string>(const std::string &name, size_t size, const std::shared_ptr<attribute_definition> &ref_column) {
attribute_definition make_fk_column<std::string>(const std::string &name, size_t size, const std::shared_ptr<attribute_definition> &ref_column) {
return {
name, utils::data_type_traits<std::string>::type(size), 0, ref_column,
{size, utils::constraints::FOREIGN_KEY}, null_option::NOT_NULL
};
}
template<>
attribute_definition 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_definition>(ref_column_name, ref_table_name, utils::basic_type::type_varchar, utils::constraints::FOREIGN_KEY),
{ 0, utils::constraints::FOREIGN_KEY }, null_option::NOT_NULL
};
}
template<>
attribute_definition 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_definition>(ref_column_name, ref_table_name, utils::basic_type::type_varchar, utils::constraints::FOREIGN_KEY);
return {
name, utils::data_type_traits<std::string>::type(size), 0, ref_column,
{size, utils::constraints::FOREIGN_KEY}, null_option::NOT_NULL
+9 -5
View File
@@ -5,22 +5,26 @@
#include <algorithm>
namespace matador::object {
basic_object_info::basic_object_info(schema_node &node,
const std::type_index type_index,
basic_object_info::basic_object_info(const std::type_index type_index,
object_definition &&definition,
std::shared_ptr<attribute_definition> &&reference_column)
: node_(node)
, type_index_(type_index)
: type_index_(type_index)
, definition_(std::move(definition))
, reference_column_(std::move(reference_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)) {
}
std::type_index basic_object_info::type_index() const {
return type_index_;
}
std::string basic_object_info::name() const {
return node_.name();
return node_->name();
}
const object_definition &basic_object_info::definition() const {
+3 -6
View File
@@ -2,21 +2,18 @@
namespace matador::object {
object_definition::object_definition(const std::initializer_list<attribute_definition> columns)
: columns_(columns)
{
: columns_(columns) {
init();
}
object_definition::object_definition(const std::vector<attribute_definition> &columns)
: columns_(columns)
{
: columns_(columns) {
init();
}
object_definition::object_definition(const object_definition &x)
: columns_(x.columns_)
, pk_index_(x.pk_index_)
{
, pk_index_(x.pk_index_) {
for (auto& col : columns_) {
add_to_map(col, col.index());
}
+1 -1
View File
@@ -45,7 +45,7 @@ utils::result<std::shared_ptr<attribute_definition>, utils::error> schema::refer
return utils::failure(make_error(error_code::Failure, "Primary key not found"));
}
return utils::ok(std::make_pair(node->name(), node->basic_info().definition().primary_key()->name()));
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));
}
utils::result<std::shared_ptr<schema_node>, utils::error> schema::attach_node(const std::shared_ptr<schema_node> &node,
+1 -2
View File
@@ -5,13 +5,12 @@
namespace matador::object {
schema_node::schema_node(schema &tree)
: schema_(tree)
, info_(std::make_unique<null_info>(*this, object_definition{})) {
, info_(std::make_unique<null_info>(object_definition{}, std::shared_ptr<attribute_definition>{})) {
}
schema_node::schema_node(schema &tree, std::string name, std::unique_ptr<basic_object_info> &&info)
: schema_(tree)
, info_(std::move(info))
// , info_(std::make_unique<object_info<Type>>(*this, object_definition(attribute_definition_generator::generate<Type>(schema_))))
, 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)) {