renamed constraint to restriction
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
#include "matador/object/restriction.hpp"
|
||||
|
||||
#include "matador/object/attribute.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
restriction::restriction(std::string name)
|
||||
: name_(std::move(name)) {}
|
||||
|
||||
const std::string & restriction::name() const {
|
||||
return name_;
|
||||
}
|
||||
|
||||
const class attribute* restriction::attribute() const {
|
||||
if (std::holds_alternative<class attribute*>(attr_)) {
|
||||
return std::get<class attribute*>(attr_);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string restriction::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 "";
|
||||
}
|
||||
|
||||
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 ref_table_name_;
|
||||
}
|
||||
|
||||
const std::string& restriction::ref_column_name() const {
|
||||
return ref_column_name_;
|
||||
}
|
||||
|
||||
std::ostream & operator<<(std::ostream &os, const class restriction &c) {
|
||||
os << "constraint " << c.name_ << " for column " << c.column_name();
|
||||
return os;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user