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
+1 -1
View File
@@ -47,7 +47,7 @@ utils::basic_type attribute::type() const {
return type_;
}
object* attribute::owner() const {
std::shared_ptr<object> attribute::owner() const {
return owner_;
}
+4 -4
View File
@@ -4,14 +4,14 @@
namespace matador::object {
attribute_generator::attribute_generator(std::vector<attribute> &columns, const repository &repo, object &obj)
attribute_generator::attribute_generator(std::vector<attribute> &columns, const repository &repo, const std::shared_ptr<object> &obj)
: columns_(columns)
, repo_(repo)
, obj_(obj)
{}
void attribute_generator::on_revision(const char *id, uint64_t &rev) {
on_attribute(id, rev);
on_attribute(id, rev);
}
utils::result<attribute*, utils::error> attribute_generator::determine_foreign_ref(const std::type_index &ti) const {
@@ -23,7 +23,7 @@ void attribute_generator::insert_missing_reference_column(const std::type_index&
}
void attribute_generator::prepare_primary_key(attribute& ref, utils::identifier &&pk) const {
obj_.pk_attribute_ = &ref;
obj_.pk_identifier_ = std::move(pk);
obj_->pk_attribute_ = &ref;
obj_->pk_identifier_ = std::move(pk);
}
}
+2 -5
View File
@@ -11,7 +11,7 @@ constraints_generator::constraints_generator(std::list<class restriction> &const
, obj_(obj) {}
void constraints_generator::create_pk_constraint(const std::string& name) const {
class restriction pk_constraint("PK_" + obj_->name());
restriction pk_constraint("PK_" + obj_->name());
pk_constraint.options_ |= utils::constraints::PrimaryKey;
if (const auto pk_attr = find_attribute_by_name(name); pk_attr != std::end(obj_->attributes_)) {
pk_constraint.attr_ = &*pk_attr;
@@ -25,15 +25,12 @@ void constraints_generator::create_fk_constraint(const std::type_index& ti, cons
if (!result) {
return;
}
const auto *pk_attribute = result.value().get().primary_key_attribute();
class restriction pk_constraint("FK_" + obj_->name() + "_" + name);
restriction pk_constraint("FK_" + obj_->name() + "_" + name);
pk_constraint.options_ |= utils::constraints::ForeignKey;
if (const auto pk_attr = find_attribute_by_name(name); pk_attr != std::end(obj_->attributes_)) {
pk_constraint.attr_ = &*pk_attr;
}
pk_constraint.owner_ = obj_;
pk_constraint.ref_column_name_ = pk_attribute->name();
pk_constraint.ref_table_name_ = pk_attribute->owner() ? pk_attribute->owner()->name() : "";
constraints_.emplace_back(std::move(pk_constraint));
}
+3 -3
View File
@@ -5,10 +5,10 @@ object::object( std::string name, std::string alias )
: name_(std::move(name))
, alias_(std::move(alias)) {}
const attribute& object::create_attribute( std::string name, object& obj ) {
const attribute& object::create_attribute(std::string name, const std::shared_ptr<object>& obj) {
attribute attr{std::move(name)};
attr.owner_ = &obj;
return obj.attributes_.emplace_back(std::move(attr));
attr.owner_ = obj;
return obj->attributes_.emplace_back(std::move(attr));
}
// void object::add_attribute( attribute attr ) {
+3 -8
View File
@@ -14,7 +14,7 @@ void object_generator::on_revision(const char* id, uint64_t& rev) {
}
void object_generator::create_pk_constraint(const std::string& name) const {
class restriction pk_constraint("PK_" + object_->name());
restriction pk_constraint("PK_" + object_->name());
pk_constraint.options_ |= utils::constraints::PrimaryKey;
if (const auto pk_attr = find_attribute_by_name(name); pk_attr != std::end(object_->attributes_)) {
pk_constraint.attr_ = &*pk_attr;
@@ -25,23 +25,18 @@ void object_generator::create_pk_constraint(const std::string& name) const {
void object_generator::create_fk_constraint(const std::type_index& ti, const std::string& name) const {
const auto obj = fk_object(ti);
const auto *pk_attribute = obj->primary_key_attribute();
class restriction pk_constraint("FK_" + object_->name() + "_" + name);
restriction pk_constraint("FK_" + object_->name() + "_" + name);
pk_constraint.options_ |= utils::constraints::ForeignKey;
if (const auto pk_attr = find_attribute_by_name(name); pk_attr != std::end(object_->attributes_)) {
pk_constraint.attr_ = &*pk_attr;
}
pk_constraint.owner_ = object_;
pk_constraint.reference_ = obj;
if (pk_attribute) {
pk_constraint.ref_column_name_ = pk_attribute->name();
pk_constraint.ref_table_name_ = pk_attribute->owner() ? pk_attribute->owner()->name() : "";
}
object_->constraints_.emplace_back(std::move(pk_constraint));
}
void object_generator::create_unique_constraint(const std::string& name) const {
class restriction pk_constraint("UK_" + object_->name() + "_" + name);
restriction pk_constraint("UK_" + object_->name() + "_" + name);
pk_constraint.options_ |= utils::constraints::Unique;
if (const auto pk_attr = find_attribute_by_name(name); pk_attr != std::end(object_->attributes_)) {
pk_constraint.attr_ = &*pk_attr;
+41 -40
View File
@@ -1,6 +1,7 @@
#include "matador/object/restriction.hpp"
#include "matador/object/attribute.hpp"
#include "matador/object/object.hpp"
namespace matador::object {
restriction::restriction(std::string name)
@@ -46,11 +47,11 @@ bool restriction::is_unique_constraint() const {
}
const std::string& restriction::ref_table_name() const {
return ref_table_name_;
return reference_->name();
}
const std::string& restriction::ref_column_name() const {
return ref_column_name_;
return reference_->primary_key_attribute()->name();
}
std::ostream & operator<<(std::ostream &os, const class restriction &c) {
@@ -58,42 +59,42 @@ std::ostream & operator<<(std::ostream &os, const class restriction &c) {
return os;
}
constraint_builder & constraint_builder::constraint(std::string name) {
constraint_name = std::move(name);
return *this;
}
constraint_builder & constraint_builder::primary_key(std::string name) {
column_name = std::move(name);
options_ |= utils::constraints::PrimaryKey;
return *this;
}
constraint_builder & constraint_builder::foreign_key(std::string name) {
column_name = std::move(name);
options_ |= utils::constraints::ForeignKey;
return *this;
}
constraint_builder & constraint_builder::references(std::string table, std::string column) {
ref_table_name = std::move(table);
ref_column_name = std::move(column);
return *this;
}
constraint_builder::operator class restriction() const {
class restriction c;
c.name_ = constraint_name;
c.attr_ = column_name;
c.options_ = options_;
c.ref_column_name_ = ref_column_name;
c.ref_table_name_ = ref_table_name;
return c;
}
constraint_builder constraint(std::string name) {
constraint_builder builder;
return builder.constraint(std::move(name));
}
// constraint_builder & constraint_builder::constraint(std::string name) {
// constraint_name = std::move(name);
// return *this;
// }
//
// constraint_builder & constraint_builder::primary_key(std::string name) {
// column_name = std::move(name);
// options_ |= utils::constraints::PrimaryKey;
// return *this;
// }
//
// constraint_builder & constraint_builder::foreign_key(std::string name) {
// column_name = std::move(name);
// options_ |= utils::constraints::ForeignKey;
// return *this;
// }
//
// constraint_builder & constraint_builder::references(std::string table, std::string column) {
// ref_table_name = std::move(table);
// ref_column_name = std::move(column);
//
// return *this;
// }
//
// constraint_builder::operator class restriction() const {
// class restriction c;
// c.name_ = constraint_name;
// c.attr_ = column_name;
// c.options_ = options_;
// c.ref_column_name_ = ref_column_name;
// c.ref_table_name_ = ref_table_name;
// return c;
// }
//
// constraint_builder constraint(std::string name) {
// constraint_builder builder;
// return builder.constraint(std::move(name));
// }
}