refactor: add SqlKata for SQL generation, move connection handling into ModelRepository

This commit is contained in:
spiral
2021-09-29 21:51:38 -04:00
parent 6251d29abb
commit 92e45a07ff
60 changed files with 806 additions and 640 deletions

View File

@@ -1,10 +1,13 @@
using SqlKata;
namespace PluralKit.Core
{
public class AccountPatch: PatchObject
{
public Partial<bool> AllowAutoproxy { get; set; }
public override UpdateQueryBuilder Apply(UpdateQueryBuilder b) => b
.With("allow_autoproxy", AllowAutoproxy);
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
.With("allow_autoproxy", AllowAutoproxy)
);
}
}

View File

@@ -3,6 +3,8 @@ using System.Text.RegularExpressions;
using Newtonsoft.Json.Linq;
using SqlKata;
namespace PluralKit.Core
{
public class GroupPatch: PatchObject
@@ -20,7 +22,7 @@ namespace PluralKit.Core
public Partial<PrivacyLevel> ListPrivacy { get; set; }
public Partial<PrivacyLevel> Visibility { get; set; }
public override UpdateQueryBuilder Apply(UpdateQueryBuilder b) => b
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
.With("name", Name)
.With("hid", Hid)
.With("display_name", DisplayName)
@@ -31,7 +33,8 @@ namespace PluralKit.Core
.With("description_privacy", DescriptionPrivacy)
.With("icon_privacy", IconPrivacy)
.With("list_privacy", ListPrivacy)
.With("visibility", Visibility);
.With("visibility", Visibility)
);
public new void AssertIsValid()
{

View File

@@ -1,3 +1,5 @@
using SqlKata;
namespace PluralKit.Core
{
public class GuildPatch: PatchObject
@@ -7,10 +9,11 @@ namespace PluralKit.Core
public Partial<ulong[]> Blacklist { get; set; }
public Partial<bool> LogCleanupEnabled { get; set; }
public override UpdateQueryBuilder Apply(UpdateQueryBuilder b) => b
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
.With("log_channel", LogChannel)
.With("log_blacklist", LogBlacklist)
.With("blacklist", Blacklist)
.With("log_cleanup_enabled", LogCleanupEnabled);
.With("log_cleanup_enabled", LogCleanupEnabled)
);
}
}

View File

@@ -1,4 +1,7 @@
#nullable enable
using SqlKata;
namespace PluralKit.Core
{
public class MemberGuildPatch: PatchObject
@@ -6,8 +9,9 @@ namespace PluralKit.Core
public Partial<string?> DisplayName { get; set; }
public Partial<string?> AvatarUrl { get; set; }
public override UpdateQueryBuilder Apply(UpdateQueryBuilder b) => b
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
.With("display_name", DisplayName)
.With("avatar_url", AvatarUrl);
.With("avatar_url", AvatarUrl)
);
}
}

View File

@@ -6,6 +6,8 @@ using NodaTime;
using Newtonsoft.Json.Linq;
using SqlKata;
namespace PluralKit.Core
{
public class MemberPatch: PatchObject
@@ -31,7 +33,7 @@ namespace PluralKit.Core
public Partial<PrivacyLevel> AvatarPrivacy { get; set; }
public Partial<PrivacyLevel> MetadataPrivacy { get; set; }
public override UpdateQueryBuilder Apply(UpdateQueryBuilder b) => b
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
.With("name", Name)
.With("hid", Hid)
.With("display_name", DisplayName)
@@ -51,7 +53,8 @@ namespace PluralKit.Core
.With("pronoun_privacy", PronounPrivacy)
.With("birthday_privacy", BirthdayPrivacy)
.With("avatar_privacy", AvatarPrivacy)
.With("metadata_privacy", MetadataPrivacy);
.With("metadata_privacy", MetadataPrivacy)
);
public new void AssertIsValid()
{

View File

@@ -1,11 +1,13 @@
using System;
using System.Text.RegularExpressions;
using SqlKata;
namespace PluralKit.Core
{
public abstract class PatchObject
{
public abstract UpdateQueryBuilder Apply(UpdateQueryBuilder b);
public abstract Query Apply(Query q);
public void AssertIsValid() { }

View File

@@ -1,4 +1,7 @@
#nullable enable
using SqlKata;
namespace PluralKit.Core
{
public class SystemGuildPatch: PatchObject
@@ -9,11 +12,12 @@ namespace PluralKit.Core
public Partial<string?> Tag { get; set; }
public Partial<bool?> TagEnabled { get; set; }
public override UpdateQueryBuilder Apply(UpdateQueryBuilder b) => b
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
.With("proxy_enabled", ProxyEnabled)
.With("autoproxy_mode", AutoproxyMode)
.With("autoproxy_member", AutoproxyMember)
.With("tag", Tag)
.With("tag_enabled", TagEnabled);
.With("tag_enabled", TagEnabled)
);
}
}

View File

@@ -6,6 +6,8 @@ using Newtonsoft.Json.Linq;
using NodaTime;
using SqlKata;
namespace PluralKit.Core
{
public class SystemPatch: PatchObject
@@ -29,7 +31,7 @@ namespace PluralKit.Core
public Partial<int?> MemberLimitOverride { get; set; }
public Partial<int?> GroupLimitOverride { get; set; }
public override UpdateQueryBuilder Apply(UpdateQueryBuilder b) => b
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
.With("name", Name)
.With("hid", Hid)
.With("description", Description)
@@ -47,7 +49,8 @@ namespace PluralKit.Core
.With("pings_enabled", PingsEnabled)
.With("latch_timeout", LatchTimeout)
.With("member_limit_override", MemberLimitOverride)
.With("group_limit_override", GroupLimitOverride);
.With("group_limit_override", GroupLimitOverride)
);
public new void AssertIsValid()
{