add column info (progress, not compiling)
This commit is contained in:
+2
-2
@@ -16,7 +16,7 @@ set(SQL_SOURCES
|
||||
sql/column_name_generator.cpp
|
||||
sql/key_value_generator.cpp
|
||||
sql/fk_value_extractor.cpp
|
||||
sql/table_repository.cpp
|
||||
sql/schema.cpp
|
||||
sql/query_result.cpp
|
||||
sql/query_result_reader.cpp
|
||||
sql/statement_cache.cpp
|
||||
@@ -55,7 +55,7 @@ set(SQL_HEADER
|
||||
../include/matador/sql/key_value_generator.hpp
|
||||
../include/matador/sql/entity.hpp
|
||||
../include/matador/sql/fk_value_extractor.hpp
|
||||
../include/matador/sql/table_repository.hpp
|
||||
../include/matador/sql/schema.hpp
|
||||
../include/matador/sql/any_type_to_visitor.hpp
|
||||
../include/matador/sql/query_result_reader.hpp
|
||||
../include/matador/sql/to_value.hpp
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "matador/sql/column_generator.hpp"
|
||||
#include "matador/sql/table_repository.hpp"
|
||||
#include "matador/sql/schema.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
column_generator::column_generator(std::vector<column> &columns, const table_repository &repo)
|
||||
column_generator::column_generator(std::vector<column> &columns, const schema &repo)
|
||||
: columns_(columns)
|
||||
, repo_(repo)
|
||||
{}
|
||||
|
||||
@@ -2,18 +2,30 @@
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
column_name_generator::column_name_generator(std::vector<std::string> &column_names)
|
||||
: column_names_(column_names)
|
||||
{}
|
||||
column_name_generator::column_name_generator(std::vector<column_info> &column_infos,
|
||||
const sql::schema &ts,
|
||||
const std::string &table_name)
|
||||
: column_infos_(column_infos)
|
||||
, table_schema_(ts)
|
||||
{
|
||||
table_name_stack_.push(table_name);
|
||||
}
|
||||
|
||||
void column_name_generator::on_primary_key(const char *id, std::string &, size_t)
|
||||
{
|
||||
column_names_.emplace_back(id);
|
||||
push(id);
|
||||
}
|
||||
|
||||
void column_name_generator::on_revision(const char *id, unsigned long long int &)
|
||||
{
|
||||
column_names_.emplace_back(id);
|
||||
push(id);
|
||||
}
|
||||
|
||||
void column_name_generator::push(const std::string &column_name)
|
||||
{
|
||||
char str[4];
|
||||
snprintf(str, 4, "c%02d", ++column_index);
|
||||
column_infos_.emplace_back(column_info{table_name_stack_.top(), column_name, str});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,16 +8,16 @@
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
connection::connection(connection_info info, const std::shared_ptr<table_repository> &repo)
|
||||
connection::connection(connection_info info, const std::shared_ptr<schema> &repo)
|
||||
: connection_info_(std::move(info))
|
||||
, logger_(stdout, "SQL")
|
||||
, dialect_(backend_provider::instance().connection_dialect(connection_info_.type))
|
||||
, table_repository_(repo)
|
||||
, schema_(repo)
|
||||
{
|
||||
connection_.reset(backend_provider::instance().create_connection(connection_info_.type, connection_info_));
|
||||
}
|
||||
|
||||
connection::connection(const std::string& dns, const std::shared_ptr<table_repository> &repo)
|
||||
connection::connection(const std::string& dns, const std::shared_ptr<schema> &repo)
|
||||
: connection(connection_info::parse(dns), repo)
|
||||
{}
|
||||
|
||||
@@ -160,9 +160,9 @@ const class dialect &connection::dialect() const
|
||||
return dialect_;
|
||||
}
|
||||
|
||||
std::shared_ptr<table_repository> connection::tables() const
|
||||
std::shared_ptr<schema> connection::tables() const
|
||||
{
|
||||
return table_repository_;
|
||||
return schema_;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "matador/sql/query_builder.hpp"
|
||||
#include "matador/sql/column_name_generator.hpp"
|
||||
#include "matador/sql/dialect.hpp"
|
||||
|
||||
#include "matador/utils/string.hpp"
|
||||
@@ -255,12 +256,12 @@ query_builder &query_builder::table(const std::string &table)
|
||||
return *this;
|
||||
}
|
||||
|
||||
query_builder &query_builder::into(const std::string &table, std::initializer_list<std::string> column_names)
|
||||
query_builder &query_builder::into(const std::string &table, std::initializer_list<column_info> column_names)
|
||||
{
|
||||
return into(table, std::vector<std::string>{column_names});
|
||||
return into(table, std::vector<column_info>{column_names});
|
||||
}
|
||||
|
||||
query_builder &query_builder::into(const std::string &table, const std::vector<std::string> &column_names)
|
||||
query_builder &query_builder::into(const std::string &table, const std::vector<column_info> &column_names)
|
||||
{
|
||||
transition_to(state_t::QUERY_INTO);
|
||||
|
||||
@@ -270,14 +271,14 @@ query_builder &query_builder::into(const std::string &table, const std::vector<s
|
||||
std::string result{"("};
|
||||
if (column_names.size() < 2) {
|
||||
for (const auto &col: column_names) {
|
||||
result.append(dialect_.prepare_identifier(col));
|
||||
result.append(dialect_.prepare_identifier(col.name));
|
||||
}
|
||||
} else {
|
||||
auto it = column_names.begin();
|
||||
result.append(dialect_.prepare_identifier(*it++));
|
||||
result.append(dialect_.prepare_identifier((it++)->name));
|
||||
for (; it != column_names.end(); ++it) {
|
||||
result.append(", ");
|
||||
result.append(dialect_.prepare_identifier(*it));
|
||||
result.append(dialect_.prepare_identifier(it->name));
|
||||
}
|
||||
}
|
||||
result += (")");
|
||||
|
||||
@@ -2,6 +2,13 @@
|
||||
#include "matador/sql/session.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
basic_query_intermediate::basic_query_intermediate(connection &db)
|
||||
: connection_(db) {}
|
||||
|
||||
std::shared_ptr<schema> basic_query_intermediate::tables() const
|
||||
{
|
||||
return connection_.tables();
|
||||
}
|
||||
|
||||
query_result<record> query_select_finish::fetch_all()
|
||||
{
|
||||
@@ -24,7 +31,7 @@ statement query_select_finish::prepare()
|
||||
}
|
||||
|
||||
query_intermediate::query_intermediate(connection &db, query_builder &query)
|
||||
: connection_(db), builder_(query) {}
|
||||
: basic_query_intermediate(db), builder_(query) {}
|
||||
|
||||
query_offset_intermediate query_order_direction_intermediate::offset(size_t offset)
|
||||
{
|
||||
@@ -128,7 +135,7 @@ query_insert_intermediate::query_insert_intermediate(connection &s)
|
||||
builder_.insert();
|
||||
}
|
||||
|
||||
query_into_intermediate query_insert_intermediate::into(const std::string &table, std::initializer_list<std::string> column_names)
|
||||
query_into_intermediate query_insert_intermediate::into(const std::string &table, std::initializer_list<column_info> column_names)
|
||||
{
|
||||
return {connection_, builder_.into(table, column_names)};
|
||||
}
|
||||
@@ -163,11 +170,6 @@ query_execute_finish query_create_intermediate::table(const std::string &table_n
|
||||
return {connection_, builder_.table(table_name, columns)};
|
||||
}
|
||||
|
||||
std::shared_ptr<table_repository> query_create_intermediate::tables() const
|
||||
{
|
||||
return connection_.tables();
|
||||
}
|
||||
|
||||
query_drop_intermediate::query_drop_intermediate(connection &s)
|
||||
: query_start_intermediate(s)
|
||||
{
|
||||
@@ -217,7 +219,7 @@ query_delete_from_intermediate query_delete_intermediate::from(const std::string
|
||||
}
|
||||
|
||||
query_start_intermediate::query_start_intermediate(connection &s)
|
||||
: connection_(s)
|
||||
: basic_query_intermediate(s)
|
||||
, builder_(s.dialect())
|
||||
{}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "matador/sql/table_repository.hpp"
|
||||
#include "matador/sql/schema.hpp"
|
||||
#include "matador/sql/connection.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
@@ -15,12 +15,12 @@ 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)
|
||||
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> table_repository::info(std::type_index ti)
|
||||
std::optional<table_info> schema::info(std::type_index ti) const
|
||||
{
|
||||
const auto it = repository_.find(ti);
|
||||
if (it == repository_.end()) {
|
||||
@@ -29,7 +29,7 @@ std::optional<table_info> table_repository::info(std::type_index ti)
|
||||
return it->second;
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string> table_repository::reference(const std::type_index &ti) const
|
||||
std::pair<std::string, std::string> schema::reference(const std::type_index &ti) const
|
||||
{
|
||||
const auto it = repository_.find(ti);
|
||||
if (it != repository_.end()) {
|
||||
@@ -42,32 +42,32 @@ std::pair<std::string, std::string> table_repository::reference(const std::type_
|
||||
return {};
|
||||
}
|
||||
|
||||
bool table_repository::exists(const std::type_index &ti) const
|
||||
bool schema::exists(const std::type_index &ti) const
|
||||
{
|
||||
return repository_.count(ti) > 0;
|
||||
}
|
||||
|
||||
table_repository::iterator table_repository::begin()
|
||||
schema::iterator schema::begin()
|
||||
{
|
||||
return repository_.begin();
|
||||
}
|
||||
|
||||
table_repository::const_iterator table_repository::begin() const
|
||||
schema::const_iterator schema::begin() const
|
||||
{
|
||||
return repository_.begin();
|
||||
}
|
||||
|
||||
table_repository::iterator table_repository::end()
|
||||
schema::iterator schema::end()
|
||||
{
|
||||
return repository_.end();
|
||||
}
|
||||
|
||||
table_repository::const_iterator table_repository::end() const
|
||||
schema::const_iterator schema::end() const
|
||||
{
|
||||
return repository_.end();
|
||||
}
|
||||
|
||||
bool table_repository::empty() const
|
||||
bool schema::empty() const
|
||||
{
|
||||
return repository_.empty();
|
||||
}
|
||||
+3
-3
@@ -13,7 +13,7 @@ session::session(connection_pool<connection> &pool)
|
||||
void session::create_schema()
|
||||
{
|
||||
auto c = pool_.acquire();
|
||||
for (const auto &t : table_repository_) {
|
||||
for (const auto &t : schema_) {
|
||||
t.second.create(*c);
|
||||
}
|
||||
}
|
||||
@@ -88,9 +88,9 @@ bool session::table_exists(const std::string &table_name) const
|
||||
return c->exists(dialect_.default_schema_name(), table_name);
|
||||
}
|
||||
|
||||
const table_repository& session::tables() const
|
||||
const schema& session::tables() const
|
||||
{
|
||||
return table_repository_;
|
||||
return schema_;
|
||||
}
|
||||
|
||||
const class dialect &session::dialect() const
|
||||
|
||||
Reference in New Issue
Block a user