lovely servers
parent
802962a2fa
commit
0de6e2a439
|
@ -97,6 +97,23 @@ namespace db
|
||||||
std::string content;
|
std::string content;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto make_server_info_table()
|
||||||
|
{
|
||||||
|
using namespace sqlite_orm;
|
||||||
|
return make_table("server_info",
|
||||||
|
make_column("member_count", &server_info_t::member_count),
|
||||||
|
make_column("name", &server_info_t::name),
|
||||||
|
make_column("description", &server_info_t::description),
|
||||||
|
make_column("icon", &server_info_t::icon),
|
||||||
|
make_column("splash", &server_info_t::splash),
|
||||||
|
make_column("discovery_splash", &server_info_t::discovery_splash),
|
||||||
|
make_column("banner", &server_info_t::banner),
|
||||||
|
primary_key(&server_info_t::member_count, &server_info_t::name, &server_info_t::description, &server_info_t::icon,
|
||||||
|
&server_info_t::splash, &server_info_t::discovery_splash, &server_info_t::banner));
|
||||||
|
}
|
||||||
|
|
||||||
|
using server_info_table_t = decltype(make_server_info_table());
|
||||||
|
|
||||||
auto make_user_table()
|
auto make_user_table()
|
||||||
{
|
{
|
||||||
using namespace sqlite_orm;
|
using namespace sqlite_orm;
|
||||||
|
@ -208,7 +225,8 @@ namespace db
|
||||||
{
|
{
|
||||||
using namespace sqlite_orm;
|
using namespace sqlite_orm;
|
||||||
return make_storage(std::move(path), make_user_table(), make_user_history_table(), make_channel_table(), make_channel_history_table(),
|
return make_storage(std::move(path), make_user_table(), make_user_history_table(), make_channel_table(), make_channel_history_table(),
|
||||||
make_message_table(), make_attachment_table(), make_message_edits_table(), make_message_deletes_table());
|
make_message_table(), make_attachment_table(), make_message_edits_table(), make_message_deletes_table(),
|
||||||
|
make_server_info_table());
|
||||||
}
|
}
|
||||||
|
|
||||||
using database_type = decltype(make_database(""));
|
using database_type = decltype(make_database(""));
|
||||||
|
|
21
src/main.cpp
21
src/main.cpp
|
@ -103,7 +103,8 @@ struct db_obj
|
||||||
|
|
||||||
void commit(const user_info_t& edited)
|
void commit(const user_info_t& edited)
|
||||||
{
|
{
|
||||||
auto existing_user = db.select(sql::object<user_info_t>(), sql::where(sql::c(&user_info_t::userID) == edited.userID));
|
auto existing_user = db.select(sql::object<user_info_t>(), sql::from<user_info_t>(),
|
||||||
|
sql::where(sql::c(&user_info_t::userID) == edited.userID));
|
||||||
|
|
||||||
if (!existing_user.empty())
|
if (!existing_user.empty())
|
||||||
{
|
{
|
||||||
|
@ -149,17 +150,27 @@ struct db_obj
|
||||||
|
|
||||||
void commit(const message_edits_t& edited)
|
void commit(const message_edits_t& edited)
|
||||||
{
|
{
|
||||||
|
db.insert(edited);
|
||||||
}
|
}
|
||||||
|
|
||||||
void commit(const message_deletes_t& deleted)
|
void commit(const message_deletes_t& deleted)
|
||||||
{
|
{
|
||||||
|
db.insert(deleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void commit(const server_info_t& deleted)
|
void commit(const server_info_t& server)
|
||||||
{
|
{
|
||||||
|
using namespace sql;
|
||||||
|
auto data = db.select(columns(&server_info_t::name), from<server_info_t>(),
|
||||||
|
where((c(&server_info_t::member_count) == server.member_count) &&
|
||||||
|
(c(&server_info_t::name) == server.name) &&
|
||||||
|
(c(&server_info_t::description) == server.description) &&
|
||||||
|
(c(&server_info_t::icon) == server.icon) &&
|
||||||
|
(c(&server_info_t::splash) == server.splash) &&
|
||||||
|
(c(&server_info_t::discovery_splash) == server.discovery_splash) &&
|
||||||
|
(c(&server_info_t::banner) == server.banner)));
|
||||||
|
if (data.empty())
|
||||||
|
db.insert(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_queue(dpp::cluster& bot)
|
void process_queue(dpp::cluster& bot)
|
||||||
|
|
Loading…
Reference in New Issue