session insert builder progress
This commit is contained in:
parent
261f9fd6cb
commit
6ec5011e21
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef SESSION_INSERT_BUILDER_HPP
|
||||
#define SESSION_INSERT_BUILDER_HPP
|
||||
|
||||
namespace matador::orm {
|
||||
|
||||
class session_insert_builder final {
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //SESSION_INSERT_BUILDER_HPP
|
||||
|
|
@ -21,14 +21,25 @@ private:
|
|||
column_generator(std::vector<column> &column_infos,
|
||||
const object::schema &ts,
|
||||
const std::string &table_name,
|
||||
bool force_lazy);
|
||||
bool force_lazy,
|
||||
bool has_many_to_many = false);
|
||||
|
||||
public:
|
||||
~column_generator() = default;
|
||||
template < class Type >
|
||||
static std::vector<column> generate(const object::schema &scm, const bool force_lazy = false) {
|
||||
const auto info = scm.info<Type>();
|
||||
if (!info) {
|
||||
return {};
|
||||
}
|
||||
std::vector<column> columns;
|
||||
column_generator gen(columns, scm, info.value().get().name(), force_lazy);
|
||||
Type obj;
|
||||
access::process(gen, obj);
|
||||
return columns;
|
||||
}
|
||||
|
||||
template < class Type >
|
||||
static std::vector<column> generate(const object::schema &scm, const bool force_lazy = false)
|
||||
{
|
||||
static std::vector<column> generate_has_many_to_many(const object::schema &scm, const bool force_lazy = false) {
|
||||
const auto info = scm.info<Type>();
|
||||
if (!info) {
|
||||
return {};
|
||||
|
|
@ -42,6 +53,9 @@ public:
|
|||
|
||||
template < class V >
|
||||
void on_primary_key(const char *id, V &, std::enable_if_t<std::is_integral_v<V> && !std::is_same_v<bool, V>>* = nullptr) {
|
||||
if (has_many_to_many_) {
|
||||
return;
|
||||
}
|
||||
push(id);
|
||||
}
|
||||
void on_primary_key(const char *id, std::string &, size_t);
|
||||
|
|
@ -49,51 +63,26 @@ public:
|
|||
|
||||
template<typename Type>
|
||||
void on_attribute(const char *id, Type &, const utils::field_attributes &/*attr*/ = utils::null_attributes) {
|
||||
if (has_many_to_many_) {
|
||||
return;
|
||||
}
|
||||
push(id);
|
||||
}
|
||||
|
||||
template<class Pointer>
|
||||
void on_belongs_to(const char *id, Pointer &, const utils::foreign_attributes &attr) {
|
||||
if (attr.fetch() == utils::fetch_type::LAZY || force_lazy_) {
|
||||
push(id);
|
||||
} else {
|
||||
const auto info = table_schema_.info<typename Pointer::value_type>();
|
||||
if (!info) {
|
||||
return;
|
||||
}
|
||||
if (seen_tables.count(info->get().name()) == 0) {
|
||||
auto it = seen_tables.insert(info->get().name()).first;
|
||||
table_name_stack_.push(info->get().name());
|
||||
typename Pointer::value_type obj;
|
||||
access::process(*this, obj);
|
||||
table_name_stack_.pop();
|
||||
seen_tables.erase(it);
|
||||
}
|
||||
}
|
||||
void on_belongs_to(const char *id, Pointer &x, const utils::foreign_attributes &attr) {
|
||||
on_foreign_key(id, x, attr);
|
||||
}
|
||||
template<class Pointer>
|
||||
void on_has_one(const char *id, Pointer &, const utils::foreign_attributes &attr)
|
||||
{
|
||||
if (attr.fetch() == utils::fetch_type::LAZY || force_lazy_) {
|
||||
push(id);
|
||||
} else {
|
||||
const auto info = table_schema_.info<typename Pointer::value_type>();
|
||||
if (!info) {
|
||||
void on_has_one(const char *id, Pointer &x, const utils::foreign_attributes &attr) {
|
||||
on_foreign_key(id, x, attr);
|
||||
}
|
||||
|
||||
template<class ContainerType>
|
||||
void on_has_many(const char * /*id*/, ContainerType &, const char *, const utils::foreign_attributes &attr) {
|
||||
if (has_many_to_many_) {
|
||||
return;
|
||||
}
|
||||
if (seen_tables.count(info->get().name()) == 0) {
|
||||
auto it = seen_tables.insert(info->get().name()).first;
|
||||
table_name_stack_.push(info.value().get().name());
|
||||
typename Pointer::value_type obj;
|
||||
access::process(*this, obj);
|
||||
table_name_stack_.pop();
|
||||
seen_tables.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
template<class ContainerType>
|
||||
void on_has_many(const char * /*id*/, ContainerType &, const char *, const utils::foreign_attributes &attr)
|
||||
{
|
||||
if (attr.fetch() == utils::fetch_type::LAZY || force_lazy_) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -113,12 +102,41 @@ public:
|
|||
}
|
||||
|
||||
template<class ContainerType>
|
||||
static void on_has_many_to_many(const char * /*id*/, ContainerType & /*cont*/, const char * /*join_column*/, const char * /*inverse_join_column*/, const utils::foreign_attributes & /*attr*/) {}
|
||||
void on_has_many_to_many(const char * /*id*/, ContainerType & /*cont*/, const char *join_column, const char *inverse_join_column, const utils::foreign_attributes &/*attr*/) {
|
||||
if (!has_many_to_many_) {
|
||||
return;
|
||||
}
|
||||
push(join_column);
|
||||
push(inverse_join_column);
|
||||
}
|
||||
|
||||
template<class ContainerType>
|
||||
static void on_has_many_to_many(const char * /*id*/, ContainerType & /*cont*/, const utils::foreign_attributes &/*attr*/) {}
|
||||
|
||||
private:
|
||||
template<class Pointer>
|
||||
void on_foreign_key(const char *id, Pointer &, const utils::foreign_attributes &attr) {
|
||||
if (has_many_to_many_) {
|
||||
return;
|
||||
}
|
||||
if (attr.fetch() == utils::fetch_type::LAZY || force_lazy_) {
|
||||
push(id);
|
||||
} else {
|
||||
const auto info = table_schema_.info<typename Pointer::value_type>();
|
||||
if (!info) {
|
||||
return;
|
||||
}
|
||||
if (seen_tables.count(info->get().name()) == 0) {
|
||||
auto it = seen_tables.insert(info->get().name()).first;
|
||||
table_name_stack_.push(info.value().get().name());
|
||||
typename Pointer::value_type obj;
|
||||
access::process(*this, obj);
|
||||
table_name_stack_.pop();
|
||||
seen_tables.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void push(const std::string &column_name);
|
||||
|
||||
private:
|
||||
|
|
@ -128,6 +146,7 @@ private:
|
|||
const object::schema &table_schema_;
|
||||
int column_index{0};
|
||||
bool force_lazy_{false};
|
||||
bool has_many_to_many_{false};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ add_library(matador-orm STATIC
|
|||
../../include/matador/query/value_extractor.hpp
|
||||
../../include/matador/orm/error_code.hpp
|
||||
../../include/matador/orm/session.hpp
|
||||
../../include/matador/orm/session_insert_builder.hpp
|
||||
../../include/matador/orm/session_query_builder.hpp
|
||||
../../include/matador/sql/abstract_sql_logger.hpp
|
||||
../../include/matador/sql/backend_provider.hpp
|
||||
|
|
@ -108,6 +109,7 @@ add_library(matador-orm STATIC
|
|||
query/value_extractor.cpp
|
||||
orm/error_code.cpp
|
||||
orm/session.cpp
|
||||
orm/session_insert_builder.cpp
|
||||
orm/session_query_builder.cpp
|
||||
sql/backend_provider.cpp
|
||||
sql/column.cpp
|
||||
|
|
|
|||
|
|
@ -7,10 +7,12 @@ namespace matador::sql {
|
|||
column_generator::column_generator(std::vector<column> &column_infos,
|
||||
const object::schema &scm,
|
||||
const std::string &table_name,
|
||||
bool force_lazy)
|
||||
const bool force_lazy,
|
||||
const bool has_many_to_many)
|
||||
: column_infos_(column_infos)
|
||||
, table_schema_(scm)
|
||||
, force_lazy_(force_lazy)
|
||||
, has_many_to_many_(has_many_to_many)
|
||||
{
|
||||
table_name_stack_.push(table_name);
|
||||
seen_tables.insert(table_name);
|
||||
|
|
@ -18,11 +20,17 @@ column_generator::column_generator(std::vector<column> &column_infos,
|
|||
|
||||
void column_generator::on_primary_key(const char *id, std::string &, size_t)
|
||||
{
|
||||
if (has_many_to_many_) {
|
||||
return;
|
||||
}
|
||||
push(id);
|
||||
}
|
||||
|
||||
void column_generator::on_revision(const char *id, unsigned long long int &)
|
||||
{
|
||||
if (has_many_to_many_) {
|
||||
return;
|
||||
}
|
||||
push(id);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue