83 lines
1.6 KiB
C++
83 lines
1.6 KiB
C++
#include "matador/sql/schema.hpp"
|
|
#include "matador/sql/connection.hpp"
|
|
|
|
#include <stdexcept>
|
|
|
|
namespace matador::sql {
|
|
|
|
void table_info::create(connection &conn, schema &scm) const
|
|
{
|
|
// conn.query().create().table(name, prototype.columns()).execute();
|
|
}
|
|
|
|
void table_info::drop(connection &conn, schema &scm) const
|
|
{
|
|
// conn.query().drop().table(name).execute();
|
|
}
|
|
|
|
schema::schema(std::string name)
|
|
: name_(std::move(name)) {}
|
|
|
|
std::string schema::name() const
|
|
{
|
|
return name_;
|
|
}
|
|
|
|
const table_info& schema::attach(const std::type_index ti, const table_info& table)
|
|
{
|
|
return repository_.try_emplace(ti, table).first->second;
|
|
}
|
|
|
|
std::optional<table_info> schema::info(std::type_index ti) const
|
|
{
|
|
const auto it = repository_.find(ti);
|
|
if (it == repository_.end()) {
|
|
return std::nullopt;
|
|
}
|
|
return it->second;
|
|
}
|
|
|
|
std::pair<std::string, std::string> schema::reference(const std::type_index &ti) const
|
|
{
|
|
const auto it = repository_.find(ti);
|
|
if (it != repository_.end()) {
|
|
if (!it->second.prototype.has_primary_key()) {
|
|
throw std::logic_error("table doesn't has primary key");
|
|
}
|
|
return { it->second.name, it->second.prototype.primary_key().name() };
|
|
}
|
|
|
|
return {};
|
|
}
|
|
|
|
bool schema::exists(const std::type_index &ti) const
|
|
{
|
|
return repository_.count(ti) > 0;
|
|
}
|
|
|
|
schema::iterator schema::begin()
|
|
{
|
|
return repository_.begin();
|
|
}
|
|
|
|
schema::const_iterator schema::begin() const
|
|
{
|
|
return repository_.begin();
|
|
}
|
|
|
|
schema::iterator schema::end()
|
|
{
|
|
return repository_.end();
|
|
}
|
|
|
|
schema::const_iterator schema::end() const
|
|
{
|
|
return repository_.end();
|
|
}
|
|
|
|
bool schema::empty() const
|
|
{
|
|
return repository_.empty();
|
|
}
|
|
|
|
} |