diff options
Diffstat (limited to 'src/database/insert_query.hpp')
-rw-r--r-- | src/database/insert_query.hpp | 91 |
1 files changed, 40 insertions, 51 deletions
diff --git a/src/database/insert_query.hpp b/src/database/insert_query.hpp index 04c098c..ed1944f 100644 --- a/src/database/insert_query.hpp +++ b/src/database/insert_query.hpp @@ -11,20 +11,17 @@ #include <tuple> template <std::size_t N=0, typename... T> -typename std::enable_if<N < sizeof...(T), void>::type -update_autoincrement_id(std::tuple<T...>& columns, Statement& statement) +void update_autoincrement_id(std::tuple<T...>& columns, Statement& statement) { - using ColumnType = typename std::decay<decltype(std::get<N>(columns))>::type; - if (std::is_same<ColumnType, Id>::value) - auto&& column = std::get<Id>(columns); - update_autoincrement_id<N+1>(columns, statement); + if constexpr(N < sizeof...(T)) + { + using ColumnType = typename std::decay<decltype(std::get<N>(columns))>::type; + if (std::is_same<ColumnType, Id>::value) + auto&& column = std::get<Id>(columns); + update_autoincrement_id<N + 1>(columns, statement); + } } -template <std::size_t N=0, typename... T> -typename std::enable_if<N == sizeof...(T), void>::type -update_autoincrement_id(std::tuple<T...>&, Statement&) -{} - struct InsertQuery: public Query { template <typename... T> @@ -53,23 +50,20 @@ struct InsertQuery: public Query } template <int N=0, typename... T> - typename std::enable_if<N < sizeof...(T), void>::type - bind_param(const std::tuple<T...>& columns, Statement& statement, int index=1) + void bind_param(const std::tuple<T...>& columns, Statement& statement, int index=1) { - auto&& column = std::get<N>(columns); - using ColumnType = std::decay_t<decltype(column)>; + if constexpr(N < sizeof...(T)) + { + auto&& column = std::get<N>(columns); + using ColumnType = std::decay_t<decltype(column)>; - if (!std::is_same<ColumnType, Id>::value) - actual_bind(statement, column.value, index++); + if constexpr(!std::is_same<ColumnType, Id>::value) + actual_bind(statement, column.value, index++); - this->bind_param<N+1>(columns, statement, index); + this->bind_param<N + 1>(columns, statement, index); + } } - template <int N=0, typename... T> - typename std::enable_if<N == sizeof...(T), void>::type - bind_param(const std::tuple<T...>&, Statement&, int) - {} - template <typename... T> void insert_values(const std::tuple<T...>& columns) { @@ -79,23 +73,21 @@ struct InsertQuery: public Query } template <int N=0, typename... T> - typename std::enable_if<N < sizeof...(T), void>::type - insert_value(const std::tuple<T...>& columns, int index=1) + void insert_value(const std::tuple<T...>& columns, int index=1) { - using ColumnType = std::decay_t<decltype(std::get<N>(columns))>; - - if (!std::is_same<ColumnType, Id>::value) + if constexpr(N < sizeof...(T)) { - this->body += "$" + std::to_string(index++); - if (N != sizeof...(T) - 1) - this->body += ", "; + using ColumnType = std::decay_t<decltype(std::get<N>(columns))>; + + if (!std::is_same<ColumnType, Id>::value) + { + this->body += "$" + std::to_string(index++); + if (N != sizeof...(T) - 1) + this->body += ", "; + } + this->insert_value<N + 1>(columns, index); } - this->insert_value<N+1>(columns, index); } - template <int N=0, typename... T> - typename std::enable_if<N == sizeof...(T), void>::type - insert_value(const std::tuple<T...>&, const int) - { } template <typename... T> void insert_col_names(const std::tuple<T...>& columns) @@ -106,24 +98,21 @@ struct InsertQuery: public Query } template <int N=0, typename... T> - typename std::enable_if<N < sizeof...(T), void>::type - insert_col_name(const std::tuple<T...>& columns) + void insert_col_name(const std::tuple<T...>& columns) { - using ColumnType = std::decay_t<decltype(std::get<N>(columns))>; - - if (!std::is_same<ColumnType, Id>::value) + if constexpr(N < sizeof...(T)) { - this->body += ColumnType::name; + using ColumnType = std::decay_t<decltype(std::get<N>(columns))>; - if (N < (sizeof...(T) - 1)) - this->body += ", "; - } + if (!std::is_same<ColumnType, Id>::value) + { + this->body += ColumnType::name; - this->insert_col_name<N+1>(columns); - } + if (N < (sizeof...(T) - 1)) + this->body += ", "; + } - template <int N=0, typename... T> - typename std::enable_if<N == sizeof...(T), void>::type - insert_col_name(const std::tuple<T...>&) - {} + this->insert_col_name<N + 1>(columns); + } + } }; |