added pk information to class object
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "matador/utils/data_type_traits.hpp"
|
||||
#include "matador/utils/error.hpp"
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
#include "matador/utils/identifier.hpp"
|
||||
#include "matador/utils/primary_key_attribute.hpp"
|
||||
#include "matador/utils/result.hpp"
|
||||
|
||||
@@ -91,9 +92,7 @@ public:
|
||||
on_foreign_key(id, x);
|
||||
}
|
||||
template<class Pointer>
|
||||
void on_has_one(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {
|
||||
// on_foreign_key(id, x);
|
||||
}
|
||||
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
||||
|
||||
template <class Pointer>
|
||||
void on_foreign_key(const char *id, Pointer &x) {
|
||||
@@ -123,6 +122,15 @@ private:
|
||||
[[nodiscard]] utils::result<std::shared_ptr<attribute>, utils::error> determine_foreign_ref(const std::type_index &ti) const;
|
||||
void insert_missing_reference_column(const std::type_index &ti, const std::shared_ptr<attribute>& ref_column) const;
|
||||
|
||||
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_;
|
||||
return ref;
|
||||
}
|
||||
|
||||
void prepare_primary_key(attribute &ref, utils::identifier &&pk) const;
|
||||
|
||||
private:
|
||||
size_t index_ = 0;
|
||||
std::vector<attribute> &columns_;
|
||||
@@ -134,19 +142,18 @@ private:
|
||||
|
||||
template<typename ValueType>
|
||||
void attribute_generator::on_primary_key(const char *id, ValueType &x, const utils::primary_key_attribute& attr) {
|
||||
on_attribute(id, x, { attr.size(), utils::constraints::PrimaryKey });
|
||||
auto &ref = emplace_attribute<ValueType>(id, { attr.size(), utils::constraints::PrimaryKey }, null_option_type::NOT_NULL);
|
||||
prepare_primary_key(ref, utils::identifier(x));
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
void attribute_generator::on_attribute(const char *id, Type &/*x*/, const utils::field_attributes &attr) {
|
||||
auto &ref = columns_.emplace_back(id, utils::data_type_traits<Type>::type(attr.size()), attr, null_option_type::NOT_NULL);
|
||||
ref.owner_ = &obj_;
|
||||
std::ignore = emplace_attribute<Type>(id, attr, null_option_type::NOT_NULL);
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
void attribute_generator::on_attribute(const char *id, std::optional<Type> & /*x*/, const utils::field_attributes &attr) {
|
||||
auto &ref = columns_.emplace_back(id, utils::data_type_traits<Type>::type(attr.size()), attr, null_option_type::NULLABLE);
|
||||
ref.owner_ = &obj_;
|
||||
std::ignore = emplace_attribute<Type>(id, attr, null_option_type::NULLABLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ protected:
|
||||
basic_object_info(std::shared_ptr<repository_node> node, const std::vector<attribute> &attributes);
|
||||
|
||||
protected:
|
||||
std::unique_ptr<object> node_ptr_;
|
||||
std::shared_ptr<repository_node> node_; /**< prototype node of the represented object type */
|
||||
std::vector<attribute> attributes_;
|
||||
std::optional<utils::identifier> identifier_;
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include "matador/object/constraint.hpp"
|
||||
#include "matador/object/constraints_generator.hpp"
|
||||
|
||||
#include "matador/utils/identifier.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
|
||||
class repository;
|
||||
@@ -27,6 +29,10 @@ public:
|
||||
void add_attribute(attribute attr);
|
||||
void add_constraint(class constraint c);
|
||||
|
||||
[[nodiscard]] const attribute* primary_key_attribute() const;
|
||||
[[nodiscard]] const utils::identifier& primary_key() const;
|
||||
[[nodiscard]] bool has_primary_key() const;
|
||||
|
||||
[[nodiscard]] const std::string& name() const;
|
||||
[[nodiscard]] const std::string& alias() const;
|
||||
|
||||
@@ -40,10 +46,13 @@ public:
|
||||
|
||||
private:
|
||||
friend class constraints_generator;
|
||||
friend class attribute_generator;
|
||||
|
||||
std::string name_;
|
||||
std::string alias_;
|
||||
|
||||
attribute* pk_attribute_{nullptr};
|
||||
utils::identifier pk_identifier_;
|
||||
std::vector<attribute> attributes_;
|
||||
std::vector<class constraint> constraints_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user