Skip to content

Commit

Permalink
Guarded usage of upsert_clause
Browse files Browse the repository at this point in the history
  • Loading branch information
trueqbit committed May 19, 2024
1 parent 58a1abc commit 0c18e0f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
14 changes: 10 additions & 4 deletions dev/ast/upsert_clause.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <sqlite3.h>
#if SQLITE_VERSION_NUMBER >= 3024000
#include <tuple> // std::tuple
#include <utility> // std::forward, std::move
Expand Down Expand Up @@ -38,13 +39,18 @@ namespace sqlite_orm {

actions_tuple actions;
};
#endif

template<class T>
using is_upsert_clause = polyfill::is_specialization_of<T, upsert_clause>;
SQLITE_ORM_INLINE_VAR constexpr bool is_upsert_clause_v =
#if SQLITE_VERSION_NUMBER >= 3024000
polyfill::is_specialization_of<T, upsert_clause>::value;
#else
template<class T>
struct is_upsert_clause : polyfill::bool_constant<false> {};
false;
#endif

template<class T>
using is_upsert_clause = polyfill::bool_constant<is_upsert_clause_v<T>>;
}

#if SQLITE_VERSION_NUMBER >= 3024000
Expand All @@ -62,7 +68,7 @@ namespace sqlite_orm {
*/
template<class... Args>
internal::conflict_target<Args...> on_conflict(Args... args) {
return {std::tuple<Args...>(std::forward<Args>(args)...)};
return {{std::forward<Args>(args)...}};
}
#endif
}
2 changes: 2 additions & 0 deletions dev/node_tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ namespace sqlite_orm {
template<class T, class... Args>
struct node_tuple<group_by_with_having<T, Args...>, void> : node_tuple_for<Args..., T> {};

#if SQLITE_VERSION_NUMBER >= 3024000
template<class Targets, class Actions>
struct node_tuple<upsert_clause<Targets, Actions>, void> : node_tuple<Actions> {};
#endif

template<class... Args>
struct node_tuple<set_t<Args...>, void> : node_tuple_for<Args...> {};
Expand Down
2 changes: 2 additions & 0 deletions examples/insert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ int main(int, char**) {
cout << storage.dump(employee) << endl;
}

#if SQLITE_VERSION_NUMBER >= 3024000
// INSERT INTO COMPANY(ID, NAME, AGE, ADDRESS, SALARY)
// VALUES (3, 'Sofia', 26, 'Madrid', 15000.0)
// (4, 'Doja', 26, 'LA', 25000.0)
Expand All @@ -127,6 +128,7 @@ int main(int, char**) {
c(&Employee::age) = excluded(&Employee::age),
c(&Employee::address) = excluded(&Employee::address),
c(&Employee::salary) = excluded(&Employee::salary))));
#endif

return 0;
}
16 changes: 12 additions & 4 deletions include/sqlite_orm/sqlite_orm.h
Original file line number Diff line number Diff line change
Expand Up @@ -13773,6 +13773,7 @@ namespace sqlite_orm {

// #include "ast/upsert_clause.h"

#include <sqlite3.h>
#if SQLITE_VERSION_NUMBER >= 3024000
#include <tuple> // std::tuple
#include <utility> // std::forward, std::move
Expand Down Expand Up @@ -13811,13 +13812,18 @@ namespace sqlite_orm {

actions_tuple actions;
};
#endif

template<class T>
using is_upsert_clause = polyfill::is_specialization_of<T, upsert_clause>;
SQLITE_ORM_INLINE_VAR constexpr bool is_upsert_clause_v =
#if SQLITE_VERSION_NUMBER >= 3024000
polyfill::is_specialization_of<T, upsert_clause>::value;
#else
template<class T>
struct is_upsert_clause : polyfill::bool_constant<false> {};
false;
#endif

template<class T>
using is_upsert_clause = polyfill::bool_constant<is_upsert_clause_v<T>>;
}

#if SQLITE_VERSION_NUMBER >= 3024000
Expand All @@ -13835,7 +13841,7 @@ namespace sqlite_orm {
*/
template<class... Args>
internal::conflict_target<Args...> on_conflict(Args... args) {
return {std::tuple<Args...>(std::forward<Args>(args)...)};
return {{std::forward<Args>(args)...}};
}
#endif
}
Expand Down Expand Up @@ -22950,8 +22956,10 @@ namespace sqlite_orm {
template<class T, class... Args>
struct node_tuple<group_by_with_having<T, Args...>, void> : node_tuple_for<Args..., T> {};

#if SQLITE_VERSION_NUMBER >= 3024000
template<class Targets, class Actions>
struct node_tuple<upsert_clause<Targets, Actions>, void> : node_tuple<Actions> {};
#endif

template<class... Args>
struct node_tuple<set_t<Args...>, void> : node_tuple_for<Args...> {};
Expand Down

0 comments on commit 0c18e0f

Please sign in to comment.