73 lines
2.3 KiB
C++
73 lines
2.3 KiB
C++
#ifndef PRIMARY_KEY_RESOLVER_HPP
|
|
#define PRIMARY_KEY_RESOLVER_HPP
|
|
|
|
#include "matador/utils/access.hpp"
|
|
#include "matador/utils/field_attributes.hpp"
|
|
#include "matador/utils/identifier.hpp"
|
|
#include "matador/utils/primary_key_attribute.hpp"
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
namespace matador::utils {
|
|
class foreign_attributes;
|
|
}
|
|
|
|
namespace matador::object {
|
|
|
|
struct primary_key_info {
|
|
std::string pk_column_name;
|
|
utils::basic_type type;
|
|
utils::identifier pk;
|
|
};
|
|
|
|
class primary_key_resolver final {
|
|
public:
|
|
template <typename Type>
|
|
primary_key_info resolve() {
|
|
Type obj;
|
|
|
|
return resolve(obj);
|
|
}
|
|
|
|
template <typename Type>
|
|
primary_key_info resolve(const Type& obj) {
|
|
access::process(*this, obj);
|
|
|
|
return primary_key_info_;
|
|
}
|
|
|
|
template <typename Type>
|
|
static primary_key_info resolve_object(const Type& obj) {
|
|
primary_key_resolver resolver;
|
|
return resolver.resolve(obj);
|
|
}
|
|
|
|
template < class Type >
|
|
void on_primary_key(const char *id, Type &pk, const utils::primary_key_attribute& attr = utils::default_pk_attributes) {
|
|
primary_key_info_.pk_column_name = id;
|
|
primary_key_info_.type = utils::data_type_traits<Type>::type(attr.size());
|
|
primary_key_info_.pk = pk;
|
|
}
|
|
|
|
static void on_revision(const char * /*id*/, uint64_t &/*rev*/) {}
|
|
template<typename Type>
|
|
static void on_attribute(const char * /*id*/, Type &/*val*/, const utils::field_attributes &/*attr*/ = utils::null_attributes) {}
|
|
template<class Pointer>
|
|
static void on_belongs_to(const char * /*id*/, Pointer &/*val*/, const utils::foreign_attributes &/*attr*/) {}
|
|
template<class Pointer>
|
|
static void on_has_one(const char * /*id*/, Pointer &/*val*/, const utils::foreign_attributes &/*attr*/) {}
|
|
template<class ContainerType>
|
|
static void on_has_many(const char * /*id*/, ContainerType &/*col*/, const char *, const utils::foreign_attributes &/*attr*/) {}
|
|
template<class ContainerType>
|
|
static void on_has_many_to_many(const char * /*id*/, ContainerType &/*col*/, 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 &/*col*/, const utils::foreign_attributes &/*attr*/) {}
|
|
|
|
private:
|
|
primary_key_info primary_key_info_{};
|
|
};
|
|
|
|
}
|
|
#endif //PRIMARY_KEY_RESOLVER_HPP
|