removed string from restriction

This commit is contained in:
2025-12-09 21:13:47 +01:00
parent c4f8731262
commit 9b7b74524f
13 changed files with 86 additions and 166 deletions
+2 -68
View File
@@ -39,7 +39,7 @@ public:
[[nodiscard]] utils::field_attributes& attributes();
[[nodiscard]] bool is_nullable() const;
[[nodiscard]] utils::basic_type type() const;
[[nodiscard]] object* owner() const;
[[nodiscard]] std::shared_ptr<object> owner() const;
void change_type(utils::basic_type type, const utils::field_attributes &attr = utils::null_attributes);
template < typename Type >
void change_type(const utils::field_attributes &attr = utils::null_attributes) {
@@ -69,78 +69,12 @@ private:
friend class object_generator;
std::string name_;
object *owner_{nullptr};
std::shared_ptr<object> owner_;
utils::basic_type type_{utils::basic_type::Null};
utils::field_attributes options_{};
null_option_type null_option_{null_option_type::NotNull};
};
/**
* User defined literal to have a shortcut creating a column object
* @param name Name of the column
* @param type
* @param attr Length of the column name
* @param null_opt
* @return A column object with a given name
*/
// attribute make_column(const std::string &name, utils::basic_type type, utils::field_attributes attr = utils::null_attributes, null_option_type null_opt = null_option_type::NOT_NULL);
//
// template < typename Type >
// attribute make_column(const std::string &name, utils::field_attributes attr = utils::null_attributes, null_option_type null_opt = null_option_type::NOT_NULL)
// {
// return make_column(name, utils::data_type_traits<Type>::type(0), attr, null_opt);
// }
// template <>
// attribute make_column<std::string>(const std::string &name, utils::field_attributes attr, null_option_type null_opt);
//
// template < typename Type >
// attribute make_pk_column(const std::string &name, size_t size = 0)
// {
// return make_column<Type>(name, { size, utils::constraints::PrimaryKey });
// }
//
// template <>
// 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::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::ForeignKey }, null_option_type::NOT_NULL};
// }
//
// template <>
// [[maybe_unused]] attribute make_fk_column<std::string>(const std::string &name, size_t size, const std::shared_ptr<attribute> &ref_column);
//
// 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::ForeignKey),
// { 0, utils::constraints::ForeignKey }, null_option_type::NOT_NULL
// };
// }
//
// 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::ForeignKey}),
// { 0, utils::constraints::ForeignKey }, null_option_type::NOT_NULL
// };
// }
//
// template <>
// [[maybe_unused]] attribute make_fk_column<std::string>(const std::string &name, const std::string &ref_table_name, const std::string &ref_column_name);
//
// template <>
// [[maybe_unused]] 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);
}
#endif //QUERY_COLUMN_DEFINITION_HPP
@@ -55,19 +55,19 @@ private:
class attribute_generator final {
private:
attribute_generator(std::vector<attribute> &columns, const repository &repo, object &obj);
attribute_generator(std::vector<attribute> &columns, const repository &repo, const std::shared_ptr<object>& obj);
public:
~attribute_generator() = default;
template < class Type >
static std::vector<attribute> generate(const repository &repo, object &obj) {
static std::vector<attribute> generate(const repository &repo, const std::shared_ptr<object> &obj) {
Type t;
return generate(t, repo, obj);
}
template < class Type >
static std::vector<attribute> generate(const Type& t, const repository &repo, object &obj) {
static std::vector<attribute> generate(const Type& t, const repository &repo, const std::shared_ptr<object> &obj) {
std::vector<attribute> columns;
attribute_generator gen(columns, repo, obj);
access::process(gen, t);
@@ -122,7 +122,7 @@ private:
template<typename ValueType>
attribute &emplace_attribute(const char *id, const utils::field_attributes& attr, null_option_type null_option) {
auto &ref = columns_.emplace_back(id, utils::data_type_traits<ValueType>::type(attr.size()), attr, null_option);
ref.owner_ = &obj_;
ref.owner_ = obj_;
return ref;
}
@@ -132,7 +132,7 @@ private:
size_t index_ = 0;
std::vector<attribute> &columns_;
const repository &repo_;
object &obj_;
const std::shared_ptr<object> obj_;
fk_attribute_generator fk_column_generator_;
};
+1 -4
View File
@@ -17,10 +17,7 @@ class object {
public:
explicit object(std::string name, std::string alias = "");
static const attribute& create_attribute(std::string name, object& obj);
// void add_attribute(attribute attr);
// void add_constraint(class constraint c);
static const attribute& create_attribute(std::string name, const std::shared_ptr<object>& obj);
[[nodiscard]] attribute* primary_key_attribute() const;
[[nodiscard]] const utils::identifier& primary_key() const;
+3 -3
View File
@@ -88,7 +88,7 @@ public:
void on_foreign_key(const char *id, Pointer &/*x*/) {
const auto type = pk_type_determinator::determine<typename Pointer::value_type>();
auto &ref = object_->attributes_.emplace_back(id, type, utils::constraints::ForeignKey, null_option_type::NotNull);
ref.owner_ = object_.get();
ref.owner_ = object_;
}
template<class ContainerType>
static void on_has_many(const char * /*id*/, ContainerType &, const char *, const utils::foreign_attributes &/*attr*/) {}
@@ -101,7 +101,7 @@ private:
template<typename ValueType>
attribute &emplace_attribute(const char *id, const utils::field_attributes& attr, null_option_type null_option) {
auto &ref = object_->attributes_.emplace_back(id, utils::data_type_traits<ValueType>::type(attr.size()), attr, null_option);
ref.owner_ = object_.get();
ref.owner_ = object_;
return ref;
}
@@ -113,7 +113,7 @@ private:
void prepare_primary_key(attribute &ref, utils::identifier &&pk) const;
std::shared_ptr<class object> fk_object(const std::type_index& ti) const;
[[nodiscard]] std::shared_ptr<class object> fk_object(const std::type_index& ti) const;
private:
repository &repo_;
+16 -20
View File
@@ -43,28 +43,24 @@ private:
std::shared_ptr<object> owner_;
std::shared_ptr<object> reference_;
utils::constraints options_{utils::constraints::None};
std::string ref_table_name_{};
std::string ref_column_name_{};
};
class constraint_builder {
public:
constraint_builder& constraint(std::string name);
constraint_builder& primary_key(std::string name);
constraint_builder& foreign_key(std::string name);
constraint_builder& references(std::string table, std::string column);
operator class restriction() const;
private:
std::string constraint_name;
utils::constraints options_{utils::constraints::None};
std::string column_name;
std::string ref_table_name;
std::string ref_column_name;
};
constraint_builder constraint(std::string name);
// class constraint_builder {
// public:
// constraint_builder& constraint(std::string name);
// constraint_builder& primary_key(std::string name);
// constraint_builder& foreign_key(std::string name);
// constraint_builder& references(std::string table, std::string column);
//
// operator class restriction() const;
//
// private:
// std::string constraint_name;
// utils::constraints options_{utils::constraints::None};
// std::string column_name;
// };
//
// constraint_builder constraint(std::string name);
}
#endif //MATADOR_CONSTRAINT_HPP