101 lines
2.8 KiB
C++
101 lines
2.8 KiB
C++
#include "matador/object/restriction.hpp"
|
|
|
|
#include "matador/object/attribute.hpp"
|
|
#include "matador/object/object.hpp"
|
|
|
|
namespace matador::object {
|
|
restriction::restriction(const class attribute& attr)
|
|
: attr_(attr) {}
|
|
|
|
const class attribute& restriction::attribute() const {
|
|
return attr_;
|
|
}
|
|
|
|
std::string restriction::column_name() const {
|
|
return attr_.name();
|
|
}
|
|
std::shared_ptr<object> restriction::owner() const {
|
|
return owner_;
|
|
}
|
|
|
|
bool restriction::is_primary_key_constraint() const {
|
|
return utils::is_constraint_set(options_, utils::constraints::PrimaryKey);
|
|
}
|
|
|
|
bool restriction::is_foreign_key_constraint() const {
|
|
return utils::is_constraint_set(options_, utils::constraints::ForeignKey);
|
|
}
|
|
|
|
bool restriction::is_unique_constraint() const {
|
|
return utils::is_constraint_set(options_, utils::constraints::Unique);
|
|
}
|
|
|
|
const std::string& restriction::ref_table_name() const {
|
|
return reference_->name();
|
|
}
|
|
|
|
const std::string& restriction::ref_column_name() const {
|
|
return reference_->primary_key_attribute()->name();
|
|
}
|
|
|
|
std::ostream & operator<<(std::ostream &os, const class restriction &c) {
|
|
os << "constraint " << c.type_string() << " for column " << c.column_name();
|
|
if (c.is_foreign_key_constraint()) {
|
|
os << " references " << c.ref_table_name() << "." << c.ref_column_name();
|
|
}
|
|
return os;
|
|
}
|
|
|
|
std::string restriction::type_string() const {
|
|
if (utils::is_constraint_set(options_, utils::constraints::PrimaryKey)) {
|
|
return "PrimaryKey";
|
|
}
|
|
if (utils::is_constraint_set(options_, utils::constraints::ForeignKey)) {
|
|
return "ForeignKey";
|
|
}
|
|
if (utils::is_constraint_set(options_, utils::constraints::Unique)) {
|
|
return "Unique";
|
|
}
|
|
return "Unknown";
|
|
}
|
|
|
|
// constraint_builder & constraint_builder::constraint(std::string name) {
|
|
// constraint_name = std::move(name);
|
|
// return *this;
|
|
// }
|
|
//
|
|
// constraint_builder & constraint_builder::primary_key(std::string name) {
|
|
// column_name = std::move(name);
|
|
// options_ |= utils::constraints::PrimaryKey;
|
|
// return *this;
|
|
// }
|
|
//
|
|
// constraint_builder & constraint_builder::foreign_key(std::string name) {
|
|
// column_name = std::move(name);
|
|
// options_ |= utils::constraints::ForeignKey;
|
|
// return *this;
|
|
// }
|
|
//
|
|
// constraint_builder & constraint_builder::references(std::string table, std::string column) {
|
|
// ref_table_name = std::move(table);
|
|
// ref_column_name = std::move(column);
|
|
//
|
|
// return *this;
|
|
// }
|
|
//
|
|
// constraint_builder::operator class restriction() const {
|
|
// class restriction 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 c;
|
|
// }
|
|
//
|
|
// constraint_builder constraint(std::string name) {
|
|
// constraint_builder builder;
|
|
// return builder.constraint(std::move(name));
|
|
// }
|
|
}
|