progress on session_insert_builder
This commit is contained in:
@@ -136,12 +136,12 @@ public:
|
||||
* Returns true if the schema contains
|
||||
* no schema nodes.
|
||||
*
|
||||
* @return True if schema is empty
|
||||
* @return True if the schema is empty
|
||||
*/
|
||||
[[nodiscard]] bool empty() const;
|
||||
|
||||
/**
|
||||
* Returns the current number of schema node.
|
||||
* Returns the current number of the schema node.
|
||||
*
|
||||
* @return Number of schema nodes
|
||||
*/
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -23,5 +23,7 @@ inline cascade_type& operator|= (cascade_type& a, cascade_type b) { return reint
|
||||
inline cascade_type& operator&= (cascade_type& a, cascade_type b) { return reinterpret_cast<cascade_type &>(reinterpret_cast<int &>(a) &= static_cast<int>(b)); }
|
||||
inline cascade_type& operator^= (cascade_type& a, cascade_type b) { return reinterpret_cast<cascade_type &>(reinterpret_cast<int &>(a) ^= static_cast<int>(b)); }
|
||||
|
||||
inline bool is_cascade_type_set(const cascade_type source, const cascade_type needle) { return static_cast<int>(source & needle) > 0; }
|
||||
|
||||
}
|
||||
#endif //OOS_CASCADE_TYPE_HPP
|
||||
|
||||
@@ -14,23 +14,12 @@ enum class constraints : unsigned char {
|
||||
// UNIQUE_NOT_NULL = UNIQUE | NOT_NULL
|
||||
};
|
||||
|
||||
inline constraints operator|(constraints a, constraints b)
|
||||
{
|
||||
return static_cast<constraints>(static_cast<unsigned int>(a) | static_cast<unsigned int>(b));
|
||||
}
|
||||
|
||||
inline constraints operator&(constraints a, constraints b)
|
||||
{
|
||||
return static_cast<constraints>(static_cast<unsigned int>(a) & static_cast<unsigned int>(b));
|
||||
}
|
||||
|
||||
inline constraints operator|(constraints a, constraints b) { return static_cast<constraints>(static_cast<unsigned int>(a) | static_cast<unsigned int>(b)); }
|
||||
inline constraints operator&(constraints a, constraints b) { return static_cast<constraints>(static_cast<unsigned int>(a) & static_cast<unsigned int>(b)); }
|
||||
inline constraints& operator|= (constraints& a, constraints b) { return (constraints&)((int&)a |= (int)b); }
|
||||
inline constraints& operator&= (constraints& a, constraints b) { return (constraints&)((int&)a &= (int)b); }
|
||||
|
||||
inline bool is_constraint_set(const constraints source, const constraints needle)
|
||||
{
|
||||
return static_cast<int>(source & needle) > 0;
|
||||
}
|
||||
inline bool is_constraint_set(const constraints source, const constraints needle) { return static_cast<int>(source & needle) > 0; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user