60 lines
2.6 KiB
C++
60 lines
2.6 KiB
C++
#ifndef MATADOR_OBJECT_PK_BINDER_HPP
|
|
#define MATADOR_OBJECT_PK_BINDER_HPP
|
|
|
|
#include "matador/utils/access.hpp"
|
|
#include "matador/utils/attribute_writer.hpp"
|
|
#include "matador/utils/default_type_traits.hpp"
|
|
#include "matador/utils/field_attributes.hpp"
|
|
#include "matador/utils/foreign_attributes.hpp"
|
|
#include "matador/utils/primary_key_attribute.hpp"
|
|
|
|
namespace matador::sql {
|
|
class object_pk_binder {
|
|
public:
|
|
template<class Type>
|
|
void bind(Type &obj, const size_t column_index, utils::attribute_writer &binder) {
|
|
binder_ = &binder;
|
|
index_ = column_index;
|
|
access::process(*this, obj);
|
|
binder_ = nullptr;
|
|
}
|
|
|
|
template<typename ValueType>
|
|
void on_primary_key(const char *id, ValueType &value, const utils::primary_key_attribute& attr = utils::default_pk_attributes);
|
|
static void on_revision(const char * /*id*/, unsigned long long &/*rev*/) {}
|
|
|
|
template < class Type >
|
|
static void on_attribute(const char * /*id*/, Type &/*x*/, const utils::field_attributes &/*attr*/ = utils::null_attributes) {}
|
|
template < class Pointer >
|
|
static void on_belongs_to(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/ = utils::CascadeNoneFetchLazy) {}
|
|
template < class Pointer >
|
|
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/ = utils::CascadeNoneFetchLazy) {}
|
|
|
|
template<class ContainerType>
|
|
static void on_has_many(const char * /*id*/,
|
|
ContainerType &/*c*/,
|
|
const char * /*join_column*/,
|
|
const utils::foreign_attributes &/*attr*/ = utils::CascadeNoneFetchLazy) {}
|
|
template<class ContainerType>
|
|
static void on_has_many_to_many(const char * /*id*/,
|
|
ContainerType &/*c*/,
|
|
const char * /*join_column*/,
|
|
const char * /*inverse_join_column*/,
|
|
const utils::foreign_attributes &/*attr*/) {}
|
|
template<class ContainerType>
|
|
static void on_has_many_to_many(const char * /*id*/,
|
|
ContainerType &/*c*/,
|
|
const utils::foreign_attributes &/*attr*/) {}
|
|
|
|
private:
|
|
utils::attribute_writer *binder_{};
|
|
size_t index_{0};
|
|
};
|
|
|
|
template<typename ValueType>
|
|
void object_pk_binder::on_primary_key(const char * /*id*/, ValueType &value, const utils::primary_key_attribute& attr) {
|
|
utils::data_type_traits<ValueType>::bind_value(*binder_, index_++, value, attr.size());
|
|
}
|
|
|
|
}
|
|
#endif //MATADOR_OBJECT_PK_BINDER_HPP
|