added schema creation to session class
This commit is contained in:
@@ -153,9 +153,14 @@ query_create_intermediate::query_create_intermediate(connection &db)
|
||||
builder_.create();
|
||||
}
|
||||
|
||||
query_execute_finish query_create_intermediate::table(const std::string &table, std::initializer_list<column> columns)
|
||||
query_execute_finish query_create_intermediate::table(const std::string &table_name, std::initializer_list<column> columns)
|
||||
{
|
||||
return {connection_, builder_.table(table, columns)};
|
||||
return table(table_name, std::vector<column>{columns});
|
||||
}
|
||||
|
||||
query_execute_finish query_create_intermediate::table(const std::string &table_name, const std::vector<column> &columns)
|
||||
{
|
||||
return {connection_, builder_.table(table_name, columns)};
|
||||
}
|
||||
|
||||
std::shared_ptr<table_repository> query_create_intermediate::tables() const
|
||||
|
||||
@@ -10,6 +10,14 @@ session::session(connection_pool<connection> &pool)
|
||||
: pool_(pool)
|
||||
, dialect_(backend_provider::instance().connection_dialect(pool_.info().type)) {}
|
||||
|
||||
void session::create_schema()
|
||||
{
|
||||
auto c = pool_.acquire();
|
||||
for (const auto &t : table_repository_) {
|
||||
t.second.create(*c);
|
||||
}
|
||||
}
|
||||
|
||||
void session::drop_table(const std::string &table_name)
|
||||
{
|
||||
auto c = pool_.acquire();
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
#include "matador/sql/table_repository.hpp"
|
||||
#include "matador/sql/connection.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
void table_info::create(connection &conn) const
|
||||
{
|
||||
conn.create().table(name, prototype.columns()).execute();
|
||||
}
|
||||
|
||||
void table_info::drop(connection &conn) const
|
||||
{
|
||||
conn.drop().table(name).execute();
|
||||
}
|
||||
|
||||
const table_info& table_repository::attach(const std::type_index ti, const table_info& table)
|
||||
{
|
||||
return repository_.try_emplace(ti, table).first->second;
|
||||
@@ -36,4 +47,28 @@ bool table_repository::exists(const std::type_index &ti) const
|
||||
return repository_.count(ti) > 0;
|
||||
}
|
||||
|
||||
table_repository::iterator table_repository::begin()
|
||||
{
|
||||
return repository_.begin();
|
||||
}
|
||||
|
||||
table_repository::const_iterator table_repository::begin() const
|
||||
{
|
||||
return repository_.begin();
|
||||
}
|
||||
|
||||
table_repository::iterator table_repository::end()
|
||||
{
|
||||
return repository_.end();
|
||||
}
|
||||
|
||||
table_repository::const_iterator table_repository::end() const
|
||||
{
|
||||
return repository_.end();
|
||||
}
|
||||
|
||||
bool table_repository::empty() const
|
||||
{
|
||||
return repository_.empty();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user