added foreign_attributes class containing cascade and fetch information for foreign relations
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
#ifndef QUERY_ACCESS_HPP
|
||||
#define QUERY_ACCESS_HPP
|
||||
|
||||
#include "matador/utils/cascade_type.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <optional>
|
||||
|
||||
@@ -12,6 +10,7 @@ template < class Type, template < class ... > class ContainerType >
|
||||
class container;
|
||||
|
||||
class field_attributes;
|
||||
class foreign_attributes;
|
||||
|
||||
namespace access {
|
||||
|
||||
@@ -56,23 +55,23 @@ void attribute(Operator &op, const char *id, Type &value) {
|
||||
}
|
||||
|
||||
template<class Operator, class Type>
|
||||
void has_one(Operator &op, const char *id, Type &value, cascade_type cascade) {
|
||||
op.on_has_one(id, value, cascade);
|
||||
void has_one(Operator &op, const char *id, Type &value, const foreign_attributes &attr) {
|
||||
op.on_has_one(id, value, attr);
|
||||
}
|
||||
|
||||
template<class Operator, class Type>
|
||||
void belongs_to(Operator &op, const char *id, Type &value, cascade_type cascade) {
|
||||
op.on_belongs_to(id, value, cascade);
|
||||
void belongs_to(Operator &op, const char *id, Type &value, const foreign_attributes &attr) {
|
||||
op.on_belongs_to(id, value, attr);
|
||||
}
|
||||
|
||||
template<class Operator, class Type, template<class ...> class ContainerType>
|
||||
void has_many(Operator &op, const char *id, container<Type, ContainerType> &container, cascade_type cascade) {
|
||||
op.on_has_many(id, container, cascade);
|
||||
void has_many(Operator &op, const char *id, container<Type, ContainerType> &container, const foreign_attributes &attr) {
|
||||
op.on_has_many(id, container, attr);
|
||||
}
|
||||
|
||||
template<class Operator, class Type, template<class ...> class ContainerType>
|
||||
void has_many(Operator &op, const char *id, container<Type, ContainerType> &container, const char *left_column, const char *right_column, cascade_type cascade) {
|
||||
op.on_has_many(id, container, left_column, right_column, cascade);
|
||||
void has_many(Operator &op, const char *id, container<Type, ContainerType> &container, const char *left_column, const char *right_column, const foreign_attributes &attr) {
|
||||
op.on_has_many(id, container, left_column, right_column, attr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef QUERY_FETCH_TYPE_HPP
|
||||
#define QUERY_FETCH_TYPE_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* @brief Defines fetch types
|
||||
*
|
||||
* Defines fetch types for foreign relations
|
||||
*/
|
||||
enum class fetch_type : uint8_t
|
||||
{
|
||||
LAZY, /**< Indicates lazy fetch */
|
||||
EAGER /**< Indicates eager fetch */
|
||||
};
|
||||
|
||||
#endif //QUERY_FETCH_TYPE_HPP
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef QUERY_FOREIGN_ATTRIBUTES_HPP
|
||||
#define QUERY_FOREIGN_ATTRIBUTES_HPP
|
||||
|
||||
#include "matador/utils/fetch_type.hpp"
|
||||
#include "matador/utils/cascade_type.hpp"
|
||||
|
||||
namespace matador::utils {
|
||||
|
||||
class foreign_attributes
|
||||
{
|
||||
public:
|
||||
foreign_attributes() = default;
|
||||
foreign_attributes(cascade_type cascade); // NOLINT(*-explicit-constructor)
|
||||
foreign_attributes(fetch_type fetch); // NOLINT(*-explicit-constructor)
|
||||
foreign_attributes(cascade_type cascade, fetch_type fetch);
|
||||
foreign_attributes(const foreign_attributes &x) = default;
|
||||
foreign_attributes& operator=(const foreign_attributes &x) = default;
|
||||
foreign_attributes(foreign_attributes &&x) = default;
|
||||
foreign_attributes& operator=(foreign_attributes &&x) = default;
|
||||
~foreign_attributes() = default;
|
||||
|
||||
[[nodiscard]] cascade_type cascade() const;
|
||||
[[nodiscard]] fetch_type fetch() const;
|
||||
|
||||
private:
|
||||
cascade_type cascade_{cascade_type::NONE};
|
||||
fetch_type fetch_{fetch_type::LAZY};
|
||||
};
|
||||
|
||||
const foreign_attributes default_foreign_attributes {};
|
||||
|
||||
}
|
||||
|
||||
#endif //QUERY_FOREIGN_ATTRIBUTES_HPP
|
||||
Reference in New Issue
Block a user