object generating progress
This commit is contained in:
@@ -1,49 +1,22 @@
|
||||
#include "matador/object/attribute.hpp"
|
||||
#include "matador/object/object.hpp"
|
||||
|
||||
#include <ostream>
|
||||
#include <utility>
|
||||
|
||||
namespace matador::object {
|
||||
attribute::attribute(const char *name)
|
||||
: attribute(name, utils::basic_type::type_null, "", {utils::null_attributes}) {
|
||||
}
|
||||
|
||||
attribute::attribute(std::string name)
|
||||
: attribute(std::move(name), utils::basic_type::type_null, "", {utils::null_attributes}) {
|
||||
: attribute(std::move(name), utils::basic_type::type_null, {}, null_option_type::NOT_NULL) {
|
||||
}
|
||||
|
||||
attribute::attribute(std::string name,
|
||||
const utils::basic_type type,
|
||||
const utils::field_attributes &attr,
|
||||
const null_option_type null_opt,
|
||||
const int index)
|
||||
: attribute(std::move(name), type, "", {attr, null_opt, index}) {
|
||||
}
|
||||
|
||||
attribute::attribute(std::string name,
|
||||
const utils::basic_type type,
|
||||
const int index,
|
||||
const std::shared_ptr<attribute> &ref_column,
|
||||
const utils::field_attributes &attr,
|
||||
const null_option_type null_opt)
|
||||
: attribute(std::move(name), type, "", {attr, null_opt, index}, ref_column) {
|
||||
}
|
||||
|
||||
attribute::attribute( std::string name, const utils::basic_type type, const std::shared_ptr<attribute>& ref_column )
|
||||
: attribute(std::move(name), type, {}, {}, ref_column) {
|
||||
}
|
||||
|
||||
attribute::attribute(std::string name,
|
||||
const utils::basic_type type,
|
||||
std::string table_name,
|
||||
const attribute_options& options,
|
||||
const std::shared_ptr<attribute>& ref_column)
|
||||
const utils::basic_type type,
|
||||
const utils::field_attributes &attr,
|
||||
const null_option_type null_opt)
|
||||
: name_(std::move(name))
|
||||
, table_name_(std::move(table_name))
|
||||
, options_( options )
|
||||
, type_( type )
|
||||
, reference_column_( ref_column ) {
|
||||
}
|
||||
, options_{attr, null_opt}
|
||||
, type_(type)
|
||||
{}
|
||||
|
||||
const std::string &attribute::name() const {
|
||||
return name_;
|
||||
@@ -54,7 +27,7 @@ void attribute::name( const std::string& n ) {
|
||||
}
|
||||
|
||||
std::string attribute::full_name() const {
|
||||
return !table_name_.empty() ? table_name_ + "." + name_ : name_;
|
||||
return owner_ ? owner_->name() + "." + name_ : name_;
|
||||
}
|
||||
|
||||
int attribute::index() const {
|
||||
@@ -77,27 +50,23 @@ utils::basic_type attribute::type() const {
|
||||
return type_;
|
||||
}
|
||||
|
||||
const std::string& attribute::table_name() const {
|
||||
return table_name_;
|
||||
object* attribute::owner() const {
|
||||
return owner_;
|
||||
}
|
||||
|
||||
void attribute::table_name( const std::string& name ) {
|
||||
table_name_ = name;
|
||||
}
|
||||
// const std::string& attribute::table_name() const {
|
||||
// return owner_ ? owner_->name() : "";
|
||||
// }
|
||||
//
|
||||
// void attribute::table_name( const std::string& name ) {
|
||||
// table_name_ = name;
|
||||
// }
|
||||
|
||||
void attribute::change_type(const utils::basic_type type, const utils::field_attributes& attr) {
|
||||
options_.attributes = attr;
|
||||
type_ = type;
|
||||
}
|
||||
|
||||
std::shared_ptr<attribute> attribute::reference_column() const {
|
||||
return reference_column_;
|
||||
}
|
||||
|
||||
bool attribute::is_foreign_reference() const {
|
||||
return reference_column_ != nullptr;
|
||||
}
|
||||
|
||||
bool attribute::is_integer() const {
|
||||
return type_ >= utils::basic_type::type_int8 && type_ <= utils::basic_type::type_uint64;
|
||||
}
|
||||
@@ -134,45 +103,45 @@ bool attribute::is_null() const {
|
||||
return type_ == utils::basic_type::type_null;
|
||||
}
|
||||
|
||||
attribute make_column(const std::string &name, utils::basic_type type, utils::field_attributes attr,
|
||||
null_option_type null_opt) {
|
||||
return {name, type, attr, null_opt};
|
||||
}
|
||||
|
||||
template<>
|
||||
attribute make_column<std::string>(const std::string &name, utils::field_attributes attr,
|
||||
null_option_type null_opt) {
|
||||
return make_column(name, utils::data_type_traits<std::string>::type(attr.size()), attr, null_opt);
|
||||
}
|
||||
|
||||
template<>
|
||||
attribute make_pk_column<std::string>(const std::string &name, size_t size) {
|
||||
return make_column<std::string>(name, {size, utils::constraints::PrimaryKey});
|
||||
}
|
||||
|
||||
template<>
|
||||
attribute make_fk_column<std::string>(const std::string &name, size_t size, const std::shared_ptr<attribute> &ref_column) {
|
||||
return {
|
||||
name, utils::data_type_traits<std::string>::type(size), 0, ref_column,
|
||||
{size, utils::constraints::ForeignKey}, null_option_type::NOT_NULL
|
||||
};
|
||||
}
|
||||
|
||||
template<>
|
||||
attribute make_fk_column<std::string>( const std::string& name, const std::string& ref_table_name, const std::string& ref_column_name ) {
|
||||
return {
|
||||
name, utils::basic_type::type_varchar, 0,
|
||||
std::make_shared<attribute>(ref_column_name, utils::basic_type::type_varchar, ref_table_name, attribute_options{utils::constraints::ForeignKey}),
|
||||
{ 0, utils::constraints::ForeignKey }, null_option_type::NOT_NULL
|
||||
};
|
||||
}
|
||||
|
||||
template<>
|
||||
attribute make_fk_column<std::string>(const std::string &name, size_t size, const std::string &ref_table_name, const std::string &ref_column_name) {
|
||||
const auto ref_column = std::make_shared<attribute>(ref_column_name, utils::basic_type::type_varchar, ref_table_name, attribute_options{utils::constraints::ForeignKey});
|
||||
return {
|
||||
name, utils::data_type_traits<std::string>::type(size), 0, ref_column,
|
||||
{size, utils::constraints::ForeignKey}, null_option_type::NOT_NULL
|
||||
};
|
||||
}
|
||||
// attribute make_column(const std::string &name, utils::basic_type type, utils::field_attributes attr,
|
||||
// null_option_type null_opt) {
|
||||
// return {name, type, attr, null_opt};
|
||||
// }
|
||||
//
|
||||
// template<>
|
||||
// attribute make_column<std::string>(const std::string &name, utils::field_attributes attr,
|
||||
// null_option_type null_opt) {
|
||||
// return make_column(name, utils::data_type_traits<std::string>::type(attr.size()), attr, null_opt);
|
||||
// }
|
||||
//
|
||||
// template<>
|
||||
// attribute make_pk_column<std::string>(const std::string &name, size_t size) {
|
||||
// return make_column<std::string>(name, {size, utils::constraints::PrimaryKey});
|
||||
// }
|
||||
//
|
||||
// template<>
|
||||
// attribute make_fk_column<std::string>(const std::string &name, size_t size, const std::shared_ptr<attribute> &ref_column) {
|
||||
// return {
|
||||
// name, utils::data_type_traits<std::string>::type(size), 0, ref_column,
|
||||
// {size, utils::constraints::ForeignKey}, null_option_type::NOT_NULL
|
||||
// };
|
||||
// }
|
||||
//
|
||||
// template<>
|
||||
// attribute make_fk_column<std::string>( const std::string& name, const std::string& ref_table_name, const std::string& ref_column_name ) {
|
||||
// return {
|
||||
// name, utils::basic_type::type_varchar, 0,
|
||||
// std::make_shared<attribute>(ref_column_name, utils::basic_type::type_varchar, ref_table_name, attribute_options{utils::constraints::ForeignKey}),
|
||||
// { 0, utils::constraints::ForeignKey }, null_option_type::NOT_NULL
|
||||
// };
|
||||
// }
|
||||
//
|
||||
// template<>
|
||||
// attribute make_fk_column<std::string>(const std::string &name, size_t size, const std::string &ref_table_name, const std::string &ref_column_name) {
|
||||
// const auto ref_column = std::make_shared<attribute>(ref_column_name, utils::basic_type::type_varchar, ref_table_name, attribute_options{utils::constraints::ForeignKey});
|
||||
// return {
|
||||
// name, utils::data_type_traits<std::string>::type(size), 0, ref_column,
|
||||
// {size, utils::constraints::ForeignKey}, null_option_type::NOT_NULL
|
||||
// };
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user