62 lines
2.4 KiB
C++
62 lines
2.4 KiB
C++
#ifndef QUERY_OBJECT_PARAMETER_BINDER_HPP
|
|
#define QUERY_OBJECT_PARAMETER_BINDER_HPP
|
|
|
|
#include "matador/sql/object_pk_binder.hpp"
|
|
|
|
namespace matador::sql {
|
|
|
|
class object_parameter_binder {
|
|
public:
|
|
template<class Type>
|
|
void bind(Type &obj, utils::attribute_writer &binder) {
|
|
binder_ = &binder;
|
|
access::process(*this, obj);
|
|
binder_ = nullptr;
|
|
}
|
|
|
|
void reset(size_t start_index);
|
|
[[nodiscard]] size_t current_index() const;
|
|
|
|
template < class Type >
|
|
void on_primary_key(const char * /*id*/, Type &val, const utils::primary_key_attribute& attr = utils::default_pk_attributes) {
|
|
utils::data_type_traits<Type>::bind_value(*binder_, index_++, val, attr.size());
|
|
}
|
|
void on_revision(const char *id, uint64_t &/*rev*/);
|
|
|
|
template<typename Type>
|
|
void on_attribute(const char * /*id*/, Type &val, const utils::field_attributes &/*attr*/ = utils::null_attributes) {
|
|
utils::data_type_traits<Type>::bind_value(*binder_, index_++, val);
|
|
}
|
|
|
|
template<class Type, template < class ... > class Pointer>
|
|
void on_belongs_to(const char * /*id*/, Pointer<Type> &x, const utils::foreign_attributes &/*attr*/ = utils::CascadeNoneFetchLazy) {
|
|
pk_binder_.bind(*x, index_++, *binder_);
|
|
}
|
|
template<class Type, template < class ... > class Pointer>
|
|
void on_has_one(const char * /*id*/, Pointer<Type> &x, const utils::foreign_attributes &/*attr*/ = utils::CascadeNoneFetchLazy) {
|
|
pk_binder_.bind(*x, index_++, *binder_);
|
|
}
|
|
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};
|
|
object_pk_binder pk_binder_;
|
|
};
|
|
}
|
|
#endif //QUERY_OBJECT_PARAMETER_BINDER_HPP
|