Add a ChannelOptions table in the DB
And a way to retrieve its values, defaulting on the ServerOptions for unset values.
This commit is contained in:
@@ -49,6 +49,39 @@ db::IrcServerOptions Database::get_irc_server_options(const std::string& owner,
|
||||
}
|
||||
}
|
||||
|
||||
db::IrcChannelOptions Database::get_irc_channel_options(const std::string& owner,
|
||||
const std::string& server,
|
||||
const std::string& channel)
|
||||
{
|
||||
try {
|
||||
auto options = litesql::select<db::IrcChannelOptions>(Database::get_db(),
|
||||
db::IrcChannelOptions::Owner == owner &&
|
||||
db::IrcChannelOptions::Server == server &&
|
||||
db::IrcChannelOptions::Channel == channel).one();
|
||||
return options;
|
||||
} catch (const litesql::NotFound& e) {
|
||||
db::IrcChannelOptions options(Database::get_db());
|
||||
options.owner = owner;
|
||||
options.server = server;
|
||||
options.channel = channel;
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
||||
db::IrcChannelOptions Database::get_irc_channel_options_with_server_default(const std::string& owner,
|
||||
const std::string& server,
|
||||
const std::string& channel)
|
||||
{
|
||||
auto coptions = Database::get_irc_channel_options(owner, server, channel);
|
||||
auto soptions = Database::get_irc_server_options(owner, server);
|
||||
if (coptions.encodingIn.value().empty())
|
||||
coptions.encodingIn = soptions.encodingIn;
|
||||
if (coptions.encodingOut.value().empty())
|
||||
coptions.encodingOut = soptions.encodingOut;
|
||||
|
||||
return coptions;
|
||||
}
|
||||
|
||||
void Database::close()
|
||||
{
|
||||
Database::db.reset(nullptr);
|
||||
|
||||
Reference in New Issue
Block a user