object generation progress

This commit is contained in:
Sascha Kühl
2025-12-10 17:05:24 +01:00
parent 9b7b74524f
commit 5afb616205
9 changed files with 59 additions and 45 deletions
+11 -24
View File
@@ -1,9 +1,10 @@
#include "matador/object/object.hpp"
namespace matador::object {
object::object( std::string name, std::string alias )
: name_(std::move(name))
, alias_(std::move(alias)) {}
object::object(std::string name)
: name_(std::move(name)) {
int i = 9;
}
const attribute& object::create_attribute(std::string name, const std::shared_ptr<object>& obj) {
attribute attr{std::move(name)};
@@ -11,16 +12,6 @@ const attribute& object::create_attribute(std::string name, const std::shared_pt
return obj->attributes_.emplace_back(std::move(attr));
}
// void object::add_attribute( attribute attr ) {
// auto &ref = attributes_.emplace_back(std::move(attr));
// ref.owner_ = this;
// }
//
// void object::add_constraint( class constraint c ) {
// auto &ref = constraints_.emplace_back(std::move(c));
// ref.owner_ = this;
// }
attribute* object::primary_key_attribute() const {
return pk_attribute_;
}
@@ -37,19 +28,15 @@ const std::string& object::name() const {
return name_;
}
const std::string& object::alias() const {
return alias_;
}
void object::update_name(const std::string& name) {
name_ = name;
for (auto& con : constraints_) {
if (con.is_primary_key_constraint()) {
con.name_ += name;
} else if (con.is_foreign_key_constraint()) {
con.name_ = "FK_" + name + "_" + con.column_name();
}
}
// for (auto& con : constraints_) {
// if (con.is_primary_key_constraint()) {
// con.name_ += name;
// } else if (con.is_foreign_key_constraint()) {
// con.name_ = "FK_" + name + "_" + con.column_name();
// }
// }
}
bool object::has_attributes() const {
+14
View File
@@ -9,6 +9,17 @@ object_generator::object_generator(repository& repo, const std::shared_ptr<objec
: repo_(repo)
, object_(object) {}
std::shared_ptr<object> object_generator::acquire_object(repository &repo, const std::type_index &ti, const std::string& name) {
if (repo.has_object_for_type(ti)) {
auto obj = repo.object_for_type(ti);
repo.remove_object_for_type(ti);
obj->update_name(name);
return obj;
}
return repo.provide_object_in_advance(ti, std::make_shared<object>(name));
}
void object_generator::on_revision(const char* id, uint64_t& rev) {
on_attribute(id, rev);
}
@@ -61,6 +72,9 @@ std::shared_ptr<class object> object_generator::fk_object(const std::type_index&
return result->get().object();
}
if (repo_.has_object_for_type(ti)) {
return repo_.object_for_type(ti);
}
return repo_.provide_object_in_advance(ti, std::make_shared<object>(""));
}
}
+16 -3
View File
@@ -7,8 +7,8 @@ namespace matador::object {
restriction::restriction(std::string name)
: name_(std::move(name)) {}
const std::string & restriction::name() const {
return name_;
std::string restriction::name() const {
return prefix() + name_;
}
const class attribute* restriction::attribute() const {
@@ -55,10 +55,23 @@ const std::string& restriction::ref_column_name() const {
}
std::ostream & operator<<(std::ostream &os, const class restriction &c) {
os << "constraint " << c.name_ << " for column " << c.column_name();
os << "constraint " << c.name() << " for column " << c.column_name();
return os;
}
std::string restriction::prefix() const {
if (utils::is_constraint_set(options_, utils::constraints::PrimaryKey)) {
return "PK_";
}
if (utils::is_constraint_set(options_, utils::constraints::ForeignKey)) {
return "FK_";
}
if (utils::is_constraint_set(options_, utils::constraints::Unique)) {
return "UK_";
}
return "";
}
// constraint_builder & constraint_builder::constraint(std::string name) {
// constraint_name = std::move(name);
// return *this;