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,
|
column_generator(std::vector<column> &column_infos,
|
||||||
const object::schema &ts,
|
const object::schema &ts,
|
||||||
const std::string &table_name,
|
const std::string &table_name,
|
||||||
bool force_lazy);
|
bool force_lazy,
|
||||||
|
bool has_many_to_many = false);
|
||||||
|
|
||||||
public:
|
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 >
|
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>();
|
const auto info = scm.info<Type>();
|
||||||
if (!info) {
|
if (!info) {
|
||||||
return {};
|
return {};
|
||||||
|
|
@ -42,6 +53,9 @@ public:
|
||||||
|
|
||||||
template < class V >
|
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) {
|
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);
|
push(id);
|
||||||
}
|
}
|
||||||
void on_primary_key(const char *id, std::string &, size_t);
|
void on_primary_key(const char *id, std::string &, size_t);
|
||||||
|
|
@ -49,51 +63,26 @@ public:
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
void on_attribute(const char *id, Type &, const utils::field_attributes &/*attr*/ = utils::null_attributes) {
|
void on_attribute(const char *id, Type &, const utils::field_attributes &/*attr*/ = utils::null_attributes) {
|
||||||
|
if (has_many_to_many_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
push(id);
|
push(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
void on_belongs_to(const char *id, Pointer &, const utils::foreign_attributes &attr) {
|
void on_belongs_to(const char *id, Pointer &x, const utils::foreign_attributes &attr) {
|
||||||
if (attr.fetch() == utils::fetch_type::LAZY || force_lazy_) {
|
on_foreign_key(id, x, attr);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
void on_has_one(const char *id, Pointer &, const utils::foreign_attributes &attr)
|
void on_has_one(const char *id, Pointer &x, const utils::foreign_attributes &attr) {
|
||||||
{
|
on_foreign_key(id, x, attr);
|
||||||
if (attr.fetch() == utils::fetch_type::LAZY || force_lazy_) {
|
}
|
||||||
push(id);
|
|
||||||
} else {
|
template<class ContainerType>
|
||||||
const auto info = table_schema_.info<typename Pointer::value_type>();
|
void on_has_many(const char * /*id*/, ContainerType &, const char *, const utils::foreign_attributes &attr) {
|
||||||
if (!info) {
|
if (has_many_to_many_) {
|
||||||
return;
|
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_) {
|
if (attr.fetch() == utils::fetch_type::LAZY || force_lazy_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -113,12 +102,41 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class ContainerType>
|
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>
|
template<class ContainerType>
|
||||||
static void on_has_many_to_many(const char * /*id*/, ContainerType & /*cont*/, const utils::foreign_attributes &/*attr*/) {}
|
static void on_has_many_to_many(const char * /*id*/, ContainerType & /*cont*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
|
|
||||||
private:
|
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);
|
void push(const std::string &column_name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -128,6 +146,7 @@ private:
|
||||||
const object::schema &table_schema_;
|
const object::schema &table_schema_;
|
||||||
int column_index{0};
|
int column_index{0};
|
||||||
bool force_lazy_{false};
|
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/query/value_extractor.hpp
|
||||||
../../include/matador/orm/error_code.hpp
|
../../include/matador/orm/error_code.hpp
|
||||||
../../include/matador/orm/session.hpp
|
../../include/matador/orm/session.hpp
|
||||||
|
../../include/matador/orm/session_insert_builder.hpp
|
||||||
../../include/matador/orm/session_query_builder.hpp
|
../../include/matador/orm/session_query_builder.hpp
|
||||||
../../include/matador/sql/abstract_sql_logger.hpp
|
../../include/matador/sql/abstract_sql_logger.hpp
|
||||||
../../include/matador/sql/backend_provider.hpp
|
../../include/matador/sql/backend_provider.hpp
|
||||||
|
|
@ -108,6 +109,7 @@ add_library(matador-orm STATIC
|
||||||
query/value_extractor.cpp
|
query/value_extractor.cpp
|
||||||
orm/error_code.cpp
|
orm/error_code.cpp
|
||||||
orm/session.cpp
|
orm/session.cpp
|
||||||
|
orm/session_insert_builder.cpp
|
||||||
orm/session_query_builder.cpp
|
orm/session_query_builder.cpp
|
||||||
sql/backend_provider.cpp
|
sql/backend_provider.cpp
|
||||||
sql/column.cpp
|
sql/column.cpp
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,12 @@ namespace matador::sql {
|
||||||
column_generator::column_generator(std::vector<column> &column_infos,
|
column_generator::column_generator(std::vector<column> &column_infos,
|
||||||
const object::schema &scm,
|
const object::schema &scm,
|
||||||
const std::string &table_name,
|
const std::string &table_name,
|
||||||
bool force_lazy)
|
const bool force_lazy,
|
||||||
|
const bool has_many_to_many)
|
||||||
: column_infos_(column_infos)
|
: column_infos_(column_infos)
|
||||||
, table_schema_(scm)
|
, table_schema_(scm)
|
||||||
, force_lazy_(force_lazy)
|
, force_lazy_(force_lazy)
|
||||||
|
, has_many_to_many_(has_many_to_many)
|
||||||
{
|
{
|
||||||
table_name_stack_.push(table_name);
|
table_name_stack_.push(table_name);
|
||||||
seen_tables.insert(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)
|
void column_generator::on_primary_key(const char *id, std::string &, size_t)
|
||||||
{
|
{
|
||||||
|
if (has_many_to_many_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
push(id);
|
push(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void column_generator::on_revision(const char *id, unsigned long long int &)
|
void column_generator::on_revision(const char *id, unsigned long long int &)
|
||||||
{
|
{
|
||||||
|
if (has_many_to_many_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
push(id);
|
push(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue