determine NOT NULL constraint from std::optional
This commit is contained in:
@@ -73,7 +73,10 @@ public:
|
||||
void on_revision(const char *id, unsigned long long &rev);
|
||||
|
||||
template<typename Type>
|
||||
void on_attribute(const char *id, Type &x, const utils::field_attributes &attr = utils::null_attributes);
|
||||
void on_attribute(const char *id, Type &x, const utils::field_attributes &attr = utils::not_null_attributes);
|
||||
|
||||
template<typename Type>
|
||||
void on_attribute(const char *id, std::optional<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)
|
||||
@@ -106,13 +109,23 @@ private:
|
||||
template<typename V>
|
||||
void column_generator::on_primary_key(const char *id, V &x, typename std::enable_if<std::is_integral<V>::value && !std::is_same<bool, V>::value>::type*)
|
||||
{
|
||||
on_attribute(id, x, { utils::constraints::PRIMARY_KEY });
|
||||
on_attribute(id, x, { utils::constraints::PRIMARY_KEY | utils::constraints::NOT_NULL });
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
void column_generator::on_attribute(const char *id, Type &x, const utils::field_attributes &attr)
|
||||
{
|
||||
columns_.emplace_back(id, x, attr);
|
||||
if (attr.options() == utils::constraints::NONE) {
|
||||
columns_.push_back(column{id, x, { attr.size(), utils::constraints::NOT_NULL}});
|
||||
} else {
|
||||
columns_.emplace_back(id, x, attr);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
void column_generator::on_attribute(const char *id, std::optional<Type> &x, const utils::field_attributes &attr)
|
||||
{
|
||||
columns_.emplace_back(id, data_type_traits<Type>::builtin_type(attr.size()), attr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "matador/utils/cascade_type.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <optional>
|
||||
|
||||
namespace matador::utils {
|
||||
|
||||
@@ -44,6 +45,11 @@ void attribute(Operator &op, const char *id, Type &value, const field_attributes
|
||||
op.on_attribute(id, value, attr);
|
||||
}
|
||||
|
||||
template<class Operator, class Type>
|
||||
void attribute(Operator &op, const char *id, std::optional<Type> &value, const field_attributes &attr) {
|
||||
op.on_attribute(id, value, attr);
|
||||
}
|
||||
|
||||
template<class Operator, class Type>
|
||||
void attribute(Operator &op, const char *id, Type &value) {
|
||||
op.on_attribute(id, value);
|
||||
|
||||
Reference in New Issue
Block a user