query builder progress
This commit is contained in:
@@ -10,14 +10,9 @@
|
||||
namespace matador::object {
|
||||
|
||||
enum class null_option_type : uint8_t {
|
||||
NULLABLE, NOT_NULL
|
||||
Nullable, NotNull
|
||||
};
|
||||
|
||||
struct attribute_options {
|
||||
utils::field_attributes attributes;
|
||||
null_option_type null_option{null_option_type::NOT_NULL};
|
||||
int index{-1};
|
||||
};
|
||||
class object;
|
||||
class attribute_generator;
|
||||
|
||||
@@ -33,20 +28,17 @@ public:
|
||||
attribute() = default;
|
||||
attribute(std::string name,
|
||||
utils::basic_type type,
|
||||
const utils::field_attributes&,
|
||||
null_option_type null_opt);
|
||||
const utils::field_attributes &attr = utils::null_attributes,
|
||||
null_option_type null_opt = null_option_type::NotNull);
|
||||
|
||||
[[nodiscard]] const std::string& name() const;
|
||||
void name(const std::string& n);
|
||||
[[nodiscard]] std::string full_name() const;
|
||||
[[nodiscard]] int index() const;
|
||||
[[nodiscard]] const utils::field_attributes& attributes() const;
|
||||
[[nodiscard]] utils::field_attributes& attributes();
|
||||
[[nodiscard]] bool is_nullable() const;
|
||||
[[nodiscard]] utils::basic_type type() const;
|
||||
[[nodiscard]] object* owner() const;
|
||||
// [[nodiscard]] const std::string& table_name() const;
|
||||
// void table_name(const std::string& name);
|
||||
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) {
|
||||
@@ -75,8 +67,9 @@ private:
|
||||
|
||||
std::string name_;
|
||||
object *owner_{nullptr};
|
||||
attribute_options options_;
|
||||
utils::basic_type type_{utils::basic_type::type_null};
|
||||
utils::field_attributes options_{};
|
||||
null_option_type null_option_{null_option_type::NotNull};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
template<class Type>
|
||||
attribute generate(const char *id, Type &x) {
|
||||
access::process(*this, x);
|
||||
return attribute{id, type_, {utils::constraints::ForeignKey }, null_option_type::NOT_NULL};
|
||||
return attribute{id, type_, {utils::constraints::ForeignKey }, null_option_type::NotNull};
|
||||
}
|
||||
|
||||
template<typename ValueType>
|
||||
@@ -139,18 +139,18 @@ private:
|
||||
|
||||
template<typename ValueType>
|
||||
void attribute_generator::on_primary_key(const char *id, ValueType &x, const utils::primary_key_attribute& attr) {
|
||||
auto &ref = emplace_attribute<ValueType>(id, { attr.size(), utils::constraints::PrimaryKey }, null_option_type::NOT_NULL);
|
||||
auto &ref = emplace_attribute<ValueType>(id, { attr.size(), utils::constraints::PrimaryKey }, null_option_type::NotNull);
|
||||
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) {
|
||||
std::ignore = emplace_attribute<Type>(id, attr, null_option_type::NOT_NULL);
|
||||
std::ignore = emplace_attribute<Type>(id, attr, null_option_type::NotNull);
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
void attribute_generator::on_attribute(const char *id, std::optional<Type> & /*x*/, const utils::field_attributes &attr) {
|
||||
std::ignore = emplace_attribute<Type>(id, attr, null_option_type::NULLABLE);
|
||||
std::ignore = emplace_attribute<Type>(id, attr, null_option_type::Nullable);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define BASIC_PROTOTYPE_INFO_HPP
|
||||
|
||||
#include "matador/object/attribute.hpp"
|
||||
#include "matador/object/constraint.hpp"
|
||||
#include "matador/object/relation_endpoint.hpp"
|
||||
|
||||
#include "matador/utils/identifier.hpp"
|
||||
@@ -26,6 +27,7 @@ public:
|
||||
[[nodiscard]] std::type_index type_index() const;
|
||||
[[nodiscard]] std::string name() const;
|
||||
[[nodiscard]] const std::list<attribute>& attributes() const;
|
||||
[[nodiscard]] const std::list<class constraint>& constraints() const;
|
||||
|
||||
[[nodiscard]] bool has_primary_key() const;
|
||||
[[nodiscard]] const utils::identifier& primary_key() const;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "matador/utils/constraints.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
namespace matador::object {
|
||||
|
||||
@@ -18,6 +19,14 @@ public:
|
||||
explicit constraint(std::string name);
|
||||
|
||||
[[nodiscard]] const std::string& name() const;
|
||||
[[nodiscard]] const class attribute* attribute() const;
|
||||
[[nodiscard]] std::string column_name() const;
|
||||
[[nodiscard]] const object* owner() const;
|
||||
[[nodiscard]] bool is_primary_key_constraint() const;
|
||||
[[nodiscard]] bool is_foreign_key_constraint() const;
|
||||
[[nodiscard]] bool is_unique_constraint() const;
|
||||
[[nodiscard]] const std::string& ref_table_name() const;
|
||||
[[nodiscard]] const std::string& ref_column_name() const;
|
||||
|
||||
private:
|
||||
friend class constraint_builder;
|
||||
@@ -26,7 +35,8 @@ private:
|
||||
friend class object;
|
||||
|
||||
std::string name_;
|
||||
attribute* attr_{nullptr};
|
||||
std::variant<class attribute*, std::string> attr_;
|
||||
// class attribute* attr_{nullptr};
|
||||
object *owner_{nullptr};
|
||||
utils::constraints options_{utils::constraints::None};
|
||||
std::string ref_table_name_{};
|
||||
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
template <class Pointer>
|
||||
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::NOT_NULL);
|
||||
auto &ref = object_->attributes_.emplace_back(id, type, utils::constraints::ForeignKey, null_option_type::NotNull);
|
||||
ref.owner_ = object_.get();
|
||||
}
|
||||
template<class ContainerType>
|
||||
@@ -121,19 +121,19 @@ private:
|
||||
|
||||
template<typename ValueType>
|
||||
void object_generator::on_primary_key(const char *id, ValueType &x, const utils::primary_key_attribute& attr) {
|
||||
auto &ref = emplace_attribute<ValueType>(id, { attr.size(), utils::constraints::PrimaryKey }, null_option_type::NOT_NULL);
|
||||
auto &ref = emplace_attribute<ValueType>(id, { attr.size(), utils::constraints::PrimaryKey }, null_option_type::NotNull);
|
||||
prepare_primary_key(ref, utils::identifier(x));
|
||||
create_pk_constraint(id);
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
void object_generator::on_attribute(const char *id, Type &/*x*/, const utils::field_attributes &attr) {
|
||||
std::ignore = emplace_attribute<Type>(id, attr, null_option_type::NOT_NULL);
|
||||
std::ignore = emplace_attribute<Type>(id, attr, null_option_type::NotNull);
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
void object_generator::on_attribute(const char *id, std::optional<Type> & /*x*/, const utils::field_attributes &attr) {
|
||||
std::ignore = emplace_attribute<Type>(id, attr, null_option_type::NULLABLE);
|
||||
std::ignore = emplace_attribute<Type>(id, attr, null_option_type::Nullable);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user