summaryrefslogtreecommitdiff
path: root/src/database
diff options
context:
space:
mode:
Diffstat (limited to 'src/database')
-rw-r--r--src/database/column.hpp16
-rw-r--r--src/database/database.hpp10
-rw-r--r--src/database/row.hpp21
3 files changed, 37 insertions, 10 deletions
diff --git a/src/database/column.hpp b/src/database/column.hpp
index 50c9c14..837aa3f 100644
--- a/src/database/column.hpp
+++ b/src/database/column.hpp
@@ -9,18 +9,30 @@ struct Column
value{default_value} {}
Column():
value{} {}
+ void clear()
+ {
+ this->value = {};
+ }
using real_type = T;
T value{};
};
+template <typename T>
+struct UnclearableColumn: public Column<T>
+{
+ using Column<T>::Column;
+ void clear()
+ { }
+};
+
struct ForeignKey: Column<std::size_t> {
static constexpr auto name = "fk_";
};
-struct Id: Column<std::size_t> {
+struct Id: UnclearableColumn<std::size_t> {
static constexpr std::size_t unset_value = static_cast<std::size_t>(-1);
static constexpr auto name = "id_";
static constexpr auto options = "PRIMARY KEY";
- Id(): Column<std::size_t>(unset_value) {}
+ Id(): UnclearableColumn<std::size_t>(unset_value) {}
};
diff --git a/src/database/database.hpp b/src/database/database.hpp
index d986ecc..30ffcb4 100644
--- a/src/database/database.hpp
+++ b/src/database/database.hpp
@@ -27,15 +27,15 @@ class Database
struct Uuid: Column<std::string> { static constexpr auto name = "uuid_"; };
- struct Owner: Column<std::string> { static constexpr auto name = "owner_"; };
+ struct Owner: UnclearableColumn<std::string> { static constexpr auto name = "owner_"; };
- struct IrcChanName: Column<std::string> { static constexpr auto name = "ircchanname_"; };
+ struct IrcChanName: UnclearableColumn<std::string> { static constexpr auto name = "ircchanname_"; };
- struct Channel: Column<std::string> { static constexpr auto name = "channel_"; };
+ struct Channel: UnclearableColumn<std::string> { static constexpr auto name = "channel_"; };
- struct IrcServerName: Column<std::string> { static constexpr auto name = "ircservername_"; };
+ struct IrcServerName: UnclearableColumn<std::string> { static constexpr auto name = "ircservername_"; };
- struct Server: Column<std::string> { static constexpr auto name = "server_"; };
+ struct Server: UnclearableColumn<std::string> { static constexpr auto name = "server_"; };
struct Date: Column<time_point::rep> { static constexpr auto name = "date_"; };
diff --git a/src/database/row.hpp b/src/database/row.hpp
index 27caf43..1253f93 100644
--- a/src/database/row.hpp
+++ b/src/database/row.hpp
@@ -1,7 +1,5 @@
#pragma once
-#include <utils/is_one_of.hpp>
-
#include <type_traits>
template <typename... T>
@@ -25,7 +23,24 @@ struct Row
return col.value;
}
-public:
+ void clear()
+ {
+ this->clear_col<0>();
+ }
+
std::tuple<T...> columns;
std::string table_name;
+
+private:
+ template <std::size_t N>
+ typename std::enable_if<N < sizeof...(T), void>::type
+ clear_col()
+ {
+ std::get<N>(this->columns).clear();
+ this->clear_col<N+1>();
+ }
+ template <std::size_t N>
+ typename std::enable_if<N == sizeof...(T), void>::type
+ clear_col()
+ { }
};