diff options
Diffstat (limited to 'src/database/query.hpp')
-rw-r--r-- | src/database/query.hpp | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/src/database/query.hpp b/src/database/query.hpp index 2a2d2d4..1c4a5ff 100644 --- a/src/database/query.hpp +++ b/src/database/query.hpp @@ -13,12 +13,12 @@ void actual_bind(Statement& statement, const std::string& value, int index); void actual_bind(Statement& statement, const std::int64_t& value, int index); -void actual_bind(Statement& statement, const std::optional<bool>& value, int index); -template <typename T> +template <typename T, typename std::enable_if_t<std::is_integral<T>::value>* = 0> void actual_bind(Statement& statement, const T& value, int index) { actual_bind(statement, static_cast<std::int64_t>(value), index); } +void actual_bind(Statement& statement, const std::optional<bool>& value, int index); #ifdef DEBUG_SQL_QUERIES #include <utils/scopetimer.hpp> @@ -57,27 +57,38 @@ struct Query #endif }; -void actual_add_param(Query& query, const std::string& val); -void actual_add_param(Query& query, const std::optional<bool>& val); +template <typename ColumnType> +void add_param(Query& query, const ColumnType& column) +{ + std::cout << "add_param<ColumnType>" << std::endl; + actual_add_param(query, column.value); +} + template <typename T> void actual_add_param(Query& query, const T& val) { query.params.push_back(std::to_string(val)); } +void actual_add_param(Query& query, const std::string& val); + +template <typename T> +typename std::enable_if<!std::is_integral<T>::value, Query&>::type +operator<<(Query& query, const T&) +{ + query.body += T::name; + return query; +} +void actual_add_param(Query& query, const std::optional<bool>& val); + Query& operator<<(Query& query, const char* str); Query& operator<<(Query& query, const std::string& str); -template <typename T> -Query& operator<<(Query& query, const T& i) +template <typename Integer> +typename std::enable_if<std::is_integral<Integer>::value, Query&>::type +operator<<(Query& query, const Integer& i) { - if constexpr(std::is_integral<T>::value) - { - query.body += "$" + std::to_string(query.current_param++); - actual_add_param(query, i); - } - else - { - query.body += T::name; - } + query.body += "$" + std::to_string(query.current_param++); + actual_add_param(query, i); return query; } + |