object generator progress
This commit is contained in:
@@ -17,11 +17,12 @@ add_library(matador-core STATIC
|
||||
../../include/matador/object/attribute_generator.hpp
|
||||
../../include/matador/object/basic_object_info.hpp
|
||||
../../include/matador/object/constraint.hpp
|
||||
../../include/matador/object/constraints_generator.hpp
|
||||
../../include/matador/object/error_code.hpp
|
||||
../../include/matador/object/foreign_node_completer.hpp
|
||||
../../include/matador/object/internal/shadow_repository.hpp
|
||||
../../include/matador/object/many_to_many_relation.hpp
|
||||
../../include/matador/object/object_generator.hpp
|
||||
../../include/matador/object/object.hpp
|
||||
../../include/matador/object/object_info.hpp
|
||||
../../include/matador/object/object_proxy.hpp
|
||||
../../include/matador/object/object_ptr.hpp
|
||||
@@ -80,6 +81,7 @@ add_library(matador-core STATIC
|
||||
object/attribute_generator.cpp
|
||||
object/basic_object_info.cpp
|
||||
object/constraint.cpp
|
||||
object/constraints_generator.cpp
|
||||
object/error_code.cpp
|
||||
object/foreign_node_completer.cpp
|
||||
object/internal/shadow_repository.cpp
|
||||
@@ -105,6 +107,7 @@ add_library(matador-core STATIC
|
||||
utils/uuid.cpp
|
||||
utils/value.cpp
|
||||
utils/version.cpp
|
||||
object/object.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(matador-core ${CMAKE_DL_LIBS})
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
|
||||
namespace matador::object {
|
||||
|
||||
attribute_generator::attribute_generator(std::vector<attribute> &columns, const repository &repo)
|
||||
attribute_generator::attribute_generator(std::vector<attribute> &columns, const repository &repo, object &obj)
|
||||
: columns_(columns)
|
||||
, repo_(repo)
|
||||
, obj_(obj)
|
||||
{}
|
||||
|
||||
void attribute_generator::on_revision(const char *id, uint64_t &rev) {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#include "matador/object/constraints_generator.hpp"
|
||||
#include "matador/object/object.hpp"
|
||||
#include "matador/object/repository.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
constraints_generator::constraints_generator(std::vector<class constraint> &constraints, const repository& repo, object &obj)
|
||||
: constraints_(constraints)
|
||||
, repo_(repo)
|
||||
, obj_(obj) {}
|
||||
|
||||
void constraints_generator::create_pk_constraint(const std::string& name) const {
|
||||
class constraint 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;
|
||||
}
|
||||
pk_constraint.owner_ = &obj_;
|
||||
constraints_.emplace_back(std::move(pk_constraint));
|
||||
}
|
||||
|
||||
void constraints_generator::create_fk_constraint(const std::string& name, const basic_object_info& info) const {
|
||||
const auto pk_attribute = info.reference_column();
|
||||
class constraint 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->table_name();
|
||||
constraints_.emplace_back(std::move(pk_constraint));
|
||||
}
|
||||
|
||||
void constraints_generator::create_unique_constraint(const std::string& name) const {
|
||||
class constraint pk_constraint("UK_" + obj_.name() + "_" + name);
|
||||
pk_constraint.options_ |= utils::constraints::Unique;
|
||||
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_;
|
||||
}
|
||||
|
||||
std::vector<attribute>::iterator constraints_generator::find_attribute_by_name(const std::string& name) const {
|
||||
return std::find_if(std::begin(obj_.attributes_), std::end(obj_.attributes_), [&name](const attribute& elem) {
|
||||
return elem.name() == name;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "matador/object/object.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
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 ) {
|
||||
attribute attr{std::move(name)};
|
||||
attr.owner_ = &obj;
|
||||
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;
|
||||
}
|
||||
|
||||
const std::string& object::name() const {
|
||||
return name_;
|
||||
}
|
||||
|
||||
const std::string& object::alias() const {
|
||||
return alias_;
|
||||
}
|
||||
|
||||
bool object::has_attributes() const {
|
||||
return attributes_.empty();
|
||||
}
|
||||
|
||||
size_t object::attribute_count() const {
|
||||
return attributes_.size();
|
||||
}
|
||||
|
||||
const std::vector<attribute>& object::attributes() const {
|
||||
return attributes_;
|
||||
}
|
||||
|
||||
bool object::has_constraints() const {
|
||||
return constraints_.empty();
|
||||
}
|
||||
|
||||
size_t object::constraint_count() const {
|
||||
return constraints_.size();
|
||||
}
|
||||
|
||||
const std::vector<class constraint>& object::constraints() const {
|
||||
return constraints_;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user