renamed column_generator to column_definition_generator and column_name_generator to column_generator
This commit is contained in:
@@ -7,4 +7,38 @@ column operator ""_col(const char *name, size_t len)
|
||||
return {{name, len}};
|
||||
}
|
||||
|
||||
column::column(const char *name) : name(name) {}
|
||||
|
||||
column::column(std::string name) : name(std::move(name)) {}
|
||||
|
||||
column::column(sql_function_t func, std::string name) : name(std::move(name)), function_(func) {}
|
||||
|
||||
column::column(std::string table_name, std::string name, std::string as)
|
||||
: table(std::move(table_name))
|
||||
, name(std::move(name))
|
||||
, alias(std::move(as)) {}
|
||||
|
||||
column::column(std::string table_name, const char *name, std::string as)
|
||||
: table(std::move(table_name))
|
||||
, name(name)
|
||||
, alias(std::move(as)) {}
|
||||
|
||||
bool column::equals(const column &x) const
|
||||
{
|
||||
return table == x.table &&
|
||||
name == x.name &&
|
||||
alias == x.alias &&
|
||||
function_ == x.function_;
|
||||
}
|
||||
|
||||
column &column::as(std::string a)
|
||||
{
|
||||
alias = std::move(a);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool column::is_function() const
|
||||
{
|
||||
return function_ != sql_function_t::NONE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "matador/sql/column_definition_generator.hpp"
|
||||
#include "matador/sql/schema.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
column_definition_generator::column_definition_generator(std::vector<column_definition> &columns, const schema &repo)
|
||||
: columns_(columns)
|
||||
, repo_(repo)
|
||||
{}
|
||||
|
||||
void column_definition_generator::on_primary_key(const char *id, std::string &pk, size_t size)
|
||||
{
|
||||
on_attribute(id, pk, { size, utils::constraints::PRIMARY_KEY });
|
||||
}
|
||||
|
||||
void column_definition_generator::on_revision(const char *id, unsigned long long int &x)
|
||||
{
|
||||
on_attribute(id, x);
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string> column_definition_generator::determine_foreign_ref(const std::type_index &ti)
|
||||
{
|
||||
return repo_.reference(ti);
|
||||
}
|
||||
|
||||
void fk_column_generator::on_primary_key(const char *, std::string &, size_t size)
|
||||
{
|
||||
type_ = data_type_traits<std::string>::builtin_type(size);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +1,31 @@
|
||||
#include "matador/sql/column_generator.hpp"
|
||||
#include "matador/sql/schema.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
column_generator::column_generator(std::vector<column_definition> &columns, const schema &repo)
|
||||
: columns_(columns)
|
||||
, repo_(repo)
|
||||
{}
|
||||
|
||||
void column_generator::on_primary_key(const char *id, std::string &pk, size_t size)
|
||||
column_generator::column_generator(std::vector<column> &column_infos,
|
||||
const sql::schema &ts,
|
||||
const std::string &table_name)
|
||||
: column_infos_(column_infos)
|
||||
, table_schema_(ts)
|
||||
{
|
||||
on_attribute(id, pk, { size, utils::constraints::PRIMARY_KEY });
|
||||
table_name_stack_.push(table_name);
|
||||
}
|
||||
|
||||
void column_generator::on_revision(const char *id, unsigned long long int &x)
|
||||
void column_generator::on_primary_key(const char *id, std::string &, size_t)
|
||||
{
|
||||
on_attribute(id, x);
|
||||
push(id);
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string> column_generator::determine_foreign_ref(const std::type_index &ti)
|
||||
void column_generator::on_revision(const char *id, unsigned long long int &)
|
||||
{
|
||||
return repo_.reference(ti);
|
||||
push(id);
|
||||
}
|
||||
|
||||
void fk_column_generator::on_primary_key(const char *, std::string &, size_t size)
|
||||
void column_generator::push(const std::string &column_name)
|
||||
{
|
||||
type_ = data_type_traits<std::string>::builtin_type(size);
|
||||
char str[4];
|
||||
snprintf(str, 4, "c%02d", ++column_index);
|
||||
column_infos_.emplace_back(table_name_stack_.top(), column_name, str);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
#include "matador/sql/column_name_generator.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
column_name_generator::column_name_generator(std::vector<column> &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)
|
||||
{
|
||||
push(id);
|
||||
}
|
||||
|
||||
void column_name_generator::on_revision(const char *id, unsigned long long int &)
|
||||
{
|
||||
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(table_name_stack_.top(), column_name, str);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "matador/sql/query_builder.hpp"
|
||||
#include "matador/sql/column_name_generator.hpp"
|
||||
#include "matador/sql/column_generator.hpp"
|
||||
#include "matador/sql/column.hpp"
|
||||
#include "matador/sql/dialect.hpp"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user