changed the interface of on_primary_key to have a third parameter of type primary_key_attribute

This commit is contained in:
Sascha Kühl
2025-07-18 12:08:21 +02:00
parent d8e43c1f95
commit 7b5123df16
38 changed files with 274 additions and 392 deletions
+6 -5
View File
@@ -15,6 +15,7 @@ class container;
namespace utils {
class field_attributes;
class foreign_attributes;
class primary_key_attribute;
}
namespace access {
@@ -29,13 +30,13 @@ void process(Operator &op, const Type &object) {
}
template< class Operator, class Type >
void primary_key(Operator &op, const char *id, Type &value) {
op.on_primary_key(id, value);
void primary_key(Operator &op, const char *id, Type &value, const utils::primary_key_attribute &attr) {
op.on_primary_key(id, value, attr);
}
template< class Operator >
void primary_key(Operator &op, const char *id, std::string &value, size_t size ) {
op.on_primary_key(id, value, size);
template< class Operator, class Type >
void primary_key(Operator &op, const char *id, Type &value) {
op.on_primary_key(id, value);
}
template<class Operator>
+30 -32
View File
@@ -13,85 +13,85 @@ namespace matador::utils {
template <> struct data_type_traits<nullptr_t, void>
{
static basic_type type(std::size_t /*size*/) { return basic_type::type_null; }
static void read_value(attribute_reader &reader, const char *id, size_t index, nullptr_t &/*value*/);
static void bind_value(attribute_writer &binder, size_t index, nullptr_t &/*value*/);
static void read_value(attribute_reader &reader, const char *id, size_t index, nullptr_t &/*value*/, size_t /*size*/ = 0);
static void bind_value(attribute_writer &binder, size_t index, nullptr_t &/*value*/, size_t /*size*/ = 0);
};
template <> struct data_type_traits<int8_t, void>
{
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_int8; }
static void read_value(attribute_reader &reader, const char *id, size_t index, int8_t &value);
static void bind_value(attribute_writer &binder, size_t index, const int8_t &value);
static void read_value(attribute_reader &reader, const char *id, size_t index, int8_t &value, size_t /*size*/ = 0);
static void bind_value(attribute_writer &binder, size_t index, const int8_t &value, size_t /*size*/ = 0);
};
template <> struct data_type_traits<int16_t, void>
{
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_int16; }
static void read_value(attribute_reader &reader, const char *id, size_t index, int16_t &value);
static void bind_value(attribute_writer &binder, size_t index, const int16_t &value);
static void read_value(attribute_reader &reader, const char *id, size_t index, int16_t &value, size_t /*size*/ = 0);
static void bind_value(attribute_writer &binder, size_t index, const int16_t &value, size_t /*size*/ = 0);
};
template <> struct data_type_traits<int32_t, void>
{
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_int32; }
static void read_value(attribute_reader &reader, const char *id, size_t index, int32_t &value);
static void bind_value(attribute_writer &binder, size_t index, const int32_t &value);
static void read_value(attribute_reader &reader, const char *id, size_t index, int32_t &value, size_t /*size*/ = 0);
static void bind_value(attribute_writer &binder, size_t index, const int32_t &value, size_t /*size*/ = 0);
};
template <> struct data_type_traits<int64_t, void>
{
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_int64; }
static void read_value(attribute_reader &reader, const char *id, size_t index, int64_t &value);
static void bind_value(attribute_writer &binder, size_t index, const int64_t &value);
static void read_value(attribute_reader &reader, const char *id, size_t index, int64_t &value, size_t /*size*/ = 0);
static void bind_value(attribute_writer &binder, size_t index, const int64_t &value, size_t /*size*/ = 0);
};
template <> struct data_type_traits<uint8_t, void>
{
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_uint8; }
static void read_value(attribute_reader &reader, const char *id, size_t index, uint8_t &value);
static void bind_value(attribute_writer &binder, size_t index, const uint8_t &value);
static void read_value(attribute_reader &reader, const char *id, size_t index, uint8_t &value, size_t /*size*/ = 0);
static void bind_value(attribute_writer &binder, size_t index, const uint8_t &value, size_t /*size*/ = 0);
};
template <> struct data_type_traits<uint16_t, void>
{
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_uint16; }
static void read_value(attribute_reader &reader, const char *id, size_t index, uint16_t &value);
static void bind_value(attribute_writer &binder, size_t index, const uint16_t &value);
static void read_value(attribute_reader &reader, const char *id, size_t index, uint16_t &value, size_t /*size*/ = 0);
static void bind_value(attribute_writer &binder, size_t index, const uint16_t &value, size_t /*size*/ = 0);
};
template <> struct data_type_traits<uint32_t, void>
{
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_uint32; }
static void read_value(attribute_reader &reader, const char *id, size_t index, uint32_t &value);
static void bind_value(attribute_writer &binder, size_t index, const uint32_t &value);
static void read_value(attribute_reader &reader, const char *id, size_t index, uint32_t &value, size_t /*size*/ = 0);
static void bind_value(attribute_writer &binder, size_t index, const uint32_t &value, size_t /*size*/ = 0);
};
template <> struct data_type_traits<uint64_t, void>
{
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_uint64; }
static void read_value(attribute_reader &reader, const char *id, size_t index, uint64_t &value);
static void bind_value(attribute_writer &binder, size_t index, const uint64_t &value);
static void read_value(attribute_reader &reader, const char *id, size_t index, uint64_t &value, size_t /*size*/ = 0);
static void bind_value(attribute_writer &binder, size_t index, const uint64_t &value, size_t /*size*/ = 0);
};
template <> struct data_type_traits<bool, void>
{
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_bool; }
static void read_value(attribute_reader &reader, const char *id, size_t index, bool &value);
static void bind_value(attribute_writer &binder, size_t index, const bool &value);
static void read_value(attribute_reader &reader, const char *id, size_t index, bool &value, size_t /*size*/ = 0);
static void bind_value(attribute_writer &binder, size_t index, const bool &value, size_t /*size*/ = 0);
};
template <> struct data_type_traits<float, void>
{
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_float; }
static void read_value(attribute_reader &reader, const char *id, size_t index, float &value);
static void bind_value(attribute_writer &binder, size_t index, const float &value);
static void read_value(attribute_reader &reader, const char *id, size_t index, float &value, size_t /*size*/ = 0);
static void bind_value(attribute_writer &binder, size_t index, const float &value, size_t /*size*/ = 0);
};
template <> struct data_type_traits<double, void>
{
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_double; }
static void read_value(attribute_reader &reader, const char *id, size_t index, double &value);
static void bind_value(attribute_writer &binder, size_t index, const double &value);
static void read_value(attribute_reader &reader, const char *id, size_t index, double &value, size_t /*size*/ = 0);
static void bind_value(attribute_writer &binder, size_t index, const double &value, size_t /*size*/ = 0);
};
template <> struct data_type_traits<const char*, void>
@@ -131,8 +131,8 @@ template <> struct data_type_traits<std::string, void>
template <> struct data_type_traits<utils::blob, void>
{
static basic_type type(std::size_t /*size*/) { return basic_type::type_blob; }
static void read_value(attribute_reader &reader, const char *id, size_t index, utils::blob &value);
static void bind_value(attribute_writer &binder, size_t index, utils::blob &value);
static void read_value(attribute_reader &reader, const char *id, size_t index, utils::blob &value, size_t /*size*/ = 0);
static void bind_value(attribute_writer &binder, size_t index, utils::blob &value, size_t /*size*/ = 0);
};
//template <> struct data_type_traits<matador::date, void>
@@ -153,13 +153,11 @@ template < typename EnumType >
struct data_type_traits<EnumType, std::enable_if_t<std::is_enum_v<EnumType>>>
{
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_int32; }
static void read_value(attribute_reader &reader, const char *id, const size_t index, EnumType &value)
{
data_type_traits<int>::read_value(reader, id, index, reinterpret_cast<int&>(value));
static void read_value(attribute_reader &reader, const char *id, const size_t index, EnumType &value, const size_t size = 0) {
data_type_traits<int>::read_value(reader, id, index, reinterpret_cast<int&>(value), size);
}
static void bind_value(attribute_writer &binder, const size_t index, EnumType &value)
{
data_type_traits<int>::bind_value(binder, index, static_cast<int &>(value));
static void bind_value(attribute_writer &binder, const size_t index, EnumType &value, const size_t size = 0) {
data_type_traits<int>::bind_value(binder, index, static_cast<int &>(value), size);
}
};
/// @endcond
+2 -2
View File
@@ -9,10 +9,10 @@ namespace matador::utils {
/**
* This class represents field attributes in
* form of size and constraints for a database
* the form of size and constraints for a database
* field (column)
*
* Currently the size is only applied
* Currently, the size is only applied
* to a field of type string leading
* to VARCHAR(size).
*/
@@ -1,6 +1,8 @@
#ifndef PRIMARY_KEY_ATTRIBUTE_HPP
#define PRIMARY_KEY_ATTRIBUTE_HPP
#include "matador/utils/primary_key_generator_type.hpp"
#include <cstddef>
namespace matador::utils {
@@ -18,6 +20,8 @@ public:
* @param size Size of the attribute
*/
primary_key_attribute(size_t size); // NOLINT(*-explicit-constructor)
primary_key_attribute(generator_type generator); // NOLINT(*-explicit-constructor)
primary_key_attribute(size_t size, generator_type generator);
~primary_key_attribute() = default;
primary_key_attribute(const primary_key_attribute &) = default;
primary_key_attribute(primary_key_attribute &&) = default;
@@ -25,6 +29,7 @@ public:
primary_key_attribute &operator=(primary_key_attribute &&) = default;
primary_key_attribute& operator=(size_t size);
primary_key_attribute& operator=(generator_type generator);
/**
* Returns the size of the field
@@ -33,9 +38,18 @@ public:
*/
[[nodiscard]] size_t size() const;
/**
* Returns the generator type of the field
*
* @return Generator type of the field
*/
[[nodiscard]] generator_type generator() const;
private:
size_t size_ = 0;
generator_type generator_ = generator_type::MANUALLY;
};
const primary_key_attribute default_pk_attributes {};
}
#endif //PRIMARY_KEY_ATTRIBUTE_HPP
@@ -0,0 +1,13 @@
#ifndef PRIMARY_KEY_GENERATOR_TYPE_HPP
#define PRIMARY_KEY_GENERATOR_TYPE_HPP
namespace matador::utils {
enum class generator_type {
MANUALLY,
AUTO,
IDENTITY,
SEQUENCE,
TABLE
};
}
#endif //PRIMARY_KEY_GENERATOR_TYPE_HPP