120 lines
2.9 KiB
C++
120 lines
2.9 KiB
C++
#ifndef MATADOR_BUILDER_HPP
|
|
#define MATADOR_BUILDER_HPP
|
|
|
|
#include "matador/object/attribute_definition.hpp"
|
|
|
|
#include "matador/query/column.hpp"
|
|
#include "matador/query/table.hpp"
|
|
|
|
#include "matador/utils/basic_types.hpp"
|
|
|
|
#include <string>
|
|
|
|
namespace matador::object {
|
|
|
|
class entity {
|
|
public:
|
|
explicit entity(std::string name)
|
|
: name_(std::move(name)) {}
|
|
|
|
[[nodiscard]] const std::string& name() const;
|
|
|
|
private:
|
|
std::string name_;
|
|
std::string alias_;
|
|
};
|
|
|
|
class attribute {
|
|
public:
|
|
attribute(std::string name, const utils::basic_type type)
|
|
: name_(std::move(name))
|
|
, type_(type) {}
|
|
|
|
[[nodiscard]] const std::string& name() const;
|
|
[[nodiscard]] utils::basic_type type() const;
|
|
[[nodiscard]] const attribute_options& options() const;
|
|
|
|
private:
|
|
friend class entity;
|
|
|
|
std::string name_;
|
|
std::string alias_;
|
|
utils::basic_type type_{};
|
|
attribute_options options_;
|
|
|
|
entity* owner_{nullptr};
|
|
};
|
|
|
|
class constraint {
|
|
public:
|
|
explicit constraint(std::string name)
|
|
: name_(std::move(name)) {}
|
|
|
|
[[nodiscard]] const std::string& name() const;
|
|
[[nodiscard]] const std::string& column_name() const;
|
|
[[nodiscard]] const utils::constraints& type() 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& referenced_table() const;
|
|
[[nodiscard]] const std::string& referenced_column() const;
|
|
|
|
private:
|
|
std::string name_;
|
|
std::string column_name_;
|
|
utils::constraints type_{};
|
|
std::string referenced_table_;
|
|
std::string referenced_column_;
|
|
};
|
|
}
|
|
namespace matador::query {
|
|
|
|
class column_builder {
|
|
public:
|
|
explicit column_builder(std::string column_name);
|
|
|
|
// ReSharper disable once CppNonExplicitConversionOperator
|
|
operator query::column() const; // NOLINT(*-explicit-constructor)
|
|
|
|
private:
|
|
std::string column_name;
|
|
};
|
|
|
|
class table_builder {
|
|
public:
|
|
explicit table_builder(std::string name);
|
|
|
|
table_builder& as(std::string table_alias);
|
|
|
|
// ReSharper disable once CppNonExplicitConversionOperator
|
|
operator query::table() const; // NOLINT(*-explicit-constructor)
|
|
|
|
private:
|
|
std::string table_name;
|
|
std::string alias;
|
|
};
|
|
|
|
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);
|
|
|
|
// ReSharper disable once CppNonExplicitConversionOperator
|
|
operator object::constraint() const; // NOLINT(*-explicit-constructor)
|
|
|
|
private:
|
|
std::string constraint_name;
|
|
std::string pk_column_name;
|
|
std::string fk_column_name;
|
|
std::string table_name;
|
|
std::string column_name;
|
|
};
|
|
|
|
constraint_builder constraint(std::string name);
|
|
table_builder table(std::string name);
|
|
column_builder column(std::string name);
|
|
|
|
}
|
|
#endif //MATADOR_BUILDER_HPP
|