preparations for object_generator (generating objects with attributes and constraints)

This commit is contained in:
2025-11-23 15:58:14 +01:00
parent 19b0adf737
commit e67c0f39a3
23 changed files with 468 additions and 69 deletions
+11 -23
View File
@@ -18,6 +18,7 @@ struct attribute_options {
null_option_type null_option{null_option_type::NOT_NULL};
int index{-1};
};
class object;
class attribute {
public:
@@ -85,7 +86,10 @@ public:
}
private:
friend class object;
std::string name_;
object *owner_{nullptr};
std::string table_name_;
attribute_options options_;
utils::basic_type type_{utils::basic_type::type_null};
@@ -94,22 +98,6 @@ private:
};
class object {
public:
using iterator = std::vector<attribute>::iterator;
using const_iterator = std::vector<attribute>::const_iterator;
private:
std::vector<attribute> columns_;
std::string name_;
std::string alias_;
};
class constraint {
public:
private:
std::shared_ptr<attribute> column_;
};
/**
* User defined literal to have a shortcut creating a column object
* @param name Name of the column
@@ -131,7 +119,7 @@ attribute make_column<std::string>(const std::string &name, utils::field_attribu
template < typename Type >
attribute make_pk_column(const std::string &name, size_t size = 0)
{
return make_column<Type>(name, { size, utils::constraints::PRIMARY_KEY });
return make_column<Type>(name, { size, utils::constraints::PrimaryKey });
}
template <>
@@ -139,13 +127,13 @@ attribute make_pk_column<std::string>(const std::string &name, size_t size);
template < typename Type >
attribute make_fk_column(const std::string &name, size_t size, const std::shared_ptr<attribute> &ref_column) {
return {name, utils::data_type_traits<Type>::type(size), ref_column, { size, utils::constraints::FOREIGN_KEY }};
return {name, utils::data_type_traits<Type>::type(size), ref_column, { size, utils::constraints::ForeignKey }};
}
template < typename Type >
[[maybe_unused]] attribute make_fk_column(const std::string &name, const std::shared_ptr<attribute> &ref_column)
{
return {name, utils::data_type_traits<Type>::type(0), 0, ref_column, { 0, utils::constraints::FOREIGN_KEY }, null_option_type::NOT_NULL};
return {name, utils::data_type_traits<Type>::type(0), 0, ref_column, { 0, utils::constraints::ForeignKey }, null_option_type::NOT_NULL};
}
template <>
@@ -155,8 +143,8 @@ template < typename Type >
[[maybe_unused]] attribute make_fk_column(const std::string &name, size_t size, const std::string &ref_table_name, const std::string &ref_column_name) {
return {
name, utils::data_type_traits<Type>::type(size), 0,
std::make_shared<attribute>(ref_column_name, ref_table_name, utils::data_type_traits<Type>::type(size), utils::constraints::FOREIGN_KEY),
{ 0, utils::constraints::FOREIGN_KEY }, null_option_type::NOT_NULL
std::make_shared<attribute>(ref_column_name, ref_table_name, utils::data_type_traits<Type>::type(size), utils::constraints::ForeignKey),
{ 0, utils::constraints::ForeignKey }, null_option_type::NOT_NULL
};
}
@@ -164,8 +152,8 @@ template < typename Type >
[[maybe_unused]] attribute make_fk_column(const std::string &name, const std::string &ref_table_name, const std::string &ref_column_name) {
return {
name, utils::data_type_traits<Type>::type(0), 0,
std::make_shared<attribute>(ref_column_name, utils::data_type_traits<Type>::type(0), ref_table_name, attribute_options{utils::constraints::FOREIGN_KEY}),
{ 0, utils::constraints::FOREIGN_KEY }, null_option_type::NOT_NULL
std::make_shared<attribute>(ref_column_name, utils::data_type_traits<Type>::type(0), ref_table_name, attribute_options{utils::constraints::ForeignKey}),
{ 0, utils::constraints::ForeignKey }, null_option_type::NOT_NULL
};
}