diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-10-29 01:35:16 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-10-29 01:35:16 -0400 |
commit | 12c105623cf236a632d29f41b56c3f1e8df27416 (patch) | |
tree | 8b49ab0baaffbaebcf9046c7f19ac32880311ed7 /discord/store.hpp | |
parent | d950460e149d78962508f221c5e81717798cb228 (diff) | |
download | abaddon-portaudio-12c105623cf236a632d29f41b56c3f1e8df27416.tar.gz abaddon-portaudio-12c105623cf236a632d29f41b56c3f1e8df27416.zip |
templatize some stuff
Diffstat (limited to 'discord/store.hpp')
-rw-r--r-- | discord/store.hpp | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/discord/store.hpp b/discord/store.hpp index b30d4f4..791c790 100644 --- a/discord/store.hpp +++ b/discord/store.hpp @@ -100,13 +100,9 @@ private: bool OK() const; - int Bind(int index, int32_t num); - int Bind(int index, uint32_t num); - int Bind(int index, size_t num); int Bind(int index, Snowflake id); int Bind(int index, const char *str, size_t len = -1); int Bind(int index, const std::string &str); - int Bind(int index, bool val); int Bind(int index); template<typename T> @@ -135,14 +131,6 @@ private: } template<typename T> - int BindAsJSON(int index, const std::optional<T> &obj) { - if (obj.has_value()) - return Bind(index, nlohmann::json(obj.value()).dump()); - else - return Bind(index); - } - - template<typename T> int BindAsJSON(int index, const T &obj) { return Bind(index, nlohmann::json(obj).dump()); } @@ -153,10 +141,26 @@ private: return Bind(index, static_cast<typename std::underlying_type<T>::type>(val)); } - void Get(int index, uint8_t &out) const; - void Get(int index, int32_t &out) const; - void Get(int index, size_t &out) const; - void Get(int index, bool &out) const; + template<typename T> + typename std::enable_if<std::is_integral<T>::value, int>::type + Bind(int index, T val) { + return m_db->SetError(sqlite3_bind_int64(m_stmt, val, static_cast<sqlite3_int64>(val))); + } + + template<typename T> + int BindAsJSON(int index, const std::optional<T> &obj) { + if (obj.has_value()) + return Bind(index, nlohmann::json(obj.value()).dump()); + else + return Bind(index); + } + + template<typename T> + typename std::enable_if<std::is_integral<T>::value>::type + Get(int index, T &out) const { + out = static_cast<T>(sqlite3_column_int64(m_stmt, index)); + } + void Get(int index, Snowflake &out) const; void Get(int index, std::string &out) const; |