#pragma once #include #ifdef USE_DATABASE #include #include #include #include #include #include class Database { public: using time_point = std::chrono::system_clock::time_point; struct Uuid: Column { static constexpr auto name = "uuid_"; static constexpr auto options = ""; }; struct Owner: Column { static constexpr auto name = "owner_"; static constexpr auto options = ""; }; struct IrcChanName: Column { static constexpr auto name = "ircChanName_"; static constexpr auto options = ""; }; struct Channel: Column { static constexpr auto name = "channel_"; static constexpr auto options = ""; }; struct IrcServerName: Column { static constexpr auto name = "ircServerName_"; static constexpr auto options = ""; }; struct Server: Column { static constexpr auto name = "server_"; static constexpr auto options = ""; }; struct Date: Column { static constexpr auto name = "date_"; static constexpr auto options = ""; }; struct Body: Column { static constexpr auto name = "body_"; static constexpr auto options = ""; }; struct Nick: Column { static constexpr auto name = "nick_"; static constexpr auto options = ""; }; struct Pass: Column { static constexpr auto name = "pass_"; static constexpr auto options = ""; }; struct Ports: Column { static constexpr auto name = "tlsPorts_"; static constexpr auto options = ""; }; struct TlsPorts: Column { static constexpr auto name = "ports_"; static constexpr auto options = ""; }; struct Username: Column { static constexpr auto name = "username_"; static constexpr auto options = ""; }; struct Realname: Column { static constexpr auto name = "realname_"; static constexpr auto options = ""; }; struct AfterConnectionCommand: Column { static constexpr auto name = "afterConnectionCommand_"; static constexpr auto options = ""; }; struct TrustedFingerprint: Column { static constexpr auto name = "trustedFingerprint_"; static constexpr auto options = ""; }; struct EncodingOut: Column { static constexpr auto name = "encodingOut_"; static constexpr auto options = ""; }; struct EncodingIn: Column { static constexpr auto name = "encodingIn_"; static constexpr auto options = ""; }; struct MaxHistoryLength: Column { static constexpr auto name = "maxHistoryLength_"; static constexpr auto options = ""; }; struct RecordHistory: Column { static constexpr auto name = "recordHistory_"; static constexpr auto options = ""; }; struct VerifyCert: Column { static constexpr auto name = "verifyCert_"; static constexpr auto options = ""; }; struct Persistent: Column { static constexpr auto name = "persistent_"; static constexpr auto options = ""; }; using MucLogLineTable = Table; using MucLogLine = MucLogLineTable::RowType; using GlobalOptionsTable = Table; using GlobalOptions = GlobalOptionsTable::RowType; using IrcServerOptionsTable = Table; using IrcServerOptions = IrcServerOptionsTable::RowType; using IrcChannelOptionsTable = Table; using IrcChannelOptions = IrcChannelOptionsTable::RowType; Database() = default; ~Database() = default; Database(const Database&) = delete; Database(Database&&) = delete; Database& operator=(const Database&) = delete; Database& operator=(Database&&) = delete; static GlobalOptions get_global_options(const std::string& owner); static IrcServerOptions get_irc_server_options(const std::string& owner, const std::string& server); static IrcChannelOptions get_irc_channel_options(const std::string& owner, const std::string& server, const std::string& channel); static IrcChannelOptions get_irc_channel_options_with_server_default(const std::string& owner, const std::string& server, const std::string& channel); static IrcChannelOptions get_irc_channel_options_with_server_and_global_default(const std::string& owner, const std::string& server, const std::string& channel); static std::vector get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server, int limit=-1, const std::string& start="", const std::string& end=""); static std::string store_muc_message(const std::string& owner, const std::string& chan_name, const std::string& server_name, time_point date, const std::string& body, const std::string& nick); static void close(); static void open(const std::string& filename); template static std::size_t count(const TableType& table) { CountQuery query{table.get_name()}; return query.execute(Database::db); } static MucLogLineTable muc_log_lines; static GlobalOptionsTable global_options; static IrcServerOptionsTable irc_server_options; static IrcChannelOptionsTable irc_channel_options; static sqlite3* db; private: static std::string gen_uuid(); }; #endif /* USE_DATABASE */