1
0
mirror of https://github.com/anope/anope.git synced 2026-07-07 05:53:13 +02:00

Automatically determine SQL column type from the field.

Also add more column types to ensure we are storing data in the
best format in the database.
This commit is contained in:
Sadie Powell
2024-08-14 02:40:48 +01:00
parent 03bee17063
commit 528b5938ec
36 changed files with 330 additions and 222 deletions
+8 -8
View File
@@ -160,14 +160,14 @@ NickCore *ChanAccess::GetAccount() const
void ChanAccess::Serialize(Serialize::Data &data) const
{
data["provider"] << this->provider->name;
data["ci"] << this->ci->name;
data["mask"] << this->Mask();
data["creator"] << this->creator;
data["description"] << this->description;
data.SetType("last_seen", Serialize::Data::DT_INT); data["last_seen"] << this->last_seen;
data.SetType("created", Serialize::Data::DT_INT); data["created"] << this->created;
data["data"] << this->AccessSerialize();
data.Store("provider", this->provider->name);
data.Store("ci", this->ci->name);
data.Store("mask", this->Mask());
data.Store("creator", this->creator);
data.Store("description", this->description);
data.Store("last_seen", this->last_seen);
data.Store("created", this->created);
data.Store("data", this->AccessSerialize());
}
Serializable *ChanAccess::Unserialize(Serializable *obj, Serialize::Data &data)
+6 -6
View File
@@ -75,12 +75,12 @@ BotInfo::~BotInfo()
void BotInfo::Serialize(Serialize::Data &data) const
{
data["nick"] << this->nick;
data["user"] << this->ident;
data["host"] << this->host;
data["realname"] << this->realname;
data["created"] << this->created;
data["oper_only"] << this->oper_only;
data.Store("nick", this->nick);
data.Store("user", this->ident);
data.Store("host", this->host);
data.Store("realname", this->realname);
data.Store("created", this->created);
data.Store("oper_only", this->oper_only);
Extensible::ExtensibleSerialize(this, this, data);
}
+6 -6
View File
@@ -36,12 +36,12 @@ Memo::~Memo()
void Memo::Serialize(Serialize::Data &data) const
{
data["owner"] << this->owner;
data.SetType("time", Serialize::Data::DT_INT); data["time"] << this->time;
data["sender"] << this->sender;
data["text"] << this->text;
data["unread"] << this->unread;
data["receipt"] << this->receipt;
data.Store("owner", this->owner);
data.Store("time", this->time);
data.Store("sender", this->sender);
data.Store("text", this->text);
data.Store("unread", this->unread);
data.Store("receipt", this->receipt);
}
Serializable *Memo::Unserialize(Serializable *obj, Serialize::Data &data)
+12 -12
View File
@@ -141,21 +141,21 @@ NickAlias *NickAlias::Find(const Anope::string &nick)
void NickAlias::Serialize(Serialize::Data &data) const
{
data["nick"] << this->nick;
data["last_quit"] << this->last_quit;
data["last_realname"] << this->last_realname;
data["last_usermask"] << this->last_usermask;
data["last_realhost"] << this->last_realhost;
data.SetType("time_registered", Serialize::Data::DT_INT); data["time_registered"] << this->time_registered;
data.SetType("last_seen", Serialize::Data::DT_INT); data["last_seen"] << this->last_seen;
data["nc"] << this->nc->display;
data.Store("nick", this->nick);
data.Store("last_quit", this->last_quit);
data.Store("last_realname", this->last_realname);
data.Store("last_usermask", this->last_usermask);
data.Store("last_realhost", this->last_realhost);
data.Store("time_registered", this->time_registered);
data.Store("last_seen", this->last_seen);
data.Store("nc", this->nc->display);
if (this->HasVHost())
{
data["vhost_ident"] << this->GetVHostIdent();
data["vhost_host"] << this->GetVHostHost();
data["vhost_creator"] << this->GetVHostCreator();
data["vhost_time"] << this->GetVHostCreated();
data.Store("vhost_ident", this->GetVHostIdent());
data.Store("vhost_host", this->GetVHostHost());
data.Store("vhost_creator", this->GetVHostCreator());
data.Store("vhost_time", this->GetVHostCreated());
}
Extensible::ExtensibleSerialize(this, this, data);
+12 -9
View File
@@ -68,17 +68,20 @@ NickCore::~NickCore()
void NickCore::Serialize(Serialize::Data &data) const
{
data["display"] << this->display;
data["uniqueid"] << this->id;
data["pass"] << this->pass;
data["email"] << this->email;
data["language"] << this->language;
data.SetType("lastmail", Serialize::Data::DT_INT); data["lastmail"] << this->lastmail;
data.SetType("time_registered", Serialize::Data::DT_INT); data["time_registered"] << this->time_registered;
data.Store("display", this->display);
data.Store("uniqueid", this->id);
data.Store("pass", this->pass);
data.Store("email", this->email);
data.Store("language", this->language);
data.Store("lastmail", this->lastmail);
data.Store("time_registered", this->time_registered);
data.Store("memomax", this->memos.memomax);
data["memomax"] << this->memos.memomax;
std::ostringstream oss;
for (const auto &ignore : this->memos.ignores)
data["memoignores"] << ignore << " ";
oss << ignore << " ";
data.Store("memoignores", oss.str());
Extensible::ExtensibleSerialize(this, this, data);
}
+25 -22
View File
@@ -40,15 +40,15 @@ AutoKick::~AutoKick()
void AutoKick::Serialize(Serialize::Data &data) const
{
data["ci"] << this->ci->name;
data.Store("ci", this->ci->name);
if (this->nc)
data["nc"] << this->nc->display;
data.Store("nc", this->nc->display);
else
data["mask"] << this->mask;
data["reason"] << this->reason;
data["creator"] << this->creator;
data.SetType("addtime", Serialize::Data::DT_INT); data["addtime"] << this->addtime;
data.SetType("last_used", Serialize::Data::DT_INT); data["last_used"] << this->last_used;
data.Store("mask", this->mask);
data.Store("reason", this->reason);
data.Store("creator", this->creator);
data.Store("addtime", this->addtime);
data.Store("last_used", this->last_used);
}
Serializable *AutoKick::Unserialize(Serializable *obj, Serialize::Data &data)
@@ -180,30 +180,33 @@ ChannelInfo::~ChannelInfo()
void ChannelInfo::Serialize(Serialize::Data &data) const
{
data["name"] << this->name;
data.Store("name", this->name);
if (this->founder)
data["founder"] << this->founder->display;
data.Store("founder", this->founder->display);
if (this->successor)
data["successor"] << this->successor->display;
data["description"] << this->desc;
data.SetType("time_registered", Serialize::Data::DT_INT); data["time_registered"] << this->time_registered;
data.SetType("last_used", Serialize::Data::DT_INT); data["last_used"] << this->last_used;
data["last_topic"] << this->last_topic;
data["last_topic_setter"] << this->last_topic_setter;
data.SetType("last_topic_time", Serialize::Data::DT_INT); data["last_topic_time"] << this->last_topic_time;
data.SetType("bantype", Serialize::Data::DT_INT); data["bantype"] << this->bantype;
data.Store("successor", this->successor->display);
data.Store("description", this->desc);
data.Store("time_registered", this->time_registered);
data.Store("last_used", this->last_used);
data.Store("last_topic", this->last_topic);
data.Store("last_topic_setter", this->last_topic_setter);
data.Store("last_topic_time", this->last_topic_time);
data.Store("bantype", this->bantype);
{
Anope::string levels_buffer;
for (const auto &[name, level] : this->levels)
levels_buffer += name + " " + Anope::ToString(level) + " ";
data["levels"] << levels_buffer;
data.Store("levels", levels_buffer);
}
if (this->bi)
data["bi"] << this->bi->nick;
data.SetType("banexpire", Serialize::Data::DT_INT); data["banexpire"] << this->banexpire;
data["memomax"] << this->memos.memomax;
data.Store("bi", this->bi->nick);
data.Store("banexpire", this->banexpire);
data.Store("memomax", this->memos.memomax);
std::ostringstream oss;
for (const auto &ignore : this->memos.ignores)
data["memoignores"] << ignore << " ";
oss << ignore << " ";
data.Store("memoignores", oss.str());
Extensible::ExtensibleSerialize(this, this, data);
}
+7 -7
View File
@@ -153,14 +153,14 @@ bool XLine::IsRegex() const
void XLine::Serialize(Serialize::Data &data) const
{
data["mask"] << this->mask;
data["by"] << this->by;
data["created"] << this->created;
data["expires"] << this->expires;
data["reason"] << this->reason;
data["uid"] << this->id;
data.Store("mask", this->mask);
data.Store("by", this->by);
data.Store("created", this->created);
data.Store("expires", this->expires);
data.Store("reason", this->reason);
data.Store("uid", this->id);
if (this->manager)
data["manager"] << this->manager->name;
data.Store("manager", this->manager->name);
}
Serializable *XLine::Unserialize(Serializable *obj, Serialize::Data &data)