renamed class attribute_definition to attribute

This commit is contained in:
Sascha Kühl
2025-11-21 09:22:00 +01:00
parent dae3c1645b
commit 758284c2b3
44 changed files with 490 additions and 491 deletions
+2 -2
View File
@@ -13,7 +13,7 @@ add_library(matador-core STATIC
../../include/matador/net/reactor.hpp
../../include/matador/net/select_fd_sets.hpp
../../include/matador/net/socket_interrupter.hpp
../../include/matador/object/attribute_definition.hpp
../../include/matador/object/attribute.hpp
../../include/matador/object/attribute_definition_generator.hpp
../../include/matador/object/basic_object_info.hpp
../../include/matador/object/error_code.hpp
@@ -74,7 +74,7 @@ add_library(matador-core STATIC
logger/log_manager.cpp
logger/logger.cpp
logger/rotating_file_sink.cpp
object/attribute_definition.cpp
object/attribute.cpp
object/attribute_definition_generator.cpp
object/basic_object_info.cpp
object/error_code.cpp
+178
View File
@@ -0,0 +1,178 @@
#include "matador/object/attribute.hpp"
#include <ostream>
#include <utility>
namespace matador::object {
attribute::attribute(const char *name)
: attribute(name, utils::basic_type::type_null, "", {utils::null_attributes}) {
}
attribute::attribute(std::string name)
: attribute(std::move(name), utils::basic_type::type_null, "", {utils::null_attributes}) {
}
attribute::attribute(std::string name,
const utils::basic_type type,
const utils::field_attributes &attr,
const null_option_type null_opt,
const int index)
: attribute(std::move(name), type, "", {attr, null_opt, index}) {
}
attribute::attribute(std::string name,
const utils::basic_type type,
const int index,
const std::shared_ptr<attribute> &ref_column,
const utils::field_attributes &attr,
const null_option_type null_opt)
: attribute(std::move(name), type, "", {attr, null_opt, index}, ref_column) {
}
attribute::attribute( std::string name, const utils::basic_type type, const std::shared_ptr<attribute>& ref_column )
: attribute(std::move(name), type, {}, {}, ref_column) {
}
attribute::attribute(std::string name,
const utils::basic_type type,
std::string table_name,
const attribute_options& options,
const std::shared_ptr<attribute>& ref_column)
: name_(std::move(name))
, table_name_(std::move(table_name))
, options_( options )
, type_( type )
, reference_column_( ref_column ) {
}
const std::string &attribute::name() const {
return name_;
}
void attribute::name( const std::string& n ) {
name_ = n;
}
std::string attribute::full_name() const {
return !table_name_.empty() ? table_name_ + "." + name_ : name_;
}
int attribute::index() const {
return options_.index;
}
const utils::field_attributes &attribute::attributes() const {
return options_.attributes;
}
utils::field_attributes& attribute::attributes() {
return options_.attributes;
}
bool attribute::is_nullable() const {
return options_.null_option == null_option_type::NULLABLE;
}
utils::basic_type attribute::type() const {
return type_;
}
const std::string& attribute::table_name() const {
return table_name_;
}
void attribute::table_name( const std::string& name ) {
table_name_ = name;
}
void attribute::change_type(const utils::basic_type type, const utils::field_attributes& attr) {
options_.attributes = attr;
type_ = type;
}
std::shared_ptr<attribute> attribute::reference_column() const {
return reference_column_;
}
bool attribute::is_foreign_reference() const {
return reference_column_ != nullptr;
}
bool attribute::is_integer() const {
return type_ >= utils::basic_type::type_int8 && type_ <= utils::basic_type::type_uint64;
}
bool attribute::is_floating_point() const {
return type_ == utils::basic_type::type_float || type_ == utils::basic_type::type_double;
}
bool attribute::is_bool() const {
return type_ == utils::basic_type::type_bool;
}
bool attribute::is_string() const {
return type_ == utils::basic_type::type_text;
}
bool attribute::is_varchar() const {
return type_ == utils::basic_type::type_varchar;
}
bool attribute::is_date() const {
return type_ == utils::basic_type::type_date;
}
bool attribute::is_time() const {
return type_ == utils::basic_type::type_time;
}
bool attribute::is_blob() const {
return type_ == utils::basic_type::type_blob;
}
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::PRIMARY_KEY});
}
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
};
}
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
};
}
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});
return {
name, utils::data_type_traits<std::string>::type(size), 0, ref_column,
{size, utils::constraints::FOREIGN_KEY}, null_option_type::NOT_NULL
};
}
}
-178
View File
@@ -1,178 +0,0 @@
#include "matador/object/attribute_definition.hpp"
#include <ostream>
#include <utility>
namespace matador::object {
attribute_definition::attribute_definition(const char *name)
: attribute_definition(name, utils::basic_type::type_null, "", {utils::null_attributes}) {
}
attribute_definition::attribute_definition(std::string name)
: attribute_definition(std::move(name), utils::basic_type::type_null, "", {utils::null_attributes}) {
}
attribute_definition::attribute_definition(std::string name,
const utils::basic_type type,
const utils::field_attributes &attr,
const null_option_type null_opt,
const int index)
: attribute_definition(std::move(name), type, "", {attr, null_opt, index}) {
}
attribute_definition::attribute_definition(std::string name,
const utils::basic_type type,
const int index,
const std::shared_ptr<attribute_definition> &ref_column,
const utils::field_attributes &attr,
const null_option_type null_opt)
: attribute_definition(std::move(name), type, "", {attr, null_opt, index}, ref_column) {
}
attribute_definition::attribute_definition( std::string name, const utils::basic_type type, const std::shared_ptr<attribute_definition>& ref_column )
: attribute_definition(std::move(name), type, {}, {}, ref_column) {
}
attribute_definition::attribute_definition(std::string name,
const utils::basic_type type,
std::string table_name,
const attribute_options& options,
const std::shared_ptr<attribute_definition>& ref_column)
: name_(std::move(name))
, table_name_(std::move(table_name))
, options_( options )
, type_( type )
, reference_column_( ref_column ) {
}
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_.empty() ? table_name_ + "." + name_ : name_;
}
int attribute_definition::index() const {
return options_.index;
}
const utils::field_attributes &attribute_definition::attributes() const {
return options_.attributes;
}
utils::field_attributes& attribute_definition::attributes() {
return options_.attributes;
}
bool attribute_definition::is_nullable() const {
return options_.null_option == null_option_type::NULLABLE;
}
utils::basic_type attribute_definition::type() const {
return type_;
}
const std::string& attribute_definition::table_name() const {
return table_name_;
}
void attribute_definition::table_name( const std::string& name ) {
table_name_ = name;
}
void attribute_definition::change_type(const utils::basic_type type, const utils::field_attributes& attr) {
options_.attributes = attr;
type_ = type;
}
std::shared_ptr<attribute_definition> attribute_definition::reference_column() const {
return reference_column_;
}
bool attribute_definition::is_foreign_reference() const {
return reference_column_ != nullptr;
}
bool attribute_definition::is_integer() const {
return type_ >= utils::basic_type::type_int8 && type_ <= utils::basic_type::type_uint64;
}
bool attribute_definition::is_floating_point() const {
return type_ == utils::basic_type::type_float || type_ == utils::basic_type::type_double;
}
bool attribute_definition::is_bool() const {
return type_ == utils::basic_type::type_bool;
}
bool attribute_definition::is_string() const {
return type_ == utils::basic_type::type_text;
}
bool attribute_definition::is_varchar() const {
return type_ == utils::basic_type::type_varchar;
}
bool attribute_definition::is_date() const {
return type_ == utils::basic_type::type_date;
}
bool attribute_definition::is_time() const {
return type_ == utils::basic_type::type_time;
}
bool attribute_definition::is_blob() const {
return type_ == utils::basic_type::type_blob;
}
bool attribute_definition::is_null() const {
return type_ == utils::basic_type::type_null;
}
attribute_definition 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_definition 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_definition make_pk_column<std::string>(const std::string &name, size_t size) {
return make_column<std::string>(name, {size, utils::constraints::PRIMARY_KEY});
}
template<>
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_type::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, utils::basic_type::type_varchar, ref_table_name, attribute_options{utils::constraints::FOREIGN_KEY}),
{ 0, utils::constraints::FOREIGN_KEY }, null_option_type::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, utils::basic_type::type_varchar, ref_table_name, attribute_options{utils::constraints::FOREIGN_KEY});
return {
name, utils::data_type_traits<std::string>::type(size), 0, ref_column,
{size, utils::constraints::FOREIGN_KEY}, null_option_type::NOT_NULL
};
}
}
@@ -3,7 +3,7 @@
namespace matador::object {
attribute_definition_generator::attribute_definition_generator(std::vector<attribute_definition> &columns, const repository &repo)
attribute_definition_generator::attribute_definition_generator(std::vector<attribute> &columns, const repository &repo)
: columns_(columns)
, repo_(repo)
{}
@@ -12,11 +12,11 @@ void attribute_definition_generator::on_revision(const char *id, uint64_t &rev)
on_attribute(id, rev);
}
utils::result<std::shared_ptr<attribute_definition>, utils::error> attribute_definition_generator::determine_foreign_ref(const std::type_index &ti) const {
utils::result<std::shared_ptr<attribute>, utils::error> attribute_definition_generator::determine_foreign_ref(const std::type_index &ti) const {
return repo_.reference_column(ti);
}
void attribute_definition_generator::insert_missing_reference_column(const std::type_index& ti, const std::shared_ptr<attribute_definition>& ref_column) const {
void attribute_definition_generator::insert_missing_reference_column(const std::type_index& ti, const std::shared_ptr<attribute>& ref_column) const {
const_cast<repository&>(repo_).missing_references_.insert({ti, ref_column});
}
+5 -5
View File
@@ -6,9 +6,9 @@
namespace matador::object {
basic_object_info::basic_object_info(std::shared_ptr<repository_node> node,
const std::vector<attribute_definition> &attributes,
const std::vector<attribute> &attributes,
utils::identifier &&pk,
const std::shared_ptr<attribute_definition> &pk_as_fk_column)
const std::shared_ptr<attribute> &pk_as_fk_column)
: node_(std::move(node))
, attributes_(attributes)
, identifier_(std::move(pk))
@@ -16,7 +16,7 @@ basic_object_info::basic_object_info(std::shared_ptr<repository_node> node,
}
basic_object_info::basic_object_info(std::shared_ptr<repository_node> node,
const std::vector<attribute_definition> &attributes)
const std::vector<attribute> &attributes)
: node_(std::move(node))
, attributes_(attributes) {}
@@ -28,11 +28,11 @@ std::string basic_object_info::name() const {
return node_->name();
}
const std::vector<attribute_definition>& basic_object_info::attributes() const {
const std::vector<attribute>& basic_object_info::attributes() const {
return attributes_;
}
std::shared_ptr<attribute_definition> basic_object_info::reference_column() const {
std::shared_ptr<attribute> basic_object_info::reference_column() const {
return pk_as_fk_column_;
}
+1 -1
View File
@@ -62,7 +62,7 @@ utils::result<basic_object_info_ref, utils::error> repository::basic_info( const
return utils::ok(basic_object_info_ref{result.value()->info()});
}
utils::result<std::shared_ptr<attribute_definition>, utils::error> repository::reference_column(const std::type_index &type_index) const {
utils::result<std::shared_ptr<attribute>, utils::error> repository::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());
+2 -2
View File
@@ -104,13 +104,13 @@ utils::result<repository_node::node_ptr, utils::error> repository_node::make_and
return repo.attach_node(node, "");
}
std::shared_ptr<attribute_definition> repository_node::determine_reference_column(const std::type_index& ti,
std::shared_ptr<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 std::make_shared<attribute_definition>(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::FOREIGN_KEY});
}
auto ref_column = it->second;