query/include/matador/object/constraint.hpp

66 lines
1.8 KiB
C++

#ifndef MATADOR_CONSTRAINT_HPP
#define MATADOR_CONSTRAINT_HPP
#include "matador/utils/constraints.hpp"
#include <string>
#include <variant>
namespace matador::object {
class attribute;
class constraint_builder;
class constraint_generator;
class object;
class constraint {
public:
constraint() = default;
explicit constraint(std::string name);
[[nodiscard]] const std::string& name() const;
[[nodiscard]] const class attribute* attribute() const;
[[nodiscard]] std::string column_name() const;
[[nodiscard]] const object* owner() const;
[[nodiscard]] bool is_primary_key_constraint() const;
[[nodiscard]] bool is_foreign_key_constraint() const;
[[nodiscard]] bool is_unique_constraint() const;
[[nodiscard]] const std::string& ref_table_name() const;
[[nodiscard]] const std::string& ref_column_name() const;
private:
friend class constraint_builder;
friend class constraints_generator;
friend class object_generator;
friend class object;
std::string name_;
std::variant<class attribute*, std::string> attr_;
// class attribute* attr_{nullptr};
object *owner_{nullptr};
utils::constraints options_{utils::constraints::None};
std::string ref_table_name_{};
std::string ref_column_name_{};
};
class constraint_builder {
public:
constraint_builder& constraint(std::string name);
constraint_builder& primary_key(std::string name);
constraint_builder& foreign_key(std::string name);
constraint_builder& references(std::string table, std::string column);
operator class constraint() const;
private:
std::string constraint_name;
utils::constraints options_{utils::constraints::None};
std::string column_name;
std::string ref_table_name;
std::string ref_column_name;
};
constraint_builder constraint(std::string name);
}
#endif //MATADOR_CONSTRAINT_HPP