diff --git a/include/sqlgen/dynamic/Type.hpp b/include/sqlgen/dynamic/Type.hpp index 93a0615..6f2b301 100644 --- a/include/sqlgen/dynamic/Type.hpp +++ b/include/sqlgen/dynamic/Type.hpp @@ -11,7 +11,8 @@ namespace sqlgen::dynamic { using Type = rfl::TaggedUnion<"type", types::Unknown, types::Boolean, types::Float32, types::Float64, types::Int8, types::Int16, types::Int32, - types::Int64, types::Text, types::Timestamp, + types::Int64, types::UInt8, types::UInt16, types::UInt32, + types::UInt64, types::Text, types::Timestamp, types::TimestampWithTZ, types::VarChar>; } // namespace sqlgen::dynamic diff --git a/include/sqlgen/parsing/to_create_table.hpp b/include/sqlgen/parsing/to_create_table.hpp index cd4a2b3..fa7171f 100644 --- a/include/sqlgen/parsing/to_create_table.hpp +++ b/include/sqlgen/parsing/to_create_table.hpp @@ -24,7 +24,45 @@ std::string to_name() { template dynamic::Type to_type() { - // TODO + using T = std::remove_cvref_t; + if constexpr (std::is_same_v) { + return types::Boolean{}; + } else if constexpr (std::is_integral_v && std::is_signed_v) { + if constexpr (sizeof(T) == 1) { + return types::Int8{}; + } else if constexpr (sizeof(T) == 2) { + return types::Int16{}; + } else if constexpr (sizeof(T) == 4) { + return types::Int32{}; + } else if constexpr (sizeof(T) == 8) { + return types::Int64{}; + } else { + static_assert(rfl::always_false_v, "Unsupported signed integer."); + } + } else if constexpr (std::is_integral_v && !std::is_signed_v) { + if constexpr (sizeof(T) == 1) { + return types::UInt8{}; + } else if constexpr (sizeof(T) == 2) { + return types::UInt16{}; + } else if constexpr (sizeof(T) == 4) { + return types::UInt32{}; + } else if constexpr (sizeof(T) == 8) { + return types::UInt64{}; + } else { + static_assert(rfl::always_false_v, "Unsupported unsigned integer."); + } + } else if constexpr (std::is_floating_point_v) { + if constexpr (sizeof(T) == 4) { + return types::Float32{}; + } else if constexpr (sizeof(T) == 8) { + return types::Float64{}; + } else { + static_assert(rfl::always_false_v, + "Unsupported floating point value."); + } + } else if constexpr (std::is_same_v) { + return types::Text{}; + } } template