#ifndef QUERY_OBJECT_PARAMETER_BINDER_HPP #define QUERY_OBJECT_PARAMETER_BINDER_HPP #include "matador/sql/parameter_binder.hpp" #include "matador/sql/types.hpp" #include "matador/utils/access.hpp" #include "matador/utils/cascade_type.hpp" #include "matador/utils/field_attributes.hpp" #include namespace matador::sql { namespace detail { class fk_binder { public: explicit fk_binder(parameter_binder &binder); template void bind(Type &obj, size_t column_index) { index_ = column_index; utils::access::process(*this, obj); } template void on_primary_key(const char *id, ValueType &value, typename std::enable_if::value && !std::is_same::value>::type* = 0); void on_primary_key(const char *id, std::string &value, size_t size); void on_revision(const char * /*id*/, unsigned long long &/*rev*/) {} template < class Type > void on_attribute(const char * /*id*/, Type &/*x*/, const utils::field_attributes &/*attr*/ = utils::null_attributes) {} template < class Pointer > void on_belongs_to(const char * /*id*/, Pointer &/*x*/, utils::cascade_type) {} template < class Pointer > void on_has_one(const char * /*id*/, Pointer &/*x*/, utils::cascade_type) {} template void on_has_many(const char *, ContainerType &, const char *, const char *, utils::cascade_type) {} template void on_has_many(const char *, ContainerType &, utils::cascade_type) {} private: parameter_binder &binder_; size_t index_{0}; }; } class object_parameter_binder { public: explicit object_parameter_binder(parameter_binder &binder); void reset(); template < class Type > void on_primary_key(const char *id, Type &val, typename std::enable_if::value && !std::is_same::value>::type* = 0) { data_type_traits::bind_value(binder_, index_++, val); } void on_primary_key(const char *id, std::string &, size_t size); void on_revision(const char *id, unsigned long long &/*rev*/); template void on_attribute(const char *id, Type &val, const utils::field_attributes &/*attr*/ = utils::null_attributes) { data_type_traits::bind_value(binder_, index_++, val); } template class Pointer> void on_belongs_to(const char *id, Pointer &x, utils::cascade_type) { fk_binder_.bind(index_++, x); } template class Pointer> void on_has_one(const char *id, Pointer &x, utils::cascade_type) { fk_binder_.bind(index_++, x); } template void on_has_many(const char *, ContainerType &, const char *, const char *, utils::cascade_type) {} template void on_has_many(const char *, ContainerType &, utils::cascade_type) {} private: parameter_binder &binder_; size_t index_{0}; detail::fk_binder fk_binder_; }; namespace detail { template void fk_binder::on_primary_key(const char *id, ValueType &value, typename std::enable_if::value && !std::is_same::value>::type *) { data_type_traits::bind_value(binder_, index_++, value); } } } #endif //QUERY_OBJECT_PARAMETER_BINDER_HPP