query/include/matador/query/table.hpp

67 lines
1.8 KiB
C++

#ifndef QUERY_TABLE_HPP
#define QUERY_TABLE_HPP
#include "matador/query/table_column.hpp"
#include <string>
#include <vector>
namespace matador::query {
// ReSharper disable CppNonExplicitConvertingConstructor
class table {
public:
table() = default;
table(const char *name); // NOLINT(*-explicit-constructor)
table(const std::string& name); // NOLINT(*-explicit-constructor)
table(const std::string& name, const std::vector<table_column>& columns);
table(const table& other);
table& operator=(const table& other);
table(table&& other) noexcept;
table& operator=(table&& other) noexcept;
~table() = default;
[[nodiscard]] table as(const std::string &alias) const;
[[nodiscard]] bool operator==(const table &x) const;
[[nodiscard]] const std::string& table_name() const;
[[nodiscard]] const std::string& name() const;
[[nodiscard]] const std::vector<table_column>& columns() const;
[[nodiscard]] bool has_alias() const;
// ReSharper disable once CppNonExplicitConversionOperator
operator const std::vector<query::table_column>&() const; // NOLINT(*-explicit-constructor)
const table_column* operator[](const std::string& column_name) const;
static const table_column* column_by_name(const table &tab, const std::string& column_name);
protected:
static const table_column& create_column(class table& tab, const std::string& name);
table(std::string name, std::string alias, const std::vector<table_column>& columns);
private:
friend table_column;
std::string name_;
std::string alias_;
std::string schema_name_;
std::vector<table_column> columns_;
};
table operator ""_tab(const char *name, size_t len);
template<typename Type>
class typed_table : public table {
public:
using table::table;
Type as(std::string alias) const { return Type{std::move(alias)}; }
};
}
#endif //QUERY_TABLE_HPP