#include "matador/sql/column_definition.hpp" #include #include namespace matador::sql { column_definition::column_definition(const char *name) : name_(name) , attributes_(utils::null_attributes) {} column_definition::column_definition(std::string name) : name_(std::move(name)) , attributes_(utils::null_attributes) {} column_definition::column_definition(std::string name, const utils::basic_type type, const utils::field_attributes& attr, const null_option null_opt, const size_t index) : name_(std::move(name)) , index_(index) , attributes_(attr) , null_option_(null_opt) , value_(type, attr.size()) {} column_definition::column_definition(std::string name, const utils::basic_type type, const size_t index, std::string ref_table, std::string ref_column, const utils::field_attributes& attr, const null_option null_opt) : name_(std::move(name)) , index_(index) , attributes_(attr) , null_option_(null_opt) , value_(type, attr.size()) , ref_table_(std::move(ref_table)) , ref_column_(std::move(ref_column)) {} const std::string &column_definition::name() const { return name_; } std::string column_definition::full_name() const { return table_ + "." + name_; } std::string column_definition::table_name() const { return table_; } int column_definition::index() const { return index_; } const utils::field_attributes &column_definition::attributes() const { return attributes_; } bool column_definition::is_nullable() const { return null_option_ == null_option::NULLABLE; } utils::basic_type column_definition::type() const { return value_.type(); } const std::string &column_definition::ref_table() const { return ref_table_; } const std::string &column_definition::ref_column() const { return ref_column_; } bool column_definition::is_foreign_reference() const { return !ref_column_.empty() && !ref_table_.empty(); } bool column_definition::is_integer() const { return value_.is_integer(); } bool column_definition::is_floating_point() const { return value_.is_floating_point(); } bool column_definition::is_bool() const { return value_.is_bool(); } bool column_definition::is_string() const { return value_.is_string(); } bool column_definition::is_varchar() const { return value_.is_varchar(); } bool column_definition::is_date() const { return value_.is_date(); } bool column_definition::is_time() const { return value_.is_time(); } bool column_definition::is_blob() const { return value_.is_blob(); } bool column_definition::is_null() const { return value_.is_null(); } void column_definition::type(utils::basic_type /*type*/) { // type_ = type; // utils::initialize_by_utils::basic_type(type, value_); } std::string column_definition::str() const { return value_.str(); } std::ostream& operator<<(std::ostream &out, const column_definition &col) { out << col.str(); return out; } column_definition make_column(const std::string &name, utils::basic_type type, utils::field_attributes attr, null_option null_opt) { return {name, type, attr, null_opt}; } template<> column_definition make_column(const std::string &name, utils::field_attributes attr, null_option null_opt) { return make_column(name, utils::data_type_traits::type(attr.size()), attr, null_opt); } template<> column_definition make_pk_column(const std::string &name, size_t size) { return make_column(name, {size, utils::constraints::FOREIGN_KEY}); } template<> [[maybe_unused]] column_definition make_fk_column(const std::string &name, size_t size, const std::string &ref_table, const std::string &ref_column) { return {name, utils::data_type_traits::type(size), 0, ref_table, ref_column, {size, utils::constraints::FOREIGN_KEY}, null_option::NOT_NULL}; } }