progress on session_insert_builder
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
#ifndef QUERY_BUILDER_EXCEPTION_HPP
|
||||
#define QUERY_BUILDER_EXCEPTION_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <system_error>
|
||||
|
||||
namespace matador::orm {
|
||||
|
||||
enum class query_build_error : std::uint8_t {
|
||||
Ok = 0,
|
||||
UnknownType,
|
||||
MissingPrimaryKey,
|
||||
UnexpectedError
|
||||
};
|
||||
|
||||
|
||||
class query_builder_exception final : public std::exception {
|
||||
public:
|
||||
explicit query_builder_exception(const query_build_error error) : error_(error) {}
|
||||
|
||||
[[nodiscard]] query_build_error error() const { return error_; }
|
||||
|
||||
private:
|
||||
const query_build_error error_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //QUERY_BUILDER_EXCEPTION_HPP
|
||||
@@ -1,11 +1,15 @@
|
||||
#ifndef SESSION_INSERT_BUILDER_HPP
|
||||
#define SESSION_INSERT_BUILDER_HPP
|
||||
|
||||
#include "matador/orm/query_builder_exception.hpp"
|
||||
|
||||
#include "matador/query/condition.hpp"
|
||||
#include "matador/query/query_intermediates.hpp"
|
||||
|
||||
#include "matador/object/schema.hpp"
|
||||
|
||||
#include "matador/utils/cascade_type.hpp"
|
||||
|
||||
namespace matador::orm {
|
||||
struct entity_insert_data {
|
||||
sql::table table;
|
||||
@@ -58,8 +62,7 @@ public:
|
||||
}
|
||||
|
||||
template<class V>
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -73,10 +76,27 @@ public:
|
||||
|
||||
template<class Pointer>
|
||||
void on_belongs_to(const char *id, Pointer &obj, const utils::foreign_attributes &attr) {
|
||||
if (!utils::is_cascade_type_set(attr.cascade(), utils::cascade_type::INSERT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto info = schema_.info<typename Pointer::value_type::value_type>();
|
||||
if (!info) {
|
||||
throw query_builder_exception{query_build_error::UnknownType};
|
||||
}
|
||||
}
|
||||
|
||||
template<class Pointer>
|
||||
void on_has_one(const char *id, Pointer &obj, const utils::foreign_attributes &attr) {
|
||||
if (!utils::is_cascade_type_set(attr.cascade(), utils::cascade_type::INSERT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto info = schema_.info<typename Pointer::value_type::value_type>();
|
||||
if (!info) {
|
||||
throw query_builder_exception{query_build_error::UnknownType};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template<class ContainerType>
|
||||
@@ -94,7 +114,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
[[nodiscard]] bool is_root_entity() const;
|
||||
void push(const std::string &column_name, const utils::database_type &value);
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef QUERY_ENTITY_QUERY_BUILDER_HPP
|
||||
#define QUERY_ENTITY_QUERY_BUILDER_HPP
|
||||
|
||||
#include "matador/orm/query_builder_exception.hpp"
|
||||
|
||||
#include "matador/query/condition.hpp"
|
||||
#include "matador/query/query_intermediates.hpp"
|
||||
|
||||
@@ -66,24 +68,6 @@ struct entity_query_data {
|
||||
std::unique_ptr<query::basic_condition> where_clause{};
|
||||
};
|
||||
|
||||
enum class query_build_error : std::uint8_t {
|
||||
Ok = 0,
|
||||
UnknownType,
|
||||
MissingPrimaryKey,
|
||||
UnexpectedError
|
||||
};
|
||||
|
||||
class query_builder_exception final : public std::exception
|
||||
{
|
||||
public:
|
||||
explicit query_builder_exception(const query_build_error error) : error_(error) {}
|
||||
|
||||
[[nodiscard]] query_build_error error() const { return error_; }
|
||||
|
||||
private:
|
||||
const query_build_error error_;
|
||||
};
|
||||
|
||||
class session_query_builder final
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user