#ifndef QUERY_FIELD_HPP #define QUERY_FIELD_HPP #include "matador/utils/value.hpp" #include "matador/utils/basic_types.hpp" #include #include namespace matador::utils { enum class constraints : unsigned char; } namespace matador::sql { enum struct field_type { Attribute, PrimaryKey, ForeignKey }; /** * */ class field { public: explicit field(std::string name); template field(std::string name, Type value, const field_type type = field_type::Attribute, const size_t size = 0, const int index = -1) : name_(std::move(name)) , type_(type) , index_(index) , value_(value, size) {} field(std::string name, utils::basic_type dt, field_type type = field_type::Attribute, size_t size = 0, int index = -1); field(const field &x) = default; field& operator=(const field &x) = default; field(field &&x) noexcept; field& operator=(field &&x) noexcept; template field& operator=(Type value) { value_ = std::move(value); return *this; } [[nodiscard]] const std::string& name() const; [[nodiscard]] field_type type() const; [[nodiscard]] size_t size() const; [[nodiscard]] int index() const; template std::optional as() const { return value_.as(); } [[nodiscard]] std::string str() const; [[nodiscard]] bool is_integer() const; [[nodiscard]] bool is_floating_point() const; [[nodiscard]] bool is_bool() const; [[nodiscard]] bool is_string() const; [[nodiscard]] bool is_varchar() const; [[nodiscard]] bool is_blob() const; [[nodiscard]] bool is_null() const; [[nodiscard]] bool is_primary_key() const; [[nodiscard]] bool is_foreign_key() const; [[nodiscard]] bool is_attribute() const; friend std::ostream& operator<<(std::ostream &out, const field &col); private: static utils::constraints determine_constraint(field_type type); template void process(Operator &op) { op.on_attribute(name_.c_str(), value_, { value_.size(), determine_constraint(type_) } ); } private: friend class record; std::string name_; field_type type_{field_type::Attribute}; int index_{-1}; utils::value value_; }; } #endif //QUERY_FIELD_HPP