63 lines
1.4 KiB
C++
63 lines
1.4 KiB
C++
#ifndef QUERY_TABLE_REPOSITORY_HPP
|
|
#define QUERY_TABLE_REPOSITORY_HPP
|
|
|
|
#include "matador/sql/column_generator.hpp"
|
|
#include "matador/sql/record.hpp"
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <typeindex>
|
|
#include <unordered_map>
|
|
|
|
namespace matador::sql {
|
|
|
|
struct table_info
|
|
{
|
|
std::string name;
|
|
record prototype;
|
|
};
|
|
|
|
class table_repository
|
|
{
|
|
public:
|
|
template<typename Type>
|
|
const table_info& attach(const std::string &table_name)
|
|
{
|
|
return attach(std::type_index(typeid(Type)), table_info{table_name, record{column_generator::generate<Type>(*this)}});
|
|
}
|
|
|
|
const table_info& attach(std::type_index ti, const table_info& table);
|
|
|
|
template<typename Type>
|
|
std::optional<table_info> info()
|
|
{
|
|
return info(std::type_index(typeid(Type)));
|
|
}
|
|
|
|
std::optional<table_info> info(std::type_index ti);
|
|
|
|
template<typename Type>
|
|
[[nodiscard]] std::pair<std::string, std::string> reference() const
|
|
{
|
|
return reference(std::type_index(typeid(Type)));
|
|
}
|
|
|
|
[[nodiscard]] std::pair<std::string, std::string> reference(const std::type_index &ti) const;
|
|
|
|
template<typename Type>
|
|
[[nodiscard]] bool exists() const
|
|
{
|
|
return exists(std::type_index(typeid(Type)));
|
|
}
|
|
|
|
[[nodiscard]] bool exists(const std::type_index &ti) const;
|
|
|
|
private:
|
|
using repository = std::unordered_map<std::type_index, table_info>;
|
|
repository repository_;
|
|
};
|
|
|
|
}
|
|
|
|
#endif //QUERY_TABLE_REPOSITORY_HPP
|