mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-27 16:16:35 +03:00
templatize some stuff
This commit is contained in:
+1
-33
@@ -2161,20 +2161,8 @@ bool Store::Statement::OK() const {
|
||||
return m_stmt != nullptr;
|
||||
}
|
||||
|
||||
int Store::Statement::Bind(int index, int32_t num) {
|
||||
return Bind(index, static_cast<uint32_t>(num));
|
||||
}
|
||||
|
||||
int Store::Statement::Bind(int index, uint32_t num) {
|
||||
return m_db->SetError(sqlite3_bind_int(m_stmt, index, num));
|
||||
}
|
||||
|
||||
int Store::Statement::Bind(int index, size_t num) {
|
||||
return m_db->SetError(sqlite3_bind_int64(m_stmt, index, num));
|
||||
}
|
||||
|
||||
int Store::Statement::Bind(int index, Snowflake id) {
|
||||
return m_db->SetError(sqlite3_bind_int64(m_stmt, index, static_cast<sqlite3_int64>(id)));
|
||||
return Bind(index, static_cast<uint64_t>(id));
|
||||
}
|
||||
|
||||
int Store::Statement::Bind(int index, const char *str, size_t len) {
|
||||
@@ -2186,30 +2174,10 @@ int Store::Statement::Bind(int index, const std::string &str) {
|
||||
return m_db->SetError(sqlite3_bind_blob(m_stmt, index, str.c_str(), str.size(), SQLITE_TRANSIENT));
|
||||
}
|
||||
|
||||
int Store::Statement::Bind(int index, bool val) {
|
||||
return m_db->SetError(sqlite3_bind_int(m_stmt, index, val ? 1L : 0L));
|
||||
}
|
||||
|
||||
int Store::Statement::Bind(int index) {
|
||||
return m_db->SetError(sqlite3_bind_null(m_stmt, index));
|
||||
}
|
||||
|
||||
void Store::Statement::Get(int index, uint8_t &out) const {
|
||||
out = sqlite3_column_int(m_stmt, index);
|
||||
}
|
||||
|
||||
void Store::Statement::Get(int index, int32_t &out) const {
|
||||
out = sqlite3_column_int(m_stmt, index);
|
||||
}
|
||||
|
||||
void Store::Statement::Get(int index, size_t &out) const {
|
||||
out = static_cast<size_t>(sqlite3_column_int64(m_stmt, index));
|
||||
}
|
||||
|
||||
void Store::Statement::Get(int index, bool &out) const {
|
||||
out = sqlite3_column_int(m_stmt, index) != 0;
|
||||
}
|
||||
|
||||
void Store::Statement::Get(int index, Snowflake &out) const {
|
||||
out = static_cast<uint64_t>(sqlite3_column_int64(m_stmt, index));
|
||||
}
|
||||
|
||||
+20
-16
@@ -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>
|
||||
@@ -134,14 +130,6 @@ private:
|
||||
return Bind(index, std::string("[]"));
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user