diff --git a/include/parsing/has_reflection_method.hpp b/include/parsing/has_reflection_method.hpp new file mode 100644 index 0000000..ff0e238 --- /dev/null +++ b/include/parsing/has_reflection_method.hpp @@ -0,0 +1,15 @@ +#ifndef SQLGEN_PARSING_HAS_REFLECTION_TYPE_HPP_ +#define SQLGEN_PARSING_HAS_REFLECTION_TYPE_HPP_ + +#include + +namespace sqlgen::parsing { + +template +concept has_reflection_method = requires(T _t) { + { _t.reflection() } -> std::convertible_to; +}; + +} // namespace sqlgen::parsing + +#endif diff --git a/include/parsing/is_nullable.hpp b/include/parsing/is_nullable.hpp new file mode 100644 index 0000000..7c64df4 --- /dev/null +++ b/include/parsing/is_nullable.hpp @@ -0,0 +1,38 @@ +#ifndef SQLGEN_PARSING_IS_NULLABLE_HPP_ +#define SQLGEN_PARSING_IS_NULLABLE_HPP_ + +#include +#include +#include + +namespace sqlgen::parsing { + +/// Determines whether a field in a named tuple is required. +/// General case - most fields are required. +template +class has_nullopt; + +template +class has_nullopt : public std::false_type {}; + +template +class has_nullopt> : public std::true_type {}; + +template +class has_nullopt> : public std::true_type {}; + +template +class has_nullopt> : public std::true_type {}; + +template +consteval bool is_nullable() { + if constexpr (has_reflection_method) { + return is_nullable(); + } else { + return has_nullopt::value; + } +} + +} // namespace sqlgen::parsing + +#endif