query builder progress
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
namespace matador::object {
|
||||
attribute::attribute(std::string name)
|
||||
: attribute(std::move(name), utils::basic_type::type_null, {}, null_option_type::NOT_NULL) {
|
||||
: attribute(std::move(name), utils::basic_type::type_null, {}, null_option_type::NotNull) {
|
||||
}
|
||||
|
||||
attribute::attribute(std::string name,
|
||||
@@ -14,8 +14,9 @@ attribute::attribute(std::string name,
|
||||
const utils::field_attributes &attr,
|
||||
const null_option_type null_opt)
|
||||
: name_(std::move(name))
|
||||
, options_{attr, null_opt}
|
||||
, type_(type)
|
||||
, options_(attr)
|
||||
, null_option_(null_opt)
|
||||
{}
|
||||
|
||||
const std::string &attribute::name() const {
|
||||
@@ -30,20 +31,16 @@ std::string attribute::full_name() const {
|
||||
return owner_ ? owner_->name() + "." + name_ : name_;
|
||||
}
|
||||
|
||||
int attribute::index() const {
|
||||
return options_.index;
|
||||
}
|
||||
|
||||
const utils::field_attributes &attribute::attributes() const {
|
||||
return options_.attributes;
|
||||
return options_;
|
||||
}
|
||||
|
||||
utils::field_attributes& attribute::attributes() {
|
||||
return options_.attributes;
|
||||
return options_;
|
||||
}
|
||||
|
||||
bool attribute::is_nullable() const {
|
||||
return options_.null_option == null_option_type::NULLABLE;
|
||||
return null_option_ == null_option_type::Nullable;
|
||||
}
|
||||
|
||||
utils::basic_type attribute::type() const {
|
||||
@@ -54,16 +51,8 @@ object* attribute::owner() const {
|
||||
return owner_;
|
||||
}
|
||||
|
||||
// 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;
|
||||
options_ = attr;
|
||||
type_ = type;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,10 @@ const std::list<attribute>& basic_object_info::attributes() const {
|
||||
return object_->attributes();
|
||||
}
|
||||
|
||||
const std::list<class constraint>& basic_object_info::constraints() const {
|
||||
return object_->constraints();
|
||||
}
|
||||
|
||||
bool basic_object_info::has_primary_key() const {
|
||||
return object_->has_primary_key();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "matador/object/constraint.hpp"
|
||||
#include "matador/object/attribute.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
constraint::constraint(std::string name)
|
||||
@@ -8,6 +9,49 @@ const std::string & constraint::name() const {
|
||||
return name_;
|
||||
}
|
||||
|
||||
const class attribute* constraint::attribute() const {
|
||||
if (std::holds_alternative<class attribute*>(attr_)) {
|
||||
return std::get<class attribute*>(attr_);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string constraint::column_name() const {
|
||||
if (std::holds_alternative<class attribute*>(attr_)) {
|
||||
return std::get<class attribute*>(attr_)->name();
|
||||
}
|
||||
if (std::holds_alternative<std::string>(attr_)) {
|
||||
return std::get<std::string>(attr_);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
const object* constraint::owner() const {
|
||||
return owner_;
|
||||
}
|
||||
|
||||
bool constraint::is_primary_key_constraint() const {
|
||||
return utils::is_constraint_set(options_, utils::constraints::PrimaryKey);
|
||||
}
|
||||
|
||||
bool constraint::is_foreign_key_constraint() const {
|
||||
return utils::is_constraint_set(options_, utils::constraints::ForeignKey);
|
||||
}
|
||||
|
||||
bool constraint::is_unique_constraint() const {
|
||||
return utils::is_constraint_set(options_, utils::constraints::Unique);
|
||||
}
|
||||
|
||||
const std::string& constraint::ref_table_name() const {
|
||||
return ref_table_name_;
|
||||
}
|
||||
|
||||
const std::string& constraint::ref_column_name() const {
|
||||
return ref_column_name_;
|
||||
}
|
||||
|
||||
constraint_builder & constraint_builder::constraint(std::string name) {
|
||||
constraint_name = std::move(name);
|
||||
return *this;
|
||||
@@ -35,10 +79,11 @@ constraint_builder & constraint_builder::references(std::string table, std::stri
|
||||
constraint_builder::operator class constraint() const {
|
||||
class constraint c;
|
||||
c.name_ = constraint_name;
|
||||
c.attr_ = column_name;
|
||||
c.options_ = options_;
|
||||
c.ref_column_name_ = ref_column_name;
|
||||
c.ref_table_name_ = ref_table_name;
|
||||
return {};
|
||||
return c;
|
||||
}
|
||||
|
||||
constraint_builder constraint(std::string name) {
|
||||
|
||||
@@ -110,7 +110,7 @@ attribute* repository_node::determine_reference_column(const std::type_index& ti
|
||||
repository& repo) {
|
||||
const auto it = repo.missing_references_.find(ti);
|
||||
if (it == repo.missing_references_.end()) {
|
||||
return new attribute(pk_info.pk_column_name, pk_info.type, {utils::constraints::ForeignKey}, null_option_type::NOT_NULL);
|
||||
return new attribute(pk_info.pk_column_name, pk_info.type, {utils::constraints::ForeignKey}, null_option_type::NotNull);
|
||||
}
|
||||
|
||||
auto ref_column = it->second;
|
||||
|
||||
Reference in New Issue
Block a user