Add a generic Dynamic type for db-specific columns (#43)

This commit is contained in:
hosein
2025-08-21 20:08:32 +02:00
committed by GitHub
parent b46c3fe03d
commit 5c8cf00625
5 changed files with 13 additions and 2 deletions

View File

@@ -13,7 +13,7 @@ using Type =
types::Float64, types::Int8, types::Int16, types::Int32,
types::Int64, types::UInt8, types::UInt16, types::UInt32,
types::UInt64, types::Text, types::Date, types::Timestamp,
types::TimestampWithTZ, types::VarChar>;
types::TimestampWithTZ, types::VarChar, types::Dynamic>;
} // namespace sqlgen::dynamic

View File

@@ -93,6 +93,11 @@ struct VarChar {
Properties properties;
};
struct Dynamic {
std::string type_name;
Properties properties;
};
} // namespace sqlgen::dynamic::types
#endif

View File

@@ -865,6 +865,8 @@ std::string type_to_sql(const dynamic::Type& _type) noexcept {
} else if constexpr (std::is_same_v<T, dynamic::types::Timestamp> ||
std::is_same_v<T, dynamic::types::TimestampWithTZ>) {
return "DATETIME";
} else if constexpr (std::is_same_v<T, dynamic::types::Dynamic>) {
return _t.type_name;
} else if constexpr (std::is_same_v<T, dynamic::types::Unknown>) {
return "TEXT";

View File

@@ -751,9 +751,11 @@ std::string type_to_sql(const dynamic::Type& _type) noexcept {
} else if constexpr (std::is_same_v<T, dynamic::types::TimestampWithTZ>) {
return "TIMESTAMP WITH TIME ZONE";
} else if constexpr (std::is_same_v<T, dynamic::types::Dynamic>) {
return _t.type_name;
} else if constexpr (std::is_same_v<T, dynamic::types::Unknown>) {
return "TEXT";
} else {
static_assert(rfl::always_false_v<T>, "Not all cases were covered.");
}

View File

@@ -740,6 +740,8 @@ std::string type_to_sql(const dynamic::Type& _type) noexcept {
std::is_same_v<T, dynamic::types::Timestamp> ||
std::is_same_v<T, dynamic::types::TimestampWithTZ>) {
return "TEXT";
} else if constexpr (std::is_same_v<T, dynamic::types::Dynamic>) {
return _t.type_name;
} else {
static_assert(rfl::always_false_v<T>, "Not all cases were covered.");
}