94 lines
2.3 KiB
C++
94 lines
2.3 KiB
C++
#include "matador/object/constraint.hpp"
|
|
#include "matador/object/attribute.hpp"
|
|
|
|
namespace matador::object {
|
|
constraint::constraint(std::string name)
|
|
: name_(std::move(name)) {}
|
|
|
|
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;
|
|
}
|
|
|
|
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 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 c;
|
|
}
|
|
|
|
constraint_builder constraint(std::string name) {
|
|
constraint_builder builder;
|
|
return builder.constraint(std::move(name));
|
|
}
|
|
}
|