summaryrefslogtreecommitdiff
path: root/src/database/database.cpp
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2018-03-18 02:31:18 +0100
committerlouiz’ <louiz@louiz.org>2018-03-18 02:31:18 +0100
commit577984faf2befaa7f11a1e4a115dc8d80805fec7 (patch)
treedb65417e4dc37123841309f9c9ee8d375bf9e003 /src/database/database.cpp
parentad7aa5b7090f093a8a167a3fcb29c421881946f7 (diff)
downloadbiboumi-577984faf2befaa7f11a1e4a115dc8d80805fec7.tar.gz
biboumi-577984faf2befaa7f11a1e4a115dc8d80805fec7.tar.bz2
biboumi-577984faf2befaa7f11a1e4a115dc8d80805fec7.tar.xz
biboumi-577984faf2befaa7f11a1e4a115dc8d80805fec7.zip
Allow the execution of multiple commands after the IRC connection
fix #3275
Diffstat (limited to 'src/database/database.cpp')
-rw-r--r--src/database/database.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/database/database.cpp b/src/database/database.cpp
index d19ed7a..812d27c 100644
--- a/src/database/database.cpp
+++ b/src/database/database.cpp
@@ -21,6 +21,7 @@ Database::GlobalOptionsTable Database::global_options("globaloptions_");
Database::IrcServerOptionsTable Database::irc_server_options("ircserveroptions_");
Database::IrcChannelOptionsTable Database::irc_channel_options("ircchanneloptions_");
Database::RosterTable Database::roster("roster");
+Database::AfterConnectionCommandsTable Database::after_connection_commands("after_connection_commands_");
std::map<Database::CacheKey, Database::EncodingIn::real_type> Database::encoding_in_cache{};
Database::GlobalPersistent::GlobalPersistent():
@@ -53,6 +54,8 @@ void Database::open(const std::string& filename)
Database::irc_channel_options.upgrade(*Database::db);
Database::roster.create(*Database::db);
Database::roster.upgrade(*Database::db);
+ Database::after_connection_commands.create(*Database::db);
+ Database::after_connection_commands.upgrade(*Database::db);
create_index<Database::Owner, Database::IrcChanName, Database::IrcServerName>(*Database::db, "archive_index", Database::muc_log_lines.get_name());
}
@@ -88,6 +91,32 @@ Database::IrcServerOptions Database::get_irc_server_options(const std::string& o
return options;
}
+Database::AfterConnectionCommands Database::get_after_connection_commands(const IrcServerOptions& server_options)
+{
+ const auto id = server_options.col<Id>();
+ if (id == Id::unset_value)
+ return {};
+ auto request = Database::after_connection_commands.select();
+ request.where() << ForeignKey{} << "=" << id;
+ return request.execute(*Database::db);
+}
+
+void Database::set_after_connection_commands(const Database::IrcServerOptions& server_options, Database::AfterConnectionCommands& commands)
+{
+ const auto id = server_options.col<Id>();
+ if (id == Id::unset_value)
+ return ;
+ auto query = Database::after_connection_commands.del();
+ query.where() << ForeignKey{} << "=" << id;
+ query.execute(*Database::db);
+
+ for (auto& command: commands)
+ {
+ command.col<ForeignKey>() = server_options.col<Id>();
+ command.save(Database::db);
+ }
+}
+
Database::IrcChannelOptions Database::get_irc_channel_options(const std::string& owner, const std::string& server, const std::string& channel)
{
auto request = Database::irc_channel_options.select();