formatted file
This commit is contained in:
parent
7d47ef0b82
commit
62e3d18144
|
|
@ -7,67 +7,68 @@
|
||||||
#include "matador/object/schema.hpp"
|
#include "matador/object/schema.hpp"
|
||||||
|
|
||||||
namespace matador::orm {
|
namespace matador::orm {
|
||||||
|
|
||||||
struct entity_insert_data {
|
struct entity_insert_data {
|
||||||
sql::table table;
|
sql::table table;
|
||||||
std::vector<std::string> columns;
|
std::vector<std::string> columns;
|
||||||
std::vector<utils::database_type> values;
|
std::vector<utils::database_type> values;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class insert_build_error : std::uint8_t {
|
enum class insert_build_error : std::uint8_t {
|
||||||
Ok = 0,
|
Ok = 0,
|
||||||
UnknownType,
|
UnknownType,
|
||||||
MissingPrimaryKey,
|
MissingPrimaryKey,
|
||||||
UnexpectedError
|
UnexpectedError
|
||||||
};
|
};
|
||||||
|
|
||||||
class insert_builder_exception final : public std::exception
|
class insert_builder_exception final : public std::exception {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
explicit insert_builder_exception(const insert_build_error error) : error_(error) {}
|
explicit insert_builder_exception(const insert_build_error error) : error_(error) {
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] insert_build_error error() const { return error_; }
|
[[nodiscard]] insert_build_error error() const { return error_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const insert_build_error error_;
|
const insert_build_error error_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class session_insert_builder final {
|
class session_insert_builder final {
|
||||||
public:
|
public:
|
||||||
explicit session_insert_builder(const object::schema &scm)
|
explicit session_insert_builder(const object::schema &scm)
|
||||||
: schema_(scm) {}
|
: schema_(scm) {
|
||||||
|
}
|
||||||
|
|
||||||
template<class EntityType>
|
template<class EntityType>
|
||||||
utils::result<std::vector<entity_insert_data>, insert_build_error> build(const EntityType &obj) {
|
utils::result<std::vector<entity_insert_data>, insert_build_error> build(const EntityType &obj) {
|
||||||
auto info = schema_.info<EntityType>();
|
auto info = schema_.info<EntityType>();
|
||||||
if (!info) {
|
if (!info) {
|
||||||
return utils::failure(insert_build_error::UnknownType);
|
return utils::failure(insert_build_error::UnknownType);
|
||||||
}
|
|
||||||
table_info_stack_.push({info.value()});
|
|
||||||
entity_insert_data_ = {{sql::table{info.value().get().name()}}};
|
|
||||||
// processed_tables_.insert({info->get().name(), entity_insert_data_.root_table});
|
|
||||||
try {
|
|
||||||
access::process(*this, obj);
|
|
||||||
|
|
||||||
return {utils::ok(std::move(entity_insert_data_))};
|
|
||||||
} catch (const insert_builder_exception &ex) {
|
|
||||||
return {utils::failure(ex.error())};
|
|
||||||
} catch (...) {
|
|
||||||
return {utils::failure(insert_build_error::UnexpectedError)};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
table_info_stack_.push({info.value()});
|
||||||
|
entity_insert_data_ = {{sql::table{info.value().get().name()}}};
|
||||||
|
// processed_tables_.insert({info->get().name(), entity_insert_data_.root_table});
|
||||||
|
try {
|
||||||
|
access::process(*this, obj);
|
||||||
|
|
||||||
template < class V >
|
return {utils::ok(std::move(entity_insert_data_))};
|
||||||
void on_primary_key(const char *id, V &x, std::enable_if_t<std::is_integral_v<V> && !std::is_same_v<bool, V>>* = nullptr)
|
} catch (const insert_builder_exception &ex) {
|
||||||
{
|
return {utils::failure(ex.error())};
|
||||||
push(id, x);
|
} catch (...) {
|
||||||
|
return {utils::failure(insert_build_error::UnexpectedError)};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void on_primary_key(const char *id, std::string &, size_t);
|
template<class V>
|
||||||
void on_revision(const char *id, unsigned long long &/*rev*/);
|
void on_primary_key(const char *id, V &x,
|
||||||
|
std::enable_if_t<std::is_integral_v<V> && !std::is_same_v<bool, V>> * = nullptr) {
|
||||||
|
push(id, x);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Type>
|
void on_primary_key(const char *id, std::string &, size_t);
|
||||||
void on_attribute(const char *id, Type &, const utils::field_attributes &/*attr*/ = utils::null_attributes) {
|
void on_revision(const char *id, unsigned long long &/*rev*/);
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
void on_attribute(const char *id, Type &x, const utils::field_attributes &/*attr*/ = utils::null_attributes) {
|
||||||
|
push(id, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Pointer>
|
template<class Pointer>
|
||||||
|
|
@ -79,11 +80,13 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
void on_has_many(const char * /*id*/, ContainerType &, const char *join_column, const utils::foreign_attributes &attr) {
|
void on_has_many(const char * /*id*/, ContainerType &, const char *join_column,
|
||||||
|
const utils::foreign_attributes &attr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
|
|
@ -100,11 +103,10 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
std::stack<table_info> table_info_stack_;
|
std::stack<table_info> table_info_stack_;
|
||||||
std::unordered_map<std::string, std::shared_ptr<sql::table>> processed_tables_;
|
std::unordered_map<std::string, std::shared_ptr<sql::table> > processed_tables_;
|
||||||
const object::schema &schema_;
|
const object::schema &schema_;
|
||||||
std::vector<entity_insert_data> entity_insert_data_;
|
std::vector<entity_insert_data> entity_insert_data_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //SESSION_INSERT_BUILDER_HPP
|
#endif //SESSION_INSERT_BUILDER_HPP
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue