added primary key resolver
This commit is contained in:
parent
e3e0eb932c
commit
a631a5a36c
|
|
@ -0,0 +1,64 @@
|
||||||
|
#ifndef PRIMARY_KEY_RESOLVER_HPP
|
||||||
|
#define PRIMARY_KEY_RESOLVER_HPP
|
||||||
|
|
||||||
|
#include "matador/utils/access.hpp"
|
||||||
|
#include "matador/utils/field_attributes.hpp"
|
||||||
|
#include "matador/utils/foreign_attributes.hpp"
|
||||||
|
#include "matador/utils/identifier.hpp"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
|
||||||
|
namespace matador::object {
|
||||||
|
|
||||||
|
struct primary_key_info {
|
||||||
|
std::string column_name;
|
||||||
|
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 < class Type >
|
||||||
|
void on_primary_key(const char *id, Type &pk, std::enable_if_t<std::is_integral_v<Type> && !std::is_same_v<bool, Type>>* = nullptr) {
|
||||||
|
primary_key_info_.column_name = id;
|
||||||
|
primary_key_info_.pk = pk;
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_primary_key(const char *id, const std::string &pk, size_t 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) {}
|
||||||
|
template<class Pointer>
|
||||||
|
void on_belongs_to(const char * /*id*/, Pointer &/*val*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
|
template<class Pointer>
|
||||||
|
void on_has_one(const char * /*id*/, Pointer &/*val*/, const utils::foreign_attributes &/*attr*/) {}
|
||||||
|
template<class ContainerType>
|
||||||
|
void on_has_many(const char * /*id*/, ContainerType &/*col*/, const char *, const utils::foreign_attributes &/*attr*/) {}
|
||||||
|
template<class ContainerType>
|
||||||
|
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>
|
||||||
|
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
|
||||||
|
|
@ -59,6 +59,8 @@ add_library(matador-core STATIC
|
||||||
utils/types.cpp
|
utils/types.cpp
|
||||||
utils/value.cpp
|
utils/value.cpp
|
||||||
utils/version.cpp
|
utils/version.cpp
|
||||||
|
../../include/matador/object/primary_key_resolver.hpp
|
||||||
|
object/primary_key_resolver.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(matador-core ${CMAKE_DL_LIBS})
|
target_link_libraries(matador-core ${CMAKE_DL_LIBS})
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
#include "matador/object/primary_key_resolver.hpp"
|
||||||
|
|
||||||
|
namespace matador::object {
|
||||||
|
void primary_key_resolver::on_primary_key(const char *id, const std::string &pk, size_t /*size*/) {
|
||||||
|
primary_key_info_.column_name = id;
|
||||||
|
primary_key_info_.pk = pk;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue