Skip to content

Commit f9693ac

Browse files
committed
Variant write support
1 parent bc71305 commit f9693ac

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

hdr/sqlite_modern_cpp.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
#endif
1717
#endif
1818

19+
#ifdef __has_include
20+
#if __cplusplus > 201402 && __has_include(<variant>)
21+
#define MODERN_SQLITE_STD_VARIANT_SUPPORT
22+
#endif
23+
#endif
24+
1925
#ifdef MODERN_SQLITE_STD_OPTIONAL_SUPPORT
2026
#include <optional>
2127
#endif
@@ -896,6 +902,14 @@ namespace sqlite {
896902
}
897903
#endif
898904

905+
template <typename ...Args> inline database_binder& operator <<(database_binder& db, const std::variant<Args...>& val) {
906+
std::visit([&](auto &&opt) {db << std::forward<decltype(opt)>(opt);}, val);
907+
return db;
908+
}
909+
template <typename ...Args> inline void store_result_in_db(sqlite3_context* db, const std::variant<Args...>& val) {
910+
std::visit([&](auto &&opt) {store_result_in_db(db, std::forward<decltype(opt)>(opt));}, val);
911+
}
912+
899913
// Some ppl are lazy so we have a operator for proper prep. statemant handling.
900914
void inline operator++(database_binder& db, int) { db.execute(); db.reset(); }
901915

0 commit comments

Comments
 (0)